[-]
[+]
|
Changed |
check_tcptraffic.spec
|
|
[-]
[+]
|
Changed |
check_tcptraffic-2.2.3.tar.bz2/Changes
^
|
@@ -1,3 +1,12 @@
+2011-03-05 Matteo Corti <matteo.corti@id.ethz.ch>
+
+ * check_tcptraffic: corrected a bug in the handling of counter
+ overflows
+
+2011-02-17 Matteo Corti <matteo.corti@id.ethz.ch>
+
+ * check_tcptraffic: added a debug log
+
2011-02-10 Matteo Corti <matteo.corti@id.ethz.ch>
* nagiosgrapher: added the nagiorgrapher template (thanks to Marcus Schopen)
|
[-]
[+]
|
Changed |
check_tcptraffic-2.2.3.tar.bz2/META.yml
^
|
@@ -22,7 +22,8 @@
Nagios::Plugin: 0
Nagios::Plugin::Range: 0
Nagios::Plugin::Threshold: 0
+ Readonly: 0
version: 0
resources:
license: http://opensource.org/licenses/gpl-license.php
-version: 2.2.2
+version: 2.2.3
|
[-]
[+]
|
Changed |
check_tcptraffic-2.2.3.tar.bz2/Makefile.PL
^
|
@@ -27,6 +27,7 @@
requires 'Nagios::Plugin' => 0;
requires 'Nagios::Plugin::Range' => 0;
requires 'Nagios::Plugin::Threshold' => 0;
+requires 'Readonly' => 0;
requires 'version' => 0;
install_script 'check_tcptraffic';
|
[-]
[+]
|
Changed |
check_tcptraffic-2.2.3.tar.bz2/NEWS
^
|
@@ -1,3 +1,5 @@
+2011-02-17 2.2.3 Added an optional debug log and corrected a bug in the handling of
+ counter overflows
2011-02-10 2.2.2 Added the NagiosGrapher tempkate (Marcus Schopen)
2010-11-03 2.2.1 Fixed a minor bug in error handling
2010-10-21 --critical and --warning now accept ranges (low:high)
|
[-]
[+]
|
Changed |
check_tcptraffic-2.2.3.tar.bz2/VERSION
^
|
@@ -1 +1 @@
-2.2.2
+2.2.3
|
[-]
[+]
|
Changed |
check_tcptraffic-2.2.3.tar.bz2/check_tcptraffic
^
|
@@ -18,10 +18,10 @@
# enable substitution with:
# $ svn propset svn:keywords "Id Revision HeadURL Source Date"
#
-# $Id: check_tcptraffic 1218 2011-02-10 06:36:18Z corti $
-# $Revision: 1218 $
+# $Id: check_tcptraffic 1227 2011-03-06 09:12:22Z corti $
+# $Revision: 1227 $
# $HeadURL: https://svn.id.ethz.ch/nagios_plugins/check_tcptraffic/check_tcptraffic $
-# $Date: 2011-02-10 07:36:18 +0100 (Thu, 10 Feb 2011) $
+# $Date: 2011-03-06 10:12:22 +0100 (Sun, 06 Mar 2011) $
use strict;
use warnings;
@@ -32,8 +32,14 @@
use Nagios::Plugin;
use Nagios::Plugin::Range;
use Nagios::Plugin::Getopt;
+use Readonly;
-our $VERSION = '2.2.2';
+################################################################################
+# constants
+
+our $VERSION = '2.2.3';
+
+Readonly my $MAX_LONG => 2**32;
# IMPORTANT: Nagios plugins could be executed using embedded perl in this case
# the main routine would be executed as a subroutine and all the
@@ -48,14 +54,15 @@
use vars qw(
$help
+ $log_file
$options
+ $os_64_bit
$plugin
$result
- $threshold
$status
$status_msg
+ $threshold
$tmp
- $os_64_bit
);
##############################################################################
@@ -64,9 +71,49 @@
use subs qw(verbose);
##############################################################################
+# Usage : debug( "message" )
+# Purpose : writes a debugging message to the console and optionally to the
+# debugging log file
+# Returns : n/a
+# Arguments : the debugging message
+# Throws : n/a
+# Comments : n/a
+# See also : n/a
+sub debug {
+
+ my $message = shift;
+
+ chomp $message;
+
+ if ( $options->debug() ) {
+ print "[DEBUG] $message\n"; ## no critic (RequireCheckedSyscalls)
+ }
+
+ if ( $options->debug_log() ) {
+
+ open $log_file, '>>', $options->debug_log()
+ or $plugin->nagios_exit( UNKNOWN,
+ 'Cannot open ' . $options->debug_log() . ": $OS_ERROR" );
+
+ print {$log_file} time
+ . " $message\n"
+ or $plugin->nagios_exit( UNKNOWN,
+ 'Cannot write to ' . $options->debug_log() . ": $OS_ERROR" );
+
+ close $log_file
+ or $plugin->nagios_exit( UNKNOWN,
+ 'Cannot close ' . $options->debug_log() . ": $OS_ERROR" );
+
+ }
+
+ return;
+
+}
+
+##############################################################################
# Usage : running_on_linux()
# Purpose : check if running on a Linux system
-# Returns : true if runnint on Linux
+# Returns : true if running on Linux
# Arguments : n/a
# Throws : n/a
# Comments : also checks if the OS is 64 bit capable and sets $os_64_bit
@@ -100,15 +147,14 @@
while (<$output>) {
chomp;
$os_64_bit = ( $_ eq 'x86_64' );
- if ( $options->debug() ) {
- if ($os_64_bit) {
- print '[DEBUG] 64'; ## no critic (RequireCheckedSyscalls)
- }
- else {
- print '[DEBUG] 32'; ## no critic (RequireCheckedSyscalls)
- }
- print "bit system\n"; ## no critic (RequireCheckedSyscalls)
+ my $message;
+ if ($os_64_bit) {
+ $message = '64';
+ }
+ else {
+ $message = '32';
}
+ debug( $message . 'bit system' );
return $linux;
}
@@ -139,9 +185,7 @@
while (<$output>) {
chomp;
- if ( $options->debug() ) {
- print "[DEBUG] user $_\n"; ## no critic (RequireCheckedSyscalls)
- }
+ debug("user $_");
return $_;
}
@@ -166,22 +210,16 @@
my $TMP; # file handler
- if ( $options->debug() ) {
- print "[DEBUG] initializing timer $tmp\n"; ## no critic (RequireCheckedSyscalls)
- }
+ my $dbg_message = "writing to $tmp";
if ( !open $TMP, q{>}, $tmp ) { ## no critic (RequireBriefOpen)
- if ( $options->debug() ) {
- print "[DEBUG] error: $OS_ERROR\n"; ## no critic (RequireCheckedSyscalls)
- }
+ debug("error: $OS_ERROR");
$plugin->nagios_exit( UNKNOWN, "Cannot initialize timer: $OS_ERROR" );
}
my $line = time . " $in $out\n";
print {$TMP} $line; ## no critic (RequireCheckedSyscalls)
- if ( $options->debug() ) {
- print "[DEBUG] $line"; ## no critic (RequireCheckedSyscalls)
- }
+ debug("$dbg_message: $line");
close $TMP
or $plugin->nagios_exit( UNKNOWN, "Cannot close timer: $OS_ERROR" );
@@ -288,6 +326,7 @@
$data{diff} = time - $time;
$data{in} = $in;
$data{out} = $out;
+ debug("reading old data: $time $in $out after $data{diff}");
}
close $TMP
@@ -340,14 +379,12 @@
$level = 0;
}
- if ( $options->debug() ) {
- print '[DEBUG] '; ## no critic (RequireCheckedSyscalls)
- }
+ debug($message);
if ( $level < $options->verbose()
|| $options->debug() )
{
- print $message; ## no critic (RequireCheckedSyscalls)
+ print $message; ## no critic (RequireCheckedSyscalls)
}
return;
@@ -413,11 +450,22 @@
required => 0,
);
+$options->arg(
+ spec => 'debug_log=s',
+ help => 'generates a log with debugging information',
+ required => 0,
+);
+
$options->getopts();
###############
# Sanity checks
+if ( $options->debug_log() && ( !-w $options->debug_log() ) ) {
+ $plugin->nagios_exit( UNKNOWN, $options->debug_log() . ' is not writable' );
+}
+debug('------------------------------------------');
+
if ( !running_on_linux() ) {
$plugin->nagios_exit( UNKNOWN, 'Not running on a Linux system' );
}
@@ -444,15 +492,14 @@
# 64 bit 2^32 2^64*8 -> 2^67 2^67 / 1024^2 -> 2^47
# 32 bit 2^32 2^32*8 -> 2^35 2^38 / 1024^2 -> 2^15
+#<<<
if ($os_64_bit) {
- $max_check_time =
- int( ( 2**47 - 1 ) / $options->speed() ); ## no critic (ProhibitMagicNumbers)
+ $max_check_time = int( ( 2**47 - 1 ) / $options->speed() ); ## no critic (ProhibitMagicNumbers)
}
else {
- $max_check_time =
- int( ( 2**15 - 1 ) / $options->speed() ); ## no critic (ProhibitMagicNumbers)
+ $max_check_time = int( ( 2**15 - 1 ) / $options->speed() ); ## no critic (ProhibitMagicNumbers)
}
-
+#>>>
verbose
"the counters can hold data for $max_check_time seconds before overflow\n";
@@ -475,7 +522,7 @@
. 's) is greater than the maximum check time allowed with speed '
. $options->speed() . ' ('
. $max_check_time
- . "s):\nsleeping 1s to gather data again\n";
+ . "s): sleeping 1s to gather data again\n";
# time difference is > max_check_time
# since the counter could overflow
@@ -500,21 +547,44 @@
my $traffic_in;
my $traffic_out;
+# in
+
if ( $data{bytes_in} >= $data{in} ) {
$traffic_in = int( ( $data{bytes_in} - $data{in} ) / $data{diff} );
+ debug(
+ "IN: $traffic_in = int( ( $data{bytes_in} - $data{in} ) / $data{diff} )"
+ );
}
else {
- $traffic_in = int( ( $data{in} - $data{bytes_in} ) / $data{diff} );
+
+ # the old value is larger than the new one: the counter overflowed
+ $traffic_in =
+ int( ( $MAX_LONG - $data{in} + $data{bytes_in} ) / $data{diff} );
+ debug(
+"IN (overflow): $traffic_in = int( ( $MAX_LONG - $data{in} + $data{bytes_in} ) / $data{diff} )"
+ );
}
+# out
+
if ( $data{bytes_out} >= $data{out} ) {
$traffic_out = int( ( $data{bytes_out} - $data{out} ) / $data{diff} );
+ debug(
+"OUT: $traffic_out = int( ( $data{bytes_out} - $data{out} ) / $data{diff} )"
+ );
}
else {
- $traffic_out = int( ( $data{out} - $data{bytes_out} ) / $data{diff} );
+
+ # the old value is larger than the new one: the counter overflowed
+ $traffic_out =
+ int( ( $MAX_LONG - $data{out} + $data{bytes_out} ) / $data{diff} );
+ debug(
+"OUT (overflow): $traffic_out = int( ( $MAX_LONG - $data{out} + $data{bytes_out} ) / $data{diff} )"
+ );
}
my $traffic = $traffic_in + $traffic_out;
+debug("TOT: $traffic = $traffic_in + $traffic_out");
$plugin->add_perfdata(
label => 'TOTAL',
|
[-]
[+]
|
Changed |
check_tcptraffic-2.2.3.tar.bz2/check_tcptraffic.pod
^
|
@@ -23,11 +23,11 @@
10Mbit/s 55'
100Mbit/s 5'8"
- q1GBit/s 32s
+ 1GBit/s 32s
=head1 VERSION
-Version 2.2.2
+Version 2.2.3
=head1 SYNOPSIS
@@ -41,10 +41,13 @@
--speed,s speed (in Mbit/s)
Options
+ --debug,d debugging output
+ --debug_log=file generates a log with debugging information
--help,-h,-? this help message
--reset,r initialize counter
--version,V print version and exit
--verbose,v verbose
+
=head1 REQUIRED ARGUMENTS
@@ -58,6 +61,10 @@
--warning=value,-w value number of sectors/s which generates a warning
+ --debug,d debugging output
+
+ --debug_log=file generates a log with debugging information
+
--help,-h,-? help message
--reset,r initialize counter
@@ -78,7 +85,8 @@
=head1 DIAGNOSTICS
You can specify multiple --verbose options to increase the program
-verbosity.
+verbosity. --debug will generate even more debugging output and
+--debug_log will save the debugging information to a file.
=head1 EXIT STATUS
@@ -103,6 +111,8 @@
=item * Nagios::Plugin::Range
+=item * Readonly
+
=item * version
=back
|
[-]
[+]
|
Changed |
check_tcptraffic-2.2.3.tar.bz2/check_tcptraffic.spec
^
|
@@ -6,7 +6,7 @@
# $Date: 2009-12-10 17:35:09 +0100 (Thu, 10 Dec 2009) $
################################################################################
-%define version 2.2.2
+%define version 2.2.3
%define release 0
%define sourcename check_tcptraffic
%define packagename nagios-plugins-check-tcptraffic
@@ -65,7 +65,10 @@
%{_mandir}/man1/%{sourcename}.1*
%changelog
-* Thu Feb 10 2011 Matteo Corti <matteo.corti@id.ethz.ch> - 2.2.2-0%{?dist}
+* Thu Feb 17 2011 Matteo Corti <matteo.corti@id.ethz.ch> - 2.2.3-0
+- added an optional debug log and corrected a bug in the handling of counter overflows
+
+* Thu Feb 10 2011 Matteo Corti <matteo.corti@id.ethz.ch> - 2.2.2-0
- Added the nagiosgrapher template and renamed the RPM
* Wed Nov 3 2010 Matteo Corti <matteo.corti@id.ethz.ch> - 2.2.1-0
|
[-]
[+]
|
Changed |
check_tcptraffic-2.2.3.tar.bz2/inc/version.pm
^
|
@@ -7,7 +7,7 @@
use vars qw(@ISA $VERSION $CLASS $STRICT $LAX *declare *qv);
-$VERSION = 0.82;
+$VERSION = 0.88;
$CLASS = 'version';
@@ -124,13 +124,7 @@
*version::qv = \&version::vpp::qv;
*version::declare = \&version::vpp::declare;
*version::_VERSION = \&version::vpp::_VERSION;
- if ($] > 5.009001 && $] < 5.010000) {
- no strict 'refs';
- *version::stringify = \&version::vpp::stringify;
- *{'version::(""'} = \&version::vpp::stringify;
- *version::new = \&version::vpp::new;
- }
- elsif ($] == 5.010000 || $] == 5.010001) {
+ if ($] >= 5.009000 && $] < 5.011004) {
no strict 'refs';
*version::stringify = \&version::vpp::stringify;
*{'version::(""'} = \&version::vpp::stringify;
@@ -144,12 +138,8 @@
*version::declare = \&version::vxs::declare;
*version::qv = \&version::vxs::qv;
*version::_VERSION = \&version::vxs::_VERSION;
- if ($] > 5.009001 && $] < 5.010000) {
- no strict 'refs';
- *version::stringify = \&version::vxs::stringify;
- *{'version::(""'} = \&version::vxs::stringify;
- }
- elsif ($] == 5.010000 || $] == 5.010001) {
+ *version::vcmp = \&version::vxs::VCMP;
+ if ($] >= 5.009000 && $] < 5.011004) {
no strict 'refs';
*version::stringify = \&version::vxs::stringify;
*{'version::(""'} = \&version::vxs::stringify;
@@ -208,14 +198,12 @@
}
if (exists($args{'is_strict'})) {
- *{$callpkg.'::is_strict'} =
- sub {return $class->is_strict(shift)}
+ *{$callpkg.'::is_strict'} = \&version::is_strict
unless defined(&{$callpkg.'::is_strict'});
}
if (exists($args{'is_lax'})) {
- *{$callpkg.'::is_lax'} =
- sub {return $class->is_lax(shift)}
+ *{$callpkg.'::is_lax'} = \&version::is_lax
unless defined(&{$callpkg.'::is_lax'});
}
}
|