NagiosXi - Action based on check

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
Bala.Mutyam
Posts: 97
Joined: Wed Apr 29, 2020 12:18 pm

NagiosXi - Action based on check

Post 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
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: NagiosXi - Action based on check

Post by ssax »

Yes it is, with event handlers and agents, see here:

https://assets.nagios.com/downloads/nag ... h-NCPA.pdf

And some other links for different agents here:

https://library.nagios.com/library/prod ... nagios-xi/

See here as well for the information on event handlers:

https://assets.nagios.com/downloads/nag ... ios-XI.pdf
Bala.Mutyam
Posts: 97
Joined: Wed Apr 29, 2020 12:18 pm

Re: NagiosXi - Action based on check

Post 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
}
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: NagiosXi - Action based on check

Post 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.
Bala.Mutyam
Posts: 97
Joined: Wed Apr 29, 2020 12:18 pm

Re: NagiosXi - Action based on check

Post 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.
benjaminsmith
Posts: 5324
Joined: Wed Aug 22, 2018 4:39 pm
Location: saint paul

Re: NagiosXi - Action based on check

Post 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.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!
Bala.Mutyam
Posts: 97
Joined: Wed Apr 29, 2020 12:18 pm

Re: NagiosXi - Action based on check

Post by Bala.Mutyam »

@benjaminsmith: Hi - Please close this thread.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: NagiosXi - Action based on check

Post by scottwilkerson »

Bala.Mutyam wrote:@benjaminsmith: Hi - Please close this thread.
Great!

Locking thread
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
Locked