Page 1 of 1

Alert if a Service IS running

Posted: Wed Sep 09, 2015 6:59 am
by neworderfac33
Good afternoon,
I created a command in commands.cfg

Code: Select all

define command {
        command_name    negatepr
        command_line    $USER1$/negate $USER1$/$ARG1$
}
to allow Nagios to generate an alert if a particular application WAS running, rather than if it wasn't:

Code: Select all

#define service{
#        use                      generic-service
#        hostgroup_name           jenkins-test-masters,jenkins-slaves
#       service_description      Alert if running - Notepad
#       check_command            negatepr!check_nt -H $HOSTADDRESS$ -p 12489 -v PROCSTATE -d SHOWALL -l notepad.exe
#        }
and this runs fine. Now I want to extend this functionality to alert when a SERVICE is running, but when I use this:

Code: Select all

define service{
        use                     generic-service
        hostgroup_name          jenkins-test-masters
        service_description     Service active - Tomcat7
        check_command           negatepr!check_nt -H $HOSTADDRESS$ -p 12489 - v SERVICESTATE -d SHOWALL -l Tomcat7
        }
the browser returns "check_nt: Could not parse arguments "

Do I need to create a different negate command that will work with services, rather than applications?

[EDIT] - another typo - I had a space between the "-" and the "v" above, although it's not easy to spot. Removed it, restarted and all is fine!

Pete

Re: Alert if a Service IS running

Posted: Wed Sep 09, 2015 9:16 am
by hsmith
peterooney wrote:Good afternoon,
I created a command in commands.cfg

Code: Select all

define command {
        command_name    negatepr
        command_line    $USER1$/negate $USER1$/$ARG1$
}
to allow Nagios to generate an alert if a particular application WAS running, rather than if it wasn't:

Code: Select all

#define service{
#        use                      generic-service
#        hostgroup_name           jenkins-test-masters,jenkins-slaves
#       service_description      Alert if running - Notepad
#       check_command            negatepr!check_nt -H $HOSTADDRESS$ -p 12489 -v PROCSTATE -d SHOWALL -l notepad.exe
#        }
and this runs fine. Now I want to extend this functionality to alert when a SERVICE is running, but when I use this:

Code: Select all

define service{
        use                     generic-service
        hostgroup_name          jenkins-test-masters
        service_description     Service active - Tomcat7
        check_command           negatepr!check_nt -H $HOSTADDRESS$ -p 12489 - v SERVICESTATE -d SHOWALL -l Tomcat7
        }
the browser returns "check_nt: Could not parse arguments "

Do I need to create a different negate command that will work with services, rather than applications?

[EDIT] - another typo - I had a space between the "-" and the "v" above, although it's not easy to spot. Removed it, restarted and all is fine!

Pete
Ooops. I assume you want me to close this one? :lol:

Re: Alert if a Service IS running

Posted: Wed Sep 09, 2015 9:33 am
by neworderfac33
Incidentally, it DOES work if you set up a dedicated command on commands.cfg

Code: Select all

define service{
        use                     generic-service
        hostgroup_name          jenkins-test-masters
        service_description     Service active - Tomcat7
        check_command           TomcatServiceRunning
        }
used in conjunction with:

Code: Select all

define command {
        command_name    TomcatServiceRunning
        command_line    $USER1$/negate $USER1$/check_nt -H $HOSTADDRESS$ -p 12489 -v SERVICESTATE -d SHOWALL -l Tomcat7
}
just in case anyone wants to know how to set up a command relating to a specific service.

Cheers

Pete

Re: Alert if a Service IS running

Posted: Wed Sep 09, 2015 9:34 am
by neworderfac33
And yes, please - this can be closed - titter ye not! :oops: