Page 4 of 5
Re: NRPE: Automatic restart of multiple services
Posted: Thu Jul 16, 2015 3:01 pm
by ssax
Ok, since you've changed the names on them, let's look at everything from the beginning, the permissions look good.
Your event handler command (restart_service_eh) should be exactly this based on your .sh script name:
Code: Select all
$USER1$/restart_service_script.sh $SERVICESTATE$ $HOSTADDRESS$ '$SERVICEOUTPUT$'
The rest of the settings look proper.
Is that how it is currently?
Are you including the spooler service in the check command, stopping the print spooler service, and then manually forcing an immediate check or doing it with a different service?
Did you revert the restart_service_script.sh code to the one that I posted?
Re: NRPE: Automatic restart of multiple services
Posted: Thu Jul 16, 2015 3:30 pm
by mhixson2
ssax wrote:Ok, since you've changed the names on them, let's look at everything from the beginning, the permissions look good.
Your event handler command (restart_service_eh) should be exactly this based on your .sh script name:
Code: Select all
$USER1$/restart_service_script.sh $SERVICESTATE$ $HOSTADDRESS$ '$SERVICEOUTPUT$'
Confirmed. It is that exactly.
ssax wrote:The rest of the settings look proper.
Is that how it is currently?
Yes, those are the current settings for the service and template.
ssax wrote:Are you including the spooler service in the check command, stopping the print spooler service, and then manually forcing an immediate check or doing it with a different service?
I'm using a different service for testing; mfcom. Spooler has a dependent relationship with the Citrix print service on this server, so to not complicate things I picked one that doesn't have that. The procedure you noted is what I'm doing.
ssax wrote:Did you revert the restart_service_script.sh code to the one that I posted?
I have not. It is still the most recent posted in the thread. Can you post what I should revert it to?
Edit: I found it. Here it is with the current batch file name.
I think it's working!! I'm testing a few scenarios. I'll report back shortly.
Code: Select all
#!/bin/sh
# Event Handler for Restarting Windows Services
case "$1" in
OK)
;;
WARNING)
;;
UNKNOWN)
;;
CRITICAL)
crittext='CRITICAL: '
autodeltext=' (auto), delayed ()'
autotext=' (auto)'
stoppedtext='=stopped'
stripped=${3//$crittext/}
stripped=${stripped//$autodeltext/}
stripped=${stripped//$autotext/}
stripped=${stripped//$stoppedtext/}
stripped=${stripped//, /,}
IFS=',' read -a array <<< "$stripped"
pattern='\ '
for ((i=0; i<${#array[@]}; i++));
do
if [[ ${array[$i]} =~ $pattern ]]; then
array[$i]="'${array[$i]}'"
fi
done
services=$(IFS=,; echo "${array[*]}")
/usr/local/nagios/libexec/check_nrpe -H "$2" -p 5666 -c restart_service_batch -a "$services"
;;
esac
exit 0
Re: NRPE: Automatic restart of multiple services
Posted: Thu Jul 16, 2015 3:56 pm
by ssax
Fingers crossed!

Re: NRPE: Automatic restart of multiple services
Posted: Thu Jul 16, 2015 4:02 pm
by mhixson2
Rats.. Still doesn't like that service with spaces in the name. Here's my service config. Any combination of a non-spacey named services restart automatically right away. The spacey named service by itself or with others keeps anything from happening.
Code: Select all
define service {
host_name [hostname]
service_description #TEST restart dead service
use #standard-service
check_command check_nrpe!check_service!service='Citrix Encryption Service' service=CitrixCseEngine service=IMAService service=MFCom service=cpsvc service=IMAAdvanceSrv service=RadeHlprSvc service=RadeSvc!'crit=not state_is_ok()'!!!!!
event_handler restart_service_eh
event_handler_enabled 1
register 1
}
Re: NRPE: Automatic restart of multiple services
Posted: Thu Jul 16, 2015 4:30 pm
by ssax
It works properly on my "NCPA Passive ncpapassive" service, restarts it just fine when I shut it down and check:
Code: Select all
define service {
host_name mytestbox
service_description Multi Service Event Handler
use xiwizard_windowsserver_nsclient_service,a_my_test_template
check_command check_nrpe!check_service!-a service=Spooler service=nxlog service='NCPA Passive ncpapassive' 'crit=not state_is_ok()'!!!!!!
event_handler service_restart
event_handler_enabled 1
notification_interval 60
notification_period xi_timeperiod_24x7
contacts nagiosadmin
_xiwizard windowsserver
register 1
}
What happens if you change your service to be:
$ARG1$
$ARG2$
Code: Select all
-a service='Citrix Encryption Service' service=CitrixCseEngine service=IMAService service=MFCom service=cpsvc service=IMAAdvanceSrv service=RadeHlprSvc service=RadeSvc 'crit=not state_is_ok()'
Then remove $ARG3$, save and apply config.
Re: NRPE: Automatic restart of multiple services
Posted: Thu Jul 16, 2015 4:33 pm
by ssax
Also, when you run it on the one with the spaces, what is the exact output shown in the XI interface, should say "CRITICAL - blah blah blah", let me see what that full output looks like.
Re: NRPE: Automatic restart of multiple services
Posted: Tue Jul 21, 2015 10:37 am
by mhixson2
Making the changes you noted to the service did not change the behavior.
Here is the Critical output: CRITICAL: Citrix Encryption Service=stopped (auto), delayed ()
I completely removed NSClient++ from the monitored host, reinstalled, and re-created the service in Nagios. Same result. Works on a service with no spaces, does nothing on the service with spaces.
Any other ideas?
Re: NRPE: Automatic restart of multiple services
Posted: Tue Jul 21, 2015 1:28 pm
by ssax
Edit your nsclient.ini and add/change these settings:
Code: Select all
; Configure log properties.
[/settings/log]
; LOG LEVEL - Log level to use. Available levels are error,warning,info,debug,trace
level = trace
Then restart the nsclient service, stop the one with a space in the name, and then run the check again in XI so the event handler fires then post the output similar to this:
Code: Select all
2015-07-21 13:25:57: debug:D:\source\nscp\modules\CheckExternalScripts\CheckExternalScripts.cpp:459: Command line: scripts\multi_service_restart.bat "'NCPA Passive ncpapassive'"
Re: NRPE: Automatic restart of multiple services
Posted: Wed Jul 22, 2015 8:25 am
by mhixson2
Interesting. A line like that is not being logged. Here is all I see when monitoring only the service with spaces:
Code: Select all
2015-07-22 09:16:24: debug:D:\source\nscp\include\nrpe/server/protocol.hpp:74: Accepting connection from: [Nagios IP], count=1
If I change the service to one without spaces, this is logged and the service restarts as expected:
Code: Select all
2015-07-22 09:22:33: debug:D:\source\nscp\modules\CheckExternalScripts\CheckExternalScripts.cpp:459: Command line: scripts\restart_service_batch.bat "mfcom"
Re: NRPE: Automatic restart of multiple services
Posted: Wed Jul 22, 2015 9:32 am
by lmiltchev
Let's make sure you implemented all of the changes as suggested by ssax. Show us the nsclient.ini and the *.bat file from the Windows box, and the command definition, service definition, and the bash script from the Nagios XI server in code wraps. Hide sensitive info.