Event handler VS number of runs
Event handler VS number of runs
Hello XI support
Just like with support for downtime (my other ticket), other key functionality for Event Handling would be number of time script runs (counted and stopped after that, alerting this things are REALLY wrong and trying to restart some service or daemon may do more harm after all).
Is there such functionality we can configure?
Thank you
Just like with support for downtime (my other ticket), other key functionality for Event Handling would be number of time script runs (counted and stopped after that, alerting this things are REALLY wrong and trying to restart some service or daemon may do more harm after all).
Is there such functionality we can configure?
Thank you
Re: Event handler VS number of runs
Are you looking to just count how many times an event handler script runs, or are you saying you have a particular event is running to often? If the latter, Event handlers are called whenever a state change occurs. This includes HARD and SOFT state types, as well as OK, WARNING, CRITICAL, and UNKNOWN states.
https://assets.nagios.com/downloads/nag ... ios-XI.pdf
https://assets.nagios.com/downloads/nag ... ios-XI.pdf
Be sure to check out the Knowledgebase for helpful articles and solutions!
Re: Event handler VS number of runs
Event handlers should be able to count, but you'd need to build it in with your assigned plugin. I don't think this is on the Nagios side, as much as it is on the plugin side.key functionality for Event Handling would be number of time script runs (counted and stopped after that, alerting this things are REALLY wrong and trying to restart some service or daemon may do more harm after all).
For example, say you have test.sh that is a global handler, you could use the variables Nagios allows you to pass to an event handler, and create a file called /tmp/$HOSTADDRESS$.txt and append +1 every time it's ran. You could also do so using a DB using dynamic variables. The sky is the limit honestly.
Former Nagios Employee
Re: Event handler VS number of runs
Not sure if I understood correctly.rkennedy wrote:Event handlers should be able to count, but you'd need to build it in with your assigned plugin. I don't think this is on the Nagios side, as much as it is on the plugin side.key functionality for Event Handling would be number of time script runs (counted and stopped after that, alerting this things are REALLY wrong and trying to restart some service or daemon may do more harm after all).
For example, say you have test.sh that is a global handler, you could use the variables Nagios allows you to pass to an event handler, and create a file called /tmp/$HOSTADDRESS$.txt and append +1 every time it's ran. You could also do so using a DB using dynamic variables. The sky is the limit honestly.
What i mean is that say we monitor host for service A. Service A went down and was restarted 10 times OR or kept restarting for 15 minutes and still down.
at this point we want to stop restarting and create an alert instead. How this could be done with Nagios?
Re: Event handler VS number of runs
This would need logic built in to your event handler, as Nagios does not have something like this built in.
Former Nagios Employee
Re: Event handler VS number of runs
Meant built into restart script?rkennedy wrote:This would need logic built in to your event handler, as Nagios does not have something like this built in.
Re: Event handler VS number of runs
Yes, it would need to be built in to your event handler scripts. As I mentioned above, you could use variables to create dynamic variables representing a count of some sort.
Former Nagios Employee
Re: Event handler VS number of runs
rkennedy wrote:Yes, it would need to be built in to your event handler scripts. As I mentioned above, you could use variables to create dynamic variables representing a count of some sort.
Thank you. Please hep with sample scripts (if any you've got) - in other monitoring systems this would be more or less standard functionality.
Otherwise please close this thread
Re: Event handler VS number of runs
Sure, a rough example is something like this, where you would pass $HOSTNAME$ and $SERVICEDISPLAYNAME$ to your event handler, and it then creates a file to use as a 'count'. This would take a lot more development to get working as you need, but this is the basis:
If it's for a host, then the file will be created as hostname., and if it's a service, it would be hostname.servicename. Every time the script runs it will add +1 to the count it gets from the flat files. You would still need to add in logic to see what the state is, and if it should reset, etc.
Code: Select all
#!/bin/bash
HOSTNAME=$1
SERVICEDISPLAYNAME=$2
FILENAME=$HOSTNAME.$SERVICEDISPLAYNAME
COUNT=$(cat /tmp/$FILENAME)
COUNTTOT=$(expr $COUNT + 1)
echo Current runs is $COUNTTOT
echo $COUNTTOT > /tmp/$FILENAME
Former Nagios Employee
Re: Event handler VS number of runs
rkennedy wrote:Sure, a rough example is something like this, where you would pass $HOSTNAME$ and $SERVICEDISPLAYNAME$ to your event handler, and it then creates a file to use as a 'count'. This would take a lot more development to get working as you need, but this is the basis:If it's for a host, then the file will be created as hostname., and if it's a service, it would be hostname.servicename. Every time the script runs it will add +1 to the count it gets from the flat files. You would still need to add in logic to see what the state is, and if it should reset, etc.Code: Select all
#!/bin/bash HOSTNAME=$1 SERVICEDISPLAYNAME=$2 FILENAME=$HOSTNAME.$SERVICEDISPLAYNAME COUNT=$(cat /tmp/$FILENAME) COUNTTOT=$(expr $COUNT + 1) echo Current runs is $COUNTTOT echo $COUNTTOT > /tmp/$FILENAME
Thank you, please close this thread