#!/usr/bin/perl -T ######################################################## # TAILORING SECTION for NEW Hosts # change these to the right locations #$stats_dir is the directory where the current raw data measured by pinger is saved #$stats_dir = "/nfs/oceanus/u2/pinger/wanmon/data"; my $stats_dir = "/nfs/slac/g/net/pinger/pinger_mon_data"; #Updated 1/23/04 Cottrell/Jerrod my $sites_fn = "/afs/slac/www/comp/net/mon/offsite.nodes"; ################Done with changes####################### use strict; ######################################################## #Get the local host name use Sys::Hostname; my $ipaddr=gethostbyname(hostname()); my ($a, $b, $c, $d)=unpack('C4',$ipaddr); my ($hostname,$aliases, $addrtype, $length, @addrs)=gethostbyaddr($ipaddr,2); ######################################################## #Set up USAGE (my $progname = $0) =~ s'^.*/'';#strip path components, if any my $version="2.0 Aug 6, 2007, Cottrell"; #See beyond __END__ for more my $USAGE = " $progname is a CGI script that enables one to gather the pingER data for a user specified time window for user specified remote sites(). It is acccess via a URL. The default by accessing http:///cgi-bin/ping_data.pl is to display a form allowing the user to select the time and remote site(s). It is also available as a program API (using Lynx or wget) with the user specifying the various parameters as part of the QUERY_STRING. The parameters are: either: begin_year, begin_month, begin_day, begin_hour, begin_min, begin_sec, begin_offset: gives the starting time, begin_ofset is the offset from UDT. end_year, end_month, end_day, end_hour, end_min, end_sec, end_offset: gives the ending time or: begin, end: begin and end times as Unix epoch times. in_form: 1 if no form is to be displayed, undefined otherwise in which case form displayed and exits begin_point: y|n, include or do not include beginning point (default = no). end_point: y|n, see above but replace begnning by ending Examples of URL calls: http://www.slac.stanford.edu/cgi-wrap/$progname?help=1 http://www.comsats.edu.pk/cgi-bin/$progname http://pinger.comsats.edu.pk/cgi-bin/$progname?in_form=1&begin_hour=00&begin_min=00&begin_sec=00&begin_day=06&begin_month=08&begin_year=2007&begin_offset=&begin_point=y&end_hour=23&end_min=59&end_sec=59&end_day=06&end_month=08&end_year=2007&end_offset=&end_point=y More generically http://www.xxx.yyy.zzz/cgi-bin/$progname?site=a&site=b&site=c&begin=x&end=y&begin_point=n&end_point=n http://www.xxx.yy.zzz/cgi-bin/$progname?site=a&site=b&site=c&begin_hour=HH&begin_min=MM&begin_sec=SS&begin_offset=[-]HH&begin_day=DD&begin_month=MM&begin_year=YYYY&end_hour=HH&end_min=MM&end_sec=SS&end_offset=[-]HH&end_day=DD&end_month=MM&end_year=YYYY&begin_point=n&end_point=n The raw PingER data is obtained from the directory $stats_dir The list of remote nodes is obtained from $sites_fn Acknowledgments: $progname originally written by David E. Martin of HEP Network Resource Center, Fermilab, Batavia, IL based on work done by Connie Logg and Les Cottrell at the Stanford Linear Accelerator Center Heavily modified over the yearts by les Cottrell, SLAC Version=$version "; ########################################################## require "timelocal.pl"; require "ctime.pl"; require "/afs/slac/g/www/cgi-lib/cgi-lib.pl"; ########################################################### #Get default time stamps for form my $time=time(); #Unix epoch time for today my ($temp, $mday, $mon, $year); ($temp, $temp, $temp, $mday, $mon, $year, $temp, $temp, $temp) = localtime($time); $year=1900+$year; $mon++; if($mon < 10) {$mon ="0".$mon;} #Add leading zero if($mday < 10) {$mday="0".$mday;} #Add leading zero my $yday=$mday-1; if($yday<=0) {$yday="01"}; my $stats_base_fn = "ping-"; # put all values from command line into $in associative array our %in; &ReadParse; #CGI::ReadParse(*in); # If the host is at slac.stanford.edu then use cgi-wrap else use cgi-bin my $cgi_bin="cgi-bin"; if($hostname =~ /.+\.slac\.stanford\.edu/) {$cgi_bin="cgi-wrap";} ############################################################################# #If help requested then provide it if (defined($in{'help'})) { print "Status: 200 OK\nContent-type: text/html\n\n" . "ping_data.pl Help\n" . "

