Event handler – win service restart

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
cabryk
Posts: 12
Joined: Fri Dec 30, 2016 8:45 am

Event handler – win service restart

Post 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
cabryk
Posts: 12
Joined: Fri Dec 30, 2016 8:45 am

Re: Event handler – win service restart

Post 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
            }
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Event handler – win service restart

Post 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$
Former Nagios Employee
cabryk
Posts: 12
Joined: Fri Dec 30, 2016 8:45 am

Re: Event handler – win service restart

Post by cabryk »

Code: Select all

event_handelr_enabled 1
and restart nagios
This is a problem. I´m forgot it.
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Event handler – win service restart

Post 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.
Former Nagios Employee
Locked