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

  • 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!

  • 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.

  • 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

  • I had this problem many times when trying to replicate resource filters between NPM and EOC views. As the variable names are different (and don't get me started about the lack of 'remember expanded state' options on key resources in EOC!) it meant that every change took twice as long to research and implement. +1 vote for this emoticons_happy.png

  • Complaint of the day: cannot use file age monitor on folder named 2014_04, because next month that will not be valid. Duh.

    So \\${IP}\share\${Year}_${MM} should work for \\10.0.0.1\share\2014_04