Enabling Maintenance Windows in Event Rules¶
This section shows you the steps necessary to enable Maintenance Windows in Event Applications rules by:
-
Modifying code in LoadRules to load the configured maintenance windows for devices into memory.
-
Modifying code in BaseRules to check if the device is in a maintenance window, and if so, set the Severity to Normal (0) and Custom5 to Under Maintenance.
Dependencies¶
- The Maintenance windows must exist in the Assure1 UI.
Best Practices¶
- The default deduplication settings for event applications will not update the Custom5 field for an event if a duplicate is received. If utilizing the maintenance window functionality, administrators may need to create a custom InsertSQLFile and FieldSetFile so the application knows to update the Custom5 field.
Modifying code in LoadRules¶
-
In the LoadRules file, add or uncomment the following code:
#======================================= # Device Maintenance Window Example #======================================= my $WindowSQL = " SELECT D.CustomName, INET_NTOA(D.IPAddress) AS IPv4, INET6_NTOA(D.IPv6Address) AS IPv6, D.DNSName AS DNS, DSI.SysName, W.StartTime, W.StopTime FROM DeviceWindows_Devices AS DWD LEFT JOIN Devices AS D ON D.DeviceID = DWD.DeviceID LEFT JOIN DeviceWindows AS W ON DWD.WindowID = W.WindowID LEFT JOIN DeviceSystemInfo AS DSI ON D.DeviceID = DSI.DeviceID "; $DBH = DBConnect($Config, 'Assure1', {AutoCommit => 1}); my $Count = 0; my $SelectStatement = $DBH->prepare($WindowSQL); $SelectStatement->execute(); while (my $ref = $SelectStatement->fetchrow_hashref()) { $WindowHash->{$ref->{CustomName}}->{StartTime} = $ref->{StartTime}; $WindowHash->{$ref->{CustomName}}->{StopTime} = $ref->{StopTime}; $WindowHash->{$ref->{IPv4}}->{StartTime} = $ref->{StartTime}; $WindowHash->{$ref->{IPv4}}->{StopTime} = $ref->{StopTime}; $WindowHash->{$ref->{IPv6}}->{StartTime} = $ref->{StartTime}; $WindowHash->{$ref->{IPv6}}->{StopTime} = $ref->{StopTime}; $WindowHash->{$ref->{DNS}}->{StartTime} = $ref->{StartTime}; $WindowHash->{$ref->{DNS}}->{StopTime} = $ref->{StopTime}; $WindowHash->{$ref->{SysName}}->{StartTime} = $ref->{StartTime}; $WindowHash->{$ref->{SysName}}->{StopTime} = $ref->{StopTime}; $Count++; } $WindowHash->{''} = 0; $SelectStatement->finish(); $DBH->disconnect; $Log->Message('INFO',"Device Maintenance Windows - Found [$Count] Devices/Windows"); $Log->Message('DEBUG',"Device Maintenance Windows - Device Dump\n-------------\n" . Dumper($WindowHash) . "\n-------------"); #--------------------------------------
-
Check the code syntax.
-
Save the file.
Modifying Code in BaseRules¶
-
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... #======================== # Device Window Suppression -- Used in Base or Include Rules #======================== my $StartWindow = int($WindowHash->{$Event->{'Node'}}->{StartTime} || $WindowHash->{$Event->{'IPAddress'}}->{StartTime}); my $EndWindow = int($WindowHash->{$Event->{'Node'}}->{StopTime} || $WindowHash->{$Event->{'IPAddress'}}->{StopTime}); my $CurrentTime = time(); if (($StartWindow <= $CurrentTime) && ($EndWindow >= $CurrentTime)) { $Event->{'Severity'} = 0; $Event->{'Custom5'} = "Under Maintenance"; } #------------------------
-
Edit the code if you wish to customize it further.
-
Check the code syntax.
-
Save the file.
-
Restart the service or use the Reload Config option, then verify via the logs that the maintenance window(s) are loaded. Below is an example log based on the above logic, but will only be logged if using an INFO or DEBUG logging level.
-
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] Device Maintenance Windows - Found [2] Devices/Windows [DATE TIME] [DEBUG] Device Maintenance Windows - Device Dump ------------- $VAR1 = { '' => 0, 'Device_1_DNS_Name' => { 'StartTime' => '(Window Start Time)', 'StopTime' => '(Window Stop Time)' }, 'Device_1_Custom_Name' => { 'StartTime' => '(Window Start Time)', 'StopTime' => '(Window Stop Time)' }, 'Device_1_Sys_Name' => { 'StartTime' => '(Window Start Time)', 'StopTime' => '(Window Stop Time)' }, 'Device_1_IPv4_Address' => { 'StartTime' => '(Window Start Time)', 'StopTime' => '(Window Stop Time)', }, 'Device_1_IPv6_Address' => { 'StartTime' => '(Window Start Time)', 'StopTime' => '(Window Stop Time)' }, 'Device_2_DNS_Name' => { 'StartTime' => '(Window Start Time)', 'StopTime' => '(Window Stop Time)' }, 'Device_2_Custom_Name' => { 'StartTime' => '(Window Start Time)', 'StopTime' => '(Window Stop Time)' }, 'Device_2_Sys_Name' => { 'StartTime' => '(Window Start Time)', 'StopTime' => '(Window Stop Time)' }, 'Device_2_IPv4_Address' => { 'StartTime' => '(Window Start Time)', 'StopTime' => '(Window Stop Time)', }, 'Device_2_IPv6_Address' => { 'StartTime' => '(Window Start Time)', 'StopTime' => '(Window Stop Time)' }, ... }; -------------