Enabling Priority Scoring In Event Rules

This section shows you the steps necessary to enable Event Priority Score calculations in Event Applications rules by:

Dependencies

Best Practices

Modifying Code in LoadRules

  1. In the LoadRules file, add or uncomment the following code:

    #==============================================
    # Priority Example Rules
    #==============================================
    my $PrioritySQL = "
           SELECT D.DevicePriorityID,
                  D.CustomName,
                  INET_NTOA(D.IPAddress) AS IPv4,
                  INET6_NTOA(D.IPv6Address) AS IPv6,
                  D.DNSName AS DNS,
                  DSI.SysName
             FROM Devices AS D
        LEFT JOIN DeviceSystemInfo AS DSI
               ON D.DeviceID = DSI.DeviceID
            WHERE D.DevicePriorityID > 0
    ";
    $DBH = DBConnect($Config, 'Assure1', {AutoCommit => 1});
    my $PriorityCount = 0;
    my $SelectStatement = $DBH->prepare($PrioritySQL);
    $SelectStatement->execute();
    while (my $ref = $SelectStatement->fetchrow_hashref()) {
        $PriorityHash->{$ref->{CustomName}} = $ref->{DevicePriorityID};
        $PriorityHash->{$ref->{IPv4}} = $ref->{DevicePriorityID};
        $PriorityHash->{$ref->{IPv6}} = $ref->{DevicePriorityID};
        $PriorityHash->{$ref->{DNS}} = $ref->{DevicePriorityID};
        $PriorityHash->{$ref->{SysName}} = $ref->{DevicePriorityID};
        $PriorityCount++;
    }
    $PriorityHash->{''} = 0;
    $SelectStatement->finish();
    $DBH->disconnect;
    $Log->Message('INFO',"Priority Scoring - Found [$PriorityCount] Devices");
    $Log->Message('DEBUG',"Priority Scoring - Device Dump\n-------------\n" . Dumper($PriorityHash) . "\n-------------");
    #----------------------------------------------
    
  2. Check the code syntax.

  3. Save the file.

Modifying Code in BaseRules

  1. In the BaseRules file, add the following near the bottom of the file so this is the last processing step that is done:

    ### ORIGINAL PROCESSING IS ABOVE...
    
    #========================
    # Priority Scoring -- Used in Base or Include Rules
    #========================
    my $Priority      = int($PriorityHash->{$Event->{'Node'}} || $PriorityHash->{$Event->{'IPAddress'}});
    $Event->{'Score'} = int($Priority) * int($Event->{'Severity'});
    #------------------------
    
  2. Edit the code if you wish to customize it further.

  3. Check the code syntax.

  4. Save the file.

  5. Restart the service or use the Reload Config option, then verify via the logs that the priority values are loaded for devices. The Score value for an event should then be set properly when an event is received from a device. Below is an example log based on the above logic, but will only be logged if using an INFO or DEBUG logging level.

  6. If a device has a duplicate value (for example, the same DNS Name and Sys Name), the hash will only have a single reference to that name.

    [DATE TIME] [INFO]   Priority Scoring - Found [2] Devices
    [DATE TIME] [DEBUG]  Priority Scoring - Device Dump
    -------------
    $VAR1 = {
              '' => 0,
              'Device_1_DNS_Name' => (Priority Value),
              'Device_1_Custom_Name' => (Priority Value),
              'Device_1_Sys_Name' => (Priority Value),
              'Device_1_IPv4_Address' => (Priority Value),
              'Device_1_IPv6_Address' => (Priority Value),
              'Device_2_DNS_Name' => (Priority Value),
              'Device_2_Custom_Name' => (Priority Value),
              'Device_2_Sys_Name' => (Priority Value),
              'Device_2_IPv4_Address' => (Priority Value),
              'Device_2_IPv6_Address' => (Priority Value),
              ...
            };
    -------------