diff options
Diffstat (limited to 'lib/Nagios/Plugin/Base.pm')
-rw-r--r-- | lib/Nagios/Plugin/Base.pm | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/lib/Nagios/Plugin/Base.pm b/lib/Nagios/Plugin/Base.pm new file mode 100644 index 0000000..f3a7f7c --- /dev/null +++ b/lib/Nagios/Plugin/Base.pm | |||
@@ -0,0 +1,65 @@ | |||
1 | # This module holds all exported variables | ||
2 | # and base functions | ||
3 | package Nagios::Plugin::Base; | ||
4 | |||
5 | use strict; | ||
6 | use warnings; | ||
7 | |||
8 | use Exporter; | ||
9 | our @ISA = qw(Exporter); | ||
10 | our @EXPORT = qw(%ERRORS); | ||
11 | |||
12 | our %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4); | ||
13 | |||
14 | our %STATUS_TEXT = reverse %ERRORS; | ||
15 | |||
16 | my $exit_on_die = 1; | ||
17 | sub exit_on_die { shift; @_ ? $exit_on_die = shift : $exit_on_die }; | ||
18 | my $print_on_die = 1; | ||
19 | sub print_on_die { shift; @_ ? $print_on_die = shift : $print_on_die }; | ||
20 | |||
21 | sub die { | ||
22 | my ($class, $args, $plugin) = @_; | ||
23 | my $return_code = $args->{return_code} || 3; | ||
24 | my $message = $args->{message} || "Internal error"; | ||
25 | my $output = join(" ", $STATUS_TEXT{$return_code}, $message); | ||
26 | if ($plugin) { | ||
27 | $output = $plugin->shortname." $output" if $plugin->shortname; | ||
28 | $output .= " | ".$plugin->all_perfoutput if $plugin->perfdata; | ||
29 | } | ||
30 | if ($print_on_die) { | ||
31 | print $output, $/; | ||
32 | } | ||
33 | if ($exit_on_die) { | ||
34 | exit $return_code; | ||
35 | } else { | ||
36 | return $output; | ||
37 | } | ||
38 | } | ||
39 | |||
40 | 1; | ||
41 | __END__ | ||
42 | |||
43 | =head1 NAME | ||
44 | |||
45 | Nagios::Plugin::Base - Base functions for Nagios::Plugins | ||
46 | |||
47 | =head1 DESCRIPTION | ||
48 | |||
49 | See Nagios::Plugin for public interfaces. This module is for Nagios::Plugin developers to incorporate | ||
50 | common backend functionality. | ||
51 | |||
52 | =head1 AUTHOR | ||
53 | |||
54 | Ton Voon, E<lt>ton.voon@altinity.comE<gt> | ||
55 | |||
56 | =head1 COPYRIGHT AND LICENSE | ||
57 | |||
58 | Copyright (C) 2006 by Nagios Plugin Development Team | ||
59 | |||
60 | This library is free software; you can redistribute it and/or modify | ||
61 | it under the same terms as Perl itself, either Perl version 5.8.4 or, | ||
62 | at your option, any later version of Perl 5 you may have available. | ||
63 | |||
64 | |||
65 | =cut | ||