SCRIPT: Weathermap example

THIS IS A CUSTOMER GENERATED SCRIPT AND COMES WITH NO WARRANTY OR SUPPORT. PROCEED AT YOUR OWN RISK.
 
APR 2020

sub sched_1m_weathermap_links
{
my $remote_user = "akips"; # e.g. 'www'
my $remote_host = "network-nms.example.com"; # e.g. 10.1.2.3
my $remote_path = "/var/www/html/weathermap"; # e.g. /var/www/html/plugins/weathermap/configs
my $remote_file = "akips.txt";
my $data_file = "/tmp/weathermap.txt";
my %data;
my $OUT;

for my $line (adb_result ("mcalc avg time last1m ifrate * * /^IF-MIB.*BitRate/ any group weathermap-links")) {
my ($device, $interface, $attr, undef, $val) = split (" ", $line, 5);
my $link = sprintf ("%s:%s", $device, $interface);
given ($attr) {
when ("IF-MIB.ifInBitRate") { $data{$link}{inbps} = $val; }
when ("IF-MIB.ifOutBitRate") { $data{$link}{outbps} = $val; }
}
}

open ($OUT, ">", $data_file) || EXIT_FATAL ("Could not create %s", $data_file);
for my $link (keys %data) {
printf $OUT "%s\t%s\t%s\n", $link, $data{$link}{inbps}, $data{$link}{outbps};
}
close $OUT;

if ($remote_user ne "" and $remote_host ne "" and $remote_path ne "" and $remote_file ne "") {
system (sprintf ("/usr/bin/scp -q %s %s@%s:%s/%s", $data_file, $remote_user, $remote_host, $remote_path, $remote_file));
}
}

 

Was this article helpful?

/

Comments

0 comments

Please sign in to leave a comment.