#!/usr/bin/perl -w # # by Nate Campi # various pieces derived from script by Matt Eagleson # # $Id: ns.txt,v 1.2 2003/01/16 18:33:46 nate Exp $ # use strict; use CGI qw/:standard/; use RRDs; # Read Configuration Data require "/etc/BINDsnmp.cfg"; my $cgi_url = "http://YOUR.HOST.HERE/cgi-bin/ns.cgi"; print header, start_html("DNS Server stats"); # long term stats my $cur = CGI->new(); # current request if ($cur->param("host")) { # we got a host param, need to graph long term stats my $rrd_db_dir = '/usr/local/BINDsnmp'; my $tainted_host = $cur->param("host"); $tainted_host =~ /([\w\d.-]+)/; my $host = "$1"; print "
\n"; print "

Long Term DNS Server stats

\n"; print "

Long term stats for $host

\n"; print "Scripts by Nate Campi \n"; print "
\n"; my ( $graph_dir, $RRDhost, ); -d "$rrd_db_dir/$host" or error_msg ("Host $host has no dir"); -r "$rrd_db_dir/$host/bind.rrd" or error_msg ("Reading $rrd_db_dir/$host/bind.rrd, $!"); -d "$graph_dir/$host" or mkdir ("$graph_dir/$host", 0755); print "
", "[ Back ]\n", "
"; print h3 ("$host: Last 48 Hours"); &graph_net ($host, 'e-48h'); print "
", "[ Back ]\n", "
"; print h3 ("$host: Last 12 Days"); &graph_net ($host, 'e-12d'); print "
", "[ Back ]\n", "
"; print h3 ("$host: Last 48 Days"); &graph_net ($host, 'e-48d'); print "
", "[ Back ]\n", "
"; print h3 ("$host: Last 576 Days"); &graph_net ($host, 'e-576d'); print "
", "[ Back ]\n", "
"; print "
\n"; print "\n"; exit; } else { # short term stats print "DNS Server stats \n"; print "\n"; print "\n"; print "
\n"; print "

48 hour DNS Server stats

\n"; print "

Click on the graph itself for long term stats

\n"; print "Scripts by Nate Campi <nate\@wired.com>\n"; print "

\n"; our ( @hosts, ); foreach my $tainted_host (@hosts){ my ( $host, ); $tainted_host =~ /([\w\d.-]+)/; $host = $1; my ( $graph_dir, $RRDhost, ); my $rrd_db_dir = '/usr/local/BINDsnmp'; -d "$rrd_db_dir/$host" or error_msg ("Host $host has no dir"); -r "$rrd_db_dir/$host/bind.rrd" or error_msg ("Reading $rrd_db_dir/$host/bind.rrd, $!"); -d "$graph_dir/$host" or mkdir ("$graph_dir/$host", 0755); print h3 ("$host: Last 48 Hours"); print "\n"; &graph_net ($host, 'e-48h'); print "\n"; print "
\n"; } print "
\n"; print "\n"; exit; } sub graph_net { my ($host, $start) = @_, my ($err, @int_args) = (); my $rrd_db_dir = '/usr/local/BINDsnmp'; my $now = localtime(); my @query_types = qw( A PTR ANY MX NS CNAME SOA SRV AAAA TOTAL ); my $i = 0; my @c = ("000088", "008800", "880000", "880088", "888800", "008888", "888888"); foreach my $interface (@query_types) { push (@int_args, "DEF:j$i=$rrd_db_dir/$host/bind.rrd:$query_types[$i]:AVERAGE", #"LINE2:j$i#$c[$i%7]:$host $query_types[$i] queries/sec", "LINE2:j$i#$c[$i%7]:$query_types[$i] queries/sec", "GPRINT:j$i:LAST:Current\\: %5.2lf%s", "GPRINT:j$i:MIN:Min\\: %5.2lf%s", "GPRINT:j$i:AVERAGE:Average\\: %5.2lf%s", "GPRINT:j$i:MAX:Max\\: %5.2lf%s\\j",); $i++; } my ($averages,$xsize,$ysize) = RRDs::graph ("/usr/local/apache/htdocs/pngs/$host.$start.gif", '--lazy', '-w', '576', '-s', $start, '--title', "DNS queries", @int_args, 'COMMENT:\s', "COMMENT:$now"); if ($err = RRDs::error) { error_msg ("while updating /usr/local/apache/htdocs/pngs/$host.$start.gif $err"); } print "
\n"; } sub error_msg { my ($mesg) = @_; print "
", "ERROR: $mesg", "
", end_html; exit; }