Page 1 of 1

How to Deal with Special Symbol in Nagios Service Parameter

Posted: Tue Sep 03, 2013 3:56 am
by Jun2013
Hi ,
In order to monitor windows service status, recently I added some monitors in my nagios application.
First I created a check command named check_win_service, the command use the check_nrpe script

Code: Select all

$USER1$/check_nrpe -H $HOSTADDRESS$ -c CheckServiceState -a ShowAll  $ARG1$
next I defined a service on every windows host, in these services I replace the variable $ARG1$ with the windows services I want to monitor, thus I didn't need to create multiple nagios services for every windows service, below is the example service list I used to replace $ARG1$:

Code: Select all

MSSQLServerOLAPService SQLSERVERAGENT MSSQL\\\$SQLEXPRESS MSSQLSERVER
If there is no symbol '$' in the service name, the check result would be successful

Code: Select all

Status Information:       OK: MSSQLServerOLAPService: started, SQLSERVERAGENT: started, MSSQLSERVER: started
If there is '$' in service name, such as a MS SQL service with an instance name, the check result would be failed

Code: Select all

Status Information:        CRITICAL: MSSQLServerOLAPService: started, SQLSERVERAGENT: started, MSSQL$SQLEXPRESS: started, MSSQLSERVER$: not found (critical)
I guess this may be caused by variable replacement, but I am not a programmer, I don't know how to read the code to find the issue point.

Please give me some ideas or suggestions, thanks in advance for your help.

Regards,
Jun

Re: How to Deal with Special Symbol in Nagios Service Parame

Posted: Tue Sep 03, 2013 10:45 am
by abrist
As '$' is reserved for the shell, you will have to escape it. Try the following method, or you may have to use the resources.cfg file for strings containing a '$'.
1. Try adding a second dollar sign to the check: MSSQL\\\$$SQLEXPRESS
2. Resources: http://nagios.sourceforge.net/docs/3_0/configmain.html

What is the output from the failing check exactly?

Re: How to Deal with Special Symbol in Nagios Service Parame

Posted: Tue Sep 03, 2013 11:50 pm
by Jun2013
abrist wrote: 1. Try adding a second dollar sign to the check: MSSQL\\\$$SQLEXPRESS
It works, after I added a second dollar sign, the check result is successful.

Code: Select all

OK	09-04-2013 12:38:26	 0d 2h 3m 58s	1/2	OK: MSSQLServerOLAPService: started, SQLSERVERAGENT: started, MSSQL$SQLEXPRESS: started, MSSQLSERVER: started 
Very appreciate for your help! I have spent several days on this problem and almost no progress no it.

Re: How to Deal with Special Symbol in Nagios Service Parame

Posted: Wed Sep 04, 2013 10:42 am
by abrist
No problem. Escaping is tricky. Escaping in nagios is *very* tricky due to the potential for parsing through multiple shells. Enjoy the week!