#!/usr/bin/perl use strict; use warnings; use Proc::Daemon; use Proc::PID::File; use Cwd; use Getopt::Std; sub usage() { print STDERR << "EOF"; This program monitors an IP at set interval for a specified duration of time. usage: [UDsrtmLRAch] [-i interval] [-d duration] [-C string] [-n name] ip -i seconds : The interval in seconds on which to send a ping (default = 10) -d seconds : The total number of seconds to run the test (default = 86400 or 1 day) -n name : Name for the RRD archive (default = current time stamp) -C string : SNMP community string (default = community) -U : Upstream bits -D : Downstream bits -s : SNR -r : RX power -t : tx power -m : micro-reflections -L : Lost Downstream Syncs -R : Resets -A : Aborted Ranging attempts -c : Channel ID -h : Display this dialog EOF exit; } my %opt; getopts("n:i:d:C:UDsrtmLRAch", \%opt); usage() if $opt{h}; my $interval = $opt{i} || 60; my $duration = $opt{d} || 86400; my $name = $opt{n} || $ARGV[0]; my $string = $opt{C} || 'community'; my $ip = $ARGV[0] or usage(); my $pwd = getcwd(); my ($DS, $start, $finish, $elap, $ping_time); my $now = time(); my $stop = $now + $duration; my $int_end = $interval*2; my $points = $duration/$interval; $DS .= " DS:Upstream:COUNTER:$int_end:0:U" if $opt{U}; $DS .= " DS:Downstream:COUNTER:$int_end:0:U" if $opt{D}; $DS .= " DS:SNR:GAUGE:$int_end:0:U" if $opt{s}; $DS .= " DS:RX:GAUGE:$int_end:0:U" if $opt{r}; $DS .= " DS:TX:GAUGE:$int_end:0:U" if $opt{t}; $DS .= " DS:micro:GAUGE:$int_end:0:U" if $opt{m}; $DS .= " DS:LostSync:COUNTER:$int_end:0:U" if $opt{L}; $DS .= " DS:Reset:COUNTER:$int_end:0:U" if $opt{R}; $DS .= " DS:Aborts:COUNTER:$int_end:0:U" if $opt{A}; $DS .= " DS:ChannelID:GAUGE:$int_end:0:U" if $opt{c}; `rrdtool create $pwd/$name.rrd --step $interval $DS RRA:LAST:.5:1:$points`; #Proc::Daemon::Init(); my %data; my $key; while(time() < $stop){ $start = time(); my $update_string = "N"; chomp($data{'out'} = `snmpget -v1 -c $string $ip 1.3.6.1.2.1.2.2.1.16.1`) if $opt{U}; chomp($data{'in'} = `snmpget -v1 -c $string $ip 1.3.6.1.2.1.2.2.1.10.1`) if $opt{D}; chomp($data{'snr'} = `snmpget -v1 -c $string $ip 1.3.6.1.2.1.10.127.1.1.4.1.5.3`) if $opt{s}; chomp($data{'rx'} = `snmpget -v1 -c $string $ip 1.3.6.1.2.1.10.127.1.1.1.1.6.3`) if $opt{r}; chomp($data{'tx'} = `snmpget -v1 -c $string $ip 1.3.6.1.2.1.10.127.1.2.2.1.3.2`) if $opt{t}; chomp($data{'micro'} = `snmpget -v1 -c $string $ip 1.3.6.1.2.1.10.127.1.1.4.1.6.3`) if $opt{m}; chomp($data{'lost'} = `snmpget -v1 -c $string $ip 1.3.6.1.2.1.10.127.1.2.2.1.5.2`) if $opt{L}; chomp($data{'resets'} = `snmpget -v1 -c $string $ip 1.3.6.1.2.1.10.127.1.2.2.1.4.2`) if $opt{R}; chomp($data{'aborts'} = `snmpget -v1 -c $string $ip 1.3.6.1.2.1.10.127.1.2.2.1.14.2`) if $opt{A}; chomp($data{'channel'} = `snmpget -v1 -c $string $ip 1.3.6.1.2.1.10.127.1.1.2.1.1.4`) if $opt{c}; foreach $key (keys (%data)){ $data{$key} =~ m/: (\d+)/; $update_string .= ":$1"; } print $update_string; print "\n"; `rrdtool update $pwd/$name.rrd $update_string`; $finish = time(); $elap = $finish - $start; sleep($interval-$elap); }