How to escape the $ in NRPE service

Working with escaping $ in NRPE service arguments

If you are using WMI Proxy to check for a Microsoft Service running on a Host you can employ the check for the service that passes in the service name and possibly the user/password credentials. But if the service name on the Microsoft host has an embedded $ character this will not work unless you properly escape the $.

Example Scenario

In checking for MSSQLSERVER, Microsoft just said no such name. A quick run of PSTools psservice command revealed the services were running under a different set of names. These names had the form of MSSQL$EFGH. Putting this into the standard check with the Monarch configuration tool resulted in a status of Unknown - MSSQL: not installed. The key information is to use a \$$ to create something that Nagios (and NRPE_NT) will interpret as a single $ in the middle of some other text. If you don't do this, Nagios will interpret the $ and the trailing characters (and later $ characters) as some kind of outer space macro. You may be confused because the configuration Test feature will produce a working result without this sequence, yet paradoxically Nagios does not like the generated config files.

  • WMI Proxy IP address (first we'll just pass it as an argument):
    10.10.10.1
  • Microsoft service name:
    MSSQL$CVP1SQL
  • A basic Monarch configuration check command assumes the WMI Proxy account has rights to do the check.
  • Check command name:
    check_wmi_service
  • Command line:
    $USER1$/check_nrpe -H $ARG1$ -t 60 -c get_service -a "$HOSTADDRESS$" $ARG2$
  • Monarch service name command line:
    check_wmi_service_auth!10.10.10.1!MSSQL\$$CVP1SQL
  • Looking at the generated service.cfg and you see:
    check_command check_wmi_service_auth!10.21.130.80!MSSQL\$$CVP1SQL
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.