Page 1 of 1
NagiosXi - Action based on check
Posted: Thu Sep 03, 2020 7:56 am
by Bala.Mutyam
Hi,
Is it possible to configure Nagios Xi trigger an action based on service check status, like kill a process and then restart a service? If so, please send us instructions.
Thanks
Re: NagiosXi - Action based on check
Posted: Thu Sep 03, 2020 4:58 pm
by ssax
Re: NagiosXi - Action based on check
Posted: Mon Sep 07, 2020 7:10 am
by Bala.Mutyam
@ssax: Thanks for the info, i have setup an event handler to check file age and restart service based on age. The file age service check is critical but it's not triggering event handler.Testing from nagiosXi is ok. Can you please have a look?
Here are the details:
Restart Script:
Code: Select all
#/bin/sh
pkill ncpa_listener
sudo service ncpa_listener restart >> /dev/null
exit 0
Event handler script:
Code: Select all
#/bin/sh
case "$1" in
OK)
;;
WARNING)
;;
UNKNOWN)
;;
CRITICAL)
/usr/local/nagios/libexec/check_ncpa.py -H "$2" -P 5693 -t "$3" -M 'plugins/restart_service.sh'
;;
esac
exit 0
Event Handler:
Code: Select all
define command {
command_name Service Restart - NCPA
command_line $USER1$/restart_service.sh $SERVICESTATE$ $HOSTADDRESS$ token
}
service definition:
Code: Select all
define service {
host_name host_name
service_description Test File Check
check_command check_xi_ncpa!-t 'token' -P 5693 -M 'plugins/check_file_age' -q 'args=-f /tmp/test -w 598 -c 720'
max_check_attempts 5
check_interval 5
retry_interval 1
check_period 24x7
event_handler Service Restart - NCPA
event_handler_enabled 1
notification_interval 15
notification_period 24x7
notifications_enabled 1
contact_groups Linux-Alerts
register 1
}
Re: NagiosXi - Action based on check
Posted: Tue Sep 08, 2020 5:09 pm
by ssax
Given the checks will be run as the nagios user, please SSH into the remote NCPA system and run these commands:
Code: Select all
su - nagios
cd /usr/local/ncpa/plugins
./restart_service.sh
If that doesn't work without asking for a password it's likely a sudoers issue.
What are the permissions of the plugin on the NCPA host?
Code: Select all
ls -l /usr/local/ncpa/plugins/restart_service.sh
What are the permissions of the event handler script on the XI server?
Code: Select all
ls -l /usr/local/nagios/libexec/restart_service.sh
Make sure the state is changing (that's when even handlers run, on state changes), so submit an OK/UP first and then test.
Re: NagiosXi - Action based on check
Posted: Wed Sep 09, 2020 3:05 am
by Bala.Mutyam
@ssax : Hi, thanks for the update. It was all working except it didn't change state. I have changed the state of the alert and it's working fine.
Re: NagiosXi - Action based on check
Posted: Wed Sep 09, 2020 5:45 pm
by benjaminsmith
Hi,
@ssax : Hi, thanks for the update. It was all working except it didn't change state. I have changed the state of the alert and it's working fine.
Sounds you got working! Did you have any other questions or may we close this thread?
When you have a minute, please let us know.
Re: NagiosXi - Action based on check
Posted: Thu Sep 10, 2020 2:54 am
by Bala.Mutyam
@benjaminsmith: Hi - Please close this thread.
Re: NagiosXi - Action based on check
Posted: Thu Sep 10, 2020 6:48 am
by scottwilkerson
Bala.Mutyam wrote:@benjaminsmith: Hi - Please close this thread.
Great!
Locking thread