#!/usr/bin/perl # # (c)2004 Andreas Wassatsch # released under GPLv2 # # based on traceroute.cgi of Ian Cass Knowledge Matters Ltd # (c)1999 Ian Cass Knowledge Matters Ltd # # This script should be put in your Nagios cgi-bin directory # (usually /usr/local/nagios/sbin) # # It will perform a traceroute from your Nagios box to # the machine that the check_ping plugin is pinging, # output includes links to host status and status map # for hosts known to Nagios # # This software is provided as-is, without any express or implied # warranty. In no event will the author be held liable for any mental # or physical damages arising from the use of this script. # # Legal note: # Nagios is a registered trademark of Ethan Galstad. # use strict; use File::Basename; use POSIX qw(strftime); # Global Settings #---------------- $| = 1; my($nagios) = "/usr/local/nagios"; my($urlbase) = "/nagios"; my($refresh) = 30; my($self) = basename($0); my($traceroute) = "/usr/sbin/traceroute -m 20 -q 1"; # Generate HTTP header #--------------------- my($mdate)=`date +"%a, %d %b %Y %H:%M:%S %Z"`; print "Cache-Control: no-store\n"; print "Pragma: no-cache\n"; print "Last-Modified: $mdate"; print "Expires: Thu, 01 Jan 1970 00:00:00 GMT\n"; print "Content-type: text/html\n\n"; # accept either traceroute/foo or traceroute?foo; default to REMOTE_ADDR # if nothing else is specified #----------------------------------------------------------------------- my($addr) = $ENV{PATH_INFO} || $ENV{QUERY_STRING} || $ENV{REMOTE_ADDR}; $addr =~ tr/+/ /; $addr =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $addr =~ s,^addr=,,; $addr =~ s/[^A-Za-z0-9\.-]//g; # for security # HTML Head with META Refresh info / stylesheet #---------------------------------------------- print "\n"; print "\n
\n";
print " traceroute ";
print "Generated by $self"; print "Last Updated: $mdate "; print "Updated every $refresh seconds "; print "Nagios® - www.nagios.org "; print "Logged in as $ENV{'REMOTE_USER'} "; print " |
\n"; print "
Hop | "; print "Host | "; print "IP | "; print "Round Trip Time | "; print "||
---|---|---|---|---|---|
$arr[0] | \n"; # hop print "";
print "
| $arr[2] | \n"; # ip print "$arr[3] | \n"; # rtt print "
"; print "$self by Andreas Wassatsch"; print "\n"; # end #---- exit 0;