sub alert_mail_threshold { my ($arg_ref) = @_; # Modify the following parameters my $mail_to = ''; # e.g. jbloggs@example.com my $profile = ''; # e.g. NetEng # Get the IP address of the device which triggered the alert my $ipaddr = adb_result (sprintf ("get %s sys SNMP.ipaddr", $arg_ref->{device})); my $time_str = strftime ("%H:%M", localtime ($arg_ref->{tt})); my $child = ""; my $thr = $arg_ref->{thr}; my $val = $arg_ref->{val}; my $subject; my @body; my $msg; # Parse the MIB and object which triggered the alert my ($mib, $obj) = split (/\./m, $arg_ref->{attr}, 2); # Apply formatting to interface thresholds if ($mib eq "IF-MIB") { given ($obj) { when (/if.*BitRate/m) { $thr = int_ifspeed ($thr); $val = int_ifspeed ($val); } when (/if.*Util/m) { $thr = int_util ($thr); $val = int_util ($val); } default { $thr = int_metric ($thr); $val = int_metric ($val); } } trim $val; $child = $arg_ref->{child}; # interface name } # Set the email subject $subject = sprintf ("%s: %s %s %s %s %s %s %s %s", $arg_ref->{alias} || "", $arg_ref->{device}, $child, $arg_ref->{descr}, $arg_ref->{lastn}, $arg_ref->{stat}, # avg or total $val, # calculated value $arg_ref->{state}, # above or below $thr); # threshold value # Set the email body $msg = sprintf ("%s %s %s %s %s %s %s %s %s %s %s", $time_str, $arg_ref->{alias} || "", $arg_ref->{device}, $ipaddr, $child, $arg_ref->{descr}, $arg_ref->{lastn}, $arg_ref->{stat}, # avg or total $val, # calculated value $arg_ref->{state}, # above or below $thr); # threshold value trim $subject; trim $msg; push @body, $msg; # 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 }); } } }