#!/usr/bin/perl use RRDs ; # GENERAL options $html_dir = "/docum.org/project/tc-snmp/example/html" ; # page with an overview of available graphs $tcrrd = "http://home.docum.org/cgi-bin/docum.org/tc-snmp/tcrrd2.pl" ; # Place and name of the cgi-script on your webserver. You don't have to specify the server name, but I have because I upload the pages to www.docum.org $dir_rrd = "/docum.org/project/tc-snmp/example/data" ; # Place where databases are stored. Make sure your webserver has read access to this dir. # SNMP options # Name or ip-address of the snmp-server $host = "kriek" ; # Read community to access the snmp-server $community = "public" ; # Snmp version $version = "2" ; # OID to query on the snmp-server $oid = ".1.3.6.1.4.1.18756" ; ##### No editing needed below this line ############## #$DEBUG = "yes" ; # Uncomment to get debug info # Check for the rrd-locatie directory if ( ! -d $dir_rrd ) { print "$dir_rrd : not found, Exitting\n" ; exit ; } # Start a new snmp session use Net::SNMP ; ($session, $error) = Net::SNMP->session( -hostname => $host, #-port => $port, #-localaddr => $localaddr, #-localport => $localport, #-nonblocking => $boolean, -version => $version, #-timeout => $seconds, #-retries => $count, #-maxmsgsize => $octets, #-translate => $translate, #-debug => $debugmask, -community => $community, # v1/v2c #-username => $username, # v3 #-authkey => $authkey, # v3 #-authpassword => $authpasswd, # v3 #-authprotocol => $protocol, # v3 #-privkey => $privkey, # v3 #-privpassword => $privpasswd, # v3 ); if (!defined($session)) { printf("ERROR: %s.\n", $error); exit 1; } # Get all the counters my $result = $session->get_table( -baseoid => $oid ); if (!defined($result)) { printf("ERROR: %s.\n", $session->error); $session->close; exit 1; } open (MRTG, ">$html_dir/mrtg.cfg") || die "Can not open $html_dir/mrtg.cfg for writing.\n"; $counter = "0" ; # Process all the counters foreach $key (keys (%{$result})) { @split = split '\.', $key ; $major_minor = $split[-1] ; if ( $major_minor eq "0" ) { next ; } else { $minor = $major_minor % 65536 ; $minor = lc(sprintf'%X', $minor ) ; # Dec -> Hex $major = $major_minor / 65536 ; $major = lc(sprintf'%X', $major ) ; # Dec -> Hex } $device = $split[-2] ; $date_type = $split[-3] ; if ( $date_type eq "6" ) { push @{$child{$device}{$result->{$key}}}, "$major:$minor" ; } elsif ( $date_type eq "7" ) { $interface{$device} = $result->{$key} ; $interface{$device}{"$major:$minor"} = $result->{$key} ; } elsif ( $date_type eq "8" ) { $type{$device}{"$major:$minor"} = $result->{$key} ; } elsif ( $date_type eq "9" ) { $bytes{$device}{"$major:$minor"} = $result->{$key} ; mrtg_info ("Bytes") ; } elsif ( $date_type eq "10" ) { $packets{$device}{"$major:$minor"} = $result->{$key} ; mrtg_info ("Packets") ; } elsif ( $date_type eq "11" ) { $dropped{$device}{"$major:$minor"} = $result->{$key} ; mrtg_info ("Dropped") ; } elsif ( $date_type eq "12" ) { $overlimit{$device}{"$major:$minor"} = $result->{$key} ; # } else { # print "Major:Minor = $major:$minor\n" ; # print " date_type : $date_type\n" ; # print " Result : $result->{$key}\n" ; } } close MRTG ; sub mrtg_info { $counter ++ ; print MRTG "Target[router_$counter]: $key&$key:public\@$host\n" ; print MRTG "MaxBytes[router_$counter]: 100000000000\n" ; print MRTG "Title[router_$counter]: Class $major:$minor\n" ; print MRTG "PageTop[router_$counter]: