Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Email Status Alert

This is a basic example which shows:

  • How to access parameters passed through from Status Alerting.
  • How to retrieve the IP address of a device from ADB (AKIPS database).
  • How to retrieve sysContact and sysLocation of a device from ADB.
  • How to create and send an email to a single address.
  • How to create and send an email to a profile.

NOTE: This example script:

  • Does not implement any alert bundling.
  • Will generate an email message for every alert passed in from Status Alerting.
sub alert_mail_status
{
   my ($arg_ref) = @_;
   my $mail_to = ''; # e.g. [email protected]
   my $profile = ''; # e.g. NetEng
   my $subject = sprintf ("Status: %s %s %s %s",
                          $arg_ref->{device},
                          $arg_ref->{child},
                          $arg_ref->{descr},
                          $arg_ref->{state});
   my $ipaddr   = adb_result (sprintf ("get %s sys SNMP.ipaddr", $arg_ref->{device}));
   my $contact  = adb_result (sprintf ("get %s sys SNMPv2-MIB.sysContact", $arg_ref->{device}));
   my $location = adb_result (sprintf ("get %s sys SNMPv2-MIB.sysLocation", $arg_ref->{device}));
   my $time_str = strftime ("%H:%M", localtime ($arg_ref->{tt}));
   my @body;

   push @body, join (" ",
                     $time_str,
                     $arg_ref->{device},
                     $ipaddr,
                     #$contact  || "",
                     #$location || "",
                     $arg_ref->{child},
                     $arg_ref->{descr},
                     $arg_ref->{attr},
                     $arg_ref->{alias} || "",
                     $arg_ref->{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 });
      }
   }
}