sub alert_handle_bgp_state_change { my ($arg_ref) = @_; my $device = $arg_ref->{device}; my $child = $arg_ref->{child}; my $attr = $arg_ref->{attr}; my $state = $arg_ref->{state}; my $TMP_MUTE_TIME = 3600; #How long to mute alerts for (in seconds) my $time_now; my $prev_time; my $adb_bgp_time; my $mib; my $mail_to = ''; # e.g. jbloggs@example.com my $profile = ''; # e.g. NetEng my $subject = sprintf ("BGP Peer State Change"); my @body; $time_now = time (); # Get the MIB value from the attribute $mib = (split (/\./m, $attr))[0]; # Gets last alert time $adb_bgp_time = adb_result (sprintf ("get %s %s %s.bgpPeerStateAlertTime", $device, $child, $mib)); if (! defined $adb_bgp_time || length($adb_bgp_time) == 0) { adb_send (sprintf ("add integer %s %s %s.bgpPeerStateAlertTime = %s", $device, $child, $mib, $time_now)); $prev_time = 0; } else { $prev_time = $adb_bgp_time; } # Checks last alert time is outside timeout if (($time_now - $prev_time) > $TMP_MUTE_TIME) { push @body, join (" ", $device, $child, $attr, $state); # Send to a single email address if ($mail_to ne "") { mail ({ subject => $subject, to => $mail_to, body => \@body }); } # Send to all email addresses in a profile if ($profile ne "") { for my $addr (config_get_emails ($profile)) { mail ({ subject => $subject, to => $addr, body => \@body }); } } # Update last alert time adb_send (sprintf ("set %s %s %s.bgpPeerStateAlertTime = %s", $device, $child, $mib, $time_now)); } }