Event Handler External Script not working
-
ramachandrank
- Posts: 12
- Joined: Wed Nov 27, 2019 11:27 am
Event Handler External Script not working
Hi Team,
I am new to Nagios and I would like get where I have missed my configuration. I have a process running on one server. Whenever memory of the process goes idle then nagios will generate a critical alert via my external script which is working good. I thought of adding my own script to the event handler so that the process goes critical then my another script in event handler will start that process again.
By this I don't need to login the server each time to start that process. I do not find any error message but I am not getting that process to get started via event handler.
Please let me know if I miss something. Share me your valuable inputs as well.
Thanks,
Ram
I am new to Nagios and I would like get where I have missed my configuration. I have a process running on one server. Whenever memory of the process goes idle then nagios will generate a critical alert via my external script which is working good. I thought of adding my own script to the event handler so that the process goes critical then my another script in event handler will start that process again.
By this I don't need to login the server each time to start that process. I do not find any error message but I am not getting that process to get started via event handler.
Please let me know if I miss something. Share me your valuable inputs as well.
Thanks,
Ram
Re: Event Handler External Script not working
Hi @ramachandrank, welcome to the forums!
The most important thing to keep in mind when setting up a script to run via event handler is that it's going to be run as the nagios user. Make sure the script is readable, and executable by nagios.
Next up, here is some documentation on event handlers. One doc is geared at Nagios XI, the other at Nagios Core. Nagos Core runs at the heart of XI, so it's still relevant information.
https://assets.nagios.com/downloads/nag ... ios-XI.pdf
https://assets.nagios.com/downloads/nag ... dlers.html
With all of that out of the way, can you tell me a little bit about this event handler script you made? Does it just ssh into another host to restart a process? Were you able to create a command for your script and select it in the Event Handler drop down menu in the Service Management page for your service?
The most important thing to keep in mind when setting up a script to run via event handler is that it's going to be run as the nagios user. Make sure the script is readable, and executable by nagios.
Next up, here is some documentation on event handlers. One doc is geared at Nagios XI, the other at Nagios Core. Nagos Core runs at the heart of XI, so it's still relevant information.
https://assets.nagios.com/downloads/nag ... ios-XI.pdf
https://assets.nagios.com/downloads/nag ... dlers.html
With all of that out of the way, can you tell me a little bit about this event handler script you made? Does it just ssh into another host to restart a process? Were you able to create a command for your script and select it in the Event Handler drop down menu in the Service Management page for your service?
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!
Be sure to check out our Knowledgebase for helpful articles and solutions!
-
ramachandrank
- Posts: 12
- Joined: Wed Nov 27, 2019 11:27 am
Re: Event Handler External Script not working
Hi mbellerue,
Thanks for your reply.
Yes, I have added my script under commands and I am able to select my script under event handler field and applied configuration successfully.
My external script to trigger CRITICAL alert is working fine without any issues.
But script added under event handler is not working even after the service moved to CRITICAL state. I have given event handler field to set ON and check interval as 30 minutes. So if we receive critical alert then we have 30 minutes interval to run event handler script. Screen shots for your reference.
Under commands, I have selected as misc command as Command Type. Is that correct?
Running my command through Nagios web console, the script works.
$USER1$/check_nrpe -H $HOSTADDRESS$ -t $ARG1$ -c <MY OWN SCRIPT FILENAME>
Thanks,
Ram
Thanks for your reply.
Yes, I have added my script under commands and I am able to select my script under event handler field and applied configuration successfully.
My external script to trigger CRITICAL alert is working fine without any issues.
But script added under event handler is not working even after the service moved to CRITICAL state. I have given event handler field to set ON and check interval as 30 minutes. So if we receive critical alert then we have 30 minutes interval to run event handler script. Screen shots for your reference.
Under commands, I have selected as misc command as Command Type. Is that correct?
Running my command through Nagios web console, the script works.
$USER1$/check_nrpe -H $HOSTADDRESS$ -t $ARG1$ -c <MY OWN SCRIPT FILENAME>
Thanks,
Ram
Re: Event Handler External Script not working
Can you post your script and the command you have defined for the event handler? I've seen some scripts that don't exit quite properly (usually Powershell scripts) where when they are run manually you get the message and the exit code, but when run via NRPE or NCPA, you don't.
Also, I didn't get the screenshots. If you can post those, I will definitely take a look at them.
Also, I didn't get the screenshots. If you can post those, I will definitely take a look at them.
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!
Be sure to check out our Knowledgebase for helpful articles and solutions!
-
ramachandrank
- Posts: 12
- Joined: Wed Nov 27, 2019 11:27 am
Re: Event Handler External Script not working
Hi,
Please find the script below:
schtasks /run /tn "Start Importer"
The above power shell script will trigger a scheduled task to start. By then another power shell script inside that task will generate.
Sorry, I have attached screen shots with this reply now.
Thanks,
Ram
Please find the script below:
schtasks /run /tn "Start Importer"
The above power shell script will trigger a scheduled task to start. By then another power shell script inside that task will generate.
Sorry, I have attached screen shots with this reply now.
Thanks,
Ram
You do not have the required permissions to view the files attached to this post.
-
scottwilkerson
- DevOps Engineer
- Posts: 19396
- Joined: Tue Nov 15, 2011 3:11 pm
- Location: Nagios Enterprises
- Contact:
Re: Event Handler External Script not working
You cannot pass an $ARG1$ value to an event handler, only to check commands, you will need to change the command to hard code the 30 in there
-
ramachandrank
- Posts: 12
- Joined: Wed Nov 27, 2019 11:27 am
Re: Event Handler External Script not working
Hi scottwilkerson,
So do I need to modify the event handler command as below?
$USER1$/check_nrpe -H $HOSTADDRESS$ -c startpxxi
Thanks,
Ram
So do I need to modify the event handler command as below?
$USER1$/check_nrpe -H $HOSTADDRESS$ -c startpxxi
Thanks,
Ram
-
scottwilkerson
- DevOps Engineer
- Posts: 19396
- Joined: Tue Nov 15, 2011 3:11 pm
- Location: Nagios Enterprises
- Contact:
Re: Event Handler External Script not working
That should work just fineramachandrank wrote:Hi scottwilkerson,
So do I need to modify the event handler command as below?
$USER1$/check_nrpe -H $HOSTADDRESS$ -c startpxxi
Thanks,
Ram
-
ramachandrank
- Posts: 12
- Joined: Wed Nov 27, 2019 11:27 am
Re: Event Handler External Script not working
Hi scottwilkerson,
I have modified the command and still customized event handler script not working.
Thanks,
Ram
I have modified the command and still customized event handler script not working.
Thanks,
Ram
-
scottwilkerson
- DevOps Engineer
- Posts: 19396
- Joined: Tue Nov 15, 2011 3:11 pm
- Location: Nagios Enterprises
- Contact:
Re: Event Handler External Script not working
Did you Apply configuration after making the change?ramachandrank wrote:Hi scottwilkerson,
I have modified the command and still customized event handler script not working.
Thanks,
Ram
If you go to Reports -> Event Log and search for the host/service this is running on, do you see the event firing?