Help for http://$hostname/$cgi_bin/ping_data.pl

\n" . "
$USAGE
\n"; exit 100; } ############################################################################# # if in_form not defined then return the form. if (!defined $in{'in_form'}) { print <<'EOM'; "Status: 200 OK Content-type: text/html EOM print "Get Ping Data from $hostname\n" . "\n" . "

Get Ping Data from $hostname

\n" . "This is a test form to retrieve ping data from $hostname " . "using $progname version=$version\n"; print <<'EOM1'; There are similar retrieval scripts running elsewhere. Most of the time the data will be retrieved by automated scripts. This form is a good way of testing installations and looking at up-to-the-minute data.
Please note SLAC no longer makes all data available via this web page. Only the most recent data is available here. Older data is available by anonymous FTP.
EOM1 print "
\n" . " \n"; my ($node,$site)=split(/\./,$hostname,2); print "Ping Data from $site to:\n" . "\n" . "Note: Selecting no site will cause data for all $nodes sites to be returned.\n"; print <<'EOM';
EOM print "
Start
HH:MM:SS
DD:MM:YYYY
Offset from GMT
Endpoint
: : \n" . " :\n" . " :\n" . " \n"; print <<'EOM';
Include
EOM print "
End
HH:MM:SS
DD:MM:YYYY
Offset from GMT

Endpoint

: : \n" . " :\n" . " :\n" . " \n"; print <<'EXECUTE';
Include

