Skip to content →

Configuring your Personal NMAgent Session Store

OrganizingSessionsToday I would like to explain a little bit what Session Stores are for the NMAgent and, therefore, what a Personal Session Store is. A Session Store is a database table that holds the information from your Agent Sessions when you have tell him to do so. Every run command invocation fires a new Agent Session and you have the option to persist the results in a database if you issue the -save parameter as well on the CLI.

Since version 4.54b0 you can choose your Session Store and define its name on your Profile Settings. Consequently, you will notice that several new parameters are present in all your settings-<ProfileName>.ps1 files. These are:

$AgentUserId           = 18              # My OpenSLIM Contact UserId
$AgentUserName         = 'cveira'        # A label to distinguish my Sessions
$AgentUserSessionStore = '_SessionStore' # The table to store my Sessions

These parameters become useful when you share your Session Database with one or more IT Teams. It is also handy when you schedule NMAgent sessions for regular execution and want to distinguish the automated sessions from your interactive ones.

The default Session Store is _SessionStore and this is the reason why all the predefined Profile Settings refer to it. In fact, if you enter the shell mode, you can see by yourself how it looks like:

PS C:\NMAgent> .\nmagent.ps1 shell

>> C:\NMAgent
>> NMAgent [1] # $SStoreDT | Get-Member

TypeName: System.Data.DataRow

Name                    MemberType            Definition
----                    ----------            ----------
AcceptChanges           Method                System.Void AcceptChanges()
BeginEdit               Method                System.Void BeginEdit()
CancelEdit              Method                System.Void CancelEdit()
ToString                Method                string ToString()
Item                    ParameterizedProperty System.Object Item(int columnIn..
AgentNodeName           Property              System.String AgentNodeName {ge..
AgentUserId             Property              System.Int32 AgentUserId {get;s..
AgentUserName           Property              System.String AgentUserName {ge..
ErrorFound              Property              System.Boolean ErrorFound {get;..
ErrorText               Property              System.String ErrorText {get;se..
NodeAttributeName       Property              System.String NodeAttributeName..
NodeExtendedAttributes  Property              System.String NodeExtendedAttri..
NodeIP                  Property              System.String NodeIP {get;set;}
NodeName                Property              System.String NodeName {get;set..
NodePropertyIsSupported Property              System.Boolean NodePropertyIsSu..
NodePropertyName        Property              System.String NodePropertyName ..
NodeQueryOutput         Property              System.String NodeQueryOutput {..
NodeValue               Property              System.String NodeValue {get;se..
NodeValue_Memo          Property              System.String NodeValue_Memo {g..
RecordDate              Property              System.DateTime RecordDate {get..
RecordId                Property              System.Int32 RecordId {get;set;..
SessionId               Property              System.String SessionId {get;se..

>> C:\NMAgent
>> NMAgent [1] #

As you may have guessed, the columns AgentUserId and AgentUserName directly map the contents of $AgentUserId and $AgentUserName respectively.

Ok, after this brief introduction, you just probably understand that, to define a different Session Store in your Profile Settings, it must previously exist. The question, is, then, how do we create new Session Stores? The answer is simple: the archive command.

To use the archive command you need you have an existing Session already stored. If that’s not the case, just set up a new session and run it with the –save parameter. This are the basic steps to do achieve it:

  1. Go to one the library (i.e: .\modules\openslim), choose one or more modules, copy and paste it/them on its _enabled folder (i.e: .\modules\openslim\_enabled).
  2. Choose a Target Computer and run an NMAgent session against it.
  3. Clean the _enabled folder after the execution (if you are not going to use them again…).

Following our example, this would be the command we should issue from the CLI:

PS C:\NMAgent> .\nmagent.ps1 run -profile openslim -node YourNodeName -save

If you already have some session information stored in the default Session Store, you can start by verifying that, in fact, that’s the case:

PS C:\NMAgent> .\nmagent.ps1 query

Now, we are ready to archive this data into a new off-line Session Store:

PS C:\NMAgent> .\nmagent.ps1 archive -store cveira

and verify that your new Session Store has been created correctly…

PS C:\NMAgent> .\nmagent.ps1 list -store none

… and that your information has also been archived:

PS C:\NMAgent> .\nmagent.ps1 query -store cveira

That’s it. Now you are ready to change the value for $AgentUserSessionStore in your profile settings files so that you can use the new Session Store as your primary Session Store. It is important to do it in all your settings-<ProfileName>.ps1 files.

$AgentUserSessionStore = 'cveira'

In any case, you should remember that settings-main.ps1 is the most important one as is the one that is use as the default profile.

You can make a quick test to see that everything is working fine:

PS C:\NMAgent> .\nmagent.ps1 query

Naturally, you can always access the old Session Store or any other one that shares the same NMAgent Session Database:

PS C:\NMAgent> .\nmagent.ps1 query -store _SessionStore

Why this matters

Now that you know how to organize your NMAgent Session Database you are ready to apply whatever criteria fits to your needs. As noted before, there are two big database sharing scenarios that make this feature useful:

  1. organize the activity of one or more IT Teams.
  2. isolate the activity or your automated/scheduled NMAgent sessions: baselining, auditing, etc.

Anyway, you can always share the same Session Store and use any of the available columns to filter the information you need. For example, remember that:

  • the value of the AgentUserName column gets populated with the contents of $AgentUserName.
  • the value of the AgentNodeName column gets populated with machine name where NMAgent has been executed.

This would be an example from the later strategy:

PS C:\NMAgent> .\nmagent.ps1 query -filter ";;;;;;;;;cveira"

As usual, I wish this information has been useful to explore the secrets hidden among your systems and infrastructures ;-). Have fun!


Creative Commons License
Except where otherwise noted, ThinkInBig by Carlos Veira Lorenzo is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Published in Automation Projects System Management