#!/usr/bin/perl # # $Id: snmp-query-graph.txt,v 1.2 2003/01/16 18:36:24 nate Exp $ # # by Nate Campi # various pieces derived from script by Matt Eagleson use RRDs; use SNMP; # Read Configuration Data require "/etc/BINDsnmp.cfg"; # @query_types = qw( A PTR ANY MX NS CNAME SOA SRV AAAA TOTAL ); foreach my $host (@hosts) { my $sess = new SNMP::Session(DestHost => $host, Community => $snmp_community); if (not defined $sess) { print ("ERROR unable to contact $host\n"); next; } # Get the data that all hosts should have # my $vars = new SNMP::VarList( [extOutput,2]); my $values = $sess->get($vars); if ($sess->{ErrorStr}) { print "ERROR $host SNMP failure: $sess->{ErrorStr}\n"; next; } else { -f "$rrd_db_dir/$host/bind.rrd" or create_bind_rrd ($host); @d = split(/[ ]+/, $values); print "$d[0] $d[1] $d[2] $d[3] $d[4] $d[5] $d[6] $d[7] $d[8] $d[9]\n"; RRDs::update ("$rrd_db_dir/$host/bind.rrd", "N:$d[0]:$d[1]:$d[2]:$d[3]:$d[4]:$d[5]:$d[6]:$d[7]:$d[8]:$d[9]"); if ($error=RRDs::error) { print "ERROR updating $rrd_db_dir/$host/bind.rrd: $error\n"; } } } sub create_bind_rrd () { my ($host) = @_; my @datasources = ('DS:A:DERIVE:600:0:U', 'DS:PTR:DERIVE:600:0:U', 'DS:ANY:DERIVE:600:0:U', 'DS:MX:DERIVE:600:0:U', 'DS:NS:DERIVE:600:0:U', 'DS:CNAME:DERIVE:600:0:U', 'DS:SOA:DERIVE:600:0:U', 'DS:SRV:DERIVE:600:0:U', 'DS:AAAA:DERIVE:600:0:U', 'DS:TOTAL:DERIVE:600:0:U'); my @rrds = ('RRA:AVERAGE:0.5:1:576', 'RRA:AVERAGE:0.5:6:576', 'RRA:AVERAGE:0.5:24:576', 'RRA:AVERAGE:0.5:288:576'); mkdir ("$rrd_db_dir/$host", 0755); RRDs::create ("$rrd_db_dir/$host/bind.rrd", @datasources, @rrds); my $ERROR = RRDs::error; if ($ERROR) { print "Unable to create $rrd_db_dir/$host/bind.rrd: $ERROR\n"; } }