Create a Windows Script monitor

The Windows Script monitor allows you to run custom scripts in SAM to monitor Windows-based computers. Before coding and testing a script, review Create custom Windows scripts and Best practices for SAM templates.

You can create a Windows Script monitor to have SAM run a script using Windows Script Host. Windows Script Host comes with VBScript and Jscript, but can be extended with other scripting languages.

Scripts run on the Orion server and use the credentials you specify. The script must both return an exit code and output a text string containing a statistic value conforming to the specifications described later in this section.

Format the Statistic value to use the same decimal separator as the Orion server. The Orion server uses the decimal separator set by its Microsoft Windows regional settings. You may need to log in with an administrator account to perform this action.

  1. Click Settings > All Settings > SAM Settings and click Manage Templates.

    The Manage Application Monitor Templates page opens. All available out-of-the-box and custom templates display.

  2. Search to locate, select, and edit an existing template or click Create New Template.

  3. Click Add Component Monitor(s) and choose Manually Add Component Monitors.
  4. Search for Windows Script. When displayed, select the Windows Script Monitor and click add.

  5. Enter Script Arguments to run for the script. Include the variables ${IP} (or ${Node.DNS}), ${USER}, and ${PASSWORD}, which are replaced with the IP address of the target node, the credential user name, and the credential password.
  6. Depending on the script type, the command line may require additional information and parameters such as the file path or hostname.

  7. Click Edit Script to enter and test the script.

  8. Test the script by selecting settings for the output, specified node, and specified credentials. Click Get Script Output.

    Output results display using the script code with success or failure and any additional notes.

  9. Click Get Script Output to generate the output and click Save.

    The metrics save to outputs to configure as part of the component monitor. These outputs display at polling intervals for the template.

  10. When complete, click Submit to save the template.

When tested, output generates into customizable sections. Each output section is named by the Unique ID with a Display Name you can edit.

For each output, you can optionally:

  • Convert the value using selected formulas.
  • Configure statistic thresholds to refine alerting for the component monitor. Set the warning and critical thresholds with specific values or baseline data.
  • Select a roll-up status sort option to display the best or worst status up through the template and component monitor.
  • Add notes to describe the script output.

Adapt an existing Visual Basic script to a Windows Script Monitor in a new template

  1. In the Orion Web Console, click Settings > SAM Settings > Create a New Template, then name the template.
  2. Click Add Component Monitor, then expand the Custom Component Monitors group, and then check Windows Script Monitor.
  3. Click Submit, and then select credentials with the appropriate permissions to run the script on the Orion server, and that also has appropriate permissions to do whatever else the script requires.
  4. Copy the Visual Basic script into the Script Body field.
  5. Type any script arguments into the Script Arguments field.
  6. Specify the critical and warning thresholds, then click Submit.

Macros for Script Arguments

Specify script arguments in the Script Arguments field if needed. You can use the following variables as script arguments:

${IP}

This is replaced with the target node’s IP Address.

${USER}

This is replaced with the user name from the credential set.

${PASSWORD}

This is replaced with the password from the credential set.

Script exit codes and text output

Scripts must report their status by exiting with the appropriate exit code, which is then used to report the status of the monitor in the Orion Web Console, as described in Report status through exit codes. For example, to inform SolarWinds SAM that a VBScript reports Up status, you would exit the script using code similar to the following, where 0 reports Up: Wscript.quit(0)

Scripts report additional details by sending text to the script’s standard output. See Scripts with text output for details.

Example scripts

Below is a sample vbscript that returns two values:

  • The total number of files in a folder
  • Twice the total number of files in the same folder

To use this script, copy and paste the following code into the Script Body field. In the Scripts Arguments field, type in C:\Windows, or any other folder you want to monitor.

Option Explicit
On Error Resume Next
Dim lstArgs, path, fso, objDir, objFiles, objFiles2
Set lstArgs = WScript.Arguments
If lstArgs.Count = 1 Then
path = Trim( lstArgs( 0 ))
Else
WScript.Echo "Message: Usage: wscript.exe filelist.vbs [pathToFiles]" &vbCRLF &"[pathToFiles] Local or UNC Path"
WScript.Echo "Statistic: 0"
WScript.Echo "Message: Usage: wscript.exe filelist.vbs [pathToFiles]" &vbCRLF &"[pathToFiles] Local or UNC Path"
WScript.Echo "Statistic: 0"
WScript.Quit( 1 )
End If
Set fso = Wscript.CreateObject( "Scripting.FileSystemObject" )
If fso.FolderExists( path ) Then
Set objDir = fso.GetFolder( path )
If( IsEmpty( objDir ) = True ) Then
WScript.Echo "Message: Object Not Initialized"
WScript.Echo "Statistic: 0" WScript.Quit( 1 )
End If
Set objFiles = objDir.Files
If( IsEmpty( objFiles ) = true) Then
WScript.Echo "Message: Object Not Initialized"
WScript.Echo "Statistic: 0"
WScript.Quit( 1 )
End If
WScript.Echo "Message.Total: " & CInt( objFiles.Count ) & " files in this folder."
WScript.Echo "Statistic.Total: " & CInt( objFiles.Count )
WScript.Echo "Message.Twice: " & CInt( objFiles.Count*2 ) & " = twice the number of files in this folder."
WScript.Echo "Statistic.Twice: " & CInt( objFiles.Count*2 )
WScript.Quit( 0 )
Else
WScript.Echo( "Message: Folder Not Found" )
WScript.Echo "Statistic: 0"
WScript.Quit( 1 )
End If

There are several examples of Windows Script component monitors included in templates, including:

  • File Count
  • File Modified
  • LDAP Connection Monitor
  • Run 3rd Party Application
  • Windows Event Log Count

Click here to learn more about individual component monitors.

Sample scripts are installed on your Orion server, in the folder: C:\Program Files\SolarWinds\Orion\APM\SampleScriptMonitors\WindowsScripts