Page 1 of 1

Event handler – win service restart

Posted: Mon Jan 02, 2017 5:20 am
by cabryk
Hello i have a little problem with understandig this handler:
This is OK

Code: Select all

/usr/local/nagios/libexec/restart_service.sh CRITICAL 172.17.54.10 autoRest.exe
But this is not

Commands.cfg

Code: Select all

define command{
        command_name    resetujSluzbu
        command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -p 5666 -c restart_service -a GSSAUT01.exe
        }
Windows.cfg

Code: Select all

define service{
        use generic-service
        host_name winserver
        service_description sollIT
        check_command check_nt!SERVICESTATE!-d SHOWALL -l GSSAUT01.exe
        event_handler resetujSluzbu
        }
Restart_service.sh

Code: Select all

#!/bin/sh
case "$1" in
OK)
;;
WARNING)
;;
UNKNOWN)
;;
CRITICAL)
/usr/local/nagios/libexec/check_nrpe -H "$2" -p 5666 -c restart_service -a "$3"
;;
esac
exit 0
restart_service.bat

Code: Select all

@echo off
net stop %1
net start %1
echo.>"C:\nagios\log\test.txt"
@exit 0
When i using /usr/local/nagios/libexec/restart_service.sh CRITICAL 172.17.54.10 autoRest.exe
I´ve got test file in nagios/log
It must be something easy, but i can´t find it.

Thanks for the reply

Re: Event handler – win service restart

Posted: Tue Jan 03, 2017 10:12 am
by cabryk
Updated with event_handelr_enabled 1

Code: Select all


    define service{
            use generic-service
            host_name winserver
            service_description sollIT
            check_command check_nt!SERVICESTATE!-d SHOWALL -l GSSAUT01.exe
            event_handler resetujSluzbu
event_handelr_enabled 1
            }

Re: Event handler – win service restart

Posted: Tue Jan 03, 2017 11:15 am
by rkennedy
Please show us how you have defined restart_service in your NRPE / NSClient++ configuration if you're attempting some sort of remote restart.

This doc outlines exactly what needs to be done - https://assets.nagios.com/downloads/nag ... ios-XI.pdf

If you're just trying to run it from the Nagios command, then all you need to do is modify the command defined here -

Code: Select all

define command{
        command_name    resetujSluzbu
        command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -p 5666 -c restart_service -a GSSAUT01.exe
        }
The restart_service.sh is already calling to NRPE, you just need to define it as mentioned in teh doc above -

Code: Select all

$USER1$/restart_serice.sh $SERVICESTATE$ $HOSTADDRESS$ $_SERVICESERVICE$

Re: Event handler – win service restart

Posted: Tue Jan 10, 2017 1:36 am
by cabryk

Code: Select all

event_handelr_enabled 1
and restart nagios
This is a problem. I´m forgot it.

Re: Event handler – win service restart

Posted: Tue Jan 10, 2017 9:54 am
by rkennedy
cabryk wrote:

Code: Select all

event_handelr_enabled 1
and restart nagios
This is a problem. I´m forgot it.
Could you please clarify? To add to this - it looks like you spelt handler wrong which will affect Nagios.