Email Newly Discovered Devices
This script runs at the end of a Discover and sends an email listing all newly discovered devices.
You will need to configure either $mail_to or $profile in the script below.
sub config_mail_new_devices
{
my ($arg_ref) = @_;
# Set one of the following two parameters
my $mail_to = ''; # e.g. [email protected]
my $profile = ''; # e.g. NetEng
my $subject;
my @body;
my $cnt = 0;
# Get the time of the last discover SNMP scan
my $fstat_ref = file_stat ($DISCOVER_SNMP_SCAN);
my $discover_tt = $fstat_ref->{mtime};
push @body, "The following devices were added into AKIPS:";
push @body, "";
# Inspect the creation time of every device
for my $line (adb_result ("mtime device *")) {
my ($device, undef, $val) = split (" ", $line);
my ($ctime, $mtime, $utime) = split (",", $val);
next if ($ctime < $discover_tt);
# Add this new device into the email body
my $time_str = strftime ("%H:%M", localtime ($ctime));
push @body, sprintf ("%s %s", $time_str, $device);
$cnt++;
}
return if ($cnt == 0);
$subject = sprintf ("Discovered %d new devices", $cnt);
# 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 });
}
}
}