Archived community.zenoss.org | full text search
Skip navigation
Currently Being Moderated

How to Add an Event Class

VERSION 1 
Created on: Sep 14, 2009 11:16 AM by Noel Brockett - Last Modified:  Apr 20, 2010 3:57 PM by Matt Ray

Instructions for creating an internal event class

 

Event classes can be added easily through the UI. If you need to use an event class internally, however,  you need to make sure that class will always be available, which involves several more steps.

Add to ZenEventClasses

Add a definition of the name of your new event class to Products/ZenEvents/ZenEventClasses:

 

...
My_New_Class = "/My/New/Class"

 

Now your event class is centralized and can be imported wherever you need to use it, e.g.:

 

from Products.ZenEvents.ZenEventClasses import My_New_Class
...
if thing.evclass == My_New_Class:
    ...

Add class permanently to the ZODB

Now you need to make sure that your class will actually exist when you need it. This involves two steps:

  • Adding the event class to the import XML
  • Writing a migrate script to add the class

Add the class to the import XML

Several event classes are imported from XML by zenload just after the ZODB is created. To include your new event class in this import, add an <object> element describing it to Products/ZenModel/data/events.xml. Be sure to nest it inside the classes that already exist, if appropriate. For example, if your new class is "/Status/NewClass", you would add it inside the <object id='Status'> that already exists:

 

<object id='Status' module='Products.ZenEvents.EventClass' class='EventClass> <!--This one exists already-->
    ...
    <object id='NewClass' module='Products.ZenEvents.EventClass' class='EventClass'> <!--This is your new one-->
    </object>
</object>

Write a migrate script

Now, since your code is no longer backwards compatible, you need to add the new event class to databases that have already been created by writing a migrate script. (See HowToMigrateZenossCode for more detailed information).  Create a new script in Products/ZenModel/migrate with a unique name (here neweventclasses.py).  Fill it with this code:

 

__doc__='Add new classes to EventManager'

import Migrate

class NewEventClasses(Migrate.Step):
    version = Migrate.Version(1, 1, 0) # Replace this with the correct version

    def cutover(self, dmd):
        dmd.Events.createOrganizer("/My/Event/Class")
        dmd.Events.createOrganizer("/My/Event/Class2") # Add multiple new classes in the same migrate script
        dmd.ZenEventManager.buildRelations()

NewEventClasses()

 

Next, add your migrate script to Products/ZenModel/migrate/__init__.py:

 

...
import neweventclasses

 

Now

 

zenmigrate run

 

to make sure your class is created properly.

 

That's it!

Comments (0)