Nagios to kick off script

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
kodlan
Posts: 10
Joined: Thu Apr 04, 2019 7:38 am

Nagios to kick off script

Post 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.
User avatar
mcapra
Posts: 3739
Joined: Thu May 05, 2016 3:54 pm

Re: Nagios to kick off script

Post 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.
Former Nagios employee
https://www.mcapra.com/
kodlan
Posts: 10
Joined: Thu Apr 04, 2019 7:38 am

Re: Nagios to kick off script

Post 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.
User avatar
tgriep
Madmin
Posts: 9177
Joined: Thu Oct 30, 2014 9:02 am

Re: Nagios to kick off script

Post 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?
Be sure to check out our Knowledgebase for helpful articles and solutions!
kodlan
Posts: 10
Joined: Thu Apr 04, 2019 7:38 am

Re: Nagios to kick off script

Post 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.
User avatar
tgriep
Madmin
Posts: 9177
Joined: Thu Oct 30, 2014 9:02 am

Re: Nagios to kick off script

Post 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.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Locked