Nagios to kick off script

This board serves as an open discussion and support collaboration point for Nagios XI. NOTE: Nagios XI customers should use the Customer Support forum to obtain expedited support.

Nagios to kick off script

Postby kodlan » Mon Jul 08, 2019 2:22 am

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.
kodlan
 
Posts: 8
Joined: Thu Apr 04, 2019 7:38 am

Re: Nagios to kick off script

Postby mcapra » Mon Jul 08, 2019 11:23 am

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
http://www.mcapra.com/
User avatar
mcapra
 
Posts: 3584
Joined: Thu May 05, 2016 3:54 pm

Re: Nagios to kick off script

Postby kodlan » Tue Jul 09, 2019 2:20 am

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.
kodlan
 
Posts: 8
Joined: Thu Apr 04, 2019 7:38 am

Re: Nagios to kick off script

Postby tgriep » Tue Jul 09, 2019 2:13 pm

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?
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!
User avatar
tgriep
Madmin
 
Posts: 8334
Joined: Thu Oct 30, 2014 9:02 am

Re: Nagios to kick off script

Postby kodlan » Wed Jul 10, 2019 7:42 am

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.
kodlan
 
Posts: 8
Joined: Thu Apr 04, 2019 7:38 am

Re: Nagios to kick off script

Postby tgriep » Wed Jul 10, 2019 2:33 pm

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


Return to Nagios XI

Who is online

Users browsing this forum: No registered users and 10 guests