
VBTK::Wrapper::Ping - System monitoring with 'ping'

$obj = new VBTK::Wrapper::Ping( Host => 'myhost1'); $obj->addVBObj(VBObjName => '.myhost1.ping'); $obj = new VBTK::Wrapper::Ping( Host => 'myhost2'); $obj->addVBObj(VBObjName => '.myhost2.ping'); # Call this at the very end to start looping and checking everything VBTK::runAll;

This perl library is a front-end to the VBTK::Wrapper class. It supports the same public methods as the VBTK::Wrapper class, but with common defaults to simplify the setup of a 'ping' monitoring process.

The following methods are supported
This method calls 'new VBTK::Wrapper' after defaulting the parameters to run and monitor the 'ping' command. For a detailed description of the parameters, see VBTK::Wrapper. Only 1 parameter 'Host' is required. The rest are defaulted appropriately, but if you don't like the defaults, you can override their settings. The defaults are as follows:
Hostname you want to ping. This is the one parameter which must be specified! (Required)
Host => 'myhost1'
Interval => 60,
Defaults to run the 'ping' command with the parameters listed below. You may need to specify this instead, if your 'ping' is in a different location, or uses different parameters.
# On Windows or Cygwin
Execute => "ping -n 1 <Host>",
# On Linux
Execute => "ping -c 1 <Host>",
# All others
Execute => "ping -s <Host> 56 1",
Defaults to the following pre-processor subroutine. This parses through all the output of the 'ping' command, picking out the response time and packet loss values, and then replaces the whole array of output with a single row of host, ip, response-time, and packet loss.
PreProcessor = sub {
my($data) = @_;
my($respTime,$pktLoss,$host,$ip,$msg) = (0,100);
foreach (@{$data}) {
if(/bytes from (\S+) \(([\d\.]+)\): icmp_seq=\d+.+time=(\d+)/) {
($host,$ip,$respTime) = ($1,$2,$3); next; }
if(/Pinging (\S+) \[([\d\.]+)\]/) { ($host,$ip) = ($1,$2); next; }
if(/Average =\s+(\d+)ms/) { ($respTime) = ($1); next; }
if(/(\d+)\% (packet )?loss/) { $pktLoss = $1; next; }
if(/PING|^\s*$|^round-trip|Approximate|statistics|Reply from/) { next; }
}
# Now replace everything in the $data array with a single line
@{$data} = ([ $host, $ip, $respTime, $pktLoss ]);
};
A URI which specifies which VB Server to report results to. Defaults to the environment variable $VBURI.
VBServerURI => $VBURI,
VBHeader => [
' Resp Pkt',
'Time HostName IP Time (ms) Loss (%)',
'------------------ -------------------------- --------------- --------- --------' ],
VBDetail => [
'@<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<< @>>>>>>>> @>>>>>>>',
'$time, @data[0..3]' ],
Same as VBHeader
Same as VBDetail
Timeout => 15,
TimeoutStatus => 'Warn',
NonZeroExitStatus => 'Warn',
DebugHeader => 'Ping <Host>',
This method calls VBTK::Wrapper::addVBObj after defaulting unspecified parameters to best monitor the 'ping' command. For a detailed description of the addVBObj parameters, see VBTK::Parser. The defaults are as follows. If you like all the defaults then you don't have to pass in any parms
VBObjName => ".<Host>.cpu",
TextHistoryLimit => 30,
ReverseText => 1,
If the response time > 250 or packet loss > 0, then set to Warning.
Rules => {
'(($data[2] > 250)||($data[3] > 0))' => 'Warn' },
StatusHistoryLimit => 30,
StatusUpgradeRules =>
'Upgrade to Failed if Warning occurs 2 times in (<Interval> * 3) sec',
ExpireAfter => (<Interval> * 3) seconds
Description = qq(
This object uses the 'ping' command to monitor '<Host>'. It will set the
status to 'Warning' if the ping command loses any packets or if the response
time is greater than 250ms.
);
Store the response time and packet loss in the rrd library.
RrdColumns => [ '$data[2]', '$data[3]' ],
RrdMin => 0,
In addition to passing these defaults on in a call to VBTK::Wrapper::addVBObj, this method captures the resulting VBTK::ClientObject pointer ($vbObj) and makes the following calls to '$vbObj->addGraphGroup':
$vbObj->addGraphGroup (
GroupNumber => 1,
DataSourceList => ':0',
Labels => 'Response Time (ms)',
Title => "Ping <Host>",
);
$vbObj->addGraphGroup (
GroupNumber => 2,
DataSourceList => ':1',
Labels => 'Packet Loss %',
Title => "Ping <Host>",
);
This defines two graphGroups for the VBObject. See VBTK::ClientObject for details on the 'addGraphGroup' method.

VBTK, VBTK::Wrapper, VBTK::Parser, VBTK::ClientObject, VBTK::Server

Brent Henry, vbtoolkit@yahoo.com

Copyright (C) 1996-2002 Brent Henry
This program is free software; you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as published by the Free Software Foundation available at: http://http://www.gnu.org/copyleft/gpl.html
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.