SF.net SVN: nagiosplug: [1773] Nagios-Plugin/trunk

[email protected]
Newsgroups gmane.network.nagios.plugins.cvs
Message-ID <[email protected]>
Revision: 1773
          http://nagiosplug.svn.sourceforge.net/nagiosplug/?rev=1773&view=rev
Author:   tonvoon
Date:     2007-08-31 07:34:18 -0700 (Fri, 31 Aug 2007)

Log Message:
-----------
Convenience function to set use_die on use of N::P::Performance

Modified Paths:
--------------
    Nagios-Plugin/trunk/Changes
    Nagios-Plugin/trunk/lib/Nagios/Plugin/Performance.pm

Added Paths:
-----------
    Nagios-Plugin/trunk/t/Nagios-Plugin-Performance-02.t

Modified: Nagios-Plugin/trunk/Changes
===================================================================
--- Nagios-Plugin/trunk/Changes	2007-08-31 13:21:10 UTC (rev 1772)
+++ Nagios-Plugin/trunk/Changes	2007-08-31 14:34:18 UTC (rev 1773)
@@ -1,9 +1,10 @@
 Revision history for Perl module Nagios::Plugin.
 
-0.18 ??
+0.18  31st August 2007
   - Fix error when parsing performance data where warn or crit are 0
   - Optional _use_die flag to force nagios_die to call die instead of exit, so
     exceptions can be caught with an eval
+  - Convenience function to set use_die so you can run 'use Nagios::Plugin::Performance use_die => 1'
 
 0.17  23rd March 2007
   - bump version number again due to cpan indexing stupidity (Gavin)

Modified: Nagios-Plugin/trunk/lib/Nagios/Plugin/Performance.pm
===================================================================
--- Nagios-Plugin/trunk/lib/Nagios/Plugin/Performance.pm	2007-08-31 13:21:10 UTC (rev 1772)
+++ Nagios-Plugin/trunk/lib/Nagios/Plugin/Performance.pm	2007-08-31 14:34:18 UTC (rev 1773)
@@ -16,6 +16,12 @@
 use Nagios::Plugin::Range;
 our ($VERSION) = $Nagios::Plugin::Functions::VERSION;
 
+sub import {
+	my ($class, %attr) = @_;
+	$_ = $attr{use_die} || 0;
+	Nagios::Plugin::Functions::_use_die($_);
+}
+
 sub _parse {
 	my $class = shift;
 	my $string = shift;
@@ -112,7 +118,7 @@
 
 =head1 SYNOPSIS
 
-  use Nagios::Plugin::Performance;
+  use Nagios::Plugin::Performance use_die => 1;
 
   # Constructor (also accepts a 'threshold' obj instead of warning/critical)
   $p = Nagios::Plugin::Performance->new(
@@ -162,6 +168,14 @@
 their components, and a composition interface (via new), for turning
 components into perfdata strings.
 
+=head1 USE'ING THE MODULE
+
+If you are using this module for the purposes of parsing perf data, you
+will probably want to set use_die => 1 at use time. This forces
+&Nagios::Plugin::Functions::nagios_exit to call die() - rather than exit() -
+when an error occurs. This is then trappable by an eval. If you don't set use_die,
+then an error in these modules will cause your script to exit
+
 =head1 CLASS METHODS
 
 =over 4

Added: Nagios-Plugin/trunk/t/Nagios-Plugin-Performance-02.t
===================================================================
--- Nagios-Plugin/trunk/t/Nagios-Plugin-Performance-02.t	                        (rev 0)
+++ Nagios-Plugin/trunk/t/Nagios-Plugin-Performance-02.t	2007-08-31 14:34:18 UTC (rev 1773)
@@ -0,0 +1,13 @@
+
+use strict;
+use Test::More tests => 3;
+use_ok("Nagios::Plugin::Performance", use_die => 1);
+
+eval { Nagios::Plugin::Functions::nagios_die("Testing") };
+is( $@, "NAGIOS-PLUGIN-PERFORMANCE-02 UNKNOWN - Testing\n", "use_die correctly set on import");
+
+
+use_ok("Nagios::Plugin::Performance");
+eval { Nagios::Plugin::Functions::nagios_die("Test OK exit", 0) };
+
+fail("Should not get here if code works correctly because prior nagios_die should have exited");


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.