Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add changes Compat/notify to delete events which are not historic an… #77

Merged
merged 2 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions lib/Compat/NMIS.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2245,6 +2245,17 @@ sub notify
my $events_config = NMISNG::Util::loadTable(dir => 'conf', name => 'Events', conf => $conf);
my $thisevent_control = $events_config->{$event} || { Log => "true", Notify => "true", Status => "true"};

# search for upevent that is not historic (no escalations run on it) event shouldn't exist
# if it does we get index issues. deleting it here means escalations will not be run
# on that up event, ok because it's going down now anyway, no reason to notify it
# this is only called when things are going down, validate with ~normal anyway
my $thisevent_up = $events_config->{$event}->{CancelingEvent} // undef;
if( $thisevent_up && $thisevent_up ne 'N/A' && $level !~ /Normal/i ) {
my $eventobjUP = $S->nmisng_node->event( event => $thisevent_up, element => $element, historic => 0 ); # no search for active, really no active up events should exist
$eventobjUP->delete() if( $eventobjUP );
}


# create new event object with all properties, when load is called if it is found these will
# be overwritten by the existing properties
my $event_obj = $S->nmisng_node->event(event => $event, element => $element, configuration => {group => $S->nmisng_node()->{'_configuration'}->{'group'}});
Expand Down
18 changes: 18 additions & 0 deletions lib/NMISNG/Event.pm
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,24 @@ sub check
# check if the event exists and load its details
if ( $exists && $self->active )
{
# we are about to take an active event and mark it in-active, creating the "up" event. process escalation will then
# find the inactive event, notify all of the up event and then delete/mark it historic.
# Two issues can occur:
# 1. marking the event active 0 can fail (save hits an error/index issue).
# 2. if escalations do not run fast enough (or at all) the up event created never goes away (which can cause #1).
# to mitigate these two issues give this event an expire_at value so it will eventually go away
if ( !NMISNG::Util::getbool( $self->nmisng->config->{"keep_event_history"}, "invert" ) ){
# set expiry in case saving/escalations do not run properly
my $expire_at = $self->nmisng->config->{purge_event_after} // 86400;
$expire_at = Time::Moment->from_epoch( time + $expire_at + 300 );
my $q = $self->_query();
my $dbres = NMISNG::DB::update(
collection => $self->nmisng->events_collection(),
query => $q,
record => {'$set' => {expire_at => $expire_at, lastupdate => time}},
freeform => 1
);
}
# a down event exists, so log an UP and delete the original event
my $new_event = $self->event;

Expand Down
4 changes: 4 additions & 0 deletions test/t_event.pl
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,11 @@
is( $event3->logged, 1, "event got logged");
is( $event3->ack, 1, "event is now acknowledged");
is( $event3->user, 'testuser', 'acknowledge set the user');
$C->{"keep_event_history"} = 'true';
is( $event3->expire_at, undef, "Expire At for event is undef");
$event3->check(sys => $S);
is( $event3->load(force => 1, only_take_missing => 0), undef, "loading event with force and not only_take_missing brings in all values");
isnt( $event3->expire_at, undef, "Expire At for event not undef after check if keep_event_history is true");
isnt( $event3->event, $event_val1, "event value should go from down->up");
isnt( $event3->active, 1, "event should now be inactive");
is( $event3->level, 'Normal', "event should now be at normal level");
Expand Down