summaryrefslogtreecommitdiffstats
path: root/lib/Nagios/Plugin/Base.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Nagios/Plugin/Base.pm')
-rw-r--r--lib/Nagios/Plugin/Base.pm65
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
3package Nagios::Plugin::Base;
4
5use strict;
6use warnings;
7
8use Exporter;
9our @ISA = qw(Exporter);
10our @EXPORT = qw(%ERRORS);
11
12our %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4);
13
14our %STATUS_TEXT = reverse %ERRORS;
15
16my $exit_on_die = 1;
17sub exit_on_die { shift; @_ ? $exit_on_die = shift : $exit_on_die };
18my $print_on_die = 1;
19sub print_on_die { shift; @_ ? $print_on_die = shift : $print_on_die };
20
21sub 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
401;
41__END__
42
43=head1 NAME
44
45Nagios::Plugin::Base - Base functions for Nagios::Plugins
46
47=head1 DESCRIPTION
48
49See Nagios::Plugin for public interfaces. This module is for Nagios::Plugin developers to incorporate
50common backend functionality.
51
52=head1 AUTHOR
53
54Ton Voon, E<lt>ton.voon@altinity.comE<gt>
55
56=head1 COPYRIGHT AND LICENSE
57
58Copyright (C) 2006 by Nagios Plugin Development Team
59
60This library is free software; you can redistribute it and/or modify
61it under the same terms as Perl itself, either Perl version 5.8.4 or,
62at your option, any later version of Perl 5 you may have available.
63
64
65=cut