diff options
author | Ton Voon <tonvoon@users.sourceforge.net> | 2007-08-31 14:34:18 +0000 |
---|---|---|
committer | Ton Voon <tonvoon@users.sourceforge.net> | 2007-08-31 14:34:18 +0000 |
commit | c6ee438b0525b73d36bbcf5e5a9e0d445f69129b (patch) | |
tree | efc1ed1556e6a4be7f6f3cd83f0ce24217dcfbbe | |
parent | 95dba9c4213c2e7e8f4b572efd873c1979406221 (diff) | |
download | monitoring-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-- | Changes | 3 | ||||
-rw-r--r-- | lib/Nagios/Plugin/Performance.pm | 16 | ||||
-rw-r--r-- | t/Nagios-Plugin-Performance-02.t | 13 |
3 files changed, 30 insertions, 2 deletions
@@ -1,9 +1,10 @@ | |||
1 | Revision history for Perl module Nagios::Plugin. | 1 | Revision history for Perl module Nagios::Plugin. |
2 | 2 | ||
3 | 0.18 ?? | 3 | 0.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 | ||
8 | 0.17 23rd March 2007 | 9 | 0.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; | |||
16 | use Nagios::Plugin::Range; | 16 | use Nagios::Plugin::Range; |
17 | our ($VERSION) = $Nagios::Plugin::Functions::VERSION; | 17 | our ($VERSION) = $Nagios::Plugin::Functions::VERSION; |
18 | 18 | ||
19 | sub import { | ||
20 | my ($class, %attr) = @_; | ||
21 | $_ = $attr{use_die} || 0; | ||
22 | Nagios::Plugin::Functions::_use_die($_); | ||
23 | } | ||
24 | |||
19 | sub _parse { | 25 | sub _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 | |||
162 | their components, and a composition interface (via new), for turning | 168 | their components, and a composition interface (via new), for turning |
163 | components into perfdata strings. | 169 | components into perfdata strings. |
164 | 170 | ||
171 | =head1 USE'ING THE MODULE | ||
172 | |||
173 | If you are using this module for the purposes of parsing perf data, you | ||
174 | will probably want to set use_die => 1 at use time. This forces | ||
175 | &Nagios::Plugin::Functions::nagios_exit to call die() - rather than exit() - | ||
176 | when an error occurs. This is then trappable by an eval. If you don't set use_die, | ||
177 | then 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 | |||
2 | use strict; | ||
3 | use Test::More tests => 3; | ||
4 | use_ok("Nagios::Plugin::Performance", use_die => 1); | ||
5 | |||
6 | eval { Nagios::Plugin::Functions::nagios_die("Testing") }; | ||
7 | is( $@, "NAGIOS-PLUGIN-PERFORMANCE-02 UNKNOWN - Testing\n", "use_die correctly set on import"); | ||
8 | |||
9 | |||
10 | use_ok("Nagios::Plugin::Performance"); | ||
11 | eval { Nagios::Plugin::Functions::nagios_die("Test OK exit", 0) }; | ||
12 | |||
13 | fail("Should not get here if code works correctly because prior nagios_die should have exited"); | ||