Open for Voting

Standardisation of Variables Across All Products

Hello,

This is something that has caught me out quite a few times.  For example sometimes NodeName will be ${NodeName} then othertimes it will be ${Node.NodeName} etc.  It would be nice to have these standardised across all products and also available for use in scripts and other templates (eg Powershell only supports ${IP} and ${CREDENTIAL})

I was wanting to pass ${Community} ${AgentPort} among others for creating a Powershell OID monitor to translate textual values to numerical so that Warning/Critical alerts can be setup based on numerical value.

Thanks,

Peter

Parents Comment Children
  • The following additional macros are now available in the SAM 6.0 RC (available now)

    • ${USER}
    • ${PASSWORD}
    • ${PORT}
    • ${Node.SysName}
    • ${Node.Caption}
    • ${Node.DNS}
    • ${Node.ID}
    • ${Component.ID}
    • ${Component.Name}
    • ${Application.Id}
    • ${Application.Name}
    • ${Application.TemplateId
    • ${Threshold.Warning}
    • ${Threshold.Critical}
    • Node Custom Property Macros ${Node.CustomPropertyName}
    • Application Custom Property Macros ${Application.CustomPropertyName}
  • FWIW .. I just tested these macros .. ${USER} works and ${IP} always worked .. however ${PASSWORD} clearly does NOT work at

    I can code other ways around this not working .. however I think the documentation should be fixed to reflect this .. BTW I tested on SAM 6.22

  • To further build on this ... the original request/post was to get the community string for a device .. and that's exactly what I needed also.

    Using the ${Node.ID} .. and the Orion Powershell SDK.. you can get the community string .. here's the code for my SAM Powershell template .. (BTW I put username/pass in CSV file)

    Add-PSSnapin SwisSnapin
    
    $credFile = Import-Csv "SwisAPI.csv"
    
    $swis = Connect-Swis -host usatl-s-solwdb1 -UserName $credFile.Username -Password $credFile.Password
    
    $curNode = Get-SwisObject $swis -Uri "swis://localhost/Orion/Orion.Nodes/NodeID=${Node.ID}"
    
    $perlCommand = "/bin/perl netapp-scripts/checkNetAppFiler.pl " + $curNode.Community + " ${IP}"
    
    c:\cygwin64\bin\bash.exe -lc "$perlCommand"
    

    The

    $curNode.Community

    is the Community string configured for the device.

  • FormerMember
    FormerMember in reply to gtalton

    gtalton,

    I ran into this issue just recently and I needed to pass creds to Powershell in order to interact with our own product's API. Then I finally found that the PowerShell Monitor only really provides the ${CREDENTIAL} object to be used with the PowerShell "Get-Credential" cmdlet. If your use-case will allow you to pass the -credential, then you can simply enter the command like this: -credential ${CREDENTIAL}   If you do this, whatever credential you selected for the component, will get passed through.

    However, in my case, our API would only allow user, domain & password to be passed in individual variables within the API call.  So, after a little digging on thwack, I found this function that engineering provided that allowed me to get the secure password out of the credential object.  This is an example of the code I used to extract the user, domain & password.  It also contains the parsing to separate the domain from the username if they exist in the credential:

    ---------------------------------------------------------

    #Solarwinds Function to Get-Credential from Powershell and extract the password securely.

    Function SecureStringToString($value)

    {

        [System.IntPtr] $bstr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($value);

        try

        {

            [System.Runtime.InteropServices.Marshal]::PtrToStringBSTR($bstr);

        }

        finally

        {

            [System.Runtime.InteropServices.Marshal]::FreeBSTR($bstr);

        }

    };

    #Username and Password Extraction

    $c = Get-Credential -credential ${CREDENTIAL};  #The ${CREDENTIAL} object is credentials passed from Solarwinds in the form of a PowerShell Get-Credential Object.

    [string] $username = $c.Username;

    [string] $password = SecureStringToString $c.Password; #Leverages the Solarwinds provided function "SecureStringToString" to parse our the password from the Get-Credential Object.

    #Extract Username and Domain from combined windows credential.

    if ($username -like "*\*") { # This if statement checks the $username variable for a backslash, if it exists parses the domain from the username into two separate variables.

    $domain = $username -replace "\\.*","";

    $user = $username -replace ".*\\","";

    }

    elseif ($username -like "*@*") { # This if statement checks the $username variable for an @ symbol, if it exists parses the domain from the username into two separate variables.

    $domain = $username -replace ".*@","";

    $user = $username -replace "@.*","";

    }

    else

    { # If neither of the two above are true, domain is set to null and $user is assigned $username.

    $domain = "";

    $user = $username;

    }

    # Set Connection Credentials

    $vltConn.userName = $user;

    $vltConn.Domain = $domain;

    $vltConn.Password = $password;

    ----------------------------------------------------------

    Hope this helps!