How to Deal with Special Symbol in Nagios Service Parameter

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
Jun2013
Posts: 2
Joined: Tue Sep 03, 2013 1:46 am

How to Deal with Special Symbol in Nagios Service Parameter

Post 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
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

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

Post 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?
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
Jun2013
Posts: 2
Joined: Tue Sep 03, 2013 1:46 am

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

Post 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.
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

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

Post 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!
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
Locked