Event Commands allow users to define arbitrary shell commands to be executed when events are received by Zenoss that meet the criteria defined in the event command. Event commands are carried out by the zenactions daemon. We're going to create an event command that uses the mappings we created in the last section. Our command will write text from our event into a log file.
This example will give you the framework for creating an event command.
-
Click on Event Manager and go to the Commands page.
-
Create a new event command called writeFile.
-
Edit the command with the following values.
Set Enabled = True
Default Command timeout = 60
Delay = 0
-
Set the command as follows:
echo "${evt/evid} ${dev/id} ${dev/manageIp} ${evt/message}" >> /tmp/cmdoutput
-
Set Clear Command
echo "${evt/evid} ${evt/clearid} ${dev/id} ${evt/message}"" >> /tmp/cmdoutput
-
In the Where area, add a filter of Message contains "testing event commands".
-
Click Save.
The Add Event page is a good tool for testing event commands. Follow these steps to create an event that meets the criteria for the event command you just created.
-
Start watching the output file with the command:
tail -f /tmp/cmdoutput
-
Create an artificial down event using the Add Event functionality and defining it as follows:
Message = My Application is totally broken
Device = <any device in your system>
Event Class Key =
Severity = Critical
-
Look at the output file. After the next zenactions cycle you should see the down event.
-
Now let’s clear the down event by sending an up event.
Message = Now everything is ok
Device = <any device in your system -same device you used above>
Event Class Key =
Severity = Info