Page 1 of 1

Nagios to kick off script

Posted: Mon Jul 08, 2019 2:22 am
by kodlan
Good morning,

I need some help and not sure if i can ask this here.

We are currently trialing Nagios and need some help.

I have 3 requests.

1. I need Nagios to kick off a local script on Nagios server, when a Warning or Critical was received, and pass some variables to this script. This is for telegram notifications. How do i go by doing this?

2. I need Nagios when it received an error that a service went down to kick off a remote script on monitored server to start service.

3. I want to know how to setup Nagios to do a "ps -ef |grep process name" and check if a service is up in that way.


Your help would really be appreciated.

Re: Nagios to kick off script

Posted: Mon Jul 08, 2019 11:23 am
by mcapra
kodlan wrote:1. I need Nagios to kick off a local script on Nagios server, when a Warning or Critical was received, and pass some variables to this script. This is for telegram notifications. How do i go by doing this?
Nagios has a concept of event handlers. And event handler could be something like firing off an email, restarting a service, or sending a telegram notification. All with some templating/macroing for information provided by Nagios XI. Here's the documentation for configuring global event handlers in Nagios XI:
https://assets.nagios.com/downloads/nag ... ios-XI.pdf

Let us know if something in that documentation isn't working, or is unclear.
kodlan wrote:2. I need Nagios when it received an error that a service went down to kick off a remote script on monitored server to start service.
Same deal as above; You're looking at scripting out some sort of custom event handler.
kodlan wrote:3. I want to know how to setup Nagios to do a "ps -ef |grep process name" and check if a service is up in that way.
Nagios plugins are relatively simple. All Nagios cares about is the exit code of the plugin/script, and the stdout of the script. Here are the plugin development guidelines:
http://nagios-plugins.org/doc/guidelines.html

The check_process.sh plugin already exists and does roughly the same thing with ps, except Unix processes are different from services under a particular Linux init system. There are a variety of other scripts that can check the status of a specific service under a specific init system.

Re: Nagios to kick off script

Posted: Tue Jul 09, 2019 2:20 am
by kodlan
Thank you very much for this information, I am currently working through the documentation.

I have immediately tried the Global Event Handlers out of pure excitement! :)

What I have done is Put a command line script into the "Service State Change Commands".

My Command is : /cdirect/scripts/telegram_service_notify.sh "$HOSTNAME$" "%hoststate%"

I have tried passing the variables/macros in 2 ways which is not working at all.
It kicks off the script perfectly but its not passing the variables.
I have tried passing the variables to $1 and $2 and also tried hard coding them in the script.

Below is the script that i execute that requires the variables.

curl --data \
$' NAGIOSDEV ALERT \n Server Down - $1,\n Time of Outage - $2' \
-H "Content-Type: text/plain" http://go2hal.legion.sbsa.local/api/alert/3533305961

Could someone please just point me in the right direction as i am trying to PoC this soonest to be able to get the funding for the Nagios XI License.

Re: Nagios to kick off script

Posted: Tue Jul 09, 2019 2:13 pm
by tgriep
The $HOSTNAME$ macro needs to be %host% instead so change the command to the following example.

Code: Select all

/cdirect/scripts/telegram_service_notify.sh "%host%" "%hoststate%"
Did you enable the Event handler in the component and Apply the Settings?

Do you see the script being ran in the /usr/local/nagiosxi/var/eventman.log log file?

Re: Nagios to kick off script

Posted: Wed Jul 10, 2019 7:42 am
by kodlan
tgriep wrote:The $HOSTNAME$ macro needs to be %host% instead so change the command to the following example.

Code: Select all

/cdirect/scripts/telegram_service_notify.sh "%host%" "%hoststate%"
Did you enable the Event handler in the component and Apply the Settings?

Do you see the script being ran in the /usr/local/nagiosxi/var/eventman.log log file?
I am not sure where to enable the event handler? I have done this at global Event handlers.
Maybe some pointers if you dont mind?

I will try the new macro and check that log file. thank you.

Re: Nagios to kick off script

Posted: Wed Jul 10, 2019 2:33 pm
by tgriep
It sounds like you already have it enabled but here are the steps to check it.
Login to the XI GUI and go to the Admin > Manage Components menu.
Edit the Settings for the Global Event Handlers component and in that menu, the Enabled box next to the command should be checked.
That is how they are enabled.

Let me know what you find in the log file.