| 1 | package JMX::Jmx4Perl::Nagios::CactiJmx4Perl; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use base qw(JMX::Jmx4Perl::Nagios::CheckJmx4Perl); | ||
| 5 | use Data::Dumper; | ||
| 6 | |||
| 7 | =head1 NAME | ||
| 8 | |||
| 9 | JMX::Jmx4Perl::Nagios::CactiJmx4Perl - Module for encapsulating the functionality of | ||
| 10 | L<cacti_jmx4perl> | ||
| 11 | |||
| 12 | =head1 SYNOPSIS | ||
| 13 | |||
| 14 | # One line in check_jmx4perl to rule them all | ||
| 15 | JMX::Jmx4Perl::Nagios::CactiJmx4Perl->new(@ARGV)->execute(); | ||
| 16 | |||
| 17 | =head1 DESCRIPTION | ||
| 18 | |||
| 19 | =cut | ||
| 20 | |||
| 21 | sub create_nagios_plugin { | ||
| 22 | my $self = shift; | ||
| 23 | |||
| 24 | my $np = Monitoring::Plugin-> | ||
| 25 | new( | ||
| 26 | usage => | ||
| 27 | "Usage: %s -u <agent-url> [-m <mbean>] [-a <attribute>]\n" . | ||
| 28 | " [--alias <alias>] [--value <shortcut>] [--base <alias/number/mbean>] [--delta <time-base>]\n" . | ||
| 29 | " [--name <name>] [--product <product>]\n". | ||
| 30 | " [--user <user>] [--password <password>] [--proxy <proxy>]\n" . | ||
| 31 | " [--target <target-url>] [--target-user <user>] [--target-password <password>]\n" . | ||
| 32 | " [--legacy-escape]\n" . | ||
| 33 | " [--config <config-file>] [--check <check-name>] [--server <server-alias>] [-v] [--help]\n" . | ||
| 34 | " arg1 arg2 ....", | ||
| 35 | version => $JMX::Jmx4Perl::VERSION, | ||
| 36 | url => "http://www.jolokia.org", | ||
| 37 | plugin => "cacti_jmx4perl", | ||
| 38 | license => undef, | ||
| 39 | blurb => "This script can be used as an script for a Cacti Data Input Method", | ||
| 40 | extra => "\n\nYou need to deploy jolokia.war on the target application server or an intermediate proxy.\n" . | ||
| 41 | "Please refer to the documentation for JMX::Jmx4Perl for further details.\n\n" . | ||
| 42 | "For a complete documentation please consult the man page of cacti_jmx4perl or use the option --doc" | ||
| 43 | ); | ||
| 44 | $np->shortname(undef); | ||
| 45 | $self->add_common_np_args($np); | ||
| 46 | # Add dummy thresholds to keep Nagios plugin happy | ||
| 47 | $np->set_thresholds(warning => undef, critical => undef); | ||
| 48 | $np->getopts(); | ||
| 49 | return $np; | ||
| 50 | } | ||
| 51 | |||
| 52 | sub verify_check { | ||
| 53 | # Not needed | ||
| 54 | } | ||
| 55 | |||
| 56 | sub do_exit { | ||
| 57 | my $self = shift; | ||
| 58 | my $error_stat = shift; | ||
| 59 | my $np = $self->{np}; | ||
| 60 | |||
| 61 | my $perf = $np->perfdata; | ||
| 62 | my @res; | ||
| 63 | for my $p (@$perf) { | ||
| 64 | my $label = $p->label; | ||
| 65 | $label =~ s/\s/_/g; | ||
| 66 | push @res,@$perf > 1 ? $label . ":" . $p->value : $p->value; | ||
| 67 | } | ||
| 68 | print join(" ",@res),"\n"; | ||
| 69 | exit 0; | ||
| 70 | } | ||
| 71 | |||
| 72 | |||
| 73 | =head1 LICENSE | ||
| 74 | |||
| 75 | This file is part of jmx4perl. | ||
| 76 | |||
| 77 | Jmx4perl is free software: you can redistribute it and/or modify | ||
| 78 | it under the terms of the GNU General Public License as published by | ||
| 79 | the Free Software Foundation, either version 2 of the License, or | ||
| 80 | (at your option) any later version. | ||
| 81 | |||
| 82 | jmx4perl is distributed in the hope that it will be useful, | ||
| 83 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 84 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 85 | GNU General Public License for more details. | ||
| 86 | |||
| 87 | You should have received a copy of the GNU General Public License | ||
| 88 | along with jmx4perl. If not, see <http://www.gnu.org/licenses/>. | ||
| 89 | |||
| 90 | =head1 AUTHOR | ||
| 91 | |||
| 92 | roland@cpan.org | ||
| 93 | |||
| 94 | =cut | ||
| 95 | |||
| 96 | 1; |