Event Handlers
Posted: Sat Feb 18, 2017 3:18 pm
Hi there, I do not have a problem with NagiosXI. I am actually looking for advice about using event handlers, so any advice will be appreciated.
First, I created a simple local check command "check_local_tcpdump" where it just checks if there are any tcpdump processes running.
I also created a service which will use that command:
$USER1$/check_procs -c $ARG1$ -C $ARG2$
where:
$ARG1$ 1:
$ARG2$ tcpdump
That works fine, but basically what I want to achieve is to create an event handler that whenever there are less than 1 tcpdump process running which means the service state is CRITICAL, call the event handler and restart the tcpdump process.
Then I created an event handler named "event_handler_tcpdump" with the following command:
$USER1$/event_handler_tcpdump.sh $SERVICESTATE$
And the script:
#!/bin/bash
SERVICESTATE=$1
if [[ $SERVICESTATE == 'CRITICAL' ]]
then
echo "The state has changed to $SERVICESTATE" > /tmp/critical.txt
sudo tcpdump -i lo -w /tmp/test.pcap
exit 0
else
echo "The state has changed to $SERVICESTATE" > /tmp/ok.txt
fi
Ideally, instead of sudo tcpdump -i lo -w /tmp/test.pcap, I would just call an external script, but this is just to simplify things.
Now this apparently works. If there are no tcpdump processes running, then the event handler will restart the tcpdump process which will change the state to OK.
Since I will be using this on a remote production server, is it important that the event handler does not duplicate and create more tcpdump processes.
So, is this the right way of doing it?
Hopefully someone can help me out.
Greetings from Mexico.
First, I created a simple local check command "check_local_tcpdump" where it just checks if there are any tcpdump processes running.
I also created a service which will use that command:
$USER1$/check_procs -c $ARG1$ -C $ARG2$
where:
$ARG1$ 1:
$ARG2$ tcpdump
That works fine, but basically what I want to achieve is to create an event handler that whenever there are less than 1 tcpdump process running which means the service state is CRITICAL, call the event handler and restart the tcpdump process.
Then I created an event handler named "event_handler_tcpdump" with the following command:
$USER1$/event_handler_tcpdump.sh $SERVICESTATE$
And the script:
#!/bin/bash
SERVICESTATE=$1
if [[ $SERVICESTATE == 'CRITICAL' ]]
then
echo "The state has changed to $SERVICESTATE" > /tmp/critical.txt
sudo tcpdump -i lo -w /tmp/test.pcap
exit 0
else
echo "The state has changed to $SERVICESTATE" > /tmp/ok.txt
fi
Ideally, instead of sudo tcpdump -i lo -w /tmp/test.pcap, I would just call an external script, but this is just to simplify things.
Now this apparently works. If there are no tcpdump processes running, then the event handler will restart the tcpdump process which will change the state to OK.
Since I will be using this on a remote production server, is it important that the event handler does not duplicate and create more tcpdump processes.
So, is this the right way of doing it?
Hopefully someone can help me out.
Greetings from Mexico.