perfSONAR_PS::Services::MP::Agent::CommandLine - A module that will run a command and return it's output.
Inherited perfSONAR_PS::MP::Agent::Base class that allows a command to be executed. Specific tools should inherit from this class and override parse() in order to be able to format the command line output in a well understood data structure.
# command line to run, variables are indicated with the '%...%' notation my $command = '/bin/ping -c %count% %destination%'; # options to use, the above keys defined in $command will be # substituted with the following values my %options = ( 'count' => 10, 'destination' => 'localhost', ); # create and setup a new Agent my $agent = perfSONAR_PS::Services::MP::Agent::CommandLine( $command, $options ); $agent->init(); # collect the results (i.e. run the command) if( $mp->collectMeasurements() == 0 ) { # get the raw datastructure for the measurement print "Results:\n" . $self->results() . "\n"; } # opps! something went wrong! :( else { print STDERR "Command: '" . $self->commandString() . "' failed with result '" . $self->results() . "': " . $agent->error() . "\n"; }
Creates a new agent class
$command = complete path to command line tool to run, eg /bin/ping $options = special parsed string of arguments for the tool; this string will have variables replaced at run time $namespace = perfSONAR_PS::XML::Namespace object
accessor/mutator function for the generic command to run (normally set in the constructor). This command should have variable fields marked up between '%'s. For example for a ping we would have something like:
'/bin/ping -c %count% %destination%';
This would then have the values to these variables substituted in at runtime.
accessor/mutator function for the actual command line to run; this would be the run time command after $self->command() has had the relevant variables substituted.
accessor/mutator function for the variable=value set to substitute the $self->command() line with. ie for the ping example with command(), we would have:
$self->command( '/bin/ping -c %count% %destination%' ); $self->options( { 'count' => 10, 'destination' => 'localhost', };
which would result in /bin/ping -c 10 localhost
does anything necessary before running the collect() such as modifying the options etc. Check to see that the command exists
Runs the command with the options specified in constructor. The return of this method should be
-1 = something failed 0 = command ran okay
on success, this method should call the parse() method to determine the relevant performance output from the tool.
Given the output of the command as a ref to an array of strings (\@array), and the original command line that generated those strings ($commandLine) at time $time (epoch secs),
do something with that output and store in into $self->{RESULTS}.
Return:
-1 = could not parse output 0 = everything parsed okay
The data structure is completely arbitary, but should be understood by the inherited class.
To install IEPM::PingER::Statistics::RTT, copy and paste the appropriate command in to your terminal.
cpanm
cpanm IEPM::PingER::Statistics::RTT
CPAN shell
perl -MCPAN -e shell install IEPM::PingER::Statistics::RTT
For more information on module installation, please visit the detailed CPAN module installation guide.