EXECUTE print "Form created by $0 version=$version.\n" . "Raw PingER data obtained from $stats_dir. " . "Remote sites obtained from $sites_fn. \n" . "The most current version of this script and instructions to install can be found at: " . "" . "Installing ping_data.pl and traceroute.pl for PingER2." . "There is USAGE " . "information on the script."; exit; } ############################################################################# #Not requesting help or a form so provide results else { print <<'EOM'; Status: 200 OK Content-type: text/plain EOM } my ($begin, $end); if (defined $in{'begin_hour'}) { $begin = &timegm($in{'begin_sec'},$in{'begin_min'},$in{'begin_hour'},$in{'begin_day'}, ($in{'begin_month'} -1), ($in{'begin_year'} -1900)); $begin = $begin - ($in{'begin_offset'} *3600); $end = &timegm($in{'end_sec'},$in{'end_min'},$in{'end_hour'},$in{'end_day'}, ($in{'end_month'} -1), $in{'end_year'} -1900); $end = $end - ($in{'end_offset'} *3600); } elsif (defined $in{'begin'}) { $begin = $in{'begin'}; $end = $in{'end'}; } else { print "No begin and end times\n"; exit; } # if no sites specified, return all sites my $all_sites; my %site_list; if (!defined $in{'sites'}) { $all_sites = 1; } else { $all_sites = 0; # put (lower-cased) site names in associate array for easy checking for (split(/\0/, $in{'sites'})) { tr/A-Z/a-z/; $site_list{$_} = 1; } } # Exclude the end points unless begin_point (or end_point) is specfied. if ($in{'begin_point'} ne 'y') { ++$begin } if ($in{'end_point'} ne 'y') { --$end } if ($end < $begin) { print "End < Begin\n"; exit; } my ($begin_sec, $begin_min, $begin_hour, $begin_mday, $begin_mon, $begin_year, $begin_wday, $begin_yday, $begin_isdst) = gmtime($begin); my ($end_sec, $end_min, $end_hour, $end_mday, $end_mon, $end_year, $end_wday, $end_yday, $end_isdst) = gmtime($end); # Add 2 minutes of "fuzz" to the timestamp search limits to allow for # the timestamps' being a little out of strict sort order. my $begin_search = $begin - 120; my $end_search = $end + 120; my $fn; # for $month ((($begin_year +1900) * 12 + $begin_mon +1).. # (($end_year+1900) * 12 + $end_mon +1)) { # $fn = sprintf("%s/%s%4.4d-%2.2d.txt", $stats_dir, # $stats_base_fn, int($month / 12), $month % 12) # # for $month ((($begin_year +1900) * 12 + $begin_mon ).. # (($end_year+1900) * 12 + $end_mon )) { # $fn = sprintf("%s/%s%4.4d-%2.2d.txt", $stats_dir, # $stats_base_fn, int($month / 12), ($month % 12) +1); my $nline=0; for my $month ((($begin_year +1900) * 12 + $begin_mon )..(($end_year+1900) * 12 + $end_mon)) { $fn = sprintf("%s/%s%4.4d-%2.2d.txt", $stats_dir, $stats_base_fn, int($month / 12), ($month % 12) +1); if (!open(PINGDATA, $fn)) { print "#Warning $progname can't open $fn: $!"; next; } # print "Opened $fn\n"; # Use a binary search to quickly position the PINGDATA file to a little # before the $begin timestamp data. &SeekBinSrch(*PINGDATA, $begin_search, 1500); while () { my ($src_name, $src_ip, $dest_name, $dest_ip, $pingsize, $ctime) = split(/\s+/, $_); # The following 5 lines are optimized for speed at the expense of beauty. next if ($ctime < $begin); if ($ctime > $end) { if ($ctime < $end_search) {next;} last; } $nline++; $dest_name =~ tr/A-Z/a-z/; print if (defined $site_list{$dest_name} || $all_sites); } # while () close (PINGDATA); } # for $month if($nline<=0) {print "No data between dates specified found in $fn\n"} ############################################################################# sub SeekBinSrch # ( *FH, $key, $close_enough ) # Subroutine to seek to the vicinity of the $begin data records in the # ping_data file using a binary search. The binary search only attempts # to get within $close_enough bytes of the "exact" position in the sorted # file which contains the search key (or, if no such record exists in the # file, then to where such a record would be placed if it existed). # More precisely, the binary search finds a region of the file such that # (1) the size of the region is less than or equal to $close_enough bytes; # (2) the beginning of the region is the beginning of a record whose key is # less than or equal to the search key if such a record exists, otherwise # the start of the region is the start of the file; and # (3) the first record that begins after the end of the region has a key # which is greater than or equal to the search key if such a record # exists, otherwise the end of the region is the end of the file. # The file is left positioned to the beginning of the region. # # Author: John Halperin 6 June 1997. { local(*FH) = $_[0]; my($key, $close_enough) = @_[1..2]; my($lo_posn, $hi_posn); # return unless (defined());#remove warning "Value of construct can be "0"; test with defined()" return unless (-f FH); # can't handle pipes or other oddities $lo_posn = 0; $hi_posn = (-s FH) or die "BinSrchFile: error stat'ing FH: $!\n"; my $loop_ct = 0; my($mid_posn, $rec_start, $rec, $rec_key, $lt_eq_gt, $errct); BinSrch: while (($hi_posn - $lo_posn) > $close_enough && ++$loop_ct < 40) { $mid_posn = ($lo_posn + $hi_posn) >> 1; seek(FH, $mid_posn, 0) or die "BinSrchFile: seek($mid_posn) failed: $!\n"; ; # skip to start of next record for ($errct = 0; ; ) { $rec_start = (tell); last BinSrch if ($rec_start >= $hi_posn); $rec = or die "SeekBinSrch: error reading file: $!\n"; $rec_key = (split(/ /, $rec, 7))[5]; last if (defined($rec_key) && $rec_key =~ m/^\d+$/); warn "BinSrchFile: record at posn $rec_start has a bad timestamp\n", "*** $rec"; die "BinSrchFile terminating\n" if (++$errct > 10); } $lt_eq_gt = $key - $rec_key; if ($lt_eq_gt < 0) { $hi_posn = $mid_posn; # srch key < rec, so drop ceiling } elsif ($lt_eq_gt > 0) { $lo_posn = $rec_start; # srch key > rec, so raise floor } else { $hi_posn = $lo_posn = $rec_start; # key == rec; found. } } # BinSrch: while () die "BinSrchFile failed; looping?\n" if (($hi_posn - $lo_posn) > $close_enough); seek(FH, $lo_posn, 0) or die "BinSrchFile: seek($lo_posn) failed: $!\n"; } # &SeekBinSrch() __END__ ########################### Copyright Notice ################################### # Copyright (c)1996 Universities Research Association, Inc. # # All Rights Reserved # # /*---------------------------------------------------------------*/ # /* STANFORD UNIVERSITY NOTICES FOR SLAC SOFTWARE */ # /* ON WHICH COPYRIGHT IS DISCLAIMED */ # /* */ # /* AUTHORSHIP */ # /* This software was created by , Stanford Linear */ # /* Accelerator Center, Stanford University. */ # /* */ # /* ACKNOWLEDGEMENT OF SPONSORSHIP */ # /* This software was produced by the Stanford Linear Accelerator */ # /* Center, Stanford University, under Contract DE-AC03-76SFO0515 */ # /* with the Department of Energy. */ # /* */ # /* GOVERNMENT DISCLAIMER OF LIABILITY */ # /* Neither the United States nor the United States Department of */ # /* Energy, nor any of their employees, makes any warranty, */ # /* express or implied, or assumes any legal liability or */ # /* responsibility for the accuracy, completeness, or usefulness */ # /* of any data, apparatus, product, or process disclosed, or */ # /* represents that its use would not infringe privately owned */ # /* rights. */ # /* */ # /* STANFORD DISCLAIMER OF LIABILITY */ # /* Stanford University makes no representations or warranties, */ # /* express or implied, nor assumes any liability for the use of */ # /* this software. */ # /* */ # /* STANFORD DISCLAIMER OF COPYRIGHT */ # /* Stanford University, owner of the copyright, hereby disclaims */ # /* its copyright and all other rights in this software. Hence, */ # /* anyone may freely use it for any purpose without restriction. */ # /* */ # /* MAINTENANCE OF NOTICES */ # /* In the interest of clarity regarding the origin and status of */ # /* this SLAC software, this and all the preceding Stanford */ # /* University notices are to remain affixed to any copy or */ # /* derivative of this software made or distributed by the */ # /* recipient and are to be affixed to any copy of software made */ # /* or distributed by the recipient that contains a copy or */ # /* derivative of this software. */ # /* */ # /* SLAC Software Notices, Set 4 (OTT.002a, 2004 FEB 03) */ # /*---------------------------------------------------------------*/ # Copyright (c) 2006, 2007 # The Board of Trustees of # the Leland Stanford Junior University. All Rights Reserved. # # *** changes in version 1.1.1 # - selecting no sites returns all sites # - refer to /usr/local/netmon # *** changes in version 1.1.2 # - fast skip to starting time, and exit after ending time # *** changes in version 1.1.4, June 24, 2006 # - Provide default dates and times in form boxes # - Sort the sites, increase the size of box, compress output # *** changes in version 1.1.5, July 20, 2006 # - Automate getting the hostname and add version number output. # - Correct URL for getting FTP data. # *** changes in version 1.1.6 August 18, 2006, Les Cottrell # Check if running on host at slac.stanford.edu, if so use cgi-wrap, else use cgi-bin # Add warning if can't open file # *** changes in version 1.1.7 March 29, 2007, Les Cottrell # use #!/usr/bin/perl -- rather than #!/usr/local/bin/perl5 # *** changes in version 1.1.8 May 30, 2007 # Report no data found in file. # Prevent $yday going < 01 #my $version="1.1.8, 5/30/07, Cottrell."; # *** changes in version 2.0 8/6/07, add help, use strict -T minos.slac.stanford.edu 134.79.196.100 dukhet.phy.duke.edu 152.3.57.20 100 862526343 10 10 90 106 133