14. Event Commands

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.

14.1. Create an Event Command Example

This example will give you the framework for creating an event command.

  1. Click on Event Manager and go to the Commands page.

  2. Create a new event command called writeFile.

  3. Edit the command with the following values.

    Set Enabled = True

    Default Command timeout = 60

    Delay = 0

  4. Set the command as follows:

    echo "${evt/evid} ${dev/id} ${dev/manageIp} ${evt/message}" >> /tmp/cmdoutput

  5. Set Clear Command

    echo "${evt/evid} ${evt/clearid} ${dev/id} ${evt/message}"" >> /tmp/cmdoutput

  6. In the Where area, add a filter of Message contains "testing event commands".

  7. Click Save.

14.2. Test the Event Command

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.

  1. Start watching the output file with the command:

    tail -f /tmp/cmdoutput

  2. 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

  3. Look at the output file. After the next zenactions cycle you should see the down event.

  4. 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