summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTon Voon <tonvoon@users.sourceforge.net>2007-08-31 14:34:18 +0000
committerTon Voon <tonvoon@users.sourceforge.net>2007-08-31 14:34:18 +0000
commitc6ee438b0525b73d36bbcf5e5a9e0d445f69129b (patch)
treeefc1ed1556e6a4be7f6f3cd83f0ce24217dcfbbe
parent95dba9c4213c2e7e8f4b572efd873c1979406221 (diff)
downloadmonitoring-plugin-perl-c6ee438b0525b73d36bbcf5e5a9e0d445f69129b.tar.gz
Convenience function to set use_die on use of N::P::Performance
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/Nagios-Plugin/trunk@1773 f882894a-f735-0410-b71e-b25c423dba1c
-rw-r--r--Changes3
-rw-r--r--lib/Nagios/Plugin/Performance.pm16
-rw-r--r--t/Nagios-Plugin-Performance-02.t13
3 files changed, 30 insertions, 2 deletions
diff --git a/Changes b/Changes
index 2b67941..c1f17ab 100644
--- a/Changes
+++ b/Changes
@@ -1,9 +1,10 @@
1Revision history for Perl module Nagios::Plugin. 1Revision history for Perl module Nagios::Plugin.
2 2
30.18 ?? 30.18 31st August 2007
4 - Fix error when parsing performance data where warn or crit are 0 4 - Fix error when parsing performance data where warn or crit are 0
5 - Optional _use_die flag to force nagios_die to call die instead of exit, so 5 - Optional _use_die flag to force nagios_die to call die instead of exit, so
6 exceptions can be caught with an eval 6 exceptions can be caught with an eval
7 - Convenience function to set use_die so you can run 'use Nagios::Plugin::Performance use_die => 1'
7 8
80.17 23rd March 2007 90.17 23rd March 2007
9 - bump version number again due to cpan indexing stupidity (Gavin) 10 - bump version number again due to cpan indexing stupidity (Gavin)
diff --git a/lib/Nagios/Plugin/Performance.pm b/lib/Nagios/Plugin/Performance.pm
index 63727c0..7ce5fa1 100644
--- a/lib/Nagios/Plugin/Performance.pm
+++ b/lib/Nagios/Plugin/Performance.pm
@@ -16,6 +16,12 @@ use Nagios::Plugin::Threshold;
16use Nagios::Plugin::Range; 16use Nagios::Plugin::Range;
17our ($VERSION) = $Nagios::Plugin::Functions::VERSION; 17our ($VERSION) = $Nagios::Plugin::Functions::VERSION;
18 18
19sub import {
20 my ($class, %attr) = @_;
21 $_ = $attr{use_die} || 0;
22 Nagios::Plugin::Functions::_use_die($_);
23}
24
19sub _parse { 25sub _parse {
20 my $class = shift; 26 my $class = shift;
21 my $string = shift; 27 my $string = shift;
@@ -112,7 +118,7 @@ performance data.
112 118
113=head1 SYNOPSIS 119=head1 SYNOPSIS
114 120
115 use Nagios::Plugin::Performance; 121 use Nagios::Plugin::Performance use_die => 1;
116 122
117 # Constructor (also accepts a 'threshold' obj instead of warning/critical) 123 # Constructor (also accepts a 'threshold' obj instead of warning/critical)
118 $p = Nagios::Plugin::Performance->new( 124 $p = Nagios::Plugin::Performance->new(
@@ -162,6 +168,14 @@ parse_perfstring), for turning nagios performance output strings into
162their components, and a composition interface (via new), for turning 168their components, and a composition interface (via new), for turning
163components into perfdata strings. 169components into perfdata strings.
164 170
171=head1 USE'ING THE MODULE
172
173If you are using this module for the purposes of parsing perf data, you
174will probably want to set use_die => 1 at use time. This forces
175&Nagios::Plugin::Functions::nagios_exit to call die() - rather than exit() -
176when an error occurs. This is then trappable by an eval. If you don't set use_die,
177then an error in these modules will cause your script to exit
178
165=head1 CLASS METHODS 179=head1 CLASS METHODS
166 180
167=over 4 181=over 4
diff --git a/t/Nagios-Plugin-Performance-02.t b/t/Nagios-Plugin-Performance-02.t
new file mode 100644
index 0000000..c0c5a71
--- /dev/null
+++ b/t/Nagios-Plugin-Performance-02.t
@@ -0,0 +1,13 @@
1
2use strict;
3use Test::More tests => 3;
4use_ok("Nagios::Plugin::Performance", use_die => 1);
5
6eval { Nagios::Plugin::Functions::nagios_die("Testing") };
7is( $@, "NAGIOS-PLUGIN-PERFORMANCE-02 UNKNOWN - Testing\n", "use_die correctly set on import");
8
9
10use_ok("Nagios::Plugin::Performance");
11eval { Nagios::Plugin::Functions::nagios_die("Test OK exit", 0) };
12
13fail("Should not get here if code works correctly because prior nagios_die should have exited");