Hi Team,
I am trying to use Eventhandler functionality of Icinga2 but seems like something is going wrong and i am unable to get the desired result. If i execute the check manually by calling this script,it works as expected.
[root@or1icinga.connect plugins]# ./restart_win_service.sh CRITICAL host123 wuauserv
The Windows Update service is stopping.
The Windows Update service was stopped successfully.
The Windows Update service is starting.
The Windows Update service was started successfully.
I am sharing the details below:
1: I have a script “restart_win_service.sh” located under /usr/lib64/nagios/plugins
#!/bin/sh
case "$1" in
OK)
;;
WARNING)
;;
UNKNOWN)
;;
CRITICAL)
/usr/lib64/nagios/plugins/check_nrpe -H "$2" -p 5666 -c restart_service -a "$3"
;;
esac
exit 0
2: restart_service.bat exists on windows machine and corresponding entries are there in nsclient.ini
[/settings/external scripts/scripts]
restart_service = scripts\restart_service.bat "$ARG1$"
3: my commands.conf file looks like below:
object EventCommand "restart_win_service" {
command = [ PluginContribDir + "/restart_win_service.sh" ]
arguments = {
"-s" = "CRITICAL"
"-H" = "$rpc_host_address$"
"-n" = "$rpc_service_name$"
}
vars.rpc_host_address = "$hostname$"
vars.rpc_service_name = "$service_name$"
}
4: My services.conf file looks like below:
object Service "Restart_Splunkforwarder_Service" {
import "generic-service"
check_command = "check_servicestatus"
event_command = "restart_win_service"
vars.service_name = "splunkforwarder"
vars.rpc_host_address = "host123"
vars.hostname = "host123"
vars.rpc_service_name = "splunkforwarder"
host_name = "host123"
}
Now i stopped splunkforwarder service and waited for eventhandler to trigger but it doesn’t. I am sure i must be doing something wrong but not sure what. Can anyone please guide me? I also followed https://www.linuxfrickeln.de/2016/07/16/icinga2-eventcommands-und-automatisiertes-neustarten-von-diensten/ but still no luck.
If anyone has any simple example please share.
Thanks,
Rahul