Creating a custom event rule

About this task

You can use the Custom1 and Custom2 event rules to define and generate events of your own design for conditions that are not already defined as events by the NPS software. An example of a custom event might be to track the user login information, but these events can also be used to construct complex events.

If you define a custom event, you must also define a process to trigger the event using the nzevent generate command. Typically, these events are generated by a customer-created script which is invoked in response to either existing NPS events or other conditions that you want to monitor.

To create a custom event rule, complete the following steps:

Procedure

  1. Use the nzevent add command to define a new event type.
    Custom events are never based on any existing event types. This example creates three different custom events. nNewRule4 and NewRule5 use the variable eventType to distinguish between the event types. The NewRule6 event type uses a custom variable and compares it with the standard event type.
    [nz@nzhost ~]$ nzevent add -eventType custom1 -name NewRule4 
    -notifyType email -dst myemail@company.com -msg "NewRule4 message" 
    -eventArgsExpr '$eventType==RandomCustomEvent'
    
    [nz@nzhost ~]$ nzevent add -eventType custom1 -name NewRule5 
    -notifyType email -dst myemail@company.com -msg "NewRule5 message" 
    -eventArgsExpr '$eventType==sysStateChanged'
    
    [nz@nzhost ~]$ nzevent add -eventType custom1 -name NewRule6 
    -notifyType email -dst myemail@company.com -msg "NewRule6 message" 
    -eventArgsExpr '$randomEventType==sysStateChanged' 
    
  2. Use the nzevent generate command to trigger the custom events.
    [nz@nzhost ~]$ nzevent generate -eventtype custom1 
                     -eventArgs 'eventType=RandomCustomEvent'
    [nz@nzhost ~]$ nzevent generate -eventtype custom1 
                     -eventArgs 'eventType=sysStateChanged'
    [nz@nzhost ~]$ nzevent generate -eventtype custom1 
                     -eventArgs 'randomEventType=sysStateChanged'
  3. After generating these custom events, email is sent to the specified destination and the following messages are logged in the /nz/kit/log/eventmgr/eventmgr.log file:
    2015-11-24 09:43:31.820612 EST (16210) Info: received & processing event 
    type =custom1, event args = 'eventType=RandomCustomEvent' event source = 
    'User initiated event'
    2015-11-24 09:43:31.820724 EST (16210) Info: invoking mail notifier, 
    cmd = '/nz/kit.7.2.1.0.45837/sbin/sendMail -dst "myemail@company.com" 
    -msg "NewRule4 message"'
    2015-11-24 09:43:31.838814 EST (16210) Info: received & processing event 
    type =custom1, event args = 'eventType=sysStateChanged' event source = 
    'User initiated event'
    2015-11-24 09:43:31.838920 EST (16210) Info: invoking mail notifier, 
    cmd = '/nz/kit.7.2.1.0.45837/sbin/sendMail -dst "myemail@company.com" 
    -msg "NewRule5 message"'
    2015-11-24 09:43:32.745636 EST (16210) Info: received & processing event 
    type =custom1, event args = 'randomEventType=sysStateChanged' event 
    source = 'User initiated event'
    2015-11-24 09:43:32.745802 EST (16210) Info: invoking mail notifier, 
    cmd = '/nz/kit.7.2.1.0.45837/sbin/sendMail -dst "myemail@company.com" 
    -msg "NewRule6 message"'

What to do next

Consider creating a script that runs the nzevent generate command as needed when your custom events occur.