fpingwrapper.pl 1.25 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
#!/usr/bin/perl -w
#
# EMULAB-COPYRIGHT
# Copyright (c) 2006, 2007 University of Utah and the Flux Group.
# All rights reserved.
#


use strict;

my %params = (@ARGV);
my $execpath = "/tmp/fping";
my %ERRID = (  #kept the same as defined in libwanetmon for backwards compatibility
    unknown => -3,
    timeout => -1,
    unknownhost => -4,
    ICMPunreachable => -5
    );

#
# Check for existence of all required params
#
# TODO

#
# Add optional args, if they exist
#
my %optional_exec_args; #TODO

#
# Form arguments specific to this execuable
#
my $execargs = " -t $params{timeout} -s -r $params{retries} $params{target}";


#
# Execute testing application
#
#print "FPING WRAPPER... executing= $execpath $execargs\n";
my $raw = `sudo $execpath $execargs 2>&1`;
#print "FPING WRAPPER... parsing raw= $raw\n";

#
# Parse output
#
$_ = $raw;
my $measr = 0;
my $error = 0;

if( /^ICMP / )
{
    $error = $ERRID{ICMPunreachable};
}elsif( /address not found/ ){
    $error = $ERRID{unknownhost};
}elsif( /2 timeouts/ ){
    $error = $ERRID{timeout};
}elsif( /[\s]+([\S]*) ms \(avg round trip time\)/ ){
    $measr = "$1" if( $1 ne "0.00" );
}else{
    $error = $ERRID{unknown};
}


#print "MEASR=$measr, ERROR=$error\n";


#
# Output result
#
print "latency=$measr,error=$error\n";