mirror of
https://github.com/centreon/centreon-plugins.git
synced 2025-09-25 18:58:39 +02:00
commit
dc41004020
@ -1,5 +1,9 @@
|
||||
# centreon-plugins
|
||||
|
||||
[](https://github.com/centreon/centreon-plugins/blob/master/LICENSE.txt)
|
||||
[](https://github.com/centreon/centreon-plugins/stargazers)
|
||||
[](https://github.com/centreon/centreon-plugins/network)
|
||||
|
||||
“centreon-plugins” is a free and open source project to monitor systems. The project can be used with Centreon and all monitoring softwares compatible with Nagios plugins.
|
||||
|
||||
You can monitor many systems:
|
||||
|
@ -33,7 +33,7 @@ sub set_counters {
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{global} = [
|
||||
{ label => 'backlog', set => {
|
||||
{ label => 'backlog', nlabel => 'backlog.file.count', set => {
|
||||
key_values => [ { name => 'backlog' } ],
|
||||
output_template => 'Backlog File Count : %s',
|
||||
perfdatas => [
|
||||
|
180
apps/antivirus/mcafee/webgateway/snmp/mode/versions.pm
Normal file
180
apps/antivirus/mcafee/webgateway/snmp/mode/versions.pm
Normal file
@ -0,0 +1,180 @@
|
||||
#
|
||||
# Copyright 2019 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package apps::antivirus::mcafee::webgateway::snmp::mode::versions;
|
||||
|
||||
use base qw(centreon::plugins::templates::counter);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::statefile;
|
||||
use Digest::MD5 qw(md5_hex);
|
||||
|
||||
sub custom_version_calc {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{result_values}->{output} = $options{extra_options}->{output_ref};
|
||||
$self->{result_values}->{version} = $options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{label_ref}};
|
||||
$self->{result_values}->{timestamp} = $options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{label_ref} . '_timestamp'};
|
||||
$self->{result_values}->{since} = time() - $self->{result_values}->{timestamp};
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub custom_version_threshold {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{since},
|
||||
threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' },
|
||||
{ label => 'warning-' . $self->{label}, exit_litteral => 'warning' } ]);
|
||||
return $exit;
|
||||
}
|
||||
|
||||
sub custom_version_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $human_since = centreon::plugins::misc::change_seconds(value => $self->{result_values}->{since});
|
||||
my $msg = sprintf("%s: %s [Last update: %s]", $self->{result_values}->{output}, $self->{result_values}->{version}, $human_since);
|
||||
return $msg;
|
||||
}
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'global', type => 0, skipped_code => { -10 => 1 } },
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{global} = [
|
||||
{ label => 'dat-version', set => {
|
||||
key_values => [ { name => 'pMFEDATVersion' }, { name => 'pMFEDATVersion_timestamp' } ],
|
||||
closure_custom_calc => $self->can('custom_version_calc'),
|
||||
closure_custom_calc_extra_options => { label_ref => 'pMFEDATVersion', output_ref => 'DAT Version' },
|
||||
closure_custom_output => $self->can('custom_version_output'),
|
||||
closure_custom_perfdata => sub { return 0; },
|
||||
closure_custom_threshold_check => $self->can('custom_version_threshold'),
|
||||
}
|
||||
},
|
||||
{ label => 'tsdb-version', set => {
|
||||
key_values => [ { name => 'pTSDBVersion' }, { name => 'pTSDBVersion_timestamp' } ],
|
||||
closure_custom_calc => $self->can('custom_version_calc'),
|
||||
closure_custom_calc_extra_options => { label_ref => 'pTSDBVersion', output_ref => 'TrustedSource Database Version' },
|
||||
closure_custom_output => $self->can('custom_version_output'),
|
||||
closure_custom_perfdata => sub { return 0; },
|
||||
closure_custom_threshold_check => $self->can('custom_version_threshold'),
|
||||
}
|
||||
},
|
||||
{ label => 'proactive-version', set => {
|
||||
key_values => [ { name => 'pAMProactiveVersion' }, { name => 'pAMProactiveVersion_timestamp' } ],
|
||||
closure_custom_calc => $self->can('custom_version_calc'),
|
||||
closure_custom_calc_extra_options => { label_ref => 'pAMProactiveVersion', output_ref => 'ProActive Database Version' },
|
||||
closure_custom_output => $self->can('custom_version_output'),
|
||||
closure_custom_perfdata => sub { return 0; },
|
||||
closure_custom_threshold_check => $self->can('custom_version_threshold'),
|
||||
}
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"filter-counters:s" => { name => 'filter_counters', default => '' },
|
||||
});
|
||||
|
||||
$self->{cache} = centreon::plugins::statefile->new(%options);
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::check_options(%options);
|
||||
|
||||
$self->{cache}->check_options(%options);
|
||||
}
|
||||
|
||||
my $oid_pMFEDATVersion = '.1.3.6.1.4.1.1230.2.7.1.20.4.0';
|
||||
my $oid_pAMProactiveVersion = '.1.3.6.1.4.1.1230.2.7.1.20.5.0';
|
||||
my $oid_pTSDBVersion = '.1.3.6.1.4.1.1230.2.7.1.20.6.0';
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{new_datas} = {};
|
||||
$self->{cache}->read(statefile => "mcafee_" . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' .
|
||||
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')));
|
||||
|
||||
my $results = $options{snmp}->get_leef(oids => [ $oid_pMFEDATVersion, $oid_pAMProactiveVersion, $oid_pTSDBVersion ],
|
||||
nothing_quit => 1);
|
||||
|
||||
$self->{global} = {};
|
||||
|
||||
$self->{new_datas} = {
|
||||
pMFEDATVersion => $results->{$oid_pMFEDATVersion},
|
||||
pAMProactiveVersion => $results->{$oid_pAMProactiveVersion},
|
||||
pTSDBVersion => $results->{$oid_pTSDBVersion},
|
||||
};
|
||||
|
||||
foreach my $version (('pMFEDATVersion', 'pAMProactiveVersion', 'pTSDBVersion')) {
|
||||
next if (!defined($self->{new_datas}->{$version}) || $self->{new_datas}->{$version} eq '');
|
||||
$self->{new_datas}->{$version . '_timestamp'} = ($self->{new_datas}->{$version} > $self->{cache}->{datas}->{$version}) ? time() : $self->{cache}->{datas}->{$version . '_timestamp'};
|
||||
$self->{new_datas}->{$version . '_timestamp'} = time() if (!defined($self->{new_datas}->{$version . '_timestamp'}));
|
||||
}
|
||||
|
||||
$self->{global} = { %{$self->{new_datas}} };
|
||||
|
||||
$self->{cache}->write(data => $self->{new_datas});
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check signature databases versions
|
||||
(last update is only guessed by version's changement,
|
||||
it does not appear clearly in the MIB).
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--filter-counters>
|
||||
|
||||
Only display some counters (regexp can be used).
|
||||
(Example: --filter-counters='dat')
|
||||
|
||||
=item B<--warning-*>
|
||||
|
||||
Threshold warning on last update.
|
||||
Can be: 'dat-version', 'tsdb-version', 'proactive-version'.
|
||||
|
||||
=item B<--critical-*>
|
||||
|
||||
Threshold critical on last update.
|
||||
Can be: 'dat-version', 'tsdb-version', 'proactive-version'.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
@ -38,6 +38,7 @@ sub new {
|
||||
'ftp-statistics' => 'apps::antivirus::mcafee::webgateway::snmp::mode::ftpstatistics',
|
||||
'http-statistics' => 'apps::antivirus::mcafee::webgateway::snmp::mode::httpstatistics',
|
||||
'https-statistics' => 'apps::antivirus::mcafee::webgateway::snmp::mode::httpsstatistics',
|
||||
'versions' => 'apps::antivirus::mcafee::webgateway::snmp::mode::versions',
|
||||
);
|
||||
|
||||
return $self;
|
||||
|
@ -32,8 +32,7 @@ sub new {
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
$options{options}->add_options(arguments => {
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"port:s" => { name => 'port', },
|
||||
"proto:s" => { name => 'proto' },
|
||||
@ -42,14 +41,12 @@ sub new {
|
||||
"basic" => { name => 'basic' },
|
||||
"username:s" => { name => 'username' },
|
||||
"password:s" => { name => 'password' },
|
||||
"proxyurl:s" => { name => 'proxyurl' },
|
||||
"header:s@" => { name => 'header' },
|
||||
"warning:s" => { name => 'warning' },
|
||||
"critical:s" => { name => 'critical' },
|
||||
"timeout:s" => { name => 'timeout' },
|
||||
"ssl-opt:s@" => { name => 'ssl_opt' },
|
||||
});
|
||||
$self->{http} = centreon::plugins::http->new(output => $self->{output});
|
||||
$self->{http} = centreon::plugins::http->new(%options);
|
||||
return $self;
|
||||
}
|
||||
|
||||
@ -118,10 +115,6 @@ IP Addr/FQDN of the webserver host
|
||||
|
||||
Port used by Apache
|
||||
|
||||
=item B<--proxyurl>
|
||||
|
||||
Proxy URL if any
|
||||
|
||||
=item B<--proto>
|
||||
|
||||
Specify https if needed
|
||||
@ -154,10 +147,6 @@ Specify this option if you access server-status page over hidden basic authentic
|
||||
|
||||
Threshold for HTTP timeout
|
||||
|
||||
=item B<--ssl-opt>
|
||||
|
||||
Set SSL Options (--ssl-opt="SSL_version => TLSv1" --ssl-opt="SSL_verify_mode => SSL_VERIFY_NONE").
|
||||
|
||||
=item B<--header>
|
||||
|
||||
Set HTTP headers (Multiple option)
|
||||
|
@ -33,8 +33,7 @@ sub new {
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
$options{options}->add_options(arguments => {
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"port:s" => { name => 'port', },
|
||||
"proto:s" => { name => 'proto' },
|
||||
@ -43,7 +42,6 @@ sub new {
|
||||
"basic" => { name => 'basic' },
|
||||
"username:s" => { name => 'username' },
|
||||
"password:s" => { name => 'password' },
|
||||
"proxyurl:s" => { name => 'proxyurl' },
|
||||
"header:s@" => { name => 'header' },
|
||||
"warning:s" => { name => 'warning' },
|
||||
"critical:s" => { name => 'critical' },
|
||||
@ -52,9 +50,8 @@ sub new {
|
||||
"warning-access:s" => { name => 'warning_access' },
|
||||
"critical-access:s" => { name => 'critical_access' },
|
||||
"timeout:s" => { name => 'timeout' },
|
||||
"ssl-opt:s@" => { name => 'ssl_opt' },
|
||||
});
|
||||
$self->{http} = centreon::plugins::http->new(output => $self->{output});
|
||||
$self->{http} = centreon::plugins::http->new(%options);
|
||||
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
|
||||
return $self;
|
||||
}
|
||||
@ -207,10 +204,6 @@ IP Addr/FQDN of the webserver host
|
||||
|
||||
Port used by Apache
|
||||
|
||||
=item B<--proxyurl>
|
||||
|
||||
Proxy URL if any
|
||||
|
||||
=item B<--proto>
|
||||
|
||||
Specify https if needed
|
||||
@ -243,10 +236,6 @@ Specify this option if you access server-status page over hidden basic authentic
|
||||
|
||||
Threshold for HTTP timeout
|
||||
|
||||
=item B<--ssl-opt>
|
||||
|
||||
Set SSL Options (--ssl-opt="SSL_version => TLSv1" --ssl-opt="SSL_verify_mode => SSL_VERIFY_NONE").
|
||||
|
||||
=item B<--header>
|
||||
|
||||
Set HTTP headers (Multiple option)
|
||||
|
@ -33,8 +33,7 @@ sub new {
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
$options{options}->add_options(arguments => {
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"port:s" => { name => 'port', },
|
||||
"proto:s" => { name => 'proto' },
|
||||
@ -43,17 +42,15 @@ sub new {
|
||||
"basic" => { name => 'basic' },
|
||||
"username:s" => { name => 'username' },
|
||||
"password:s" => { name => 'password' },
|
||||
"proxyurl:s" => { name => 'proxyurl' },
|
||||
"header:s@" => { name => 'header' },
|
||||
"warning:s" => { name => 'warning' },
|
||||
"critical:s" => { name => 'critical' },
|
||||
"timeout:s" => { name => 'timeout' },
|
||||
"ssl-opt:s@" => { name => 'ssl_opt' },
|
||||
"unknown-status:s" => { name => 'unknown_status', default => '' },
|
||||
"warning-status:s" => { name => 'warning_status' },
|
||||
"critical-status:s" => { name => 'critical_status', default => '%{http_code} < 200 or %{http_code} >= 300' },
|
||||
});
|
||||
$self->{http} = centreon::plugins::http->new(output => $self->{output});
|
||||
$self->{http} = centreon::plugins::http->new(%options);
|
||||
return $self;
|
||||
}
|
||||
|
||||
@ -142,18 +139,10 @@ Specify this option if you access server-status page over hidden basic authentic
|
||||
|
||||
(Use with --credentials)
|
||||
|
||||
=item B<--proxyurl>
|
||||
|
||||
Proxy URL if any
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Threshold for HTTP timeout
|
||||
|
||||
=item B<--ssl-opt>
|
||||
|
||||
Set SSL Options (--ssl-opt="SSL_version => TLSv1" --ssl-opt="SSL_verify_mode => SSL_VERIFY_NONE").
|
||||
|
||||
=item B<--header>
|
||||
|
||||
Set HTTP headers (Multiple option)
|
||||
|
@ -20,124 +20,20 @@
|
||||
|
||||
package apps::apache::serverstatus::mode::slotstates;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
use base qw(centreon::plugins::templates::counter);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::http;
|
||||
use centreon::plugins::values;
|
||||
|
||||
my $instance_mode;
|
||||
|
||||
my $maps_counters = {
|
||||
global => {
|
||||
'000_busy' => { set => {
|
||||
key_values => [ { name => 'busy' }, { name => 'total' } ],
|
||||
closure_custom_calc => \&custom_value_calc, closure_custom_calc_extra_options => { label_ref => 'busy' },
|
||||
closure_custom_output => \&custom_value_output,
|
||||
closure_custom_threshold_check => \&custom_value_threshold,
|
||||
closure_custom_perfdata => \&custom_value_perfdata,
|
||||
}
|
||||
},
|
||||
'001_free' => { set => {
|
||||
key_values => [ { name => 'free' }, { name => 'total' } ],
|
||||
closure_custom_calc => \&custom_value_calc, closure_custom_calc_extra_options => { label_ref => 'free' },
|
||||
closure_custom_output => \&custom_value_output,
|
||||
closure_custom_threshold_check => \&custom_value_threshold,
|
||||
closure_custom_perfdata => \&custom_value_perfdata,
|
||||
}
|
||||
},
|
||||
'002_waiting' => { set => {
|
||||
key_values => [ { name => 'waiting' }, { name => 'total' } ],
|
||||
closure_custom_calc => \&custom_value_calc, closure_custom_calc_extra_options => { label_ref => 'waiting' },
|
||||
closure_custom_output => \&custom_value_output,
|
||||
closure_custom_threshold_check => \&custom_value_threshold,
|
||||
closure_custom_perfdata => \&custom_value_perfdata,
|
||||
}
|
||||
},
|
||||
'003_starting' => { set => {
|
||||
key_values => [ { name => 'starting' }, { name => 'total' } ],
|
||||
closure_custom_calc => \&custom_value_calc, closure_custom_calc_extra_options => { label_ref => 'starting' },
|
||||
closure_custom_output => \&custom_value_output,
|
||||
closure_custom_threshold_check => \&custom_value_threshold,
|
||||
closure_custom_perfdata => \&custom_value_perfdata,
|
||||
}
|
||||
},
|
||||
'004_reading' => { set => {
|
||||
key_values => [ { name => 'reading' }, { name => 'total' } ],
|
||||
closure_custom_calc => \&custom_value_calc, closure_custom_calc_extra_options => { label_ref => 'reading' },
|
||||
closure_custom_output => \&custom_value_output,
|
||||
closure_custom_threshold_check => \&custom_value_threshold,
|
||||
closure_custom_perfdata => \&custom_value_perfdata,
|
||||
}
|
||||
},
|
||||
'005_sending' => { set => {
|
||||
key_values => [ { name => 'sending' }, { name => 'total' } ],
|
||||
closure_custom_calc => \&custom_value_calc, closure_custom_calc_extra_options => { label_ref => 'sending' },
|
||||
closure_custom_output => \&custom_value_output,
|
||||
closure_custom_threshold_check => \&custom_value_threshold,
|
||||
closure_custom_perfdata => \&custom_value_perfdata,
|
||||
}
|
||||
},
|
||||
'006_keepalive' => { set => {
|
||||
key_values => [ { name => 'keepalive' }, { name => 'total' } ],
|
||||
closure_custom_calc => \&custom_value_calc, closure_custom_calc_extra_options => { label_ref => 'keepalive' },
|
||||
closure_custom_output => \&custom_value_output,
|
||||
closure_custom_threshold_check => \&custom_value_threshold,
|
||||
closure_custom_perfdata => \&custom_value_perfdata,
|
||||
}
|
||||
},
|
||||
'007_dns-lookup' => { set => {
|
||||
key_values => [ { name => 'dns_lookup' }, { name => 'total' } ],
|
||||
closure_custom_calc => \&custom_value_calc, closure_custom_calc_extra_options => { label_ref => 'dns_lookup' },
|
||||
closure_custom_output => \&custom_value_output,
|
||||
closure_custom_threshold_check => \&custom_value_threshold,
|
||||
closure_custom_perfdata => \&custom_value_perfdata,
|
||||
}
|
||||
},
|
||||
'008_closing' => { set => {
|
||||
key_values => [ { name => 'closing' }, { name => 'total' } ],
|
||||
closure_custom_calc => \&custom_value_calc, closure_custom_calc_extra_options => { label_ref => 'closing' },
|
||||
closure_custom_output => \&custom_value_output,
|
||||
closure_custom_threshold_check => \&custom_value_threshold,
|
||||
closure_custom_perfdata => \&custom_value_perfdata,
|
||||
}
|
||||
},
|
||||
'009_logging' => { set => {
|
||||
key_values => [ { name => 'logging' }, { name => 'total' } ],
|
||||
closure_custom_calc => \&custom_value_calc, closure_custom_calc_extra_options => { label_ref => 'logging' },
|
||||
closure_custom_output => \&custom_value_output,
|
||||
closure_custom_threshold_check => \&custom_value_threshold,
|
||||
closure_custom_perfdata => \&custom_value_perfdata,
|
||||
}
|
||||
},
|
||||
'007_gracefuly-finished' => { set => {
|
||||
key_values => [ { name => 'gracefuly_finished' }, { name => 'total' } ],
|
||||
closure_custom_calc => \&custom_value_calc, closure_custom_calc_extra_options => { label_ref => 'gracefuly_finished' },
|
||||
closure_custom_output => \&custom_value_output,
|
||||
closure_custom_threshold_check => \&custom_value_threshold,
|
||||
closure_custom_perfdata => \&custom_value_perfdata,
|
||||
}
|
||||
},
|
||||
'007_idle-cleanup-worker' => { set => {
|
||||
key_values => [ { name => 'idle_cleanup_worker' }, { name => 'total' } ],
|
||||
closure_custom_calc => \&custom_value_calc, closure_custom_calc_extra_options => { label_ref => 'idle_cleanup_worker' },
|
||||
closure_custom_output => \&custom_value_output,
|
||||
closure_custom_threshold_check => \&custom_value_threshold,
|
||||
closure_custom_perfdata => \&custom_value_perfdata,
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
sub custom_value_threshold {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $exit = 'ok';
|
||||
if ($instance_mode->{option_results}->{units} eq '%') {
|
||||
$exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{prct}, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{label}, exit_litteral => 'warning' } ]);
|
||||
if ($self->{instance_mode}->{option_results}->{units} eq '%') {
|
||||
$exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{prct}, threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } ]);
|
||||
} else {
|
||||
$exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{used}, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{label}, exit_litteral => 'warning' } ]);
|
||||
$exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{used}, threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } ]);
|
||||
}
|
||||
return $exit;
|
||||
}
|
||||
@ -146,19 +42,22 @@ sub custom_value_perfdata {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my ($warning, $critical);
|
||||
if ($instance_mode->{option_results}->{units} eq '%') {
|
||||
$warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, total => $self->{result_values}->{total}, cast_int => 1);
|
||||
$critical = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, total => $self->{result_values}->{total}, cast_int => 1);
|
||||
if ($self->{instance_mode}->{option_results}->{units} eq '%') {
|
||||
$warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}, total => $self->{result_values}->{total}, cast_int => 1);
|
||||
$critical = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}, total => $self->{result_values}->{total}, cast_int => 1);
|
||||
} else {
|
||||
$warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label});
|
||||
$critical = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label});
|
||||
$warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel});
|
||||
$critical = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel});
|
||||
}
|
||||
|
||||
$self->{output}->perfdata_add(label => $self->{result_values}->{label},
|
||||
$self->{output}->perfdata_add(
|
||||
label => $self->{result_values}->{label},
|
||||
nlabel => $self->{nlabel},
|
||||
value => $self->{result_values}->{used},
|
||||
warning => $warning,
|
||||
critical => $critical,
|
||||
min => 0, max => $self->{result_values}->{total});
|
||||
min => 0, max => $self->{result_values}->{total}
|
||||
);
|
||||
}
|
||||
|
||||
sub custom_value_output {
|
||||
@ -188,14 +87,120 @@ sub custom_value_calc {
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'global', type => 0, cb_prefix_output => 'prefix_global_output', skipped_code => { -2 => 1 } }
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{global} = [
|
||||
{ label => 'busy', nlabel => 'apache.slot.busy.count', set => {
|
||||
key_values => [ { name => 'busy' }, { name => 'total' } ],
|
||||
closure_custom_calc => $self->can('custom_value_calc'), closure_custom_calc_extra_options => { label_ref => 'busy' },
|
||||
closure_custom_output => $self->can('custom_value_output'),
|
||||
closure_custom_threshold_check => $self->can('custom_value_threshold'),
|
||||
closure_custom_perfdata => $self->can('custom_value_perfdata'),
|
||||
}
|
||||
},
|
||||
{ label => 'free', nlabel => 'apache.slot.free.count', set => {
|
||||
key_values => [ { name => 'free' }, { name => 'total' } ],
|
||||
closure_custom_calc => $self->can('custom_value_calc'), closure_custom_calc_extra_options => { label_ref => 'free' },
|
||||
closure_custom_output => $self->can('custom_value_output'),
|
||||
closure_custom_threshold_check => $self->can('custom_value_threshold'),
|
||||
closure_custom_perfdata => $self->can('custom_value_perfdata'),
|
||||
}
|
||||
},
|
||||
{ label => 'waiting', nlabel => 'apache.slot.waiting.count', set => {
|
||||
key_values => [ { name => 'waiting' }, { name => 'total' } ],
|
||||
closure_custom_calc => $self->can('custom_value_calc'), closure_custom_calc_extra_options => { label_ref => 'waiting' },
|
||||
closure_custom_output => $self->can('custom_value_output'),
|
||||
closure_custom_threshold_check => $self->can('custom_value_threshold'),
|
||||
closure_custom_perfdata => $self->can('custom_value_perfdata'),
|
||||
}
|
||||
},
|
||||
{ label => 'starting', nlabel => 'apache.slot.starting.count', set => {
|
||||
key_values => [ { name => 'starting' }, { name => 'total' } ],
|
||||
closure_custom_calc => $self->can('custom_value_calc'), closure_custom_calc_extra_options => { label_ref => 'starting' },
|
||||
closure_custom_output => $self->can('custom_value_output'),
|
||||
closure_custom_threshold_check => $self->can('custom_value_threshold'),
|
||||
closure_custom_perfdata => $self->can('custom_value_perfdata'),
|
||||
}
|
||||
},
|
||||
{ label => 'reading', nlabel => 'apache.slot.reading.count', set => {
|
||||
key_values => [ { name => 'reading' }, { name => 'total' } ],
|
||||
closure_custom_calc => $self->can('custom_value_calc'), closure_custom_calc_extra_options => { label_ref => 'reading' },
|
||||
closure_custom_output => $self->can('custom_value_output'),
|
||||
closure_custom_threshold_check => $self->can('custom_value_threshold'),
|
||||
closure_custom_perfdata => $self->can('custom_value_perfdata'),
|
||||
}
|
||||
},
|
||||
{ label => 'sending', nlabel => 'apache.slot.sending.count', set => {
|
||||
key_values => [ { name => 'sending' }, { name => 'total' } ],
|
||||
closure_custom_calc => $self->can('custom_value_calc'), closure_custom_calc_extra_options => { label_ref => 'sending' },
|
||||
closure_custom_output => $self->can('custom_value_output'),
|
||||
closure_custom_threshold_check => $self->can('custom_value_threshold'),
|
||||
closure_custom_perfdata => $self->can('custom_value_perfdata'),
|
||||
}
|
||||
},
|
||||
{ label => 'keepalive', nlabel => 'apache.slot.keepalive.count', set => {
|
||||
key_values => [ { name => 'keepalive' }, { name => 'total' } ],
|
||||
closure_custom_calc => $self->can('custom_value_calc'), closure_custom_calc_extra_options => { label_ref => 'keepalive' },
|
||||
closure_custom_output => $self->can('custom_value_output'),
|
||||
closure_custom_threshold_check => $self->can('custom_value_threshold'),
|
||||
closure_custom_perfdata => $self->can('custom_value_perfdata'),
|
||||
}
|
||||
},
|
||||
{ label => 'dns-lookup', nlabel => 'apache.slot.dnslookup.count', set => {
|
||||
key_values => [ { name => 'dns_lookup' }, { name => 'total' } ],
|
||||
closure_custom_calc => $self->can('custom_value_calc'), closure_custom_calc_extra_options => { label_ref => 'dns_lookup' },
|
||||
closure_custom_output => $self->can('custom_value_output'),
|
||||
closure_custom_threshold_check => $self->can('custom_value_threshold'),
|
||||
closure_custom_perfdata => $self->can('custom_value_perfdata'),
|
||||
}
|
||||
},
|
||||
{ label => 'closing', nlabel => 'apache.slot.closing.count', set => {
|
||||
key_values => [ { name => 'closing' }, { name => 'total' } ],
|
||||
closure_custom_calc => $self->can('custom_value_calc'), closure_custom_calc_extra_options => { label_ref => 'closing' },
|
||||
closure_custom_output => $self->can('custom_value_output'),
|
||||
closure_custom_threshold_check => $self->can('custom_value_threshold'),
|
||||
closure_custom_perfdata => $self->can('custom_value_perfdata'),
|
||||
}
|
||||
},
|
||||
{ label => 'logging', nlabel => 'apache.slot.logging.count', set => {
|
||||
key_values => [ { name => 'logging' }, { name => 'total' } ],
|
||||
closure_custom_calc => $self->can('custom_value_calc'), closure_custom_calc_extra_options => { label_ref => 'logging' },
|
||||
closure_custom_output => $self->can('custom_value_output'),
|
||||
closure_custom_threshold_check => $self->can('custom_value_threshold'),
|
||||
closure_custom_perfdata => $self->can('custom_value_perfdata'),
|
||||
}
|
||||
},
|
||||
{ label => 'gracefuly-finished', nlabel => 'apache.slot.gracefulyfinished.count', set => {
|
||||
key_values => [ { name => 'gracefuly_finished' }, { name => 'total' } ],
|
||||
closure_custom_calc => $self->can('custom_value_calc'), closure_custom_calc_extra_options => { label_ref => 'gracefuly_finished' },
|
||||
closure_custom_output => $self->can('custom_value_output'),
|
||||
closure_custom_threshold_check => $self->can('custom_value_threshold'),
|
||||
closure_custom_perfdata => $self->can('custom_value_perfdata'),
|
||||
}
|
||||
},
|
||||
{ label => 'idle-cleanup-worker', nlabel => 'apache.slot.idlecleanupworker.count', set => {
|
||||
key_values => [ { name => 'idle_cleanup_worker' }, { name => 'total' } ],
|
||||
closure_custom_calc => $self->can('custom_value_calc'), closure_custom_calc_extra_options => { label_ref => 'idle_cleanup_worker' },
|
||||
closure_custom_output => $self->can('custom_value_output'),
|
||||
closure_custom_threshold_check => $self->can('custom_value_threshold'),
|
||||
closure_custom_perfdata => $self->can('custom_value_perfdata'),
|
||||
}
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
$options{options}->add_options(arguments => {
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"port:s" => { name => 'port', },
|
||||
"proto:s" => { name => 'proto' },
|
||||
@ -204,113 +209,47 @@ sub new {
|
||||
"basic" => { name => 'basic' },
|
||||
"username:s" => { name => 'username' },
|
||||
"password:s" => { name => 'password' },
|
||||
"proxyurl:s" => { name => 'proxyurl' },
|
||||
"header:s@" => { name => 'header' },
|
||||
"timeout:s" => { name => 'timeout' },
|
||||
"ssl-opt:s@" => { name => 'ssl_opt' },
|
||||
"units:s" => { name => 'units', default => '%' },
|
||||
});
|
||||
|
||||
$self->{http} = centreon::plugins::http->new(output => $self->{output});
|
||||
|
||||
foreach my $key (('global')) {
|
||||
foreach (keys %{$maps_counters->{$key}}) {
|
||||
my ($id, $name) = split /_/;
|
||||
if (!defined($maps_counters->{$key}->{$_}->{threshold}) || $maps_counters->{$key}->{$_}->{threshold} != 0) {
|
||||
$options{options}->add_options(arguments => {
|
||||
'warning-' . $name . ':s' => { name => 'warning-' . $name },
|
||||
'critical-' . $name . ':s' => { name => 'critical-' . $name },
|
||||
});
|
||||
}
|
||||
$maps_counters->{$key}->{$_}->{obj} = centreon::plugins::values->new(output => $self->{output},
|
||||
perfdata => $self->{perfdata},
|
||||
label => $name);
|
||||
$maps_counters->{$key}->{$_}->{obj}->set(%{$maps_counters->{$key}->{$_}->{set}});
|
||||
}
|
||||
}
|
||||
|
||||
$self->{http} = centreon::plugins::http->new(%options);
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
$self->SUPER::check_options(%options);
|
||||
|
||||
foreach my $key (('global')) {
|
||||
foreach (keys %{$maps_counters->{$key}}) {
|
||||
$maps_counters->{$key}->{$_}->{obj}->init(option_results => $self->{option_results});
|
||||
}
|
||||
}
|
||||
|
||||
$instance_mode = $self;
|
||||
$self->{http}->set_options(%{$self->{option_results}});
|
||||
}
|
||||
|
||||
sub run {
|
||||
sub prefix_global_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->manage_selection();
|
||||
|
||||
my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', '');
|
||||
my @exits;
|
||||
|
||||
foreach (sort keys %{$maps_counters->{global}}) {
|
||||
my $obj = $maps_counters->{global}->{$_}->{obj};
|
||||
|
||||
$obj->set(instance => 'global');
|
||||
|
||||
my ($value_check) = $obj->execute(values => $self->{global});
|
||||
|
||||
if ($value_check != 0) {
|
||||
$long_msg .= $long_msg_append . $obj->output_error();
|
||||
$long_msg_append = ', ';
|
||||
next;
|
||||
}
|
||||
my $exit2 = $obj->threshold_check();
|
||||
push @exits, $exit2;
|
||||
|
||||
my $output = $obj->output();
|
||||
$long_msg .= $long_msg_append . $output;
|
||||
$long_msg_append = ', ';
|
||||
|
||||
if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) {
|
||||
$short_msg .= $short_msg_append . $output;
|
||||
$short_msg_append = ', ';
|
||||
}
|
||||
|
||||
$obj->perfdata();
|
||||
}
|
||||
|
||||
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
|
||||
if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) {
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => "Slots $short_msg"
|
||||
);
|
||||
} else {
|
||||
$self->{output}->output_add(short_msg => "Slots $long_msg");
|
||||
}
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
return 'Slots ';
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $webcontent = $self->{http}->request();
|
||||
my ($webcontent) = $self->{http}->request();
|
||||
my $ScoreBoard = "";
|
||||
if ($webcontent =~ /^Scoreboard:\s+([^\s]+)/mi) {
|
||||
$ScoreBoard = $1;
|
||||
}
|
||||
|
||||
$self->{global} = { total => length($ScoreBoard),
|
||||
$self->{global} = {
|
||||
total => length($ScoreBoard),
|
||||
free => ($ScoreBoard =~ tr/\.//),
|
||||
busy => length($ScoreBoard) - ($ScoreBoard =~ tr/\.//),
|
||||
waiting => ($ScoreBoard =~ tr/\_//), starting => ($ScoreBoard =~ tr/S//),
|
||||
reading => ($ScoreBoard =~ tr/R//), sending => ($ScoreBoard =~ tr/W//),
|
||||
keepalive => ($ScoreBoard =~ tr/K//), dns_lookup => ($ScoreBoard =~ tr/D//),
|
||||
closing => ($ScoreBoard =~ tr/C//), logging => ($ScoreBoard =~ tr/L//),
|
||||
gracefuly_finished => ($ScoreBoard =~ tr/G//), idle_cleanup_worker => ($ScoreBoard =~ tr/I//)};
|
||||
gracefuly_finished => ($ScoreBoard =~ tr/G//), idle_cleanup_worker => ($ScoreBoard =~ tr/I//)
|
||||
};
|
||||
}
|
||||
|
||||
1;
|
||||
@ -331,10 +270,6 @@ IP Address or FQDN of the webserver host
|
||||
|
||||
Port used by Apache
|
||||
|
||||
=item B<--proxyurl>
|
||||
|
||||
Proxy URL if any
|
||||
|
||||
=item B<--proto>
|
||||
|
||||
Protocol used http or https
|
||||
@ -367,10 +302,6 @@ Specify this option if you access server-status page over hidden basic authentic
|
||||
|
||||
Threshold for HTTP timeout
|
||||
|
||||
=item B<--ssl-opt>
|
||||
|
||||
Set SSL Options (--ssl-opt="SSL_version => TLSv1" --ssl-opt="SSL_verify_mode => SSL_VERIFY_NONE").
|
||||
|
||||
=item B<--header>
|
||||
|
||||
Set HTTP headers (Multiple option)
|
||||
|
@ -32,8 +32,7 @@ sub new {
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
$options{options}->add_options(arguments => {
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"port:s" => { name => 'port', },
|
||||
"proto:s" => { name => 'proto' },
|
||||
@ -42,14 +41,12 @@ sub new {
|
||||
"basic" => { name => 'basic' },
|
||||
"username:s" => { name => 'username' },
|
||||
"password:s" => { name => 'password' },
|
||||
"proxyurl:s" => { name => 'proxyurl' },
|
||||
"header:s@" => { name => 'header' },
|
||||
"warning:s" => { name => 'warning' },
|
||||
"critical:s" => { name => 'critical' },
|
||||
"timeout:s" => { name => 'timeout' },
|
||||
"ssl-opt:s@" => { name => 'ssl_opt' },
|
||||
});
|
||||
$self->{http} = centreon::plugins::http->new(output => $self->{output});
|
||||
$self->{http} = centreon::plugins::http->new(%options);
|
||||
return $self;
|
||||
}
|
||||
|
||||
@ -122,10 +119,6 @@ IP Addr/FQDN of the webserver host
|
||||
|
||||
Port used by Apache
|
||||
|
||||
=item B<--proxyurl>
|
||||
|
||||
Proxy URL if any
|
||||
|
||||
=item B<--proto>
|
||||
|
||||
Protocol to use http or https, http is default
|
||||
@ -158,10 +151,6 @@ Specify this option if you access server-status page over hidden basic authentic
|
||||
|
||||
Threshold for HTTP timeout
|
||||
|
||||
=item B<--ssl-opt>
|
||||
|
||||
Set SSL Options (--ssl-opt="SSL_version => TLSv1" --ssl-opt="SSL_verify_mode => SSL_VERIFY_NONE").
|
||||
|
||||
=item B<--header>
|
||||
|
||||
Set HTTP headers (Multiple option)
|
||||
|
179
apps/automation/ansible/cli/custom/cli.pm
Normal file
179
apps/automation/ansible/cli/custom/cli.pm
Normal file
@ -0,0 +1,179 @@
|
||||
#
|
||||
# Copyright 2019 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package apps::automation::ansible::cli::custom::cli;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use JSON::XS;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = {};
|
||||
bless $self, $class;
|
||||
|
||||
if (!defined($options{output})) {
|
||||
print "Class Custom: Need to specify 'output' argument.\n";
|
||||
exit 3;
|
||||
}
|
||||
if (!defined($options{options})) {
|
||||
$options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument.");
|
||||
$options{output}->option_exit();
|
||||
}
|
||||
|
||||
if (!defined($options{noptions})) {
|
||||
$options{options}->add_options(arguments => {
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"remote" => { name => 'remote' },
|
||||
"ssh-option:s@" => { name => 'ssh_option' },
|
||||
"ssh-path:s" => { name => 'ssh_path' },
|
||||
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
|
||||
"timeout:s" => { name => 'timeout', default => 50 },
|
||||
"sudo" => { name => 'sudo' },
|
||||
"command:s" => { name => 'command', default => 'ANSIBLE_LOAD_CALLBACK_PLUGINS=true ANSIBLE_STDOUT_CALLBACK=json ansible' },
|
||||
"command-path:s" => { name => 'command_path' },
|
||||
"command-options:s" => { name => 'command_options', default => '' },
|
||||
});
|
||||
}
|
||||
$options{options}->add_help(package => __PACKAGE__, sections => 'CLI OPTIONS', once => 1);
|
||||
|
||||
$self->{output} = $options{output};
|
||||
$self->{mode} = $options{mode};
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub set_options {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{option_results} = $options{option_results};
|
||||
}
|
||||
|
||||
sub set_defaults {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
foreach (keys %{$options{default}}) {
|
||||
if ($_ eq $self->{mode}) {
|
||||
for (my $i = 0; $i < scalar(@{$options{default}->{$_}}); $i++) {
|
||||
foreach my $opt (keys %{$options{default}->{$_}[$i]}) {
|
||||
if (!defined($self->{option_results}->{$opt}[$i])) {
|
||||
$self->{option_results}->{$opt}[$i] = $options{default}->{$_}[$i]->{$opt};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub execute {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{output}->output_add(long_msg => "Command line: '" . $self->{option_results}->{command} . " " . $options{cmd_options} . "'", debug => 1);
|
||||
|
||||
my ($response) = centreon::plugins::misc::execute(
|
||||
output => $self->{output},
|
||||
options => $self->{option_results},
|
||||
sudo => $self->{option_results}->{sudo},
|
||||
command => $self->{option_results}->{command},
|
||||
command_path => $self->{option_results}->{command_path},
|
||||
command_options => $options{cmd_options}
|
||||
);
|
||||
|
||||
my $raw_results;
|
||||
|
||||
eval {
|
||||
$raw_results = JSON::XS->new->utf8->decode($response);
|
||||
};
|
||||
if ($@) {
|
||||
$self->{output}->output_add(long_msg => $response, debug => 1);
|
||||
$self->{output}->add_option_msg(short_msg => "Cannot decode response (add --debug option to display returned content)");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
return $raw_results;
|
||||
}
|
||||
|
||||
sub ansible_list_hosts_set_cmd {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '');
|
||||
|
||||
my $cmd_options = "$options{host_pattern} --module-name=setup";
|
||||
|
||||
return $cmd_options;
|
||||
}
|
||||
|
||||
sub ansible_list_hosts {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $cmd_options = $self->ansible_list_hosts_set_cmd(%options);
|
||||
my $raw_results = $self->execute(cmd_options => $cmd_options);
|
||||
|
||||
return $raw_results;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Ansible CLI
|
||||
|
||||
=head1 CLI OPTIONS
|
||||
|
||||
Ansible CLI
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Set timeout in seconds (Default: 50).
|
||||
|
||||
=item B<--sudo>
|
||||
|
||||
Use 'sudo' to execute the command.
|
||||
|
||||
=item B<--command>
|
||||
|
||||
Command to get information (Default: 'ANSIBLE_LOAD_CALLBACK_PLUGINS=true ANSIBLE_STDOUT_CALLBACK=json ansible').
|
||||
Can be changed if you have output in a file.
|
||||
|
||||
=item B<--command-path>
|
||||
|
||||
Command path (Default: none).
|
||||
|
||||
=item B<--command-options>
|
||||
|
||||
Command options (Default: none).
|
||||
|
||||
=back
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
B<custom>.
|
||||
|
||||
=cut
|
116
apps/automation/ansible/cli/mode/discovery.pm
Normal file
116
apps/automation/ansible/cli/mode/discovery.pm
Normal file
@ -0,0 +1,116 @@
|
||||
#
|
||||
# Copyright 2019 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package apps::automation::ansible::cli::mode::discovery;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use JSON::XS;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments => {
|
||||
"host-pattern:s" => { name => 'host_pattern', default => 'all' },
|
||||
"prettify" => { name => 'prettify' },
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my @disco_data;
|
||||
my $disco_stats;
|
||||
|
||||
$disco_stats->{start_time} = time();
|
||||
|
||||
my $result = $options{custom}->ansible_list_hosts(host_pattern => $self->{option_results}->{host_pattern});
|
||||
|
||||
$disco_stats->{end_time} = time();
|
||||
$disco_stats->{duration} = $disco_stats->{end_time} - $disco_stats->{start_time};
|
||||
|
||||
foreach my $play (@{$result->{plays}}) {
|
||||
foreach my $task (@{$play->{tasks}}) {
|
||||
foreach my $host (keys %{$task->{hosts}}) {
|
||||
my %host;
|
||||
$host{ip} = $host;
|
||||
$host{hostname} = $task->{hosts}->{$host}->{ansible_facts}->{ansible_hostname};
|
||||
$host{fqdn} = $task->{hosts}->{$host}->{ansible_facts}->{ansible_fqdn};
|
||||
$host{type} = $task->{hosts}->{$host}->{ansible_facts}->{ansible_system};
|
||||
$host{distribution} = $task->{hosts}->{$host}->{ansible_facts}->{ansible_distribution};
|
||||
$host{all_ips} = $task->{hosts}->{$host}->{ansible_facts}->{ansible_all_ipv4_addresses};
|
||||
push @disco_data, \%host;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$disco_stats->{discovered_items} = @disco_data;
|
||||
$disco_stats->{results} = \@disco_data;
|
||||
|
||||
my $encoded_data;
|
||||
eval {
|
||||
if (defined($self->{option_results}->{prettify})) {
|
||||
$encoded_data = JSON::XS->new->utf8->pretty->encode($disco_stats);
|
||||
} else {
|
||||
$encoded_data = JSON::XS->new->utf8->encode($disco_stats);
|
||||
}
|
||||
};
|
||||
if ($@) {
|
||||
$encoded_data = '{"code":"encode_error","message":"Cannot encode discovered data into JSON format"}';
|
||||
}
|
||||
|
||||
$self->{output}->output_add(short_msg => $encoded_data);
|
||||
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1);
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Resources discovery.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--host-pattern>
|
||||
|
||||
Specify host pattern to look for (Default: 'all').
|
||||
|
||||
=item B<--prettify>
|
||||
|
||||
Prettify JSON output.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
49
apps/automation/ansible/cli/plugin.pm
Normal file
49
apps/automation/ansible/cli/plugin.pm
Normal file
@ -0,0 +1,49 @@
|
||||
#
|
||||
# Copyright 2019 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package apps::automation::ansible::cli::plugin;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use base qw(centreon::plugins::script_custom);
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
%{$self->{modes}} = (
|
||||
'discovery' => 'apps::automation::ansible::cli::mode::discovery',
|
||||
);
|
||||
|
||||
$self->{custom_modes}{cli} = 'apps::automation::ansible::cli::custom::cli';
|
||||
return $self;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 PLUGIN DESCRIPTION
|
||||
|
||||
Check Ansible using CLI.
|
||||
|
||||
=cut
|
254
apps/automation/ansible/tower/custom/towercli.pm
Normal file
254
apps/automation/ansible/tower/custom/towercli.pm
Normal file
@ -0,0 +1,254 @@
|
||||
#
|
||||
# Copyright 2019 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package apps::automation::ansible::tower::custom::towercli;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use DateTime;
|
||||
use JSON::XS;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = {};
|
||||
bless $self, $class;
|
||||
|
||||
if (!defined($options{output})) {
|
||||
print "Class Custom: Need to specify 'output' argument.\n";
|
||||
exit 3;
|
||||
}
|
||||
if (!defined($options{options})) {
|
||||
$options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument.");
|
||||
$options{output}->option_exit();
|
||||
}
|
||||
|
||||
if (!defined($options{noptions})) {
|
||||
$options{options}->add_options(arguments => {
|
||||
"host:s" => { name => 'host' },
|
||||
"username:s" => { name => 'username' },
|
||||
"password:s" => { name => 'password' },
|
||||
"timeout:s" => { name => 'timeout', default => 50 },
|
||||
"sudo" => { name => 'sudo' },
|
||||
"command:s" => { name => 'command', default => 'tower-cli' },
|
||||
"command-path:s" => { name => 'command_path' },
|
||||
"command-options:s" => { name => 'command_options', default => '' },
|
||||
"proxyurl:s" => { name => 'proxyurl' },
|
||||
});
|
||||
}
|
||||
$options{options}->add_help(package => __PACKAGE__, sections => 'TOWERCLI OPTIONS', once => 1);
|
||||
|
||||
$self->{output} = $options{output};
|
||||
$self->{mode} = $options{mode};
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub set_options {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{option_results} = $options{option_results};
|
||||
}
|
||||
|
||||
sub set_defaults {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
foreach (keys %{$options{default}}) {
|
||||
if ($_ eq $self->{mode}) {
|
||||
for (my $i = 0; $i < scalar(@{$options{default}->{$_}}); $i++) {
|
||||
foreach my $opt (keys %{$options{default}->{$_}[$i]}) {
|
||||
if (!defined($self->{option_results}->{$opt}[$i])) {
|
||||
$self->{option_results}->{$opt}[$i] = $options{default}->{$_}[$i]->{$opt};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($self->{option_results}->{proxyurl}) && $self->{option_results}->{proxyurl} ne '') {
|
||||
$ENV{HTTP_PROXY} = $self->{option_results}->{proxyurl};
|
||||
$ENV{HTTPS_PROXY} = $self->{option_results}->{proxyurl};
|
||||
}
|
||||
|
||||
$self->{host} = (defined($self->{option_results}->{host})) ? $self->{option_results}->{host} : undef;
|
||||
$self->{username} = (defined($self->{option_results}->{username})) ? $self->{option_results}->{username} : undef;
|
||||
$self->{password} = (defined($self->{option_results}->{password})) ? $self->{option_results}->{password} : undef;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub execute {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{output}->output_add(long_msg => "Command line: '" . $self->{option_results}->{command} . " " . $options{cmd_options} . "'", debug => 1);
|
||||
|
||||
my ($response) = centreon::plugins::misc::execute(
|
||||
output => $self->{output},
|
||||
options => $self->{option_results},
|
||||
sudo => $self->{option_results}->{sudo},
|
||||
command => $self->{option_results}->{command},
|
||||
command_path => $self->{option_results}->{command_path},
|
||||
command_options => $options{cmd_options});
|
||||
|
||||
my $raw_results;
|
||||
|
||||
eval {
|
||||
$raw_results = JSON::XS->new->utf8->decode($response);
|
||||
};
|
||||
if ($@) {
|
||||
$self->{output}->output_add(long_msg => $response, debug => 1);
|
||||
$self->{output}->add_option_msg(short_msg => "Cannot decode response (add --debug option to display returned content)");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
return $raw_results;
|
||||
}
|
||||
|
||||
sub tower_list_hosts_set_cmd {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '');
|
||||
|
||||
my $cmd_options = "host list --insecure --all-pages --format json";
|
||||
$cmd_options .= " --tower-host '$self->{host}'" if (defined($self->{host}) && $self->{host} ne '');
|
||||
$cmd_options .= " --tower-username '$self->{username}'" if (defined($self->{username}) && $self->{username} ne '');
|
||||
$cmd_options .= " --tower-password '$self->{password}'" if (defined($self->{password}) && $self->{password} ne '');
|
||||
$cmd_options .= " --group '$options{group}'" if (defined($options{group}) && $options{group} ne '');
|
||||
$cmd_options .= " --inventory '$options{inventory}'" if (defined($options{inventory}) && $options{inventory} ne '');
|
||||
|
||||
return $cmd_options;
|
||||
}
|
||||
|
||||
sub tower_list_hosts {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $cmd_options = $self->tower_list_hosts_set_cmd(%options);
|
||||
my $raw_results = $self->execute(cmd_options => $cmd_options);
|
||||
|
||||
return $raw_results;
|
||||
}
|
||||
|
||||
sub tower_list_inventories_set_cmd {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '');
|
||||
|
||||
my $cmd_options = "inventory list --insecure --all-pages --format json";
|
||||
$cmd_options .= " --tower-host '$self->{host}'" if (defined($self->{host}) && $self->{host} ne '');
|
||||
$cmd_options .= " --tower-username '$self->{username}'" if (defined($self->{username}) && $self->{username} ne '');
|
||||
$cmd_options .= " --tower-password '$self->{password}'" if (defined($self->{password}) && $self->{password} ne '');
|
||||
|
||||
return $cmd_options;
|
||||
}
|
||||
|
||||
sub tower_list_inventories {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $cmd_options = $self->tower_list_inventories_set_cmd(%options);
|
||||
my $raw_results = $self->execute(cmd_options => $cmd_options);
|
||||
|
||||
return $raw_results;
|
||||
}
|
||||
|
||||
sub tower_list_projects_set_cmd {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '');
|
||||
|
||||
my $cmd_options = "project list --insecure --all-pages --format json";
|
||||
$cmd_options .= " --tower-host '$self->{host}'" if (defined($self->{host}) && $self->{host} ne '');
|
||||
$cmd_options .= " --tower-username '$self->{username}'" if (defined($self->{username}) && $self->{username} ne '');
|
||||
$cmd_options .= " --tower-password '$self->{password}'" if (defined($self->{password}) && $self->{password} ne '');
|
||||
|
||||
return $cmd_options;
|
||||
}
|
||||
|
||||
sub tower_list_projects {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $cmd_options = $self->tower_list_projects_set_cmd(%options);
|
||||
my $raw_results = $self->execute(cmd_options => $cmd_options);
|
||||
|
||||
return $raw_results;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Ansible Tower CLI
|
||||
|
||||
=head1 TOWERCLI OPTIONS
|
||||
|
||||
Ansible Tower CLI
|
||||
|
||||
To install the Tower CLI : https://docs.ansible.com/ansible-tower/latest/html/towerapi/tower_cli.html#installation
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--host>
|
||||
|
||||
Ansible Tower host (Default uses setting in 'tower config').
|
||||
|
||||
=item B<--username>
|
||||
|
||||
Ansible Tower username (Default uses setting in 'tower config').
|
||||
|
||||
=item B<--password>
|
||||
|
||||
Ansible Tower password (Default uses setting in 'tower config').
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Set timeout in seconds (Default: 50).
|
||||
|
||||
=item B<--sudo>
|
||||
|
||||
Use 'sudo' to execute the command.
|
||||
|
||||
=item B<--command>
|
||||
|
||||
Command to get information (Default: 'tower-cli').
|
||||
Can be changed if you have output in a file.
|
||||
|
||||
=item B<--command-path>
|
||||
|
||||
Command path (Default: none).
|
||||
|
||||
=item B<--command-options>
|
||||
|
||||
Command options (Default: none).
|
||||
|
||||
=item B<--proxyurl>
|
||||
|
||||
Proxy URL if any
|
||||
|
||||
=back
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
B<custom>.
|
||||
|
||||
=cut
|
176
apps/automation/ansible/tower/mode/dashboard.pm
Normal file
176
apps/automation/ansible/tower/mode/dashboard.pm
Normal file
@ -0,0 +1,176 @@
|
||||
#
|
||||
# Copyright 2019 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package apps::automation::ansible::tower::mode::dashboard;
|
||||
|
||||
use base qw(centreon::plugins::templates::counter);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'global', type => 0, cb_prefix_output => 'prefix_output'},
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{global} = [
|
||||
{ label => 'hosts-total', nlabel => 'hosts.total.count', set => {
|
||||
key_values => [ { name => 'hosts_total' } ],
|
||||
output_template => 'Hosts Total: %d',
|
||||
perfdatas => [
|
||||
{ value => 'hosts_total_absolute', template => '%d', min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'hosts-failed', nlabel => 'hosts.failed.count', set => {
|
||||
key_values => [ { name => 'hosts_failed' },{ name => 'hosts_total' } ],
|
||||
output_template => 'Hosts Failed: %d',
|
||||
perfdatas => [
|
||||
{ value => 'hosts_failed_absolute', template => '%d', min => 0,
|
||||
max => 'hosts_total_absolute' },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'inventories-total', nlabel => 'inventories.total.count', set => {
|
||||
key_values => [ { name => 'inventories_total' } ],
|
||||
output_template => 'Inventories Total: %d',
|
||||
perfdatas => [
|
||||
{ value => 'inventories_total_absolute', template => '%d', min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'inventories-sync-failed', nlabel => 'inventories.sync.failed.count', set => {
|
||||
key_values => [ { name => 'inventories_sync_failed' }, { name => 'inventories_total' } ],
|
||||
output_template => 'Inventories Sync Failed: %d',
|
||||
perfdatas => [
|
||||
{ value => 'inventories_sync_failed_absolute', template => '%d', min => 0,
|
||||
max => 'inventories_total_absolute' },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'projects-total', nlabel => 'projects.total.count', set => {
|
||||
key_values => [ { name => 'projects_total' } ],
|
||||
output_template => 'Projects Total: %d',
|
||||
perfdatas => [
|
||||
{ value => 'projects_total_absolute', template => '%d', min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'projects-sync-failed', nlabel => 'projects.sync.failed.count', set => {
|
||||
key_values => [ { name => 'projects_sync_failed' }, { name => 'projects_total' } ],
|
||||
output_template => 'Projects Sync Failed: %d',
|
||||
perfdatas => [
|
||||
{ value => 'projects_sync_failed_absolute', template => '%d', min => 0,
|
||||
max => 'projects_total_absolute' },
|
||||
],
|
||||
}
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments => {});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{global} = {
|
||||
hosts_total => 0, hosts_failed => 0,
|
||||
inventories_total => 0, inventories_sync_failed => 0,
|
||||
projects_total => 0, projects_sync_failed => 0
|
||||
};
|
||||
|
||||
my $hosts = $options{custom}->tower_list_hosts();
|
||||
$self->{global}->{hosts_total} = $hosts->{count};
|
||||
foreach my $host (@{$hosts->{results}}) {
|
||||
$self->{global}->{hosts_failed}++ if ($host->{has_active_failures});
|
||||
}
|
||||
|
||||
my $inventories = $options{custom}->tower_list_inventories();
|
||||
$self->{global}->{inventories_total} = $inventories->{count};
|
||||
foreach my $inventory (@{$inventories->{results}}) {
|
||||
$self->{global}->{inventories_sync_failed}++ if ($inventory->{inventory_sources_with_failures} > 0);
|
||||
}
|
||||
|
||||
my $projects = $options{custom}->tower_list_projects();
|
||||
$self->{global}->{projects_total} = $projects->{count};
|
||||
foreach my $project (@{$projects->{results}}) {
|
||||
$self->{global}->{projects_sync_failed}++ if ($project->{status} =~ /failed|canceled/);
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check several counters available through Tower dashboard.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--warning-hosts-*-count>
|
||||
|
||||
Threshold warning.
|
||||
Can be: 'total', 'failed'.
|
||||
|
||||
=item B<--critical-hosts-*-count>
|
||||
|
||||
Threshold critical.
|
||||
Can be: 'total', 'failed'.
|
||||
|
||||
=item B<--warning-inventories-*-count>
|
||||
|
||||
Threshold warning.
|
||||
Can be: 'total', 'sync-failed'.
|
||||
|
||||
=item B<--critical-inventories-*-count>
|
||||
|
||||
Threshold critical.
|
||||
Can be: 'total', 'sync-failed'.
|
||||
|
||||
=item B<--warning-projects-*-count>
|
||||
|
||||
Threshold warning.
|
||||
Can be: 'total', 'sync-failed'.
|
||||
|
||||
=item B<--critical-projects-*-count>
|
||||
|
||||
Threshold critical.
|
||||
Can be: 'total', 'sync-failed'.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
122
apps/automation/ansible/tower/mode/discovery.pm
Normal file
122
apps/automation/ansible/tower/mode/discovery.pm
Normal file
@ -0,0 +1,122 @@
|
||||
#
|
||||
# Copyright 2019 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package apps::automation::ansible::tower::mode::discovery;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use JSON::XS;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments => {
|
||||
"group" => { name => 'group' },
|
||||
"inventory" => { name => 'inventory' },
|
||||
"prettify" => { name => 'prettify' },
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my @disco_data;
|
||||
my $disco_stats;
|
||||
|
||||
$disco_stats->{start_time} = time();
|
||||
|
||||
my $hosts = $options{custom}->tower_list_hosts(
|
||||
group => $self->{option_results}->{group},
|
||||
inventory => $self->{option_results}->{inventory}
|
||||
);
|
||||
|
||||
$disco_stats->{end_time} = time();
|
||||
$disco_stats->{duration} = $disco_stats->{end_time} - $disco_stats->{start_time};
|
||||
|
||||
foreach my $host (@{$hosts->{results}}) {
|
||||
my %host;
|
||||
$host{name} = $host->{name};
|
||||
$host{id} = $host->{id};
|
||||
$host{description} = $host->{description};
|
||||
$host{type} = $host->{type};
|
||||
$host{inventory_id} = $host->{inventory};
|
||||
$host{inventory_name} = $host->{summary_fields}->{inventory}->{name};
|
||||
$host{groups} = $host->{summary_fields}->{groups}->{results};
|
||||
$host{enabled} = $host->{enabled};
|
||||
push @disco_data, \%host;
|
||||
}
|
||||
|
||||
$disco_stats->{discovered_items} = @disco_data;
|
||||
$disco_stats->{results} = \@disco_data;
|
||||
|
||||
my $encoded_data;
|
||||
eval {
|
||||
if (defined($self->{option_results}->{prettify})) {
|
||||
$encoded_data = JSON::XS->new->utf8->pretty->encode($disco_stats);
|
||||
} else {
|
||||
$encoded_data = JSON::XS->new->utf8->encode($disco_stats);
|
||||
}
|
||||
};
|
||||
if ($@) {
|
||||
$encoded_data = '{"code":"encode_error","message":"Cannot encode discovered data into JSON format"}';
|
||||
}
|
||||
|
||||
$self->{output}->output_add(short_msg => $encoded_data);
|
||||
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1);
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Resources discovery.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--group>
|
||||
|
||||
Specify host group.
|
||||
|
||||
=item B<--inventory>
|
||||
|
||||
Specify host inventory.
|
||||
|
||||
=item B<--prettify>
|
||||
|
||||
Prettify JSON output.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
220
apps/automation/ansible/tower/mode/inventorystatistics.pm
Normal file
220
apps/automation/ansible/tower/mode/inventorystatistics.pm
Normal file
@ -0,0 +1,220 @@
|
||||
#
|
||||
# Copyright 2019 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package apps::automation::ansible::tower::mode::inventorystatistics;
|
||||
|
||||
use base qw(centreon::plugins::templates::counter);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'global', type => 0, cb_prefix_output => 'prefix_output', cb_init => 'skip_global' },
|
||||
{ name => 'inventories', type => 1, cb_prefix_output => 'prefix_output_inventories',
|
||||
message_multiple => 'All inventories statistics are ok' },
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{global} = [
|
||||
{ label => 'total', nlabel => 'inventories.total.count', set => {
|
||||
key_values => [ { name => 'total' } ],
|
||||
output_template => 'Total: %d',
|
||||
perfdatas => [
|
||||
{ value => 'total_absolute', template => '%d', min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'failed', nlabel => 'inventories.failed.count', set => {
|
||||
key_values => [ { name => 'failed' }, { name => 'total' } ],
|
||||
output_template => 'Failed: %d',
|
||||
perfdatas => [
|
||||
{ value => 'failed_absolute', template => '%d', min => 0,
|
||||
max => 'total_absolute' },
|
||||
],
|
||||
}
|
||||
},
|
||||
];
|
||||
$self->{maps_counters}->{inventories} = [
|
||||
{ label => 'hosts-total', nlabel => 'inventory.hosts.total.count', set => {
|
||||
key_values => [ { name => 'total_hosts' }, { name => 'display' } ],
|
||||
output_template => 'Hosts total: %d',
|
||||
perfdatas => [
|
||||
{ value => 'total_hosts_absolute', template => '%d',
|
||||
min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'hosts-failed', nlabel => 'inventory.hosts.failed.count', set => {
|
||||
key_values => [ { name => 'hosts_with_active_failures' }, { name => 'total_hosts' },
|
||||
{ name => 'display' } ],
|
||||
output_template => 'Hosts failed: %d',
|
||||
perfdatas => [
|
||||
{ value => 'hosts_with_active_failures_absolute', template => '%d',
|
||||
min => 0, max => 'total_hosts_absolute', label_extra_instance => 1,
|
||||
instance_use => 'display_absolute' },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'sources-total', nlabel => 'inventory.sources.total.count', set => {
|
||||
key_values => [ { name => 'total_inventory_sources' }, { name => 'display' } ],
|
||||
output_template => 'Sources total: %d',
|
||||
perfdatas => [
|
||||
{ value => 'total_inventory_sources_absolute', template => '%d',
|
||||
min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'sources-failed', nlabel => 'inventory.sources.failed.count', set => {
|
||||
key_values => [ { name => 'inventory_sources_with_failures' }, { name => 'total_inventory_sources' },
|
||||
{ name => 'display' } ],
|
||||
output_template => 'Sources failed: %d',
|
||||
perfdatas => [
|
||||
{ value => 'inventory_sources_with_failures_absolute', template => '%d',
|
||||
min => 0, max => 'total_inventory_sources_absolute', label_extra_instance => 1,
|
||||
instance_use => 'display_absolute' },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'groups-total', nlabel => 'inventory.groups.total.count', set => {
|
||||
key_values => [ { name => 'total_groups' }, { name => 'display' } ],
|
||||
output_template => 'Groups total: %d',
|
||||
perfdatas => [
|
||||
{ value => 'total_groups_absolute', template => '%d',
|
||||
min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'groups-failed', nlabel => 'inventory.groups.failed.count', set => {
|
||||
key_values => [ { name => 'groups_with_active_failures' }, { name => 'total_groups' },
|
||||
{ name => 'display' } ],
|
||||
output_template => 'Groups failed: %d',
|
||||
perfdatas => [
|
||||
{ value => 'groups_with_active_failures_absolute', template => '%d',
|
||||
min => 0, max => 'total_groups_absolute', label_extra_instance => 1,
|
||||
instance_use => 'display_absolute' },
|
||||
],
|
||||
}
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
sub skip_global {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
scalar(keys %{$self->{inventories}}) > 1 ? return(0) : return(1);
|
||||
}
|
||||
|
||||
sub prefix_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Inventories ";
|
||||
}
|
||||
|
||||
sub prefix_output_inventories {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Inventory '" . $options{instance_value}->{display} . "' ";
|
||||
}
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments => {
|
||||
"filter-inventory" => { name => 'filter_inventory' },
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{global} = { total => 0, failed => 0 };
|
||||
|
||||
my $inventories = $options{custom}->tower_list_inventories();
|
||||
|
||||
$self->{global}->{total} = $inventories->{count};
|
||||
|
||||
foreach my $inventory (@{$inventories->{results}}) {
|
||||
next if (defined($self->{option_results}->{filter_inventory}) && $self->{option_results}->{filter_inventory} ne ''
|
||||
&& $inventory->{name} !~ /$self->{option_results}->{filter_inventory}/);
|
||||
|
||||
$self->{inventories}->{$inventory->{id}} = {
|
||||
display => $inventory->{name},
|
||||
total_hosts => $inventory->{total_hosts},
|
||||
hosts_with_active_failures => $inventory->{hosts_with_active_failures},
|
||||
total_inventory_sources => $inventory->{total_inventory_sources},
|
||||
inventory_sources_with_failures => $inventory->{inventory_sources_with_failures},
|
||||
total_groups => $inventory->{total_groups},
|
||||
groups_with_active_failures => $inventory->{groups_with_active_failures},
|
||||
};
|
||||
|
||||
$self->{global}->{failed}++ if ($inventory->{has_active_failures});
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check inventories statistics.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--filter-inventory>
|
||||
|
||||
Filter inventory name (Can use regexp).
|
||||
|
||||
=item B<--warning-inventories-*-count>
|
||||
|
||||
Threshold warning.
|
||||
Can be: 'total', 'failed'.
|
||||
|
||||
=item B<--critical-inventories-*-count>
|
||||
|
||||
Threshold critical.
|
||||
Can be: 'total', 'failed'.
|
||||
|
||||
=item B<--warning-instance-inventory.*.*.count>
|
||||
|
||||
Threshold warning.
|
||||
Can be 'hosts', 'sources', 'groups' and 'total', 'failed'.
|
||||
|
||||
=item B<--critical-instance-inventory.*.*.count>
|
||||
|
||||
Threshold critical.
|
||||
Can be 'hosts', 'sources', 'groups' and 'total', 'failed'
|
||||
'indexes'.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
51
apps/automation/ansible/tower/plugin.pm
Normal file
51
apps/automation/ansible/tower/plugin.pm
Normal file
@ -0,0 +1,51 @@
|
||||
#
|
||||
# Copyright 2019 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package apps::automation::ansible::tower::plugin;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use base qw(centreon::plugins::script_custom);
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
%{$self->{modes}} = (
|
||||
'dashboard' => 'apps::automation::ansible::tower::mode::dashboard',
|
||||
'discovery' => 'apps::automation::ansible::tower::mode::discovery',
|
||||
'inventory-statistics' => 'apps::automation::ansible::tower::mode::inventorystatistics',
|
||||
);
|
||||
|
||||
$self->{custom_modes}{towercli} = 'apps::automation::ansible::tower::custom::towercli';
|
||||
return $self;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 PLUGIN DESCRIPTION
|
||||
|
||||
Check Ansible Tower using API (tower-cli or RestAPI).
|
||||
|
||||
=cut
|
@ -204,8 +204,7 @@ sub new {
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
$options{options}->add_options(arguments => {
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"remote" => { name => 'remote' },
|
||||
"ssh-option:s@" => { name => 'ssh_option' },
|
||||
@ -237,8 +236,10 @@ sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::check_options(%options);
|
||||
|
||||
$self->change_macros(macros => ['ok_status', 'warning_status', 'critical_status', 'warning_long',
|
||||
'critical_long', 'warning_frozen', 'critical_frozen']);
|
||||
$self->change_macros(macros => [
|
||||
'ok_status', 'warning_status', 'critical_status', 'warning_long',
|
||||
'critical_long', 'warning_frozen', 'critical_frozen']
|
||||
);
|
||||
}
|
||||
|
||||
sub policy_long_output {
|
||||
|
@ -26,20 +26,18 @@ use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::misc;
|
||||
|
||||
my $instance_mode;
|
||||
|
||||
sub custom_usage_perfdata {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $label = 'used';
|
||||
my $value_perf = $self->{result_values}->{used};
|
||||
if (defined($instance_mode->{option_results}->{free})) {
|
||||
if (defined($self->{instance_mode}->{option_results}->{free})) {
|
||||
$label = 'free';
|
||||
$value_perf = $self->{result_values}->{free};
|
||||
}
|
||||
|
||||
my %total_options = ();
|
||||
if ($instance_mode->{option_results}->{units} eq '%') {
|
||||
if ($self->{instance_mode}->{option_results}->{units} eq '%') {
|
||||
$total_options{total} = $self->{result_values}->{total};
|
||||
$total_options{cast_int} = 1;
|
||||
}
|
||||
@ -56,10 +54,10 @@ sub custom_usage_threshold {
|
||||
|
||||
my ($exit, $threshold_value);
|
||||
$threshold_value = $self->{result_values}->{used};
|
||||
$threshold_value = $self->{result_values}->{free} if (defined($instance_mode->{option_results}->{free}));
|
||||
if ($instance_mode->{option_results}->{units} eq '%') {
|
||||
$threshold_value = $self->{result_values}->{free} if (defined($self->{instance_mode}->{option_results}->{free}));
|
||||
if ($self->{instance_mode}->{option_results}->{units} eq '%') {
|
||||
$threshold_value = $self->{result_values}->{prct_used};
|
||||
$threshold_value = $self->{result_values}->{prct_free} if (defined($instance_mode->{option_results}->{free}));
|
||||
$threshold_value = $self->{result_values}->{prct_free} if (defined($self->{instance_mode}->{option_results}->{free}));
|
||||
}
|
||||
$exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]);
|
||||
return $exit;
|
||||
@ -113,8 +111,7 @@ sub new {
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
$options{options}->add_options(arguments => {
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"remote" => { name => 'remote' },
|
||||
"ssh-option:s@" => { name => 'ssh_option' },
|
||||
@ -133,13 +130,6 @@ sub new {
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::check_options(%options);
|
||||
|
||||
$instance_mode = $self;
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
|
@ -51,19 +51,21 @@ sub custom_usage_perfdata {
|
||||
$label = 'free';
|
||||
$value_perf = $self->{result_values}->{free};
|
||||
}
|
||||
my $extra_label = '';
|
||||
$extra_label = '_' . $self->{result_values}->{display} if (!defined($options{extra_instance}) || $options{extra_instance} != 0);
|
||||
|
||||
my %total_options = ();
|
||||
if ($self->{instance_mode}->{option_results}->{units} eq '%') {
|
||||
$total_options{total} = $self->{result_values}->{total};
|
||||
$total_options{cast_int} = 1;
|
||||
}
|
||||
|
||||
$self->{output}->perfdata_add(label => $label . $extra_label, unit => 'B',
|
||||
$self->{output}->perfdata_add(
|
||||
label => $label, unit => 'B',
|
||||
instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef,
|
||||
value => $value_perf,
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options),
|
||||
min => 0, max => $self->{result_values}->{total});
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}, %total_options),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}, %total_options),
|
||||
min => 0, max => $self->{result_values}->{total}
|
||||
);
|
||||
}
|
||||
|
||||
sub custom_usage_threshold {
|
||||
@ -76,7 +78,7 @@ sub custom_usage_threshold {
|
||||
$threshold_value = $self->{result_values}->{prct_used};
|
||||
$threshold_value = $self->{result_values}->{prct_free} if (defined($self->{instance_mode}->{option_results}->{free}));
|
||||
}
|
||||
$exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]);
|
||||
$exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{thlabel}, exit_litteral => 'warning' } ]);
|
||||
return $exit;
|
||||
}
|
||||
|
||||
|
@ -51,19 +51,21 @@ sub custom_usage_perfdata {
|
||||
$label = 'free';
|
||||
$value_perf = $self->{result_values}->{free};
|
||||
}
|
||||
my $extra_label = '';
|
||||
$extra_label = '_' . $self->{result_values}->{display} if (!defined($options{extra_instance}) || $options{extra_instance} != 0);
|
||||
|
||||
my %total_options = ();
|
||||
if ($self->{instance_mode}->{option_results}->{units} eq '%') {
|
||||
$total_options{total} = $self->{result_values}->{total};
|
||||
$total_options{cast_int} = 1;
|
||||
}
|
||||
|
||||
$self->{output}->perfdata_add(label => $label . $extra_label, unit => 'B',
|
||||
$self->{output}->perfdata_add(
|
||||
label => $label, unit => 'B',
|
||||
instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef,
|
||||
value => $value_perf,
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options),
|
||||
min => 0, max => $self->{result_values}->{total});
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}, %total_options),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}, %total_options),
|
||||
min => 0, max => $self->{result_values}->{total}
|
||||
);
|
||||
}
|
||||
|
||||
sub custom_usage_threshold {
|
||||
@ -76,7 +78,7 @@ sub custom_usage_threshold {
|
||||
$threshold_value = $self->{result_values}->{prct_used};
|
||||
$threshold_value = $self->{result_values}->{prct_free} if (defined($self->{instance_mode}->{option_results}->{free}));
|
||||
}
|
||||
$exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]);
|
||||
$exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{thlabel}, exit_litteral => 'warning' } ]);
|
||||
return $exit;
|
||||
}
|
||||
|
||||
|
452
apps/bind9/web/custom/api.pm
Normal file
452
apps/bind9/web/custom/api.pm
Normal file
@ -0,0 +1,452 @@
|
||||
#
|
||||
# Copyright 2019 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package apps::bind9::web::custom::api;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::misc;
|
||||
use centreon::plugins::http;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = {};
|
||||
bless $self, $class;
|
||||
|
||||
if (!defined($options{output})) {
|
||||
print "Class Custom: Need to specify 'output' argument.\n";
|
||||
exit 3;
|
||||
}
|
||||
if (!defined($options{options})) {
|
||||
$options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument.");
|
||||
$options{output}->option_exit();
|
||||
}
|
||||
|
||||
if (!defined($options{noptions})) {
|
||||
$options{options}->add_options(arguments => {
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"port:s" => { name => 'port' },
|
||||
"proto:s" => { name => 'proto' },
|
||||
"url-path:s" => { name => 'url_path' },
|
||||
"timeout:s" => { name => 'timeout' },
|
||||
"unknown-status:s" => { name => 'unknown_status', default => '%{http_code} < 200 or %{http_code} >= 300' },
|
||||
"warning-status:s" => { name => 'warning_status' },
|
||||
"critical-status:s" => { name => 'critical_status' },
|
||||
});
|
||||
}
|
||||
$options{options}->add_help(package => __PACKAGE__, sections => 'API OPTIONS', once => 1);
|
||||
|
||||
$self->{output} = $options{output};
|
||||
$self->{mode} = $options{mode};
|
||||
$self->{http} = centreon::plugins::http->new(%options);
|
||||
|
||||
return $self;
|
||||
|
||||
}
|
||||
|
||||
# Method to manage multiples
|
||||
sub set_options {
|
||||
my ($self, %options) = @_;
|
||||
# options{options_result}
|
||||
|
||||
$self->{option_results} = $options{option_results};
|
||||
}
|
||||
|
||||
# Method to manage multiples
|
||||
sub set_defaults {
|
||||
my ($self, %options) = @_;
|
||||
# options{default}
|
||||
|
||||
# Manage default value
|
||||
foreach (keys %{$options{default}}) {
|
||||
if ($_ eq $self->{mode}) {
|
||||
for (my $i = 0; $i < scalar(@{$options{default}->{$_}}); $i++) {
|
||||
foreach my $opt (keys %{$options{default}->{$_}[$i]}) {
|
||||
if (!defined($self->{option_results}->{$opt}[$i])) {
|
||||
$self->{option_results}->{$opt}[$i] = $options{default}->{$_}[$i]->{$opt};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{hostname} = (defined($self->{option_results}->{hostname})) ? $self->{option_results}->{hostname} : undef;
|
||||
$self->{port} = (defined($self->{option_results}->{port})) ? $self->{option_results}->{port} : 8080;
|
||||
$self->{proto} = (defined($self->{option_results}->{proto})) ? $self->{option_results}->{proto} : 'http';
|
||||
$self->{timeout} = (defined($self->{option_results}->{timeout})) ? $self->{option_results}->{timeout} : 10;
|
||||
$self->{url_path} = (defined($self->{option_results}->{url_path})) ? $self->{option_results}->{url_path} : '/';
|
||||
$self->{unknown_status} = (defined($self->{option_results}->{unknown_status})) ? $self->{option_results}->{unknown_status} : undef;
|
||||
$self->{warning_status} = (defined($self->{option_results}->{warning_status})) ? $self->{option_results}->{warning_status} : undef;
|
||||
$self->{critical_status} = (defined($self->{option_results}->{critical_status})) ? $self->{option_results}->{critical_status} : undef;
|
||||
|
||||
if (!defined($self->{hostname})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Need to specify hostname option.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub get_uniq_id {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return $self->{hostname} . '_' . $self->{port};
|
||||
}
|
||||
|
||||
sub build_options_for_httplib {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{option_results}->{hostname} = $self->{hostname};
|
||||
$self->{option_results}->{timeout} = $self->{timeout};
|
||||
$self->{option_results}->{port} = $self->{port};
|
||||
$self->{option_results}->{proto} = $self->{proto};
|
||||
$self->{option_results}->{url_path} = $self->{url_path};
|
||||
$self->{option_results}->{unknown_status} = $self->{unknown_status};
|
||||
$self->{option_results}->{warning_status} = $self->{warning_status};
|
||||
$self->{option_results}->{critical_status} = $self->{critical_status};
|
||||
}
|
||||
|
||||
sub settings {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->build_options_for_httplib();
|
||||
$self->{http}->set_options(%{$self->{option_results}});
|
||||
}
|
||||
|
||||
sub load_response {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if ($self->{response_type} eq 'xml') {
|
||||
centreon::plugins::misc::mymodule_load(output => $self->{output}, module => 'XML::XPath',
|
||||
error_msg => "Cannot load module 'XML::XPath'.");
|
||||
eval {
|
||||
$self->{xpath_response} = XML::XPath->new(xml => $options{response});
|
||||
};
|
||||
if ($@) {
|
||||
$self->{output}->add_option_msg(short_msg => "Cannot load XML response");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub request {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->settings();
|
||||
my $response = $self->{http}->request();
|
||||
|
||||
my ($content_type) = $self->{http}->get_header(name => 'Content-Type');
|
||||
if (!defined($content_type) || $content_type !~ /(xml|json)/i) {
|
||||
$self->{output}->add_option_msg(short_msg => "content-type not set");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
$self->{response_type} = $1;
|
||||
if ($self->{response_type} eq 'json') {
|
||||
$self->{output}->add_option_msg(short_msg => "json format unsupported");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
$self->load_response(response => $response);
|
||||
my $method = $self->can("get_api_version_$self->{response_type}");
|
||||
if (!defined($method)) {
|
||||
$self->{output}->add_option_msg(short_msg => "method 'get_api_version_$self->{response_type}' unsupported");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
$self->$method();
|
||||
if (!defined($self->{api_version}) || $self->{api_version} !~ /^(\d+)/) {
|
||||
$self->{output}->add_option_msg(short_msg => "cannot get api version");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
$self->{api_version} = $1;
|
||||
}
|
||||
|
||||
sub get_api_version_xml {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
eval {
|
||||
my $nodesets = $self->{xpath_response}->find('//statistics/@version');
|
||||
my $node = $nodesets->get_node(1);
|
||||
$self->{api_version} = $node->getNodeValue();
|
||||
};
|
||||
if ($@) {
|
||||
$self->{output}->add_option_msg(short_msg => "Cannot lookup: $@");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
}
|
||||
|
||||
sub load_memory_xml_v3 {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $memory = {};
|
||||
|
||||
my $nodesets = $self->{xpath_response}->find('//memory/summary');
|
||||
my $node_memory = $nodesets->get_node(1);
|
||||
foreach my $node ($node_memory->getChildNodes()) {
|
||||
my $name = $node->getLocalName();
|
||||
next if (!defined($name));
|
||||
if ($name eq 'TotalUse') {
|
||||
$memory->{total_use} = $node->string_value;
|
||||
}
|
||||
if ($name eq 'InUse') {
|
||||
$memory->{in_use} = $node->string_value;
|
||||
}
|
||||
}
|
||||
|
||||
return $memory;
|
||||
}
|
||||
|
||||
sub load_memory_xml_v2 {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return $self->load_memory_xml_v3();
|
||||
}
|
||||
|
||||
sub load_zones_xml_v3 {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $zones = {};
|
||||
my $nodesets = $self->{xpath_response}->find('//views//zones/zone');
|
||||
foreach my $node ($nodesets->get_nodelist()) {
|
||||
my $name = $node->getAttribute('name');
|
||||
next if (!defined($name));
|
||||
$zones->{$name} = { counters => { rcode => {}, qtype => {} } };
|
||||
foreach my $counters_node ($node->getChildNodes()) {
|
||||
next if ($counters_node->getLocalName() ne 'counters');
|
||||
my $type = $counters_node->getAttribute('type');
|
||||
foreach my $counter_node ($counters_node->getChildNodes()) {
|
||||
my $counter_name = $counter_node->getAttribute('name');
|
||||
$zones->{$name}->{counters}->{$type}->{$counter_name} = $counter_node->string_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $zones;
|
||||
}
|
||||
|
||||
sub load_zones_xml_v2 {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $zones = {};
|
||||
my $nodesets = $self->{xpath_response}->find('//views//zones/zone');
|
||||
foreach my $node ($nodesets->get_nodelist()) {
|
||||
my $name;
|
||||
my $counters = {};
|
||||
foreach my $subnode ($node->getChildNodes()) {
|
||||
my $tag_name = $subnode->getLocalName();
|
||||
$name = $subnode->string_value
|
||||
if ($tag_name eq 'name');
|
||||
if ($tag_name eq 'counters') {
|
||||
foreach my $counter_node ($subnode->getChildNodes()) {
|
||||
$tag_name = $counter_node->getLocalName();
|
||||
next if (!defined($tag_name));
|
||||
$counters->{$tag_name} = $counter_node->string_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (defined($name)) {
|
||||
$zones->{$name}->{counters}->{rcode} = $counters;
|
||||
}
|
||||
}
|
||||
|
||||
return $zones;
|
||||
}
|
||||
|
||||
sub load_server_xml_v3 {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $server = { counters => { } };
|
||||
my $nodesets = $self->{xpath_response}->find('//server//counters');
|
||||
foreach my $node ($nodesets->get_nodelist()) {
|
||||
my $type = $node->getAttribute('type');
|
||||
next if (!defined($type));
|
||||
foreach my $counter_node ($node->getChildNodes()) {
|
||||
my $counter_name = $counter_node->getAttribute('name');
|
||||
$server->{counters}->{$type} = {}
|
||||
if (!defined($server->{counters}->{$type}));
|
||||
$server->{counters}->{$type}->{$counter_name} = $counter_node->string_value;
|
||||
}
|
||||
}
|
||||
|
||||
return $server;
|
||||
}
|
||||
|
||||
sub load_server_xml_v2 {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $server = { counters => { opcode => {}, nsstat => {}, qtype => {} } };
|
||||
|
||||
my $nodesets = $self->{xpath_response}->find('//server//opcode');
|
||||
foreach my $node ($nodesets->get_nodelist()) {
|
||||
my ($name, $value);
|
||||
foreach my $counter_node ($node->getChildNodes()) {
|
||||
my $tag_name = $counter_node->getLocalName();
|
||||
next if (!defined($tag_name));
|
||||
|
||||
$name = $counter_node->string_value if ($tag_name eq 'name');
|
||||
$value = $counter_node->string_value if ($tag_name eq 'counter');
|
||||
}
|
||||
|
||||
if (defined($name) && defined($value)) {
|
||||
$server->{counters}->{opcode}->{$name} = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$nodesets = $self->{xpath_response}->find('//server//rdtype');
|
||||
foreach my $node ($nodesets->get_nodelist()) {
|
||||
my ($name, $value);
|
||||
foreach my $counter_node ($node->getChildNodes()) {
|
||||
my $tag_name = $counter_node->getLocalName();
|
||||
next if (!defined($tag_name));
|
||||
|
||||
$name = $counter_node->string_value if ($tag_name eq 'name');
|
||||
$value = $counter_node->string_value if ($tag_name eq 'counter');
|
||||
}
|
||||
|
||||
if (defined($name) && defined($value)) {
|
||||
$server->{counters}->{qtype}->{$name} = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$nodesets = $self->{xpath_response}->find('//server//nsstat');
|
||||
foreach my $node ($nodesets->get_nodelist()) {
|
||||
my ($name, $value);
|
||||
foreach my $counter_node ($node->getChildNodes()) {
|
||||
my $tag_name = $counter_node->getLocalName();
|
||||
next if (!defined($tag_name));
|
||||
|
||||
$name = $counter_node->string_value if ($tag_name eq 'name');
|
||||
$value = $counter_node->string_value if ($tag_name eq 'counter');
|
||||
}
|
||||
|
||||
if (defined($name) && defined($value)) {
|
||||
$server->{counters}->{nsstat}->{$name} = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $server;
|
||||
}
|
||||
|
||||
sub get_memory {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->request();
|
||||
my $method = $self->can("load_memory_$self->{response_type}_v$self->{api_version}");
|
||||
if (!defined($method)) {
|
||||
$self->{output}->add_option_msg(short_msg => "method 'load_memory_$self->{response_type}_v$self->{api_version}' unsupported");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
my $memory = $self->$method();
|
||||
if (!defined($memory->{in_use})) {
|
||||
$self->{output}->add_option_msg(short_msg => "cannot find memory information");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
return $memory;
|
||||
}
|
||||
|
||||
sub get_zones {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->request();
|
||||
my $method = $self->can("load_zones_$self->{response_type}_v$self->{api_version}");
|
||||
if (!defined($method)) {
|
||||
$self->{output}->add_option_msg(short_msg => "method 'load_zones_$self->{response_type}_v$self->{api_version}' unsupported");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
my $zones = $self->$method();
|
||||
if (scalar(keys %{$zones}) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "cannot find zones information");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
return $zones;
|
||||
}
|
||||
|
||||
sub get_server {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->request();
|
||||
my $method = $self->can("load_server_$self->{response_type}_v$self->{api_version}");
|
||||
if (!defined($method)) {
|
||||
$self->{output}->add_option_msg(short_msg => "method 'load_server_$self->{response_type}_v$self->{api_version}' unsupported");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
my $server = $self->$method();
|
||||
if (scalar(keys %{$server->{counters}}) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "cannot find server information");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
return $server;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Statistics Channels API
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
Statistics Channels API custom mode
|
||||
|
||||
=head1 API OPTIONS
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--hostname>
|
||||
|
||||
Statistics Channels hostname.
|
||||
|
||||
=item B<--port>
|
||||
|
||||
Port used (Default: 8080)
|
||||
|
||||
=item B<--proto>
|
||||
|
||||
Specify https if needed (Default: 'http')
|
||||
|
||||
=item B<--url-path>
|
||||
|
||||
Statistics Channel API Path (Default: '/').
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Set HTTP timeout
|
||||
|
||||
=back
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
B<custom>.
|
||||
|
||||
=cut
|
130
apps/bind9/web/mode/memoryusage.pm
Normal file
130
apps/bind9/web/mode/memoryusage.pm
Normal file
@ -0,0 +1,130 @@
|
||||
#
|
||||
# Copyright 2019 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package apps::bind9::web::mode::memoryusage;
|
||||
|
||||
use base qw(centreon::plugins::templates::counter);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
sub custom_usage_perfdata {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{output}->perfdata_add(label => 'used', unit => 'B',
|
||||
value => $self->{result_values}->{used},
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, total => $self->{result_values}->{total}, cast_int => 1),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, total => $self->{result_values}->{total}, cast_int => 1),
|
||||
min => 0, max => $self->{result_values}->{total});
|
||||
}
|
||||
|
||||
sub custom_usage_threshold {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{prct_used}, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{label}, exit_litteral => 'warning' } ]);
|
||||
return $exit;
|
||||
}
|
||||
|
||||
sub custom_usage_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total});
|
||||
my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
|
||||
my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
|
||||
|
||||
my $msg = sprintf("Memory Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)",
|
||||
$total_size_value . " " . $total_size_unit,
|
||||
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
|
||||
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free});
|
||||
return $msg;
|
||||
}
|
||||
|
||||
sub custom_usage_calc {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'};
|
||||
$self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_used'};
|
||||
$self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used};
|
||||
$self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total};
|
||||
$self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used};
|
||||
$self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used};
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'memory', type => 0 }
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{memory} = [
|
||||
{ label => 'usage', set => {
|
||||
key_values => [ { name => 'used' }, { name => 'total' } ],
|
||||
closure_custom_calc => $self->can('custom_usage_calc'),
|
||||
closure_custom_output => $self->can('custom_usage_output'),
|
||||
closure_custom_perfdata => $self->can('custom_usage_perfdata'),
|
||||
closure_custom_threshold_check => $self->can('custom_usage_threshold'),
|
||||
}
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments => {
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $result = $options{custom}->get_memory();
|
||||
$self->{memory} = { used => $result->{in_use}, total => $result->{total_use} };
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check bind memory usage.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--warning-usage>
|
||||
|
||||
Threshold warning.
|
||||
|
||||
=item B<--critical-usage>
|
||||
|
||||
Threshold critical.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
128
apps/bind9/web/mode/serverusage.pm
Normal file
128
apps/bind9/web/mode/serverusage.pm
Normal file
@ -0,0 +1,128 @@
|
||||
#
|
||||
# Copyright 2019 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package apps::bind9::web::mode::serverusage;
|
||||
|
||||
use base qw(centreon::plugins::templates::counter);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Digest::MD5 qw(md5_hex);
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'server', type => 0, skipped_code => { -1 => 1, -10 => 1, 11 => -1 } }
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{server} = [];
|
||||
|
||||
my @map = (
|
||||
['opcode_query', 'opcode query : %s', 'opcode-query'],
|
||||
['opcode_iquery', 'opcode iquery : %s', 'opcode-iquery'],
|
||||
['opcode_status', 'opcode status : %s', 'opcode-status'],
|
||||
['opcode_notify', 'opcode notify : %s', 'opcode-notify'],
|
||||
['opcode_update', 'opcode update : %s', 'opcode-update'],
|
||||
['qtype_a', 'qtype A : %s', 'qtype-a'],
|
||||
['qtype_cname', 'qtype CNAME : %s', 'qtype-cname'],
|
||||
['qtype_mx', 'qtype MX : %s', 'qtype-mx'],
|
||||
['qtype_txt', 'qtype TXT : %s', 'qtype-txt'],
|
||||
['qtype_soa', 'qtype SOA : %s', 'qtype-soa'],
|
||||
['qtype_ptr', 'qtype PTR : %s', 'qtype-ptr'],
|
||||
['qtype_ns', 'qtype NS : %s', 'qtype-ns'],
|
||||
['nsstat_requestv4', 'nsstat request v4 : %s', 'nsstat-requestv4'],
|
||||
['nsstat_requestv6', 'nsstat request v6 : %s', 'nsstat-requestv6'],
|
||||
);
|
||||
|
||||
for (my $i = 0; $i < scalar(@map); $i++) {
|
||||
my $perf_label = $map[$i]->[2];
|
||||
$perf_label =~ s/-/_/g;
|
||||
push @{$self->{maps_counters}->{server}}, { label => $map[$i]->[2], display_ok => 0, set => {
|
||||
key_values => [ { name => $map[$i]->[0], diff => 1 } ],
|
||||
output_template => $map[$i]->[1],
|
||||
perfdatas => [
|
||||
{ label => $perf_label, value => $map[$i]->[0] . '_absolute', template => '%s', min => 0 },
|
||||
],
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments => {
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $result = $options{custom}->get_server();
|
||||
$self->{server} = { };
|
||||
|
||||
# Not present in response if no request on the server
|
||||
foreach ('a', 'cname', 'mx', 'txt', 'soa', 'ptr', 'ns', 'any') {
|
||||
$self->{server}->{'qtype_' . $_} = 0;
|
||||
}
|
||||
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => 'All bind9 counters are ok');
|
||||
foreach my $type (keys %{$result->{counters}}) {
|
||||
foreach my $counter (keys %{$result->{counters}->{$type}}) {
|
||||
$self->{server}->{lc($type) . '_' . lc($counter)} = $result->{counters}->{$type}->{$counter};
|
||||
}
|
||||
}
|
||||
|
||||
$self->{cache_name} = "bind9_" . $self->{mode} . '_' . $options{custom}->get_uniq_id() . '_' .
|
||||
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check bind global server usage.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--filter-counters>
|
||||
|
||||
Only display some counters (regexp can be used).
|
||||
Example: --filter-counters='request'
|
||||
|
||||
=item B<--warning-*> <--critical-*>
|
||||
|
||||
Thresholds.
|
||||
Can be: 'opcode-query', 'opcode-iquery', 'opcode-status', 'opcode-notify', 'opcode-update',
|
||||
'qtype-a', 'qtype-cname', 'qtype-mx', 'qtype-txt', 'qtype-soa', 'qtype-ptr', 'qtype-ns', 'qtype-any',
|
||||
'nsstat-requestv4', 'nsstat-requestv6'.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
151
apps/bind9/web/mode/zoneusage.pm
Normal file
151
apps/bind9/web/mode/zoneusage.pm
Normal file
@ -0,0 +1,151 @@
|
||||
#
|
||||
# Copyright 2019 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package apps::bind9::web::mode::zoneusage;
|
||||
|
||||
use base qw(centreon::plugins::templates::counter);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Digest::MD5 qw(md5_hex);
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'zones', type => 1, cb_prefix_output => 'prefix_zone_output', message_multiple => 'All zone counters are ok', skipped_code => { -1 => 1, -10 => 1, 11 => -1 } }
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{zones} = [
|
||||
{ label => 'message', threshold => 0, set => {
|
||||
key_values => [ { name => 'display' } ],
|
||||
closure_custom_calc => sub { return 0; },
|
||||
closure_custom_perfdata => sub { return 0; },
|
||||
closure_custom_threshold_check => sub { return 'ok'; },
|
||||
closure_custom_output => sub { return 'counters are ok' },
|
||||
}
|
||||
},
|
||||
];
|
||||
|
||||
my @map = (
|
||||
['qtype_a', 'qtype A : %s', 'qtype-a'],
|
||||
['qtype_cname', 'qtype CNAME : %s', 'qtype-cname'],
|
||||
['qtype_mx', 'qtype MX : %s', 'qtype-mx'],
|
||||
['qtype_txt', 'qtype TXT : %s', 'qtype-txt'],
|
||||
['qtype_soa', 'qtype SOA : %s', 'qtype-soa'],
|
||||
['qtype_ptr', 'qtype PTR : %s', 'qtype-ptr'],
|
||||
['qtype_ns', 'qtype NS : %s', 'qtype-ns'],
|
||||
['rcode_requestv4', 'rcode request v4 : %s', 'rcode-requestv4'],
|
||||
['rcode_requestv6', 'rcode request v6 : %s', 'rcode-requestv6'],
|
||||
);
|
||||
|
||||
for (my $i = 0; $i < scalar(@map); $i++) {
|
||||
my $perf_label = $map[$i]->[2];
|
||||
$perf_label =~ s/-/_/g;
|
||||
push @{$self->{maps_counters}->{zones}}, { label => $map[$i]->[2], display_ok => 0, set => {
|
||||
key_values => [ { name => $map[$i]->[0], diff => 1 }, { name => 'display' } ],
|
||||
output_template => $map[$i]->[1],
|
||||
perfdatas => [
|
||||
{ label => $perf_label, value => $map[$i]->[0] . '_absolute', template => '%s', min => 0,
|
||||
label_extra_instance => 1, instance_use => 'display_absolute' },
|
||||
],
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
sub prefix_zone_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Zone '" . $options{instance_value}->{display} . "' ";
|
||||
}
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments => {
|
||||
"filter-name:s" => { name => 'filter_name' },
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $result = $options{custom}->get_zones();
|
||||
$self->{zones} = { };
|
||||
|
||||
foreach my $zone_name (keys %{$result}) {
|
||||
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
|
||||
$zone_name !~ /$self->{option_results}->{filter_name}/) {
|
||||
$self->{output}->output_add(long_msg => "skipping '" . $zone_name . "': no matching filter.", debug => 1);
|
||||
next;
|
||||
}
|
||||
|
||||
$self->{zones}->{$zone_name} = { display => $zone_name };
|
||||
foreach my $type (keys %{$result->{$zone_name}->{counters}}) {
|
||||
foreach my $counter (keys %{$result->{$zone_name}->{counters}->{$type}}) {
|
||||
$self->{zones}->{$zone_name}->{lc($type) . '_' . lc($counter)} = $result->{$zone_name}->{counters}->{$type}->{$counter};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (scalar(keys %{$self->{zones}}) <= 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "No zone found.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
$self->{cache_name} = "bind9_" . $self->{mode} . '_' . $options{custom}->get_uniq_id() . '_' .
|
||||
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' .
|
||||
(defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all'));
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check bind zone usage.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--filter-counters>
|
||||
|
||||
Only display some counters (regexp can be used).
|
||||
Example: --filter-counters='request'
|
||||
|
||||
=item B<--filter-name>
|
||||
|
||||
Filter zone name (can be a regexp).
|
||||
|
||||
=item B<--warning-*> <--critical-*>
|
||||
|
||||
Thresholds.
|
||||
Can be: qtype-a', 'qtype-cname', 'qtype-mx', 'qtype-txt', 'qtype-soa', 'qtype-ptr', 'qtype-ns', 'qtype-any',
|
||||
'nsstat-requestv4', 'nsstat-requestv6'.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
51
apps/bind9/web/plugin.pm
Normal file
51
apps/bind9/web/plugin.pm
Normal file
@ -0,0 +1,51 @@
|
||||
#
|
||||
# Copyright 2019 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package apps::bind9::web::plugin;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use base qw(centreon::plugins::script_custom);
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
%{$self->{modes}} = (
|
||||
'memory-usage' => 'apps::bind9::web::mode::memoryusage',
|
||||
'server-usage' => 'apps::bind9::web::mode::serverusage',
|
||||
'zone-usage' => 'apps::bind9::web::mode::zoneusage',
|
||||
);
|
||||
|
||||
$self->{custom_modes}{api} = 'apps::bind9::web::custom::api';
|
||||
return $self;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 PLUGIN DESCRIPTION
|
||||
|
||||
Check Bind9 server through HTTP statistics channels.
|
||||
|
||||
=cut
|
@ -34,8 +34,7 @@ sub new {
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.1';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
$options{options}->add_options(arguments => {
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"port:s" => { name => 'port', default => '8086'},
|
||||
"proto:s" => { name => 'proto' },
|
||||
@ -44,14 +43,12 @@ sub new {
|
||||
"username:s" => { name => 'username' },
|
||||
"password:s" => { name => 'password' },
|
||||
"timeout:s" => { name => 'timeout' },
|
||||
"proxyurl:s" => { name => 'proxyurl' },
|
||||
"ssl-opt:s@" => { name => 'ssl_opt' },
|
||||
"warning:s" => { name => 'warning' },
|
||||
"critical:s" => { name => 'critical' },
|
||||
});
|
||||
|
||||
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
|
||||
$self->{http} = centreon::plugins::http->new(output => $self->{output});
|
||||
$self->{http} = centreon::plugins::http->new(%options);
|
||||
return $self;
|
||||
}
|
||||
|
||||
@ -198,18 +195,10 @@ Specify username for API authentification
|
||||
|
||||
Specify password for API authentification
|
||||
|
||||
=item B<--proxyurl>
|
||||
|
||||
Proxy URL if any
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Threshold for HTTP timeout (Default: 5)
|
||||
|
||||
=item B<--ssl-opt>
|
||||
|
||||
Set SSL Options (--ssl-opt="SSL_version => TLSv1" --ssl-opt="SSL_verify_mode => SSL_VERIFY_NONE").
|
||||
|
||||
=item B<--warning>
|
||||
|
||||
Warning Threshold for failure incoming mails
|
||||
|
114
apps/centreon/local/mode/bamservice.pm
Normal file
114
apps/centreon/local/mode/bamservice.pm
Normal file
@ -0,0 +1,114 @@
|
||||
#
|
||||
# Copyright 2019 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package apps::centreon::local::mode::bamservice;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::dbi;
|
||||
|
||||
use vars qw($centreon_config);
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments => {
|
||||
"centreon-config:s" => { name => 'centreon_config', default => '/etc/centreon/centreon-config.pm' },
|
||||
"bam-id:s" => { name => 'bam_id', },
|
||||
});
|
||||
$self->{options} = $options{options};
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (!defined($self->{option_results}->{bam_id}) || $self->{option_results}->{bam_id} !~ /^[0-9]+$/) {
|
||||
$self->{output}->add_option_msg(short_msg => "Need to specify bam-id (numeric value) option.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
require $self->{option_results}->{centreon_config};
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $sql = centreon::plugins::dbi->new(options => $self->{options}, output => $self->{output}, nooptions => 1);
|
||||
$sql->{data_source} = 'mysql:host=' . $centreon_config->{db_host} . 'port=' . $centreon_config->{db_port};
|
||||
$sql->{username} = $centreon_config->{db_user};
|
||||
$sql->{password} = $centreon_config->{db_passwd};
|
||||
$sql->connect();
|
||||
|
||||
$sql->query(query => "SELECT `name`,`current_level`,`level_w`,`level_c` FROM " . $centreon_config->{centreon_db} .
|
||||
".`mod_bam` WHERE `ba_id` = '" . $self->{option_results}->{bam_id} . "'"
|
||||
);
|
||||
my ($name, $current_level, $level_w, $level_c) = $self->{sql}->fetchrow_array();
|
||||
if (!defined($current_level)) {
|
||||
$self->{output}->add_option_msg(short_msg => "Cannot get bam information");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
$self->{perfdata}->threshold_validate(label => 'warning', value => $level_w . ':');
|
||||
$self->{perfdata}->threshold_validate(label => 'critical', value => $level_c . ':');
|
||||
|
||||
my $exit = $self->{perfdata}->threshold_check(value => $current_level, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => sprintf('BA : %s - current_level = %s%%', $name, $current_level));
|
||||
$self->{output}->perfdata_add(
|
||||
label => 'BA_Level',
|
||||
unit => '%',
|
||||
value => $current_level,
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
|
||||
min => 0, max => 0,
|
||||
);
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Do Centreon bam-service checks.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--centreon-config>
|
||||
|
||||
Centreon Database Config File (Default: '/etc/centreon/centreon-config.pm').
|
||||
|
||||
=item B<--bam-id>
|
||||
|
||||
Bam-id to check (required).
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
@ -163,6 +163,13 @@ sub manage_selection {
|
||||
|
||||
my $endpoint = $entry;
|
||||
$endpoint =~ s/endpoint //;
|
||||
|
||||
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
|
||||
$endpoint !~ /$self->{option_results}->{filter_name}/i) {
|
||||
$self->{output}->output_add(long_msg => "skipping endpoint '" . $endpoint . "': no matching filter name");
|
||||
next;
|
||||
}
|
||||
|
||||
my $state = $json->{$entry}->{state};
|
||||
my $type = 'output';
|
||||
$type = 'input' if (!defined($json->{$entry}->{status}));
|
||||
@ -228,6 +235,10 @@ Use 'sudo' to execute the command.
|
||||
|
||||
Specify the centreon-broker json stats file (Required). Can be multiple.
|
||||
|
||||
=item B<--filter-name>
|
||||
|
||||
Filter endpoint name.
|
||||
|
||||
=item B<--warning-*>
|
||||
|
||||
Threshold warning.
|
||||
|
@ -31,6 +31,7 @@ sub new {
|
||||
|
||||
$self->{version} = '0.1';
|
||||
%{$self->{modes}} = (
|
||||
'bamservice' => 'apps::centreon::local::mode::bamservice',
|
||||
'broker-stats' => 'apps::centreon::local::mode::brokerstats',
|
||||
'centreon-plugins-version' => 'apps::centreon::local::mode::centreonpluginsversion',
|
||||
'downtime-trap' => 'apps::centreon::local::mode::downtimetrap',
|
||||
|
278
apps/centreon/map/jmx/mode/syncstats.pm
Normal file
278
apps/centreon/map/jmx/mode/syncstats.pm
Normal file
@ -0,0 +1,278 @@
|
||||
# Copyright 2019 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package apps::centreon::map::jmx::mode::syncstats;
|
||||
|
||||
use base qw(centreon::plugins::templates::counter);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Digest::MD5 qw(md5_hex);
|
||||
use JSON::XS;
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'centreon', type => 0, cb_prefix_output => 'prefix_output_centreon' },
|
||||
{ name => 'acl', type => 1, cb_prefix_output => 'prefix_output_acl',
|
||||
message_multiple => 'All ACL synchronizations metrics are ok' },
|
||||
{ name => 'resource', type => 1, cb_prefix_output => 'prefix_output_resource',
|
||||
message_multiple => 'All resource synchronizations metrics are ok' },
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{centreon} = [
|
||||
{ label => 'map-synchronization-centreon-count',
|
||||
nlabel => 'map.synchronization.centreon.count', set => {
|
||||
key_values => [ { name => 'count' } ],
|
||||
output_template => 'Count: %d',
|
||||
perfdatas => [
|
||||
{ label => 'map.synchronization.centreon.count', value => 'count_absolute', template => '%d',
|
||||
min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'map-synchronization-centreon-duration-average-milliseconds',
|
||||
nlabel => 'map.synchronization.centreon.duration.average.milliseconds', set => {
|
||||
key_values => [ { name => 'average' } ],
|
||||
output_template => 'Average Duration: %.2f ms',
|
||||
perfdatas => [
|
||||
{ label => 'map.synchronization.centreon.duration.average.milliseconds', value => 'average_absolute',
|
||||
template => '%.2f', min => 0, unit => 'ms' },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'map-synchronization-centreon-duration-max-milliseconds',
|
||||
nlabel => 'map.synchronization.centreon.duration.max.milliseconds', set => {
|
||||
key_values => [ { name => 'max' } ],
|
||||
output_template => 'Max Duration: %.2f ms',
|
||||
perfdatas => [
|
||||
{ label => 'map.synchronization.centreon.duration.max.milliseconds', value => 'max_absolute',
|
||||
template => '%.2f', min => 0, unit => 'ms' },
|
||||
],
|
||||
}
|
||||
},
|
||||
];
|
||||
$self->{maps_counters}->{acl} = [
|
||||
{ label => 'map-synchronization-acl-count',
|
||||
nlabel => 'map.synchronization.acl.count', set => {
|
||||
key_values => [ { name => 'count' }, { name => 'name' } ],
|
||||
output_template => 'Count: %d',
|
||||
perfdatas => [
|
||||
{ label => 'map.synchronization.acl.count', value => 'count_absolute', template => '%d',
|
||||
min => 0, label_extra_instance => 1, instance_use => 'name_absolute' },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'map-synchronization-acl-duration-average-milliseconds',
|
||||
nlabel => 'map.synchronization.acl.duration.average.milliseconds', set => {
|
||||
key_values => [ { name => 'average' }, { name => 'name' } ],
|
||||
output_template => 'Average Duration: %.2f ms',
|
||||
perfdatas => [
|
||||
{ label => 'map.synchronization.acl.duration.average.milliseconds', value => 'average_absolute',
|
||||
template => '%.2f', min => 0, unit => 'ms', label_extra_instance => 1, instance_use => 'name_absolute' },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'map-synchronization-acl-duration-max-milliseconds',
|
||||
nlabel => 'map.synchronization.acl.duration.max.milliseconds', set => {
|
||||
key_values => [ { name => 'max' }, { name => 'name' } ],
|
||||
output_template => 'Max Duration: %.2f ms',
|
||||
perfdatas => [
|
||||
{ label => 'map.synchronization.acl.duration.max.milliseconds', value => 'max_absolute',
|
||||
template => '%.2f', min => 0, unit => 'ms', label_extra_instance => 1, instance_use => 'name_absolute' },
|
||||
],
|
||||
}
|
||||
},
|
||||
];
|
||||
$self->{maps_counters}->{resource} = [
|
||||
{ label => 'map-synchronization-resource-count',
|
||||
nlabel => 'map.synchronization.resource.count', set => {
|
||||
key_values => [ { name => 'count' }, { name => 'name' } ],
|
||||
output_template => 'Count: %d',
|
||||
perfdatas => [
|
||||
{ label => 'map.synchronization.resource.count', value => 'count_absolute', template => '%d',
|
||||
min => 0, label_extra_instance => 1, instance_use => 'name_absolute' },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'map-synchronization-resource-duration-average-milliseconds',
|
||||
nlabel => 'map.synchronization.resource.duration.average.milliseconds', set => {
|
||||
key_values => [ { name => 'average' }, { name => 'name' } ],
|
||||
output_template => 'Average Duration: %.2f ms',
|
||||
perfdatas => [
|
||||
{ label => 'map.synchronization.resource.duration.average.milliseconds', value => 'average_absolute',
|
||||
template => '%.2f', min => 0, unit => 'ms', label_extra_instance => 1, instance_use => 'name_absolute' },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'map-synchronization-resource-duration-max-milliseconds',
|
||||
nlabel => 'map.synchronization.resource.duration.max.milliseconds', set => {
|
||||
key_values => [ { name => 'max' }, { name => 'name' } ],
|
||||
output_template => 'Max Duration: %.2f ms',
|
||||
perfdatas => [
|
||||
{ label => 'map.synchronization.resource.duration.max.milliseconds', value => 'max_absolute',
|
||||
template => '%.2f', min => 0, unit => 'ms', label_extra_instance => 1, instance_use => 'name_absolute' },
|
||||
],
|
||||
}
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
sub prefix_output_centreon {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Centreon Synchronization ";
|
||||
}
|
||||
|
||||
sub prefix_output_acl {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "ACL Synchronization '" . $options{instance_value}->{name} . "' ";
|
||||
}
|
||||
|
||||
sub prefix_output_resource {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Resource Synchronization '" . $options{instance_value}->{name} . "' ";
|
||||
}
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments => {});
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::check_options(%options);
|
||||
}
|
||||
|
||||
my $mbean_engine = "com.centreon.studio.map:type=synchronizer,name=statistics";
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{request} = [
|
||||
{ mbean => $mbean_engine }
|
||||
];
|
||||
|
||||
my $result = $options{custom}->get_attributes(request => $self->{request}, nothing_quit => 0);
|
||||
|
||||
$self->{centreon} = {};
|
||||
$self->{acl} = {};
|
||||
$self->{resource} = {};
|
||||
|
||||
my $decoded_centreon_stats;
|
||||
my $decoded_acl_stats;
|
||||
my $decoded_resource_stats;
|
||||
eval {
|
||||
$decoded_centreon_stats = JSON::XS->new->utf8->decode($result->{$mbean_engine}->{CentreonSyncStatistics});
|
||||
$decoded_acl_stats = JSON::XS->new->utf8->decode($result->{$mbean_engine}->{AclSyncStatistics});
|
||||
$decoded_resource_stats = JSON::XS->new->utf8->decode($result->{$mbean_engine}->{ResourceSyncStatistics});
|
||||
};
|
||||
if ($@) {
|
||||
$self->{output}->output_add(long_msg => $result, debug => 1);
|
||||
$self->{output}->add_option_msg(short_msg => "Cannot decode json response: $@");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
$self->{centreon} = {
|
||||
count => $decoded_centreon_stats->{count},
|
||||
average => $decoded_centreon_stats->{average},
|
||||
max => ($decoded_centreon_stats->{count} == 0) ? 0 : $decoded_centreon_stats->{max},
|
||||
};
|
||||
|
||||
foreach my $name (keys %{$decoded_acl_stats}) {
|
||||
$self->{acl}->{$name}= {
|
||||
name => $name,
|
||||
count => $decoded_acl_stats->{$name}->{count},
|
||||
average => $decoded_acl_stats->{$name}->{average},
|
||||
max => ($decoded_acl_stats->{$name}->{count} == 0) ? 0 : $decoded_acl_stats->{$name}->{max},
|
||||
};
|
||||
}
|
||||
|
||||
foreach my $name (keys %{$decoded_resource_stats}) {
|
||||
$self->{resource}->{$name}= {
|
||||
name => $name,
|
||||
count => $decoded_resource_stats->{$name}->{count},
|
||||
average => $decoded_resource_stats->{$name}->{average},
|
||||
max => ($decoded_resource_stats->{$name}->{count} == 0) ? 0 : $decoded_resource_stats->{$name}->{max},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check synchronizer statistics.
|
||||
|
||||
Example:
|
||||
|
||||
perl centreon_plugins.pl --plugin=apps::centreon::map::jmx::plugin --custommode=jolokia
|
||||
--url=http://10.30.2.22:8080/jolokia-war --mode=sync-stats
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--filter-counters>
|
||||
|
||||
Only display some counters (regexp can be used).
|
||||
(Example: --filter-counters='centreon')
|
||||
|
||||
=item B<--warning-*>
|
||||
|
||||
Threshold warning.
|
||||
Can be: 'map-synchronization-centreon-count',
|
||||
'map-synchronization-centreon-duration-average-milliseconds',
|
||||
'map-synchronization-centreon-duration-max-milliseconds'.
|
||||
|
||||
=item B<--critical-*>
|
||||
|
||||
Threshold critical.
|
||||
Can be: 'map-synchronization-centreon-count',
|
||||
'map-synchronization-centreon-duration-average-milliseconds',
|
||||
'map-synchronization-centreon-duration-max-milliseconds'.
|
||||
|
||||
=item B<--warning-instance-*>
|
||||
|
||||
Threshold warning.
|
||||
Can be: 'map-synchronization-acl-count', 'map-synchronization-acl-duration-average-milliseconds',
|
||||
'map-synchronization-acl-duration-max-milliseconds', 'map-synchronization-resource-count',
|
||||
'map-synchronization-resource-duration-average-milliseconds',
|
||||
'map-synchronization-resource-duration-max-milliseconds'.
|
||||
|
||||
=item B<--critical-instance-*>
|
||||
|
||||
Threshold critical.
|
||||
Can be: 'map-synchronization-acl-count', 'map-synchronization-acl-duration-average-milliseconds',
|
||||
'map-synchronization-acl-duration-max-milliseconds', 'map-synchronization-resource-count',
|
||||
'map-synchronization-resource-duration-average-milliseconds',
|
||||
'map-synchronization-resource-duration-max-milliseconds'.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
@ -35,6 +35,7 @@ sub new {
|
||||
'engine-stats' => 'apps::centreon::map::jmx::mode::enginestats',
|
||||
'open-views' => 'apps::centreon::map::jmx::mode::openviews',
|
||||
'sessions' => 'apps::centreon::map::jmx::mode::sessions',
|
||||
'sync-stats' => 'apps::centreon::map::jmx::mode::syncstats',
|
||||
);
|
||||
|
||||
$self->{custom_modes}{jolokia} = 'centreon::common::protocols::jmx::custom::jolokia';
|
||||
|
@ -20,76 +20,79 @@
|
||||
|
||||
package apps::centreon::sql::mode::pollerdelay;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
use base qw(centreon::plugins::templates::counter);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'poller', type => 1, cb_prefix_output => 'prefix_poller_output', message_multiple => 'All poller delay for last update are ok', skipped_code => { -10 => 1 } }
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{poller} = [
|
||||
{ label => 'delay', set => {
|
||||
key_values => [ { name => 'delay' }, { name => 'display' } ],
|
||||
output_template => 'delay for last update is %d seconds',
|
||||
perfdatas => [
|
||||
{ label => 'delay', value => 'delay_absolute', template => '%s',
|
||||
unit => 's', label_extra_instance => 1 },
|
||||
],
|
||||
}
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
sub prefix_poller_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Poller '" . $options{instance_value}->{display} . "' : ";
|
||||
}
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"warning:s" => { name => 'warning', default => 300 },
|
||||
"critical:s" => { name => 'critical', default => 600 },
|
||||
$options{options}->add_options(arguments => {
|
||||
"filter-name:s" => { name => 'filter_name' },
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical}. "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
# $options{sql} = sqlmode object
|
||||
$self->{sql} = $options{sql};
|
||||
|
||||
$self->{sql}->connect();
|
||||
$self->{sql}->query(query => q{
|
||||
SELECT instance_id,name,last_alive,running FROM centreon_storage.instances WHERE deleted = '0';
|
||||
$options{sql}->connect();
|
||||
$options{sql}->query(query => q{
|
||||
SELECT instance_id, name, last_alive, running FROM centreon_storage.instances WHERE deleted = '0';
|
||||
});
|
||||
my $result = $self->{sql}->fetchall_arrayref();
|
||||
|
||||
my $timestamp = time();
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => sprintf("All poller delay for last update are ok"));
|
||||
my $result = $options{sql}->fetchall_arrayref();
|
||||
$self->{poller} = {};
|
||||
foreach my $row (@{$result}) {
|
||||
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
|
||||
$$row[1] !~ /$self->{option_results}->{filter_name}/) {
|
||||
$self->{output}->output_add(long_msg => "skipping poller '" . $$row[1] . "': no matching filter.", debug => 1);
|
||||
next;
|
||||
}
|
||||
|
||||
if ($$row[3] == 0) {
|
||||
$self->{output}->output_add(severity => 'CRITICAL',
|
||||
short_msg => sprintf("%s is not running", $$row[1]));
|
||||
next;
|
||||
}
|
||||
my $delay = $timestamp - $$row[2];
|
||||
my $exit_code = $self->{perfdata}->threshold_check(value => abs($delay), threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
||||
$self->{output}->output_add(long_msg => sprintf("Delay for last update of %s is %d seconds", $$row[1], $delay));
|
||||
if (!$self->{output}->is_status(value => $exit_code, compare => 'ok', litteral => 1)) {
|
||||
$self->{output}->output_add(severity => $exit_code,
|
||||
short_msg => sprintf("Delay for last update of %s is %d seconds", $$row[1], $delay));
|
||||
}
|
||||
$self->{output}->perfdata_add(label => sprintf("delay_%s", $$row[1]), unit => 's',
|
||||
value => $delay,
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
|
||||
min => 0);
|
||||
}
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
my $delay = time() - $$row[2];
|
||||
$self->{poller}->{$$row[1]} = {
|
||||
display => $$row[1],
|
||||
delay => abs($delay),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
@ -103,11 +106,15 @@ The mode should be used with mysql plugin and dyn-mode option.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--warning>
|
||||
=item B<--filter-name>
|
||||
|
||||
Filter by poller name (can be a regexp).
|
||||
|
||||
=item B<--warning-delay>
|
||||
|
||||
Threshold warning in seconds.
|
||||
|
||||
=item B<--critical>
|
||||
=item B<--critical-delay>
|
||||
|
||||
Threshold critical in seconds.
|
||||
|
||||
|
@ -42,20 +42,17 @@ sub new {
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
$options{options}->add_options(arguments => {
|
||||
"hostname:s" => { name => 'hostname', default => 'api.checkmy.ws'},
|
||||
"port:s" => { name => 'port', },
|
||||
"proto:s" => { name => 'proto', default => "https" },
|
||||
"urlpath:s" => { name => 'url_path', default => "/api/status" },
|
||||
"proxyurl:s" => { name => 'proxyurl' },
|
||||
"uid:s" => { name => 'uid' },
|
||||
"timeout:s" => { name => 'timeout' },
|
||||
"ssl-opt:s@" => { name => 'ssl_opt' },
|
||||
"threshold-overload:s@" => { name => 'threshold_overload' },
|
||||
});
|
||||
|
||||
$self->{http} = centreon::plugins::http->new(output => $self->{output});
|
||||
$self->{http} = centreon::plugins::http->new(%options);
|
||||
return $self;
|
||||
}
|
||||
|
||||
@ -194,10 +191,6 @@ Checkmyws api host (Default: 'api.checkmy.ws')
|
||||
|
||||
Port used by checkmyws
|
||||
|
||||
=item B<--proxyurl>
|
||||
|
||||
Proxy URL if any
|
||||
|
||||
=item B<--proto>
|
||||
|
||||
Specify https if needed (Default: 'https')
|
||||
@ -206,18 +199,10 @@ Specify https if needed (Default: 'https')
|
||||
|
||||
Set path to get checkmyws information (Default: '/api/status')
|
||||
|
||||
=item B<--proxyurl>
|
||||
|
||||
Proxy URL if any
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Threshold for HTTP timeout (Default: 5)
|
||||
|
||||
=item B<--ssl-opt>
|
||||
|
||||
Set SSL Options (--ssl-opt="SSL_version => TLSv1" --ssl-opt="SSL_verify_mode => SSL_VERIFY_NONE").
|
||||
|
||||
=item B<--uid>
|
||||
|
||||
ID for checkmyws API
|
||||
|
@ -40,24 +40,21 @@ sub new {
|
||||
}
|
||||
|
||||
if (!defined($options{noptions})) {
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
$options{options}->add_options(arguments => {
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"url-path:s" => { name => 'url_path' },
|
||||
"port:s" => { name => 'port' },
|
||||
"proto:s" => { name => 'proto' },
|
||||
"username:s" => { name => 'username' },
|
||||
"password:s" => { name => 'password' },
|
||||
"proxyurl:s" => { name => 'proxyurl' },
|
||||
"timeout:s" => { name => 'timeout' },
|
||||
"ssl-opt:s@" => { name => 'ssl_opt' },
|
||||
});
|
||||
}
|
||||
$options{options}->add_help(package => __PACKAGE__, sections => 'XMLAPI OPTIONS', once => 1);
|
||||
|
||||
$self->{output} = $options{output};
|
||||
$self->{mode} = $options{mode};
|
||||
$self->{http} = centreon::plugins::http->new(output => $self->{output});
|
||||
$self->{http} = centreon::plugins::http->new(%options);
|
||||
|
||||
return $self;
|
||||
}
|
||||
@ -94,8 +91,6 @@ sub check_options {
|
||||
$self->{password} = (defined($self->{option_results}->{password})) ? $self->{option_results}->{password} : undef;
|
||||
$self->{url_path} = (defined($self->{option_results}->{url_path})) ? $self->{option_results}->{url_path} : '/api/v1';
|
||||
$self->{timeout} = (defined($self->{option_results}->{timeout})) ? $self->{option_results}->{timeout} : 10;
|
||||
$self->{proxyurl} = (defined($self->{option_results}->{proxyurl})) ? $self->{option_results}->{proxyurl} : undef;
|
||||
$self->{ssl_opt} = (defined($self->{option_results}->{ssl_opt})) ? $self->{option_results}->{ssl_opt} : undef;
|
||||
|
||||
if (!defined($self->{option_results}->{username}) || $self->{option_results}->{username} eq '') {
|
||||
$self->{output}->add_option_msg(short_msg => "Need to specify --username option.");
|
||||
@ -120,7 +115,6 @@ sub build_options_for_httplib {
|
||||
$self->{option_results}->{password} = $self->{password};
|
||||
$self->{option_results}->{credentials} = 1;
|
||||
$self->{option_results}->{basic} = 1;
|
||||
$self->{option_results}->{proxyurl} = $self->{proxyurl};
|
||||
$self->{option_results}->{warning_status} = '';
|
||||
$self->{option_results}->{critical_status} = '';
|
||||
$self->{option_results}->{unknown_status} = '';
|
||||
@ -158,9 +152,8 @@ sub get_endpoint {
|
||||
$self->settings;
|
||||
|
||||
my $content = $self->{http}->request(url_path => $self->{url_path} . $options{method});
|
||||
my $response = $self->{http}->get_response();
|
||||
|
||||
if ($response->code() != 200) {
|
||||
if ($self->{http}->get_code() != 200) {
|
||||
my $xml_result;
|
||||
eval {
|
||||
$xml_result = XMLin($content);
|
||||
@ -230,18 +223,10 @@ Set API username
|
||||
|
||||
Set API password
|
||||
|
||||
=item B<--proxyurl>
|
||||
|
||||
Proxy URL if any
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Set HTTP timeout
|
||||
|
||||
=item B<--ssl-opt>
|
||||
|
||||
Set SSL options if needed (--ssl-opt="SSL_version => TLSv1" --ssl-opt="SSL_verify_mode => SSL_VERIFY_NONE").
|
||||
|
||||
=back
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
@ -40,24 +40,21 @@ sub new {
|
||||
}
|
||||
|
||||
if (!defined($options{noptions})) {
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
$options{options}->add_options(arguments => {
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"url-path:s" => { name => 'url_path' },
|
||||
"port:s" => { name => 'port' },
|
||||
"proto:s" => { name => 'proto' },
|
||||
"username:s" => { name => 'username' },
|
||||
"password:s" => { name => 'password' },
|
||||
"proxyurl:s" => { name => 'proxyurl' },
|
||||
"timeout:s" => { name => 'timeout' },
|
||||
"ssl-opt:s@" => { name => 'ssl_opt' },
|
||||
});
|
||||
}
|
||||
$options{options}->add_help(package => __PACKAGE__, sections => 'XMLAPI OPTIONS', once => 1);
|
||||
|
||||
$self->{output} = $options{output};
|
||||
$self->{mode} = $options{mode};
|
||||
$self->{http} = centreon::plugins::http->new(output => $self->{output});
|
||||
$self->{http} = centreon::plugins::http->new(%options);
|
||||
|
||||
return $self;
|
||||
}
|
||||
@ -94,8 +91,6 @@ sub check_options {
|
||||
$self->{password} = (defined($self->{option_results}->{password})) ? $self->{option_results}->{password} : undef;
|
||||
$self->{url_path} = (defined($self->{option_results}->{url_path})) ? $self->{option_results}->{url_path} : '/admin/API/mnt';
|
||||
$self->{timeout} = (defined($self->{option_results}->{timeout})) ? $self->{option_results}->{timeout} : 10;
|
||||
$self->{proxyurl} = (defined($self->{option_results}->{proxyurl})) ? $self->{option_results}->{proxyurl} : undef;
|
||||
$self->{ssl_opt} = (defined($self->{option_results}->{ssl_opt})) ? $self->{option_results}->{ssl_opt} : undef;
|
||||
|
||||
if (!defined($self->{option_results}->{username}) || $self->{option_results}->{username} eq '') {
|
||||
$self->{output}->add_option_msg(short_msg => "Need to specify --username option.");
|
||||
@ -120,7 +115,6 @@ sub build_options_for_httplib {
|
||||
$self->{option_results}->{password} = $self->{password};
|
||||
$self->{option_results}->{credentials} = 1;
|
||||
$self->{option_results}->{basic} = 1;
|
||||
$self->{option_results}->{proxyurl} = $self->{proxyurl};
|
||||
$self->{option_results}->{warning_status} = '';
|
||||
$self->{option_results}->{critical_status} = '';
|
||||
}
|
||||
@ -157,9 +151,8 @@ sub get_endpoint {
|
||||
$self->settings;
|
||||
|
||||
my $content = $self->{http}->request(url_path => $self->{url_path} . $options{category});
|
||||
my $response = $self->{http}->get_response();
|
||||
|
||||
if ($response->code() != 200) {
|
||||
if ($self->{http}->get_code() != 200) {
|
||||
my $xml_result;
|
||||
eval {
|
||||
$xml_result = XMLin($content);
|
||||
@ -229,18 +222,10 @@ Set API username
|
||||
|
||||
Set API password
|
||||
|
||||
=item B<--proxyurl>
|
||||
|
||||
Proxy URL if any
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Set HTTP timeout
|
||||
|
||||
=item B<--ssl-opt>
|
||||
|
||||
Set SSL options if needed (--ssl-opt="SSL_version => TLSv1" --ssl-opt="SSL_verify_mode => SSL_VERIFY_NONE").
|
||||
|
||||
=back
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
@ -78,7 +78,7 @@ sub new {
|
||||
"filter-name:s" => { name => 'filter_name' },
|
||||
"unknown-status:s" => { name => 'unknown_status', default => '%{state} =~ /unknown/' },
|
||||
"warning-status:s" => { name => 'warning_status', default => '' },
|
||||
"critical-status:s" => { name => 'critical_status', default => '%{state} =~ /down|paritioned|unavailable/' },
|
||||
"critical-status:s" => { name => 'critical_status', default => '%{state} =~ /down|partitioned|unavailable/' },
|
||||
});
|
||||
|
||||
return $self;
|
||||
@ -95,7 +95,7 @@ my %map_state = (
|
||||
-1 => 'unknown',
|
||||
0 => 'unavailable',
|
||||
1 => 'down',
|
||||
2 => 'paritioned',
|
||||
2 => 'partitioned',
|
||||
3 => 'up',
|
||||
);
|
||||
|
||||
@ -153,7 +153,7 @@ Can used special variables like: %{state}, %{display}
|
||||
|
||||
=item B<--critical-status>
|
||||
|
||||
Set critical threshold for status (Default: '%{state} =~ /down|paritioned|unavailable/').
|
||||
Set critical threshold for status (Default: '%{state} =~ /down|partitioned|unavailable/').
|
||||
Can used special variables like: %{state}, %{display}
|
||||
|
||||
=back
|
||||
|
@ -40,23 +40,20 @@ sub new {
|
||||
}
|
||||
|
||||
if (!defined($options{noptions})) {
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
$options{options}->add_options(arguments => {
|
||||
"hostname:s@" => { name => 'hostname' },
|
||||
"port:s@" => { name => 'port' },
|
||||
"proto:s@" => { name => 'proto' },
|
||||
"username:s@" => { name => 'username' },
|
||||
"password:s@" => { name => 'password' },
|
||||
"proxyurl:s@" => { name => 'proxyurl' },
|
||||
"timeout:s@" => { name => 'timeout' },
|
||||
"ssl-opt:s@" => { name => 'ssl_opt' },
|
||||
});
|
||||
}
|
||||
$options{options}->add_help(package => __PACKAGE__, sections => 'REST API OPTIONS', once => 1);
|
||||
|
||||
$self->{output} = $options{output};
|
||||
$self->{mode} = $options{mode};
|
||||
$self->{http} = centreon::plugins::http->new(output => $self->{output});
|
||||
$self->{http} = centreon::plugins::http->new(%options);
|
||||
|
||||
return $self;
|
||||
|
||||
@ -93,7 +90,6 @@ sub check_options {
|
||||
$self->{username} = (defined($self->{option_results}->{username})) ? shift(@{$self->{option_results}->{username}}) : '';
|
||||
$self->{password} = (defined($self->{option_results}->{password})) ? shift(@{$self->{option_results}->{password}}) : '';
|
||||
$self->{timeout} = (defined($self->{option_results}->{timeout})) ? shift(@{$self->{option_results}->{timeout}}) : 10;
|
||||
$self->{proxyurl} = (defined($self->{option_results}->{proxyurl})) ? shift(@{$self->{option_results}->{proxyurl}}) : undef;
|
||||
|
||||
if (!defined($self->{hostname})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Need to specify hostname option.");
|
||||
@ -114,7 +110,6 @@ sub build_options_for_httplib {
|
||||
$self->{option_results}->{timeout} = $self->{timeout};
|
||||
$self->{option_results}->{port} = $self->{port};
|
||||
$self->{option_results}->{proto} = $self->{proto};
|
||||
$self->{option_results}->{proxyurl} = $self->{proxyurl};
|
||||
$self->{option_results}->{credentials} = 1;
|
||||
$self->{option_results}->{basic} = 1;
|
||||
$self->{option_results}->{username} = $self->{username};
|
||||
@ -187,18 +182,10 @@ Elasticsearch username.
|
||||
|
||||
Elasticsearch password.
|
||||
|
||||
=item B<--proxyurl>
|
||||
|
||||
Proxy URL if any
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Set HTTP timeout
|
||||
|
||||
=item B<--ssl-opt>
|
||||
|
||||
Set SSL Options (--ssl-opt="SSL_version => TLSv1" --ssl-opt="SSL_verify_mode => SSL_VERIFY_NONE").
|
||||
|
||||
=back
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
@ -33,8 +33,7 @@ sub new {
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
$options{options}->add_options(arguments => {
|
||||
"remote-host:s" => { name => 'remote_host', },
|
||||
"remote-user:s" => { name => 'remote_user', },
|
||||
"remote-password:s" => { name => 'remote_password', },
|
||||
@ -49,6 +48,7 @@ sub new {
|
||||
"mailbox:s" => { name => 'mailbox', },
|
||||
"password:s" => { name => 'password', },
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
@ -33,8 +33,7 @@ sub new {
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
$options{options}->add_options(arguments => {
|
||||
"remote-host:s" => { name => 'remote_host', },
|
||||
"remote-user:s" => { name => 'remote_user', },
|
||||
"remote-password:s" => { name => 'remote_password', },
|
||||
@ -47,7 +46,9 @@ sub new {
|
||||
"warning:s" => { name => 'warning', },
|
||||
"critical:s" => { name => 'critical', default => '%{type} !~ /Success|Information/i' },
|
||||
"mailbox:s" => { name => 'mailbox', },
|
||||
"password:s" => { name => 'password', },
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
@ -81,6 +82,7 @@ sub run {
|
||||
remote_password => $self->{option_results}->{remote_password},
|
||||
no_ps => $self->{option_results}->{no_ps},
|
||||
mailbox => $self->{option_results}->{mailbox},
|
||||
password => $self->{option_results}->{password},
|
||||
);
|
||||
$self->{option_results}->{command_options} .= " " . $ps;
|
||||
my ($stdout) = centreon::plugins::misc::windows_execute(output => $self->{output},
|
||||
@ -161,6 +163,10 @@ Can used special variables like: %{type}, %{id}, %{message}
|
||||
|
||||
Set the mailbox to check (Required).
|
||||
|
||||
=item B<--password>
|
||||
|
||||
Set the password for the mailbox.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
@ -144,12 +144,12 @@ Print powershell output.
|
||||
=item B<--warning>
|
||||
|
||||
Set warning threshold.
|
||||
Can used special variables like: %{status}, %{identity}, %{isvalid}, %{deliverytype}
|
||||
Can used special variables like: %{status}, %{identity}, %{isvalid}, %{deliverytype}, %{messagecount}
|
||||
|
||||
=item B<--critical>
|
||||
|
||||
Set critical threshold (Default: '%{status} !~ /Ready|Active/i').
|
||||
Can used special variables like: %{status}, %{identity}, %{isvalid}, %{deliverytype}
|
||||
Can used special variables like: %{status}, %{identity}, %{isvalid}, %{deliverytype}, %{messagecount}
|
||||
|
||||
=back
|
||||
|
||||
|
@ -35,19 +35,16 @@ sub new {
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
$options{options}->add_options(arguments => {
|
||||
"hostname:s" => { name => 'hostname', default => 'api.github.com' },
|
||||
"port:s" => { name => 'port', default => '443'},
|
||||
"proto:s" => { name => 'proto', default => 'https' },
|
||||
"timeout:s" => { name => 'timeout' },
|
||||
"proxyurl:s" => { name => 'proxyurl' },
|
||||
"ssl-opt:s@" => { name => 'ssl_opt' },
|
||||
"owner:s" => { name => 'owner' },
|
||||
"repository:s" => { name => 'repository' },
|
||||
});
|
||||
|
||||
$self->{http} = centreon::plugins::http->new(output => $self->{output});
|
||||
$self->{http} = centreon::plugins::http->new(%options);
|
||||
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
|
||||
|
||||
return $self;
|
||||
@ -140,18 +137,10 @@ Port used by GitHub's API (Default: '443')
|
||||
|
||||
Specify https if needed (Default: 'https')
|
||||
|
||||
=item B<--proxyurl>
|
||||
|
||||
Proxy URL if any
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Threshold for HTTP timeout (Default: 5)
|
||||
|
||||
=item B<--ssl-opt>
|
||||
|
||||
Set SSL Options (--ssl-opt="SSL_version => TLSv1" --ssl-opt="SSL_verify_mode => SSL_VERIFY_NONE").
|
||||
|
||||
=item B<--owner>
|
||||
|
||||
Specify GitHub's owner
|
||||
|
@ -33,14 +33,11 @@ sub new {
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
$options{options}->add_options(arguments => {
|
||||
"hostname:s" => { name => 'hostname', default => 'api.github.com' },
|
||||
"port:s" => { name => 'port', default => '443'},
|
||||
"proto:s" => { name => 'proto', default => 'https' },
|
||||
"timeout:s" => { name => 'timeout' },
|
||||
"proxyurl:s" => { name => 'proxyurl' },
|
||||
"ssl-opt:s@" => { name => 'ssl_opt' },
|
||||
"warning:s" => { name => 'warning' },
|
||||
"critical:s" => { name => 'critical' },
|
||||
"owner:s" => { name => 'owner' },
|
||||
@ -48,7 +45,7 @@ sub new {
|
||||
"label:s" => { name => 'label', default => '' },
|
||||
});
|
||||
|
||||
$self->{http} = centreon::plugins::http->new(output => $self->{output});
|
||||
$self->{http} = centreon::plugins::http->new(%options);
|
||||
return $self;
|
||||
}
|
||||
|
||||
@ -147,18 +144,10 @@ Port used by GitHub's API (Default: '443')
|
||||
|
||||
Specify https if needed (Default: 'https')
|
||||
|
||||
=item B<--proxyurl>
|
||||
|
||||
Proxy URL if any
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Threshold for HTTP timeout (Default: 5)
|
||||
|
||||
=item B<--ssl-opt>
|
||||
|
||||
Set SSL Options (--ssl-opt="SSL_version => TLSv1" --ssl-opt="SSL_verify_mode => SSL_VERIFY_NONE").
|
||||
|
||||
=item B<--warning>
|
||||
|
||||
Threshold warning.
|
||||
|
@ -33,21 +33,18 @@ sub new {
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
$options{options}->add_options(arguments => {
|
||||
"hostname:s" => { name => 'hostname', default => 'api.github.com' },
|
||||
"port:s" => { name => 'port', default => '443' },
|
||||
"proto:s" => { name => 'proto', default => 'https' },
|
||||
"timeout:s" => { name => 'timeout' },
|
||||
"proxyurl:s" => { name => 'proxyurl' },
|
||||
"ssl-opt:s@" => { name => 'ssl_opt' },
|
||||
"warning:s" => { name => 'warning' },
|
||||
"critical:s" => { name => 'critical' },
|
||||
"owner:s" => { name => 'owner' },
|
||||
"repository:s" => { name => 'repository' },
|
||||
});
|
||||
|
||||
$self->{http} = centreon::plugins::http->new(output => $self->{output});
|
||||
$self->{http} = centreon::plugins::http->new(%options);
|
||||
return $self;
|
||||
}
|
||||
|
||||
@ -132,18 +129,10 @@ Port used by GitHub's API (Default: '443')
|
||||
|
||||
Specify https if needed (Default: 'https')
|
||||
|
||||
=item B<--proxyurl>
|
||||
|
||||
Proxy URL if any
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Threshold for HTTP timeout (Default: 5)
|
||||
|
||||
=item B<--ssl-opt>
|
||||
|
||||
Set SSL Options (--ssl-opt="SSL_version => TLSv1" --ssl-opt="SSL_verify_mode => SSL_VERIFY_NONE").
|
||||
|
||||
=item B<--warning>
|
||||
|
||||
Threshold warning.
|
||||
|
@ -26,7 +26,6 @@ use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::http;
|
||||
use JSON;
|
||||
use Data::Dumper;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
@ -34,19 +33,16 @@ sub new {
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
$options{options}->add_options(arguments => {
|
||||
"hostname:s" => { name => 'hostname', default => 'api.github.com' },
|
||||
"port:s" => { name => 'port', default => '443'},
|
||||
"proto:s" => { name => 'proto', default => 'https' },
|
||||
"timeout:s" => { name => 'timeout' },
|
||||
"proxyurl:s" => { name => 'proxyurl' },
|
||||
"ssl-opt:s@" => { name => 'ssl_opt' },
|
||||
"owner:s" => { name => 'owner' },
|
||||
"repository:s" => { name => 'repository' },
|
||||
});
|
||||
|
||||
$self->{http} = centreon::plugins::http->new(output => $self->{output});
|
||||
$self->{http} = centreon::plugins::http->new(%options);
|
||||
return $self;
|
||||
}
|
||||
|
||||
@ -80,7 +76,6 @@ sub run {
|
||||
|
||||
if ($@) {
|
||||
$self->{output}->add_option_msg(short_msg => "Cannot decode json response: $@");
|
||||
$self->{output}->output_add(long_msg => Data::Dumper::Dumper(), debug => 1);
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
@ -131,18 +126,10 @@ Specify https if needed (Default: 'https')
|
||||
|
||||
Set path to get GitHub's status information (Default: '/repo/:owner/:repository')
|
||||
|
||||
=item B<--proxyurl>
|
||||
|
||||
Proxy URL if any
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Threshold for HTTP timeout (Default: 5)
|
||||
|
||||
=item B<--ssl-opt>
|
||||
|
||||
Set SSL Options (--ssl-opt="SSL_version => TLSv1" --ssl-opt="SSL_verify_mode => SSL_VERIFY_NONE").
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
@ -41,19 +41,16 @@ sub new {
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
$options{options}->add_options(arguments => {
|
||||
"hostname:s" => { name => 'hostname', default => 'status.github.com' },
|
||||
"port:s" => { name => 'port', default => '443'},
|
||||
"proto:s" => { name => 'proto', default => 'https' },
|
||||
"urlpath:s" => { name => 'url_path', default => '/api/last-message.json' },
|
||||
"timeout:s" => { name => 'timeout' },
|
||||
"proxyurl:s" => { name => 'proxyurl' },
|
||||
"ssl-opt:s@" => { name => 'ssl_opt' },
|
||||
"threshold-overload:s@" => { name => 'threshold_overload' },
|
||||
});
|
||||
|
||||
$self->{http} = centreon::plugins::http->new(output => $self->{output});
|
||||
$self->{http} = centreon::plugins::http->new(%options);
|
||||
return $self;
|
||||
}
|
||||
|
||||
@ -151,18 +148,10 @@ Specify https if needed (Default: 'https')
|
||||
|
||||
Set path to get GitHub's status information (Default: '/api/last-message.json')
|
||||
|
||||
=item B<--proxyurl>
|
||||
|
||||
Proxy URL if any
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Threshold for HTTP timeout (Default: 5)
|
||||
|
||||
=item B<--ssl-opt>
|
||||
|
||||
Set SSL Options (--ssl-opt="SSL_version => TLSv1" --ssl-opt="SSL_verify_mode => SSL_VERIFY_NONE").
|
||||
|
||||
=item B<--threshold-overload>
|
||||
|
||||
Set to overload default threshold values (syntax: status,regexp)
|
||||
|
@ -114,11 +114,10 @@ sub new {
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"filter-name:s" => { name => 'filter_name' },
|
||||
"warning-status:s" => { name => 'warning_status', default => '' },
|
||||
"critical-status:s" => { name => 'critical_status', default => '%{status} !~ /UP/i' },
|
||||
$options{options}->add_options(arguments => {
|
||||
'filter-name:s' => { name => 'filter_name' },
|
||||
'warning-status:s' => { name => 'warning_status', default => '' },
|
||||
'critical-status:s' => { name => 'critical_status', default => '%{status} !~ /UP/i' },
|
||||
});
|
||||
|
||||
return $self;
|
||||
@ -138,13 +137,26 @@ sub prefix_backend_output {
|
||||
}
|
||||
|
||||
my $mapping = {
|
||||
alBackendName => { oid => '.1.3.6.1.4.1.23263.4.2.1.3.3.1.3' },
|
||||
entreprise => {
|
||||
alBackendQueueCur => { oid => '.1.3.6.1.4.1.23263.4.2.1.3.3.1.4' },
|
||||
alBackendSessionCur => { oid => '.1.3.6.1.4.1.23263.4.2.1.3.3.1.7' },
|
||||
alBackendSessionTotal => { oid => '.1.3.6.1.4.1.23263.4.2.1.3.3.1.10' },
|
||||
alBackendBytesIN => { oid => '.1.3.6.1.4.1.23263.4.2.1.3.3.1.12' },
|
||||
alBackendBytesOUT => { oid => '.1.3.6.1.4.1.23263.4.2.1.3.3.1.13' },
|
||||
alBackendStatus => { oid => '.1.3.6.1.4.1.23263.4.2.1.3.3.1.20' },
|
||||
},
|
||||
csv => {
|
||||
alBackendQueueCur => { oid => '.1.3.6.1.4.1.29385.106.1.1.2' },
|
||||
alBackendSessionCur => { oid => '.1.3.6.1.4.1.29385.106.1.1.4' },
|
||||
alBackendSessionTotal => { oid => '.1.3.6.1.4.1.29385.106.1.1.7' },
|
||||
alBackendBytesIN => { oid => '.1.3.6.1.4.1.29385.106.1.1.8' },
|
||||
alBackendBytesOUT => { oid => '.1.3.6.1.4.1.29385.106.1.1.9' },
|
||||
alBackendStatus => { oid => '.1.3.6.1.4.1.29385.106.1.1.17' },
|
||||
},
|
||||
};
|
||||
my $mapping_name = {
|
||||
csv => '.1.3.6.1.4.1.29385.106.1.1.0',
|
||||
entreprise => '.1.3.6.1.4.1.23263.4.2.1.3.3.1.3', # alBackendName
|
||||
};
|
||||
|
||||
sub manage_selection {
|
||||
@ -156,34 +168,25 @@ sub manage_selection {
|
||||
}
|
||||
|
||||
$self->{backend} = {};
|
||||
my $snmp_result = $options{snmp}->get_multiple_table(
|
||||
oids => [
|
||||
{ oid => $mapping->{alBackendName}->{oid} },
|
||||
{ oid => $mapping->{alBackendQueueCur}->{oid} },
|
||||
{ oid => $mapping->{alBackendSessionCur}->{oid} },
|
||||
{ oid => $mapping->{alBackendSessionTotal}->{oid} },
|
||||
{ oid => $mapping->{alBackendBytesIN}->{oid} },
|
||||
{ oid => $mapping->{alBackendBytesOUT}->{oid} },
|
||||
{ oid => $mapping->{alBackendStatus}->{oid} },
|
||||
],
|
||||
return_type => 1, nothing_quit => 1);
|
||||
|
||||
foreach my $oid (keys %{$snmp_result}) {
|
||||
next if ($oid !~ /^$mapping->{alBackendName}->{oid}\.(.*)$/);
|
||||
my $snmp_result = $options{snmp}->get_multiple_table(oids => [ { oid => $mapping_name->{csv} }, { oid => $mapping_name->{entreprise} } ], nothing_quit => 1);
|
||||
my $branch = 'entreprise';
|
||||
if (defined($snmp_result->{ $mapping_name->{csv} }) && scalar(keys %{$snmp_result->{ $mapping_name->{csv} }}) > 0) {
|
||||
$branch = 'csv';
|
||||
}
|
||||
|
||||
foreach my $oid (keys %{$snmp_result->{ $mapping_name->{$branch} }}) {
|
||||
$oid =~ /^$mapping_name->{$branch}\.(.*)$/;
|
||||
my $instance = $1;
|
||||
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
|
||||
my $name = $snmp_result->{$mapping_name->{$branch}}->{$oid};
|
||||
|
||||
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
|
||||
$result->{alBackendName} !~ /$self->{option_results}->{filter_name}/) {
|
||||
$self->{output}->output_add(long_msg => "skipping '" . $result->{wgPolicyName} . "': no matching filter.", debug => 1);
|
||||
$name !~ /$self->{option_results}->{filter_name}/) {
|
||||
$self->{output}->output_add(long_msg => "skipping backend '" . $name . "'.", debug => 1);
|
||||
next;
|
||||
}
|
||||
|
||||
$result->{alBackendBytesIN} *= 8;
|
||||
$result->{alBackendBytesOUT} *= 8;
|
||||
$self->{backend}->{$instance} = { display => $result->{alBackendName},
|
||||
%$result
|
||||
};
|
||||
$self->{backend}->{$instance} = { display => $name };
|
||||
}
|
||||
|
||||
if (scalar(keys %{$self->{backend}}) <= 0) {
|
||||
@ -191,6 +194,24 @@ sub manage_selection {
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
$options{snmp}->load(
|
||||
oids => [
|
||||
map($_->{oid}, values(%{$mapping->{$branch}}))
|
||||
],
|
||||
instances => [keys %{$self->{backend}}],
|
||||
instance_regexp => '^(.*)$'
|
||||
);
|
||||
$snmp_result = $options{snmp}->get_leef(nothing_quit => 1);
|
||||
|
||||
foreach (keys %{$self->{backend}}) {
|
||||
my $result = $options{snmp}->map_instance(mapping => $mapping->{$branch}, results => $snmp_result, instance => $_);
|
||||
|
||||
$result->{alBackendBytesIN} *= 8;
|
||||
$result->{alBackendBytesOUT} *= 8;
|
||||
|
||||
$self->{backend}->{$_} = { %{$self->{backend}->{$_}}, %$result };
|
||||
}
|
||||
|
||||
$self->{cache_name} = "haproxy_" . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' .
|
||||
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' .
|
||||
(defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all'));
|
||||
|
@ -105,8 +105,7 @@ sub new {
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
$options{options}->add_options(arguments => {
|
||||
"filter-name:s" => { name => 'filter_name' },
|
||||
"warning-status:s" => { name => 'warning_status', default => '' },
|
||||
"critical-status:s" => { name => 'critical_status', default => '%{status} !~ /OPEN/i' },
|
||||
@ -129,12 +128,24 @@ sub prefix_frontend_output {
|
||||
}
|
||||
|
||||
my $mapping = {
|
||||
alFrontendName => { oid => '.1.3.6.1.4.1.23263.4.2.1.3.2.1.3' },
|
||||
entreprise => {
|
||||
alFrontendSessionCur => { oid => '.1.3.6.1.4.1.23263.4.2.1.3.2.1.4' },
|
||||
alFrontendSessionTotal => { oid => '.1.3.6.1.4.1.23263.4.2.1.3.2.1.7' },
|
||||
alFrontendBytesIN => { oid => '.1.3.6.1.4.1.23263.4.2.1.3.2.1.8' },
|
||||
alFrontendBytesOUT => { oid => '.1.3.6.1.4.1.23263.4.2.1.3.2.1.9' },
|
||||
alFrontendStatus => { oid => '.1.3.6.1.4.1.23263.4.2.1.3.2.1.13' },
|
||||
},
|
||||
csv => {
|
||||
alFrontendSessionCur => { oid => '.1.3.6.1.4.1.29385.106.1.0.4' },
|
||||
alFrontendSessionTotal => { oid => '.1.3.6.1.4.1.29385.106.1.0.7' },
|
||||
alFrontendBytesIN => { oid => '.1.3.6.1.4.1.29385.106.1.0.8' },
|
||||
alFrontendBytesOUT => { oid => '.1.3.6.1.4.1.29385.106.1.0.9' },
|
||||
alFrontendStatus => { oid => '.1.3.6.1.4.1.29385.106.1.0.17' },
|
||||
},
|
||||
};
|
||||
my $mapping_name = {
|
||||
csv => '.1.3.6.1.4.1.29385.106.1.0.0',
|
||||
entreprise => '.1.3.6.1.4.1.23263.4.2.1.3.2.1.3', # alFrontendName
|
||||
};
|
||||
|
||||
sub manage_selection {
|
||||
@ -146,33 +157,25 @@ sub manage_selection {
|
||||
}
|
||||
|
||||
$self->{frontend} = {};
|
||||
my $snmp_result = $options{snmp}->get_multiple_table(
|
||||
oids => [
|
||||
{ oid => $mapping->{alFrontendName}->{oid} },
|
||||
{ oid => $mapping->{alFrontendSessionCur}->{oid} },
|
||||
{ oid => $mapping->{alFrontendSessionTotal}->{oid} },
|
||||
{ oid => $mapping->{alFrontendBytesIN}->{oid} },
|
||||
{ oid => $mapping->{alFrontendBytesOUT}->{oid} },
|
||||
{ oid => $mapping->{alFrontendStatus}->{oid} },
|
||||
],
|
||||
return_type => 1, nothing_quit => 1);
|
||||
|
||||
foreach my $oid (keys %{$snmp_result}) {
|
||||
next if ($oid !~ /^$mapping->{alFrontendName}->{oid}\.(.*)$/);
|
||||
my $snmp_result = $options{snmp}->get_multiple_table(oids => [ { oid => $mapping_name->{csv} }, { oid => $mapping_name->{entreprise} } ], nothing_quit => 1);
|
||||
my $branch = 'entreprise';
|
||||
if (defined($snmp_result->{ $mapping_name->{csv} }) && scalar(keys %{$snmp_result->{ $mapping_name->{csv} }}) > 0) {
|
||||
$branch = 'csv';
|
||||
}
|
||||
|
||||
foreach my $oid (keys %{$snmp_result->{ $mapping_name->{$branch} }}) {
|
||||
$oid =~ /^$mapping_name->{$branch}\.(.*)$/;
|
||||
my $instance = $1;
|
||||
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
|
||||
my $name = $snmp_result->{$mapping_name->{$branch}}->{$oid};
|
||||
|
||||
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
|
||||
$result->{alFrontendName} !~ /$self->{option_results}->{filter_name}/) {
|
||||
$self->{output}->output_add(long_msg => "skipping '" . $result->{wgPolicyName} . "': no matching filter.", debug => 1);
|
||||
$name !~ /$self->{option_results}->{filter_name}/) {
|
||||
$self->{output}->output_add(long_msg => "skipping frontend '" . $name . "'.", debug => 1);
|
||||
next;
|
||||
}
|
||||
|
||||
$result->{alFrontendBytesIN} *= 8;
|
||||
$result->{alFrontendBytesOUT} *= 8;
|
||||
$self->{frontend}->{$instance} = { display => $result->{alFrontendName},
|
||||
%$result
|
||||
};
|
||||
$self->{frontend}->{$instance} = { display => $name };
|
||||
}
|
||||
|
||||
if (scalar(keys %{$self->{frontend}}) <= 0) {
|
||||
@ -180,6 +183,24 @@ sub manage_selection {
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
$options{snmp}->load(
|
||||
oids => [
|
||||
map($_->{oid}, values(%{$mapping->{$branch}}))
|
||||
],
|
||||
instances => [keys %{$self->{frontend}}],
|
||||
instance_regexp => '^(.*)$'
|
||||
);
|
||||
$snmp_result = $options{snmp}->get_leef(nothing_quit => 1);
|
||||
|
||||
foreach (keys %{$self->{frontend}}) {
|
||||
my $result = $options{snmp}->map_instance(mapping => $mapping->{$branch}, results => $snmp_result, instance => $_);
|
||||
|
||||
$result->{alFrontendBytesIN} *= 8;
|
||||
$result->{alFrontendBytesOUT} *= 8;
|
||||
|
||||
$self->{frontend}->{$_} = { %{$self->{frontend}->{$_}}, %$result };
|
||||
}
|
||||
|
||||
$self->{cache_name} = "haproxy_" . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' .
|
||||
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' .
|
||||
(defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all'));
|
||||
|
@ -32,8 +32,7 @@ sub new {
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
$options{options}->add_options(arguments => {
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"port:s" => { name => 'port', default => '7634' },
|
||||
"timeout:s" => { name => 'timeout', default => '10' },
|
||||
@ -71,7 +70,8 @@ sub check_options {
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $oSocketConn = new IO::Socket::INET ( Proto => 'tcp',
|
||||
my $oSocketConn = new IO::Socket::INET (
|
||||
Proto => 'tcp',
|
||||
PeerAddr => $self->{option_results}->{hostname},
|
||||
PeerPort => $self->{option_results}->{port},
|
||||
Timeout => $self->{option_results}->{timeout},
|
||||
@ -147,14 +147,17 @@ sub run {
|
||||
$self->{result}->{$name}->{unit}));
|
||||
}
|
||||
|
||||
my $extra_label = '';
|
||||
my $extra_label;
|
||||
$extra_label = '_' . $name if (!defined($self->{option_results}->{name}) || defined($self->{option_results}->{use_regexp}));
|
||||
$self->{output}->perfdata_add(label => 'temp' . $extra_label,
|
||||
$self->{output}->perfdata_add(
|
||||
label => 'temp',
|
||||
intances => $extra_label,
|
||||
unit => $self->{result}->{$name}->{unit},
|
||||
value => sprintf("%.2f", $self->{result}->{$name}->{temperature}),
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
|
||||
min => 0);
|
||||
min => 0
|
||||
);
|
||||
};
|
||||
|
||||
$self->{output}->display();
|
||||
|
@ -185,13 +185,16 @@ sub check {
|
||||
$str_display .= $str_display_append . sprintf("%s %s /sec", $name, $value_display);
|
||||
$str_display_append = ', ';
|
||||
|
||||
my $extra_label = '';
|
||||
my $extra_label;
|
||||
$extra_label = '_' . $site_name if (!defined($self->{option_results}->{name}) || defined($self->{option_results}->{use_regexp}));
|
||||
$self->{output}->perfdata_add(label => $name . $extra_label, unit => $counters->{$name}->{unit},
|
||||
$self->{output}->perfdata_add(
|
||||
label => $name, unit => $counters->{$name}->{unit},
|
||||
instances => $extra_label,
|
||||
value => sprintf("%.2f", $value_per_seconds),
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning_' . $name),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical_' . $name),
|
||||
min => 0);
|
||||
min => 0
|
||||
);
|
||||
}
|
||||
|
||||
# No values computing.
|
||||
|
@ -51,19 +51,21 @@ sub custom_usage_perfdata {
|
||||
$label = 'free';
|
||||
$value_perf = $self->{result_values}->{free};
|
||||
}
|
||||
my $extra_label = '';
|
||||
$extra_label = '_' . $self->{result_values}->{display} if (!defined($options{extra_instance}) || $options{extra_instance} != 0);
|
||||
|
||||
my %total_options = ();
|
||||
if ($self->{instance_mode}->{option_results}->{units} eq '%') {
|
||||
$total_options{total} = $self->{result_values}->{total};
|
||||
$total_options{cast_int} = 1;
|
||||
}
|
||||
|
||||
$self->{output}->perfdata_add(label => $label . $extra_label, unit => 'B',
|
||||
$self->{output}->perfdata_add(
|
||||
label => $label, unit => 'B',
|
||||
instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef,
|
||||
value => $value_perf,
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options),
|
||||
min => 0, max => $self->{result_values}->{total});
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}, %total_options),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}, %total_options),
|
||||
min => 0, max => $self->{result_values}->{total}
|
||||
);
|
||||
}
|
||||
|
||||
sub custom_usage_threshold {
|
||||
@ -76,7 +78,7 @@ sub custom_usage_threshold {
|
||||
$threshold_value = $self->{result_values}->{prct_used};
|
||||
$threshold_value = $self->{result_values}->{prct_free} if (defined($self->{instance_mode}->{option_results}->{free}));
|
||||
}
|
||||
$exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]);
|
||||
$exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{thlabel}, exit_litteral => 'warning' } ]);
|
||||
return $exit;
|
||||
}
|
||||
|
||||
|
@ -25,8 +25,6 @@ use base qw(centreon::plugins::templates::counter);
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
my $instance_mode;
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
@ -62,12 +60,12 @@ sub custom_usage_perfdata {
|
||||
|
||||
my $label = 'used_' . $self->{result_values}->{display};
|
||||
my $value_perf = $self->{result_values}->{used};
|
||||
if (defined($instance_mode->{option_results}->{free})) {
|
||||
if (defined($self->{instance_mode}->{option_results}->{free})) {
|
||||
$label = 'free_' . $self->{result_values}->{display};
|
||||
$value_perf = $self->{result_values}->{free};
|
||||
}
|
||||
my %total_options = ();
|
||||
if ($instance_mode->{option_results}->{units} eq '%') {
|
||||
if ($self->{instance_mode}->{option_results}->{units} eq '%') {
|
||||
$total_options{total} = $self->{result_values}->{total};
|
||||
$total_options{cast_int} = 1;
|
||||
}
|
||||
@ -84,10 +82,10 @@ sub custom_usage_threshold {
|
||||
|
||||
my ($exit, $threshold_value);
|
||||
$threshold_value = $self->{result_values}->{used};
|
||||
$threshold_value = $self->{result_values}->{free} if (defined($instance_mode->{option_results}->{free}));
|
||||
if ($instance_mode->{option_results}->{units} eq '%') {
|
||||
$threshold_value = $self->{result_values}->{free} if (defined($self->{instance_mode}->{option_results}->{free}));
|
||||
if ($self->{instance_mode}->{option_results}->{units} eq '%') {
|
||||
$threshold_value = $self->{result_values}->{prct_used};
|
||||
$threshold_value = $self->{result_values}->{prct_free} if (defined($instance_mode->{option_results}->{free}));
|
||||
$threshold_value = $self->{result_values}->{prct_free} if (defined($self->{instance_mode}->{option_results}->{free}));
|
||||
}
|
||||
$exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]);
|
||||
return $exit;
|
||||
@ -127,21 +125,14 @@ sub new {
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
$options{options}->add_options(arguments => {
|
||||
"units:s" => { name => 'units', default => '%' },
|
||||
"free" => { name => 'free' },
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::check_options(%options);
|
||||
|
||||
$instance_mode = $self;
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
|
@ -20,72 +20,16 @@
|
||||
|
||||
package apps::java::weblogic::jmx::mode::workmanager;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
use base qw(centreon::plugins::templates::counter);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::values;
|
||||
use centreon::plugins::statefile;
|
||||
use Digest::MD5 qw(md5_hex);
|
||||
|
||||
my $thresholds = {
|
||||
health => [
|
||||
['HEALTH_OK', 'OK'],
|
||||
['HEALTH_WARNING', 'WARNING'],
|
||||
['HEALTH_CRITICAL', 'CRITICAL'],
|
||||
['HEALTH_FAILED', 'CRITICAL'],
|
||||
['HEALTH_OVERLOADED', 'CRITICAL'],
|
||||
['LOW_MEMORY_REASON', 'CRITICAL'],
|
||||
],
|
||||
};
|
||||
my $instance_mode;
|
||||
|
||||
my $maps_counters = {
|
||||
runtime => {
|
||||
'000_status' => { set => {
|
||||
key_values => [ { name => 'health_state' } ],
|
||||
closure_custom_calc => \&custom_status_calc,
|
||||
output_template => 'State : %s', output_error_template => 'State : %s',
|
||||
output_use => 'health_state',
|
||||
closure_custom_perfdata => sub { return 0; },
|
||||
closure_custom_threshold_check => \&custom_threshold_output,
|
||||
}
|
||||
},
|
||||
|
||||
'001_request-completed' => { set => {
|
||||
key_values => [ { name => 'completed', diff => 1 }, { name => 'runtime' } ],
|
||||
output_template => 'Requests completed : %s',
|
||||
perfdatas => [
|
||||
{ label => 'request_completed', value => 'completed_absolute', template => '%s',
|
||||
min => 0, label_extra_instance => 1, instance_use => 'runtime_absolute' },
|
||||
],
|
||||
}
|
||||
},
|
||||
'002_request-pending' => { set => {
|
||||
key_values => [ { name => 'pending' }, { name => 'runtime' } ],
|
||||
output_template => 'Requests pending : %s',
|
||||
perfdatas => [
|
||||
{ label => 'request_pending', value => 'pending_absolute', template => '%s',
|
||||
min => 0, label_extra_instance => 1, instance_use => 'runtime_absolute' },
|
||||
],
|
||||
}
|
||||
},
|
||||
'003_thread-stuck' => { set => {
|
||||
key_values => [ { name => 'stuck' }, { name => 'runtime' } ],
|
||||
output_template => 'Threads stuck : %s',
|
||||
perfdatas => [
|
||||
{ label => 'thread_stuck', value => 'stuck_absolute', template => '%s',
|
||||
min => 0, label_extra_instance => 1, instance_use => 'runtime_absolute' },
|
||||
],
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
sub custom_threshold_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return $instance_mode->get_severity(section => 'health', value => $self->{result_values}->{health_state});
|
||||
return $self->{instance_mode}->get_severity(section => 'health', value => $self->{result_values}->{health_state});
|
||||
}
|
||||
|
||||
sub custom_status_calc {
|
||||
@ -95,53 +39,78 @@ sub custom_status_calc {
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'wm', type => 1, cb_prefix_output => 'prefix_wm_output', message_multiple => 'All WorkerManagers are ok' }
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{wm} = [
|
||||
{ label => 'status', threshold => 0, set => {
|
||||
key_values => [ { name => 'health_state' } ],
|
||||
closure_custom_calc => $self->can('custom_status_calc'),
|
||||
output_template => 'State : %s', output_error_template => 'State : %s',
|
||||
output_use => 'health_state',
|
||||
closure_custom_perfdata => sub { return 0; },
|
||||
closure_custom_threshold_check => $self->can('custom_threshold_output'),
|
||||
}
|
||||
},
|
||||
{ label => 'request-completed', set => {
|
||||
key_values => [ { name => 'completed', diff => 1 }, { name => 'display' } ],
|
||||
output_template => 'Requests completed : %s',
|
||||
perfdatas => [
|
||||
{ label => 'request_completed', value => 'completed_absolute', template => '%s',
|
||||
min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'request-pending', set => {
|
||||
key_values => [ { name => 'pending' }, { name => 'display' } ],
|
||||
output_template => 'Requests pending : %s',
|
||||
perfdatas => [
|
||||
{ label => 'request_pending', value => 'pending_absolute', template => '%s',
|
||||
min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'thread-stuck', set => {
|
||||
key_values => [ { name => 'stuck' }, { name => 'display' } ],
|
||||
output_template => 'Threads stuck : %s',
|
||||
perfdatas => [
|
||||
{ label => 'thread_stuck', value => 'stuck_absolute', template => '%s',
|
||||
min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
|
||||
],
|
||||
}
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
sub prefix_wm_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "WorkerManager '" . $options{instance_value}->{display} . "' ";
|
||||
}
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
$options{options}->add_options(arguments => {
|
||||
"filter-application:s" => { name => 'filter_application' },
|
||||
"filter-name:s" => { name => 'filter_name' },
|
||||
"filter-runtime:s" => { name => 'filter_runtime' },
|
||||
"threshold-overload:s@" => { name => 'threshold_overload' },
|
||||
});
|
||||
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
|
||||
|
||||
foreach my $key (('runtime')) {
|
||||
foreach (keys %{$maps_counters->{$key}}) {
|
||||
my ($id, $name) = split /_/;
|
||||
if (!defined($maps_counters->{$key}->{$_}->{threshold}) || $maps_counters->{$key}->{$_}->{threshold} != 0) {
|
||||
$options{options}->add_options(arguments => {
|
||||
'warning-' . $name . ':s' => { name => 'warning-' . $name },
|
||||
'critical-' . $name . ':s' => { name => 'critical-' . $name },
|
||||
});
|
||||
}
|
||||
$maps_counters->{$key}->{$_}->{obj} = centreon::plugins::values->new(
|
||||
statefile => $self->{statefile_value},
|
||||
output => $self->{output}, perfdata => $self->{perfdata},
|
||||
label => $name);
|
||||
$maps_counters->{$key}->{$_}->{obj}->set(%{$maps_counters->{$key}->{$_}->{set}});
|
||||
}
|
||||
}
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
foreach my $key (('runtime')) {
|
||||
foreach (keys %{$maps_counters->{$key}}) {
|
||||
$maps_counters->{$key}->{$_}->{obj}->init(option_results => $self->{option_results});
|
||||
}
|
||||
}
|
||||
|
||||
$self->{statefile_value}->check_options(%options);
|
||||
$instance_mode = $self;
|
||||
$self->SUPER::check_options(%options);
|
||||
|
||||
$self->{overload_th} = {};
|
||||
foreach my $val (@{$self->{option_results}->{threshold_overload}}) {
|
||||
@ -159,77 +128,16 @@ sub check_options {
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
$self->{connector} = $options{custom};
|
||||
|
||||
$self->manage_selection();
|
||||
|
||||
my $multiple = 1;
|
||||
if (scalar(keys %{$self->{runtime}}) == 1) {
|
||||
$multiple = 0;
|
||||
}
|
||||
|
||||
if ($multiple == 1) {
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => 'All WorkerManagers are ok');
|
||||
}
|
||||
|
||||
my $matching = '';
|
||||
foreach (('filter_application', 'filter_name', 'filter_runtime')) {
|
||||
$matching .= defined($self->{option_results}->{$_}) ? $self->{option_results}->{$_} : 'all';
|
||||
}
|
||||
$self->{new_datas} = {};
|
||||
$self->{statefile_value}->read(statefile => "weblogic_" . $self->{mode} . '_' . md5_hex($self->{connector}->{url}) . '_' . md5_hex($matching));
|
||||
$self->{new_datas}->{last_timestamp} = time();
|
||||
|
||||
foreach my $id (sort keys %{$self->{runtime}}) {
|
||||
my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', '');
|
||||
my @exits = ();
|
||||
foreach (sort keys %{$maps_counters->{runtime}}) {
|
||||
my $obj = $maps_counters->{runtime}->{$_}->{obj};
|
||||
$obj->set(instance => $id);
|
||||
|
||||
my ($value_check) = $obj->execute(values => $self->{runtime}->{$id},
|
||||
new_datas => $self->{new_datas});
|
||||
|
||||
if ($value_check != 0) {
|
||||
$long_msg .= $long_msg_append . $obj->output_error();
|
||||
$long_msg_append = ', ';
|
||||
next;
|
||||
}
|
||||
my $exit2 = $obj->threshold_check();
|
||||
push @exits, $exit2;
|
||||
|
||||
my $output = $obj->output();
|
||||
$long_msg .= $long_msg_append . $output;
|
||||
$long_msg_append = ', ';
|
||||
|
||||
if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) {
|
||||
$short_msg .= $short_msg_append . $output;
|
||||
$short_msg_append = ', ';
|
||||
}
|
||||
|
||||
$obj->perfdata(level => 1, extra_instance => $multiple);
|
||||
}
|
||||
|
||||
$self->{output}->output_add(long_msg => "WorkerManager '$id' $long_msg");
|
||||
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
|
||||
if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) {
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => "WorkerManager '$id' $short_msg"
|
||||
);
|
||||
}
|
||||
|
||||
if ($multiple == 0) {
|
||||
$self->{output}->output_add(short_msg => "WorkerManager '$id' $long_msg");
|
||||
}
|
||||
}
|
||||
|
||||
$self->{statefile_value}->write(data => $self->{new_datas});
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
my $thresholds = {
|
||||
health => [
|
||||
['HEALTH_OK', 'OK'],
|
||||
['HEALTH_WARNING', 'WARNING'],
|
||||
['HEALTH_CRITICAL', 'CRITICAL'],
|
||||
['HEALTH_FAILED', 'CRITICAL'],
|
||||
['HEALTH_OVERLOADED', 'CRITICAL'],
|
||||
['LOW_MEMORY_REASON', 'CRITICAL'],
|
||||
],
|
||||
};
|
||||
|
||||
sub get_severity {
|
||||
my ($self, %options) = @_;
|
||||
@ -265,13 +173,13 @@ my %map_state = (
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{request} = [
|
||||
my $request = [
|
||||
{ mbean => 'com.bea:ApplicationRuntime=*,Name=*,ServerRuntime=*,Type=WorkManagerRuntime',
|
||||
attributes => [ { name => 'HealthState' }, { name => 'StuckThreadCount' }, { name => 'CompletedRequests' }, { name => 'PendingRequests' } ] }
|
||||
];
|
||||
my $result = $self->{connector}->get_attributes(request => $self->{request}, nothing_quit => 1);
|
||||
my $result = $options{custom}->get_attributes(request => $request, nothing_quit => 1);
|
||||
|
||||
$self->{runtime} = {};
|
||||
$self->{wm} = {};
|
||||
foreach my $mbean (keys %{$result}) {
|
||||
next if ($mbean !~ /ApplicationRuntime=(.*?),Name=(.*?),ServerRuntime=(.*?),/);
|
||||
my ($app, $name, $runtime) = ($1, $2, $3);
|
||||
@ -280,28 +188,40 @@ sub manage_selection {
|
||||
|
||||
if (defined($self->{option_results}->{filter_application}) && $self->{option_results}->{filter_application} ne '' &&
|
||||
$app !~ /$self->{option_results}->{filter_application}/) {
|
||||
$self->{output}->output_add(long_msg => "Skipping '" . $app . "': no matching filter application.");
|
||||
$self->{output}->output_add(long_msg => "skipping '" . $app . "': no matching filter application.");
|
||||
next;
|
||||
}
|
||||
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
|
||||
$name !~ /$self->{option_results}->{filter_name}/) {
|
||||
$self->{output}->output_add(long_msg => "Skipping '" . $name . "': no matching filter name.");
|
||||
$self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter name.");
|
||||
next;
|
||||
}
|
||||
if (defined($self->{option_results}->{filter_runtime}) && $self->{option_results}->{filter_runtime} ne '' &&
|
||||
$runtime !~ /$self->{option_results}->{filter_runtime}/) {
|
||||
$self->{output}->output_add(long_msg => "Skipping '" . $runtime . "': no matching filter runtime.");
|
||||
$self->{output}->output_add(long_msg => "skipping '" . $runtime . "': no matching filter runtime.");
|
||||
next;
|
||||
}
|
||||
|
||||
$self->{runtime}->{$app . '/' . $name . '/' . $runtime} = { health_state => $health_state, runtime => $app . '/' . $name . '/' . $runtime,
|
||||
completed => $result->{$mbean}->{CompletedRequests}, pending => $result->{$mbean}->{PendingRequests}, stuck => $result->{$mbean}->{StuckThreadCount} };
|
||||
$self->{wm}->{$app . '/' . $name . '/' . $runtime} = {
|
||||
health_state => $health_state,
|
||||
display => $app . '/' . $name . '/' . $runtime,
|
||||
completed => $result->{$mbean}->{CompletedRequests},
|
||||
pending => $result->{$mbean}->{PendingRequests},
|
||||
stuck => $result->{$mbean}->{StuckThreadCount}
|
||||
};
|
||||
}
|
||||
|
||||
if (scalar(keys %{$self->{runtime}}) <= 0) {
|
||||
if (scalar(keys %{$self->{wm}}) <= 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "No entry found.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
$self->{cache_name} = "weblogic_" . $self->{mode} . '_' . md5_hex($self->{connector}->{url}) . '_' .
|
||||
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' .
|
||||
(defined($self->{option_results}->{filter_application}) ? md5_hex($self->{option_results}->{filter_application}) : md5_hex('all')) . '_' .
|
||||
(defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')) . '_' .
|
||||
(defined($self->{option_results}->{filter_runtime}) ? md5_hex($self->{option_results}->{filter_runtime}) : md5_hex('all'));
|
||||
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -34,8 +34,7 @@ sub new {
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
$options{options}->add_options(arguments => {
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"port:s" => { name => 'port' },
|
||||
"proto:s" => { name => 'proto' },
|
||||
@ -45,15 +44,13 @@ sub new {
|
||||
"basic" => { name => 'basic' },
|
||||
"username:s" => { name => 'username' },
|
||||
"password:s" => { name => 'password' },
|
||||
"proxyurl:s" => { name => 'proxyurl' },
|
||||
"ssl-opt:s@" => { name => 'ssl_opt' },
|
||||
"jobname:s" => { name => 'jobname' },
|
||||
"warning:s" => { name => 'warning' },
|
||||
"critical:s" => { name => 'critical' },
|
||||
"checkstyle" => { name => 'checkstyle' },
|
||||
});
|
||||
|
||||
$self->{http} = centreon::plugins::http->new(output => $self->{output});
|
||||
$self->{http} = centreon::plugins::http->new(%options);
|
||||
return $self;
|
||||
}
|
||||
|
||||
@ -180,18 +177,10 @@ Specify username for API authentification
|
||||
|
||||
Specify password for API authentification
|
||||
|
||||
=item B<--proxyurl>
|
||||
|
||||
Proxy URL if any
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Threshold for HTTP timeout (Default: 5)
|
||||
|
||||
=item B<--ssl-opt>
|
||||
|
||||
Set SSL Options (--ssl-opt="SSL_version => TLSv1" --ssl-opt="SSL_verify_mode => SSL_VERIFY_NONE").
|
||||
|
||||
=item B<--warning>
|
||||
|
||||
Warning Threshold for tendency score
|
||||
|
@ -36,20 +36,17 @@ sub new {
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
$options{options}->add_options(arguments => {
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"port:s" => { name => 'port' },
|
||||
"proto:s" => { name => 'proto' },
|
||||
"urlpath:s" => { name => 'url_path', default => '/api/index.php?' },
|
||||
"proxyurl:s" => { name => 'proxyurl' },
|
||||
"timeout:s" => { name => 'timeout' },
|
||||
"ssl-opt:s@" => { name => 'ssl_opt' },
|
||||
"kayako-api-key:s" => { name => 'kayako_api_key' },
|
||||
"kayako-secret-key:s" => { name => 'kayako_secret_key' },
|
||||
});
|
||||
|
||||
$self->{http} = centreon::plugins::http->new(output => $self->{output});
|
||||
$self->{http} = centreon::plugins::http->new(%options);
|
||||
return $self;
|
||||
}
|
||||
|
||||
@ -116,10 +113,6 @@ Port used by Apache
|
||||
|
||||
Specify https if needed
|
||||
|
||||
=item B<--proxyurl>
|
||||
|
||||
Proxy URL if any
|
||||
|
||||
=item B<--urlpath>
|
||||
|
||||
This is the URL you should dispatch all GET, POST, PUT & DELETE requests to (Default: '/api/index.php?')
|
||||
@ -128,10 +121,6 @@ This is the URL you should dispatch all GET, POST, PUT & DELETE requests to (Def
|
||||
|
||||
Threshold for HTTP timeout.
|
||||
|
||||
=item B<--ssl-opt>
|
||||
|
||||
Set SSL Options (--ssl-opt="SSL_version => TLSv1" --ssl-opt="SSL_verify_mode => SSL_VERIFY_NONE").
|
||||
|
||||
=item B<--kayako-api-key>
|
||||
|
||||
This is your unique API key.
|
||||
|
@ -36,20 +36,17 @@ sub new {
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
$options{options}->add_options(arguments => {
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"port:s" => { name => 'port' },
|
||||
"proto:s" => { name => 'proto' },
|
||||
"urlpath:s" => { name => 'url_path', default => '/api/index.php?' },
|
||||
"proxyurl:s" => { name => 'proxyurl' },
|
||||
"timeout:s" => { name => 'timeout' },
|
||||
"ssl-opt:s@" => { name => 'ssl_opt' },
|
||||
"kayako-api-key:s" => { name => 'kayako_api_key' },
|
||||
"kayako-secret-key:s" => { name => 'kayako_secret_key' },
|
||||
});
|
||||
|
||||
$self->{http} = centreon::plugins::http->new(output => $self->{output});
|
||||
$self->{http} = centreon::plugins::http->new(%options);
|
||||
return $self;
|
||||
}
|
||||
|
||||
@ -116,10 +113,6 @@ Port used by Apache
|
||||
|
||||
Specify https if needed
|
||||
|
||||
=item B<--proxyurl>
|
||||
|
||||
Proxy URL if any
|
||||
|
||||
=item B<--urlpath>
|
||||
|
||||
This is the URL you should dispatch all GET, POST, PUT & DELETE requests to (Default: '/api/index.php?')
|
||||
@ -128,10 +121,6 @@ This is the URL you should dispatch all GET, POST, PUT & DELETE requests to (Def
|
||||
|
||||
Threshold for HTTP timeout.
|
||||
|
||||
=item B<--ssl-opt>
|
||||
|
||||
Set SSL Options (--ssl-opt="SSL_version => TLSv1" --ssl-opt="SSL_verify_mode => SSL_VERIFY_NONE").
|
||||
|
||||
=item B<--kayako-api-key>
|
||||
|
||||
This is your unique API key.
|
||||
|
@ -34,20 +34,17 @@ sub new {
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
$options{options}->add_options(arguments => {
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"port:s" => { name => 'port' },
|
||||
"proto:s" => { name => 'proto' },
|
||||
"urlpath:s" => { name => 'url_path', default => '/api/index.php?' },
|
||||
"proxyurl:s" => { name => 'proxyurl' },
|
||||
"timeout:s" => { name => 'timeout' },
|
||||
"ssl-opt:s@" => { name => 'ssl_opt' },
|
||||
"kayako-api-key:s" => { name => 'kayako_api_key' },
|
||||
"kayako-secret-key:s" => { name => 'kayako_secret_key' },
|
||||
});
|
||||
|
||||
$self->{http} = centreon::plugins::http->new(output => $self->{output});
|
||||
$self->{http} = centreon::plugins::http->new(%options);
|
||||
return $self;
|
||||
}
|
||||
|
||||
@ -114,10 +111,6 @@ Port used by Apache
|
||||
|
||||
Specify https if needed
|
||||
|
||||
=item B<--proxyurl>
|
||||
|
||||
Proxy URL if any
|
||||
|
||||
=item B<--urlpath>
|
||||
|
||||
This is the URL you should dispatch all GET, POST, PUT & DELETE requests to (Default: '/api/index.php?')
|
||||
@ -126,10 +119,6 @@ This is the URL you should dispatch all GET, POST, PUT & DELETE requests to (Def
|
||||
|
||||
Threshold for HTTP timeout.
|
||||
|
||||
=item B<--ssl-opt>
|
||||
|
||||
Set SSL Options (--ssl-opt="SSL_version => TLSv1" --ssl-opt="SSL_verify_mode => SSL_VERIFY_NONE").
|
||||
|
||||
=item B<--kayako-api-key>
|
||||
|
||||
This is your unique API key.
|
||||
|
@ -34,20 +34,17 @@ sub new {
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
$options{options}->add_options(arguments => {
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"port:s" => { name => 'port' },
|
||||
"proto:s" => { name => 'proto' },
|
||||
"urlpath:s" => { name => 'url_path', default => '/api/index.php?' },
|
||||
"proxyurl:s" => { name => 'proxyurl' },
|
||||
"timeout:s" => { name => 'timeout' },
|
||||
"ssl-opt:s@" => { name => 'ssl_opt' },
|
||||
"kayako-api-key:s" => { name => 'kayako_api_key' },
|
||||
"kayako-secret-key:s" => { name => 'kayako_secret_key' },
|
||||
});
|
||||
|
||||
$self->{http} = centreon::plugins::http->new(output => $self->{output});
|
||||
$self->{http} = centreon::plugins::http->new(%options);
|
||||
return $self;
|
||||
}
|
||||
|
||||
@ -114,10 +111,6 @@ Port used by Apache
|
||||
|
||||
Specify https if needed
|
||||
|
||||
=item B<--proxyurl>
|
||||
|
||||
Proxy URL if any
|
||||
|
||||
=item B<--urlpath>
|
||||
|
||||
This is the URL you should dispatch all GET, POST, PUT & DELETE requests to (Default: '/api/index.php?')
|
||||
@ -126,10 +119,6 @@ This is the URL you should dispatch all GET, POST, PUT & DELETE requests to (Def
|
||||
|
||||
Threshold for HTTP timeout.
|
||||
|
||||
=item B<--ssl-opt>
|
||||
|
||||
Set SSL Options (--ssl-opt="SSL_version => TLSv1" --ssl-opt="SSL_verify_mode => SSL_VERIFY_NONE").
|
||||
|
||||
=item B<--kayako-api-key>
|
||||
|
||||
This is your unique API key.
|
||||
|
@ -45,15 +45,12 @@ sub new {
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
$options{options}->add_options(arguments => {
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"port:s" => { name => 'port' },
|
||||
"proto:s" => { name => 'proto' },
|
||||
"urlpath:s" => { name => 'url_path', default => '/api/index.php?' },
|
||||
"proxyurl:s" => { name => 'proxyurl' },
|
||||
"timeout:s" => { name => 'timeout' },
|
||||
"ssl-opt:s@" => { name => 'ssl_opt' },
|
||||
"kayako-api-key:s" => { name => 'kayako_api_key' },
|
||||
"kayako-secret-key:s" => { name => 'kayako_secret_key' },
|
||||
"reload-cache-time:s" => { name => 'reload_cache_time', default => 180 },
|
||||
@ -68,7 +65,7 @@ sub new {
|
||||
});
|
||||
$self->{statefile_cache} = centreon::plugins::statefile->new(%options);
|
||||
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
|
||||
$self->{http} = centreon::plugins::http->new(output => $self->{output});
|
||||
$self->{http} = centreon::plugins::http->new(%options);
|
||||
|
||||
return $self;
|
||||
}
|
||||
@ -339,10 +336,6 @@ Port used by Apache
|
||||
|
||||
Specify https if needed
|
||||
|
||||
=item B<--proxyurl>
|
||||
|
||||
Proxy URL if any
|
||||
|
||||
=item B<--urlpath>
|
||||
|
||||
This is the URL you should dispatch all GET, POST, PUT & DELETE requests to (Default: '/api/index.php?')
|
||||
@ -351,10 +344,6 @@ This is the URL you should dispatch all GET, POST, PUT & DELETE requests to (Def
|
||||
|
||||
Threshold for HTTP timeout.
|
||||
|
||||
=item B<--ssl-opt>
|
||||
|
||||
Set SSL Options (--ssl-opt="SSL_version => TLSv1" --ssl-opt="SSL_verify_mode => SSL_VERIFY_NONE").
|
||||
|
||||
=item B<--kayako-api-key>
|
||||
|
||||
This is your unique API key. (required)
|
||||
|
155
apps/keepalived/snmp/mode/vrrpstatus.pm
Normal file
155
apps/keepalived/snmp/mode/vrrpstatus.pm
Normal file
@ -0,0 +1,155 @@
|
||||
#
|
||||
# Copyright 2019 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package apps::keepalived::snmp::mode::vrrpstatus;
|
||||
|
||||
use base qw(centreon::plugins::templates::counter);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Digest::MD5 qw(md5_hex);
|
||||
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold);
|
||||
|
||||
sub custom_status_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $msg = sprintf("state : %s [last state : %s, wanted state : '%s']",
|
||||
$self->{result_values}->{instanceState}, $self->{result_values}->{instanceStateLast}, $self->{result_values}->{instanceWantedState});
|
||||
return $msg;
|
||||
}
|
||||
|
||||
sub custom_status_calc {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{result_values}->{instanceWantedState} = $options{new_datas}->{$self->{instance} . '_instance_wanted_state'};
|
||||
$self->{result_values}->{instanceStateLast} = $options{old_datas}->{$self->{instance} . '_instance_state'};
|
||||
$self->{result_values}->{instanceState} = $options{new_datas}->{$self->{instance} . '_instance_state'};
|
||||
$self->{result_values}->{instancePrimaryInterface} = $options{new_datas}->{$self->{instance} . '_instance_primary_interface'};
|
||||
if (!defined($options{old_datas}->{$self->{instance} . '_instance_state'})) {
|
||||
$self->{error_msg} = "buffer creation";
|
||||
return -2;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'vrrp', type => 1, cb_prefix_output => 'prefix_vrrp_output', message_multiple => 'All VRRP instances are ok' },
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{vrrp} = [
|
||||
{ label => 'status', threshold => 0, set => {
|
||||
key_values => [ { name => 'instance_primary_interface' }, { name => 'instance_wanted_state' }, { name => 'instance_state' } ],
|
||||
closure_custom_calc => $self->can('custom_status_calc'),
|
||||
closure_custom_output => $self->can('custom_status_output'),
|
||||
closure_custom_perfdata => sub { return 0; },
|
||||
closure_custom_threshold_check => \&catalog_status_threshold,
|
||||
}
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
sub prefix_vrrp_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "VRRP '" . $options{instance_value}->{instance_primary_interface} . "' ";
|
||||
}
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"warning-status:s" => { name => 'warning_status', default => '' },
|
||||
"critical-status:s" => { name => 'critical_status', default => '%{instanceState} ne %{instanceWantedState} or %{instanceState} ne %{instanceStateLast}' },
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::check_options(%options);
|
||||
|
||||
$self->change_macros(macros => ['warning_status', 'critical_status']);
|
||||
}
|
||||
|
||||
my %map_instance_state = (0 => 'init', 1 => 'backup', 2 => 'master', 3 => 'fault', 4 => 'unknown');
|
||||
my %map_instance_wanted_state = (0 => 'init', 1 => 'backup', 2 => 'master', 3 => 'fault', 4 => 'unknown');
|
||||
my $mapping = {
|
||||
vrrpInstanceState => { oid => '.1.3.6.1.4.1.9586.100.5.2.3.1.4', map => \%map_instance_state },
|
||||
vrrpInstanceWantedState => { oid => '.1.3.6.1.4.1.9586.100.5.2.3.1.6', map => \%map_instance_wanted_state },
|
||||
vrrpInstancePrimaryInterface => { oid => '.1.3.6.1.4.1.9586.100.5.2.3.1.10' },
|
||||
};
|
||||
|
||||
my $oid_vrrpInstanceEntry = '.1.3.6.1.4.1.9586.100.5.2.3.1';
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{vrrp} = {};
|
||||
my $snmp_result = $options{snmp}->get_table(oid => $oid_vrrpInstanceEntry, end => $mapping->{vrrpInstancePrimaryInterface}->{oid},
|
||||
nothing_quit => 1);
|
||||
|
||||
foreach my $oid (keys %{$snmp_result}) {
|
||||
next if ($oid !~ /^$mapping->{vrrpInstanceState}->{oid}\.(.*)$/);
|
||||
my $instance = $1;
|
||||
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
|
||||
|
||||
$self->{vrrp}->{$instance} = {
|
||||
instance_primary_interface => $result->{vrrpInstancePrimaryInterface},
|
||||
instance_wanted_state => $result->{vrrpInstanceWantedState},
|
||||
instance_state => $result->{vrrpInstanceState},
|
||||
};
|
||||
}
|
||||
|
||||
$self->{cache_name} = "keepalived_" . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' .
|
||||
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check VRRP instances status.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--warning-status>
|
||||
|
||||
Set warning threshold for status.
|
||||
Can used special variables like: %{instanceWantedState}, %{instanceStateLast}, %{instanceState}, %{instancePrimaryInterface}
|
||||
|
||||
=item B<--critical-status>
|
||||
|
||||
Set critical threshold for status (Default: '%{instanceState} ne %{instanceWantedState} or %{instanceState} ne %{instanceStateLast}').
|
||||
Can used special variables like: %{instanceWantedState}, %{instanceStateLast}, %{instanceState}, %{instancePrimaryInterface}
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
48
apps/keepalived/snmp/plugin.pm
Normal file
48
apps/keepalived/snmp/plugin.pm
Normal file
@ -0,0 +1,48 @@
|
||||
#
|
||||
# Copyright 2019 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package apps::keepalived::snmp::plugin;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use base qw(centreon::plugins::script_snmp);
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
%{$self->{modes}} = (
|
||||
'vrrp-status' => 'apps::keepalived::snmp::mode::vrrpstatus',
|
||||
);
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 PLUGIN DESCRIPTION
|
||||
|
||||
Check Keepalived in SNMP.
|
||||
|
||||
=cut
|
@ -39,23 +39,20 @@ sub new {
|
||||
}
|
||||
|
||||
if (!defined($options{noptions})) {
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
$options{options}->add_options(arguments => {
|
||||
"hostname:s@" => { name => 'hostname' },
|
||||
"proto:s@" => { name => 'proto' },
|
||||
"port:s@" => { name => 'port' },
|
||||
"username:s@" => { name => 'username' },
|
||||
"password:s@" => { name => 'password' },
|
||||
"proxyurl:s@" => { name => 'proxyurl' },
|
||||
"timeout:s@" => { name => 'timeout' },
|
||||
"ssl-opt:s@" => { name => 'ssl_opt' },
|
||||
});
|
||||
}
|
||||
$options{options}->add_help(package => __PACKAGE__, sections => 'REST API OPTIONS', once => 1);
|
||||
|
||||
$self->{output} = $options{output};
|
||||
$self->{mode} = $options{mode};
|
||||
$self->{http} = centreon::plugins::http->new(output => $self->{output});
|
||||
$self->{http} = centreon::plugins::http->new(%options);
|
||||
|
||||
return $self;
|
||||
|
||||
@ -92,7 +89,6 @@ sub check_options {
|
||||
$self->{proto} = (defined($self->{option_results}->{proto})) ? shift(@{$self->{option_results}->{proto}}) : 'http';
|
||||
$self->{port} = (defined($self->{option_results}->{port})) ? shift(@{$self->{option_results}->{port}}) : 80;
|
||||
$self->{timeout} = (defined($self->{option_results}->{timeout})) ? shift(@{$self->{option_results}->{timeout}}) : 10;
|
||||
$self->{proxyurl} = (defined($self->{option_results}->{proxyurl})) ? shift(@{$self->{option_results}->{proxyurl}}) : undef;
|
||||
|
||||
if (!defined($self->{hostname})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Need to specify hostname option.");
|
||||
@ -113,7 +109,6 @@ sub build_options_for_httplib {
|
||||
$self->{option_results}->{timeout} = $self->{timeout};
|
||||
$self->{option_results}->{port} = $self->{port};
|
||||
$self->{option_results}->{proto} = $self->{proto};
|
||||
$self->{option_results}->{proxyurl} = $self->{proxyurl};
|
||||
$self->{option_results}->{credentials} = 1;
|
||||
$self->{option_results}->{basic} = 1;
|
||||
$self->{option_results}->{username} = $self->{username};
|
||||
@ -169,18 +164,10 @@ Kingdee username.
|
||||
|
||||
Kingdee password.
|
||||
|
||||
=item B<--proxyurl>
|
||||
|
||||
Proxy URL if any.
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Set HTTP timeout in seconds (Default: '10').
|
||||
|
||||
=item B<--ssl-opt>
|
||||
|
||||
Set SSL Options (--ssl-opt="SSL_version => TLSv1" --ssl-opt="SSL_verify_mode => SSL_VERIFY_NONE").
|
||||
|
||||
=back
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
@ -1,178 +0,0 @@
|
||||
#
|
||||
# Copyright 2019 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package apps::lmsensors::mode::fan;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
my $oid_SensorDesc = '.1.3.6.1.4.1.2021.13.16.3.1.2'; # fan entry description
|
||||
my $oid_SensorValue = '.1.3.6.1.4.1.2021.13.16.3.1.3'; # fan entry value (RPM)
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"warning:s" => { name => 'warning' },
|
||||
"critical:s" => { name => 'critical' },
|
||||
"name" => { name => 'use_name' },
|
||||
"sensor:s" => { name => 'sensor' },
|
||||
"regexp" => { name => 'use_regexp' },
|
||||
"regexp-isensitive" => { name => 'use_regexpi' },
|
||||
});
|
||||
|
||||
$self->{Sensor_id_selected} = [];
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
$self->{snmp} = $options{snmp};
|
||||
$self->{hostname} = $self->{snmp}->get_hostname();
|
||||
$self->{snmp_port} = $self->{snmp}->get_port();
|
||||
|
||||
$self->manage_selection();
|
||||
|
||||
$self->{snmp}->load(oids => [$oid_SensorDesc, $oid_SensorValue], instances => $self->{Sensor_id_selected});
|
||||
my $SensorValueResult = $self->{snmp}->get_leef(nothing_quit => 1);
|
||||
|
||||
if (!defined($self->{option_results}->{sensor}) || defined($self->{option_results}->{use_regexp})) {
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => 'All Fans are ok.');
|
||||
}
|
||||
|
||||
foreach my $SensorId (sort @{$self->{Sensor_id_selected}}) {
|
||||
my $SensorDesc = $SensorValueResult->{$oid_SensorDesc . '.' . $SensorId};
|
||||
my $SensorValue = $SensorValueResult->{$oid_SensorValue . '.' . $SensorId};
|
||||
|
||||
my $exit = $self->{perfdata}->threshold_check(value => $SensorValue, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
||||
|
||||
$self->{output}->output_add(long_msg => sprintf("Sensor '%s' Fan: %s",
|
||||
$SensorDesc, $SensorValue));
|
||||
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1) || (defined($self->{option_results}->{sensor}) && !defined($self->{option_results}->{use_regexp}))) {
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => sprintf("Sensor '%s' Fan: %s",
|
||||
$SensorDesc, $SensorValue));
|
||||
}
|
||||
|
||||
my $label = 'sensor_fan';
|
||||
my $extra_label = '';
|
||||
$extra_label = '_' . $SensorId . "_" . $SensorDesc if (!defined($self->{option_results}->{sensor}) || defined($self->{option_results}->{use_regexp}));
|
||||
$self->{output}->perfdata_add(label => $label . $extra_label,
|
||||
value => $SensorValue,
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'));
|
||||
}
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
my $result = $self->{snmp}->get_table(oid => $oid_SensorDesc, nothing_quit => 1);
|
||||
|
||||
foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) {
|
||||
next if ($key !~ /\.([0-9]+)$/);
|
||||
my $SensorId = $1;
|
||||
my $SensorDesc = $result->{$key};
|
||||
|
||||
next if (defined($self->{option_results}->{sensor}) && !defined($self->{option_results}->{use_name}) && !defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
|
||||
&& $SensorId !~ /$self->{option_results}->{sensor}/i);
|
||||
next if (defined($self->{option_results}->{use_name}) && defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi})
|
||||
&& $SensorDesc !~ /$self->{option_results}->{sensor}/i);
|
||||
next if (defined($self->{option_results}->{use_name}) && defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
|
||||
&& $SensorDesc !~ /$self->{option_results}->{sensor}/);
|
||||
next if (defined($self->{option_results}->{use_name}) && !defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
|
||||
&& $SensorDesc ne $self->{option_results}->{sensor});
|
||||
|
||||
|
||||
push @{$self->{Sensor_id_selected}}, $SensorId;
|
||||
}
|
||||
|
||||
if (scalar(@{$self->{Sensor_id_selected}}) <= 0) {
|
||||
if (defined($self->{option_results}->{sensor})) {
|
||||
$self->{output}->add_option_msg(short_msg => "No Sensors found for '" . $self->{option_results}->{sensor} . "'.");
|
||||
} else {
|
||||
$self->{output}->add_option_msg(short_msg => "No Sensors found.");
|
||||
};
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check LM-Sensors: Fan Sensors
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--warning>
|
||||
|
||||
Threshold warning (Fan Speed, U/min)
|
||||
|
||||
=item B<--critical>
|
||||
|
||||
Threshold critical (Fan Speed, U/min)
|
||||
|
||||
=item B<--sensor>
|
||||
|
||||
Set the Sensor Desc (number expected) ex: 1, 2,... (empty means 'check all sensors').
|
||||
|
||||
=item B<--name>
|
||||
|
||||
Allows to use Sensor Desc name with option --sensor instead of Sensor Desc oid index.
|
||||
|
||||
=item B<--regexp>
|
||||
|
||||
Allows to use regexp to filter sensordesc (with option --name).
|
||||
|
||||
=item B<--regexp-isensitive>
|
||||
|
||||
Allows to use regexp non case-sensitive (with --regexp).
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
@ -1,178 +0,0 @@
|
||||
#
|
||||
# Copyright 2019 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package apps::lmsensors::mode::misc;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
my $oid_SensorDesc = '.1.3.6.1.4.1.2021.13.16.5.1.2'; # misc entry description
|
||||
my $oid_SensorValue = '.1.3.6.1.4.1.2021.13.16.5.1.3'; # misc entry value
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"warning:s" => { name => 'warning' },
|
||||
"critical:s" => { name => 'critical' },
|
||||
"name" => { name => 'use_name' },
|
||||
"sensor:s" => { name => 'sensor' },
|
||||
"regexp" => { name => 'use_regexp' },
|
||||
"regexp-isensitive" => { name => 'use_regexpi' },
|
||||
});
|
||||
|
||||
$self->{Sensor_id_selected} = [];
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
$self->{snmp} = $options{snmp};
|
||||
$self->{hostname} = $self->{snmp}->get_hostname();
|
||||
$self->{snmp_port} = $self->{snmp}->get_port();
|
||||
|
||||
$self->manage_selection();
|
||||
|
||||
$self->{snmp}->load(oids => [$oid_SensorDesc, $oid_SensorValue], instances => $self->{Sensor_id_selected});
|
||||
my $SensorValueResult = $self->{snmp}->get_leef(nothing_quit => 1);
|
||||
|
||||
if (!defined($self->{option_results}->{sensor}) || defined($self->{option_results}->{use_regexp})) {
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => 'All Sensors are ok.');
|
||||
}
|
||||
|
||||
foreach my $SensorId (sort @{$self->{Sensor_id_selected}}) {
|
||||
my $SensorDesc = $SensorValueResult->{$oid_SensorDesc . '.' . $SensorId};
|
||||
my $SensorValue = $SensorValueResult->{$oid_SensorValue . '.' . $SensorId} / 1000;
|
||||
|
||||
my $exit = $self->{perfdata}->threshold_check(value => $SensorValue, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
||||
|
||||
$self->{output}->output_add(long_msg => sprintf("Sensor '%s': %s",
|
||||
$SensorDesc, $SensorValue));
|
||||
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1) || (defined($self->{option_results}->{sensor}) && !defined($self->{option_results}->{use_regexp}))) {
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => sprintf("Sensor '%s': %s",
|
||||
$SensorDesc, $SensorValue));
|
||||
}
|
||||
|
||||
my $label = 'sensor_misc';
|
||||
my $extra_label = '';
|
||||
$extra_label = '_' . $SensorId . "_" . $SensorDesc if (!defined($self->{option_results}->{sensor}) || defined($self->{option_results}->{use_regexp}));
|
||||
$self->{output}->perfdata_add(label => $label . $extra_label,
|
||||
value => $SensorValue,
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'));
|
||||
}
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
my $result = $self->{snmp}->get_table(oid => $oid_SensorDesc, nothing_quit => 1);
|
||||
|
||||
foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) {
|
||||
next if ($key !~ /\.([0-9]+)$/);
|
||||
my $SensorId = $1;
|
||||
my $SensorDesc = $result->{$key};
|
||||
|
||||
next if (defined($self->{option_results}->{sensor}) && !defined($self->{option_results}->{use_name}) && !defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
|
||||
&& $SensorId !~ /$self->{option_results}->{sensor}/i);
|
||||
next if (defined($self->{option_results}->{use_name}) && defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi})
|
||||
&& $SensorDesc !~ /$self->{option_results}->{sensor}/i);
|
||||
next if (defined($self->{option_results}->{use_name}) && defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
|
||||
&& $SensorDesc !~ /$self->{option_results}->{sensor}/);
|
||||
next if (defined($self->{option_results}->{use_name}) && !defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
|
||||
&& $SensorDesc ne $self->{option_results}->{sensor});
|
||||
|
||||
|
||||
push @{$self->{Sensor_id_selected}}, $SensorId;
|
||||
}
|
||||
|
||||
if (scalar(@{$self->{Sensor_id_selected}}) <= 0) {
|
||||
if (defined($self->{option_results}->{sensor})) {
|
||||
$self->{output}->add_option_msg(short_msg => "No Sensors found for '" . $self->{option_results}->{sensor} . "'.");
|
||||
} else {
|
||||
$self->{output}->add_option_msg(short_msg => "No Sensors found.");
|
||||
};
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check LM-Sensors: Misc Sensors
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--warning>
|
||||
|
||||
Threshold warning
|
||||
|
||||
=item B<--critical>
|
||||
|
||||
Threshold critical
|
||||
|
||||
=item B<--sensor>
|
||||
|
||||
Set the Sensor Desc (number expected) ex: 1, 2,... (empty means 'check all sensors').
|
||||
|
||||
=item B<--name>
|
||||
|
||||
Allows to use Sensor Desc name with option --sensor instead of Sensor Desc oid index.
|
||||
|
||||
=item B<--regexp>
|
||||
|
||||
Allows to use regexp to filter sensordesc (with option --name).
|
||||
|
||||
=item B<--regexp-isensitive>
|
||||
|
||||
Allows to use regexp non case-sensitive (with --regexp).
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
@ -1,178 +0,0 @@
|
||||
#
|
||||
# Copyright 2019 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package apps::lmsensors::mode::temperature;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
my $oid_SensorDesc = '.1.3.6.1.4.1.2021.13.16.2.1.2'; # temperature entry description
|
||||
my $oid_SensorValue = '.1.3.6.1.4.1.2021.13.16.2.1.3'; # temperature entry value (RPM)
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"warning:s" => { name => 'warning' },
|
||||
"critical:s" => { name => 'critical' },
|
||||
"name" => { name => 'use_name' },
|
||||
"sensor:s" => { name => 'sensor' },
|
||||
"regexp" => { name => 'use_regexp' },
|
||||
"regexp-isensitive" => { name => 'use_regexpi' },
|
||||
});
|
||||
|
||||
$self->{Sensor_id_selected} = [];
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
$self->{snmp} = $options{snmp};
|
||||
$self->{hostname} = $self->{snmp}->get_hostname();
|
||||
$self->{snmp_port} = $self->{snmp}->get_port();
|
||||
|
||||
$self->manage_selection();
|
||||
|
||||
$self->{snmp}->load(oids => [$oid_SensorDesc, $oid_SensorValue], instances => $self->{Sensor_id_selected});
|
||||
my $SensorValueResult = $self->{snmp}->get_leef(nothing_quit => 1);
|
||||
|
||||
if (!defined($self->{option_results}->{sensor}) || defined($self->{option_results}->{use_regexp})) {
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => 'All Temperatures are ok.');
|
||||
}
|
||||
|
||||
foreach my $SensorId (sort @{$self->{Sensor_id_selected}}) {
|
||||
my $SensorDesc = $SensorValueResult->{$oid_SensorDesc . '.' . $SensorId};
|
||||
my $SensorValue = $SensorValueResult->{$oid_SensorValue . '.' . $SensorId} / 1000;
|
||||
|
||||
my $exit = $self->{perfdata}->threshold_check(value => $SensorValue, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
||||
|
||||
$self->{output}->output_add(long_msg => sprintf("Sensor '%s' Temperature: %s",
|
||||
$SensorDesc, $SensorValue));
|
||||
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1) || (defined($self->{option_results}->{sensor}) && !defined($self->{option_results}->{use_regexp}))) {
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => sprintf("Sensor '%s' Temperature: %s",
|
||||
$SensorDesc, $SensorValue));
|
||||
}
|
||||
|
||||
my $label = 'sensor_temperature';
|
||||
my $extra_label = '';
|
||||
$extra_label = '_' . $SensorId . "_" . $SensorDesc if (!defined($self->{option_results}->{sensor}) || defined($self->{option_results}->{use_regexp}));
|
||||
$self->{output}->perfdata_add(label => $label . $extra_label,
|
||||
value => $SensorValue,
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'));
|
||||
}
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
my $result = $self->{snmp}->get_table(oid => $oid_SensorDesc, nothing_quit => 1);
|
||||
|
||||
foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) {
|
||||
next if ($key !~ /\.([0-9]+)$/);
|
||||
my $SensorId = $1;
|
||||
my $SensorDesc = $result->{$key};
|
||||
|
||||
next if (defined($self->{option_results}->{sensor}) && !defined($self->{option_results}->{use_name}) && !defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
|
||||
&& $SensorId !~ /$self->{option_results}->{sensor}/i);
|
||||
next if (defined($self->{option_results}->{use_name}) && defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi})
|
||||
&& $SensorDesc !~ /$self->{option_results}->{sensor}/i);
|
||||
next if (defined($self->{option_results}->{use_name}) && defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
|
||||
&& $SensorDesc !~ /$self->{option_results}->{sensor}/);
|
||||
next if (defined($self->{option_results}->{use_name}) && !defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
|
||||
&& $SensorDesc ne $self->{option_results}->{sensor});
|
||||
|
||||
|
||||
push @{$self->{Sensor_id_selected}}, $SensorId;
|
||||
}
|
||||
|
||||
if (scalar(@{$self->{Sensor_id_selected}}) <= 0) {
|
||||
if (defined($self->{option_results}->{sensor})) {
|
||||
$self->{output}->add_option_msg(short_msg => "No Sensors found for '" . $self->{option_results}->{sensor} . "'.");
|
||||
} else {
|
||||
$self->{output}->add_option_msg(short_msg => "No Sensors found.");
|
||||
};
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check LM-Sensors: Temperature Sensors
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--warning>
|
||||
|
||||
Threshold warning
|
||||
|
||||
=item B<--critical>
|
||||
|
||||
Threshold critical
|
||||
|
||||
=item B<--sensor>
|
||||
|
||||
Set the Sensor Desc (number expected) ex: 1, 2,... (empty means 'check all sensors').
|
||||
|
||||
=item B<--name>
|
||||
|
||||
Allows to use Sensor Desc name with option --sensor instead of Sensor Desc oid index.
|
||||
|
||||
=item B<--regexp>
|
||||
|
||||
Allows to use regexp to filter sensordesc (with option --name).
|
||||
|
||||
=item B<--regexp-isensitive>
|
||||
|
||||
Allows to use regexp non case-sensitive (with --regexp).
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
@ -1,178 +0,0 @@
|
||||
#
|
||||
# Copyright 2019 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package apps::lmsensors::mode::voltage;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
my $oid_SensorDesc = '.1.3.6.1.4.1.2021.13.16.4.1.2'; # voltage entry description
|
||||
my $oid_SensorValue = '.1.3.6.1.4.1.2021.13.16.4.1.3'; # voltage entry value (mV)
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"warning:s" => { name => 'warning' },
|
||||
"critical:s" => { name => 'critical' },
|
||||
"name" => { name => 'use_name' },
|
||||
"sensor:s" => { name => 'sensor' },
|
||||
"regexp" => { name => 'use_regexp' },
|
||||
"regexp-isensitive" => { name => 'use_regexpi' },
|
||||
});
|
||||
|
||||
$self->{Sensor_id_selected} = [];
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
$self->{snmp} = $options{snmp};
|
||||
$self->{hostname} = $self->{snmp}->get_hostname();
|
||||
$self->{snmp_port} = $self->{snmp}->get_port();
|
||||
|
||||
$self->manage_selection();
|
||||
|
||||
$self->{snmp}->load(oids => [$oid_SensorDesc, $oid_SensorValue], instances => $self->{Sensor_id_selected});
|
||||
my $SensorValueResult = $self->{snmp}->get_leef(nothing_quit => 1);
|
||||
|
||||
if (!defined($self->{option_results}->{sensor}) || defined($self->{option_results}->{use_regexp})) {
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => 'All Voltages are ok.');
|
||||
}
|
||||
|
||||
foreach my $SensorId (sort @{$self->{Sensor_id_selected}}) {
|
||||
my $SensorDesc = $SensorValueResult->{$oid_SensorDesc . '.' . $SensorId};
|
||||
my $SensorValue = $SensorValueResult->{$oid_SensorValue . '.' . $SensorId} / 1000;
|
||||
|
||||
my $exit = $self->{perfdata}->threshold_check(value => $SensorValue, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
||||
|
||||
$self->{output}->output_add(long_msg => sprintf("Sensor '%s' Volt: %s",
|
||||
$SensorDesc, $SensorValue));
|
||||
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1) || (defined($self->{option_results}->{sensor}) && !defined($self->{option_results}->{use_regexp}))) {
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => sprintf("Sensor '%s' Volt: %s",
|
||||
$SensorDesc, $SensorValue));
|
||||
}
|
||||
|
||||
my $label = 'sensor_voltage';
|
||||
my $extra_label = '';
|
||||
$extra_label = '_' . $SensorId . "_" . $SensorDesc if (!defined($self->{option_results}->{sensor}) || defined($self->{option_results}->{use_regexp}));
|
||||
$self->{output}->perfdata_add(label => $label . $extra_label, unit => 'V',
|
||||
value => $SensorValue,
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'));
|
||||
}
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
my $result = $self->{snmp}->get_table(oid => $oid_SensorDesc, nothing_quit => 1);
|
||||
|
||||
foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) {
|
||||
next if ($key !~ /\.([0-9]+)$/);
|
||||
my $SensorId = $1;
|
||||
my $SensorDesc = $result->{$key};
|
||||
|
||||
next if (defined($self->{option_results}->{sensor}) && !defined($self->{option_results}->{use_name}) && !defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
|
||||
&& $SensorId !~ /$self->{option_results}->{sensor}/i);
|
||||
next if (defined($self->{option_results}->{use_name}) && defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi})
|
||||
&& $SensorDesc !~ /$self->{option_results}->{sensor}/i);
|
||||
next if (defined($self->{option_results}->{use_name}) && defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
|
||||
&& $SensorDesc !~ /$self->{option_results}->{sensor}/);
|
||||
next if (defined($self->{option_results}->{use_name}) && !defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
|
||||
&& $SensorDesc ne $self->{option_results}->{sensor});
|
||||
|
||||
|
||||
push @{$self->{Sensor_id_selected}}, $SensorId;
|
||||
}
|
||||
|
||||
if (scalar(@{$self->{Sensor_id_selected}}) <= 0) {
|
||||
if (defined($self->{option_results}->{sensor})) {
|
||||
$self->{output}->add_option_msg(short_msg => "No Sensors found for '" . $self->{option_results}->{sensor} . "'.");
|
||||
} else {
|
||||
$self->{output}->add_option_msg(short_msg => "No Sensors found.");
|
||||
};
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check LM-Sensors: Voltage Sensors
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--warning>
|
||||
|
||||
Threshold warning (Volt)
|
||||
|
||||
=item B<--critical>
|
||||
|
||||
Threshold critical (Volt)
|
||||
|
||||
=item B<--sensor>
|
||||
|
||||
Set the Sensor Desc (number expected) ex: 1, 2,... (empty means 'check all sensors').
|
||||
|
||||
=item B<--name>
|
||||
|
||||
Allows to use Sensor Desc name with option --sensor instead of Sensor Desc oid index.
|
||||
|
||||
=item B<--regexp>
|
||||
|
||||
Allows to use regexp to filter sensordesc (with option --name).
|
||||
|
||||
=item B<--regexp-isensitive>
|
||||
|
||||
Allows to use regexp non case-sensitive (with --regexp).
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
76
apps/lmsensors/snmp/mode/components/fan.pm
Normal file
76
apps/lmsensors/snmp/mode/components/fan.pm
Normal file
@ -0,0 +1,76 @@
|
||||
#
|
||||
# Copyright 2019 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package apps::lmsensors::snmp::mode::components::fan;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
my $mapping = {
|
||||
lmFanSensorsDevice => { oid => '.1.3.6.1.4.1.2021.13.16.3.1.2' },
|
||||
lmFanSensorsValue => { oid => '.1.3.6.1.4.1.2021.13.16.3.1.3' },
|
||||
};
|
||||
|
||||
my $oid_lmFanSensorsEntry = '.1.3.6.1.4.1.2021.13.16.3.1';
|
||||
|
||||
sub load {
|
||||
my ($self) = @_;
|
||||
|
||||
push @{$self->{request}}, { oid => $oid_lmFanSensorsEntry };
|
||||
}
|
||||
|
||||
sub check {
|
||||
my ($self) = @_;
|
||||
|
||||
$self->{output}->output_add(long_msg => "Checking fans");
|
||||
$self->{components}->{fan} = {name => 'fans', total => 0, skip => 0};
|
||||
return if ($self->check_filter(section => 'fan'));
|
||||
|
||||
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_lmFanSensorsEntry}})) {
|
||||
next if ($oid !~ /^$mapping->{lmFanSensorsValue}->{oid}\.(.*)$/);
|
||||
my $instance = $1;
|
||||
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_lmFanSensorsEntry}, instance => $instance);
|
||||
|
||||
next if ($self->check_filter(section => 'fan', instance => $instance, name => $result->{lmFanSensorsDevice}));
|
||||
$self->{components}->{fan}->{total}++;
|
||||
|
||||
$self->{output}->output_add(long_msg => sprintf("fan '%s' speed is %s rpm [instance = %s]",
|
||||
$result->{lmFanSensorsDevice}, $result->{lmFanSensorsValue}, $instance,
|
||||
));
|
||||
|
||||
my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'fan', instance => $instance, name => $result->{lmFanSensorsDevice}, value => $result->{lmFanSensorsValue});
|
||||
|
||||
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => sprintf("Fan '%s' speed is %s rpm", $result->{lmFanSensorsDevice}, $result->{lmFanSensorsValue}));
|
||||
}
|
||||
$self->{output}->perfdata_add(
|
||||
label => 'fan', unit => 'rpm',
|
||||
nlabel => 'sensor.fan.speed.rpm',
|
||||
instances => $result->{lmFanSensorsDevice},
|
||||
value => $result->{lmFanSensorsValue},
|
||||
warning => $warn,
|
||||
critical => $crit,
|
||||
min => 0,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
76
apps/lmsensors/snmp/mode/components/misc.pm
Normal file
76
apps/lmsensors/snmp/mode/components/misc.pm
Normal file
@ -0,0 +1,76 @@
|
||||
#
|
||||
# Copyright 2019 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package apps::lmsensors::snmp::mode::components::misc;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
my $mapping = {
|
||||
lmMiscSensorsDevice => { oid => '.1.3.6.1.4.1.2021.13.16.5.1.2' },
|
||||
lmMiscSensorsValue => { oid => '.1.3.6.1.4.1.2021.13.16.5.1.3' },
|
||||
};
|
||||
|
||||
my $oid_lmMiscSensorsEntry = '.1.3.6.1.4.1.2021.13.16.5.1';
|
||||
|
||||
sub load {
|
||||
my ($self) = @_;
|
||||
|
||||
push @{$self->{request}}, { oid => $oid_lmMiscSensorsEntry };
|
||||
}
|
||||
|
||||
sub check {
|
||||
my ($self) = @_;
|
||||
|
||||
$self->{output}->output_add(long_msg => "Checking misc");
|
||||
$self->{components}->{misc} = {name => 'misc', total => 0, skip => 0};
|
||||
return if ($self->check_filter(section => 'misc'));
|
||||
|
||||
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_lmMiscSensorsEntry}})) {
|
||||
next if ($oid !~ /^$mapping->{lmMiscSensorsValue}->{oid}\.(.*)$/);
|
||||
my $instance = $1;
|
||||
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_lmMiscSensorsEntry}, instance => $instance);
|
||||
|
||||
next if ($self->check_filter(section => 'misc', instance => $instance, name => $result->{lmMiscSensorsDevice}));
|
||||
$self->{components}->{misc}->{total}++;
|
||||
|
||||
$self->{output}->output_add(long_msg => sprintf("misc '%s' values is %s [instance = %s]",
|
||||
$result->{lmMiscSensorsDevice}, $result->{lmMiscSensorsValue}, $instance,
|
||||
));
|
||||
|
||||
my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'misc', instance => $instance, name => $result->{lmMiscSensorsDevice}, value => $result->{lmMiscSensorsValue});
|
||||
|
||||
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => sprintf("Misc '%s' value is %s", $result->{lmMiscSensorsDevice}, $result->{lmMiscSensorsValue}));
|
||||
}
|
||||
$self->{output}->perfdata_add(
|
||||
label => 'misc',,
|
||||
nlabel => 'sensor.misc.current',
|
||||
instances => $result->{lmMiscSensorsDevice},
|
||||
value => $result->{lmMiscSensorsValue},
|
||||
warning => $warn,
|
||||
critical => $crit,
|
||||
min => 0,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
76
apps/lmsensors/snmp/mode/components/temperature.pm
Normal file
76
apps/lmsensors/snmp/mode/components/temperature.pm
Normal file
@ -0,0 +1,76 @@
|
||||
#
|
||||
# Copyright 2019 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package apps::lmsensors::snmp::mode::components::temperature;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
my $mapping = {
|
||||
lmTempSensorsDevice => { oid => '.1.3.6.1.4.1.2021.13.16.2.1.2' },
|
||||
lmTempSensorsValue => { oid => '.1.3.6.1.4.1.2021.13.16.2.1.3' },
|
||||
};
|
||||
|
||||
my $oid_lmTempSensorsEntry = '.1.3.6.1.4.1.2021.13.16.2.1';
|
||||
|
||||
sub load {
|
||||
my ($self) = @_;
|
||||
|
||||
push @{$self->{request}}, { oid => $oid_lmTempSensorsEntry };
|
||||
}
|
||||
|
||||
sub check {
|
||||
my ($self) = @_;
|
||||
|
||||
$self->{output}->output_add(long_msg => "Checking temperatures");
|
||||
$self->{components}->{temperature} = {name => 'temperatures', total => 0, skip => 0};
|
||||
return if ($self->check_filter(section => 'temperature'));
|
||||
|
||||
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_lmTempSensorsEntry}})) {
|
||||
next if ($oid !~ /^$mapping->{lmTempSensorsValue}->{oid}\.(.*)$/);
|
||||
my $instance = $1;
|
||||
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_lmTempSensorsEntry}, instance => $instance);
|
||||
|
||||
next if ($self->check_filter(section => 'temperature', instance => $instance, name => $result->{lmTempSensorsDevice}));
|
||||
$self->{components}->{temperature}->{total}++;
|
||||
|
||||
$result->{lmTempSensorsValue} /= 1000;
|
||||
$self->{output}->output_add(long_msg => sprintf("temperature '%s' is %s C [instance = %s]",
|
||||
$result->{lmTempSensorsDevice}, $result->{lmTempSensorsValue}, $instance,
|
||||
));
|
||||
|
||||
my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, name => $result->{lmTempSensorsDevice}, value => $result->{lmTempSensorsValue});
|
||||
|
||||
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => sprintf("Temperature '%s' is %s C", $result->{lmTempSensorsDevice}, $result->{lmTempSensorsValue}));
|
||||
}
|
||||
$self->{output}->perfdata_add(
|
||||
label => 'temperature', unit => 'C',
|
||||
nlabel => 'sensor.temperature.celsius',
|
||||
instances => $result->{lmTempSensorsDevice},
|
||||
value => $result->{lmTempSensorsValue},
|
||||
warning => $warn,
|
||||
critical => $crit,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
76
apps/lmsensors/snmp/mode/components/voltage.pm
Normal file
76
apps/lmsensors/snmp/mode/components/voltage.pm
Normal file
@ -0,0 +1,76 @@
|
||||
#
|
||||
# Copyright 2019 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package apps::lmsensors::snmp::mode::components::voltage;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
my $mapping = {
|
||||
lmVoltSensorsDevice => { oid => '.1.3.6.1.4.1.2021.13.16.4.1.2' },
|
||||
lmVoltSensorsValue => { oid => '.1.3.6.1.4.1.2021.13.16.4.1.3' },
|
||||
};
|
||||
|
||||
my $oid_lmVoltSensorsEntry = '.1.3.6.1.4.1.2021.13.16.4.1';
|
||||
|
||||
sub load {
|
||||
my ($self) = @_;
|
||||
|
||||
push @{$self->{request}}, { oid => $oid_lmVoltSensorsEntry };
|
||||
}
|
||||
|
||||
sub check {
|
||||
my ($self) = @_;
|
||||
|
||||
$self->{output}->output_add(long_msg => "Checking voltages");
|
||||
$self->{components}->{voltage} = {name => 'voltages', total => 0, skip => 0};
|
||||
return if ($self->check_filter(section => 'voltage'));
|
||||
|
||||
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_lmVoltSensorsEntry}})) {
|
||||
next if ($oid !~ /^$mapping->{lmVoltSensorsValue}->{oid}\.(.*)$/);
|
||||
my $instance = $1;
|
||||
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_lmVoltSensorsEntry}, instance => $instance);
|
||||
|
||||
next if ($self->check_filter(section => 'voltage', instance => $instance, name => $result->{lmVoltSensorsDevice}));
|
||||
$self->{components}->{voltage}->{total}++;
|
||||
|
||||
$result->{lmVoltSensorsValue} /= 1000;
|
||||
$self->{output}->output_add(long_msg => sprintf("voltage '%s' is %s V [instance = %s]",
|
||||
$result->{lmVoltSensorsDevice}, $result->{lmVoltSensorsValue}, $instance,
|
||||
));
|
||||
|
||||
my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'voltage', instance => $instance, name => $result->{lmVoltSensorsDevice}, value => $result->{lmVoltSensorsValue});
|
||||
|
||||
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => sprintf("Voltage '%s' is %s V", $result->{lmVoltSensorsDevice}, $result->{lmVoltSensorsValue}));
|
||||
}
|
||||
$self->{output}->perfdata_add(
|
||||
label => 'voltage', unit => 'V',
|
||||
nlabel => 'sensor.voltage.volt',
|
||||
instances => $result->{lmVoltSensorsDevice},
|
||||
value => $result->{lmVoltSensorsValue},
|
||||
warning => $warn,
|
||||
critical => $crit,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
101
apps/lmsensors/snmp/mode/sensors.pm
Normal file
101
apps/lmsensors/snmp/mode/sensors.pm
Normal file
@ -0,0 +1,101 @@
|
||||
#
|
||||
# Copyright 2019 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package apps::lmsensors::snmp::mode::sensors;
|
||||
|
||||
use base qw(centreon::plugins::templates::hardware);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
sub set_system {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{regexp_threshold_overload_check_section_option} = '^(temperature|fan|voltage|misc)$';
|
||||
$self->{regexp_threshold_numeric_check_section_option} = '^(temperature|fan|voltage|misc)$';
|
||||
|
||||
$self->{cb_hook1} = 'get_version'; # before the loads
|
||||
$self->{cb_hook2} = 'snmp_execute';
|
||||
|
||||
$self->{thresholds} = {
|
||||
};
|
||||
|
||||
$self->{components_path} = 'apps::lmsensors::snmp::mode::components';
|
||||
$self->{components_module} = ['fan', 'temperature', 'voltage', 'misc'];
|
||||
}
|
||||
|
||||
sub snmp_execute {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{snmp} = $options{snmp};
|
||||
$self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request});
|
||||
}
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, force_new_perfdata => 1);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments => {
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check components.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--component>
|
||||
|
||||
Which component to check (Default: '.*').
|
||||
Can be: 'fan', 'voltage', 'temperature', 'misc'.
|
||||
|
||||
=item B<--filter>
|
||||
|
||||
Exclude some parts (comma seperated list) (Example: --filter=fan --filter=power)
|
||||
Can also exclude specific instance: --filter=power,3.3
|
||||
|
||||
=item B<--no-component>
|
||||
|
||||
Return an error if no compenents are checked.
|
||||
If total (with skipped) is 0. (Default: 'critical' returns).
|
||||
|
||||
=item B<--warning>
|
||||
|
||||
Set warning threshold (syntax: type,instance,threshold)
|
||||
Example: --warning='temperature,.*,20'
|
||||
|
||||
=item B<--critical>
|
||||
|
||||
Set critical threshold (syntax: type,instance,threshold)
|
||||
Example: --critical='temperature,1,25'
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
@ -18,7 +18,7 @@
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package apps::lmsensors::plugin;
|
||||
package apps::lmsensors::snmp::plugin;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
@ -31,10 +31,7 @@ sub new {
|
||||
|
||||
$self->{version} = '0.1';
|
||||
%{$self->{modes}} = (
|
||||
'temperature' => 'apps::lmsensors::mode::temperature',
|
||||
'fan' => 'apps::lmsensors::mode::fan',
|
||||
'voltage' => 'apps::lmsensors::mode::voltage',
|
||||
'misc' => 'apps::lmsensors::mode::misc',
|
||||
'sensors' => 'apps::lmsensors::snmp::mode::sensors',
|
||||
);
|
||||
|
||||
return $self;
|
||||
@ -46,6 +43,6 @@ __END__
|
||||
|
||||
=head1 PLUGIN DESCRIPTION
|
||||
|
||||
Check with SNMP LM-Sensors Status
|
||||
Check with SNMP LM-Sensors
|
||||
|
||||
=cut
|
@ -39,8 +39,7 @@ sub new {
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
$options{options}->add_options(arguments => {
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"port:s" => { name => 'port', },
|
||||
"proto:s" => { name => 'proto' },
|
||||
@ -49,9 +48,7 @@ sub new {
|
||||
"basic" => { name => 'basic' },
|
||||
"username:s" => { name => 'username' },
|
||||
"password:s" => { name => 'password' },
|
||||
"proxyurl:s" => { name => 'proxyurl' },
|
||||
"timeout:s" => { name => 'timeout' },
|
||||
"ssl-opt:s@" => { name => 'ssl_opt' },
|
||||
});
|
||||
foreach (@{$maps}) {
|
||||
$options{options}->add_options(arguments => {
|
||||
@ -60,7 +57,7 @@ sub new {
|
||||
});
|
||||
}
|
||||
|
||||
$self->{http} = centreon::plugins::http->new(output => $self->{output});
|
||||
$self->{http} = centreon::plugins::http->new(%options);
|
||||
return $self;
|
||||
}
|
||||
|
||||
@ -127,10 +124,6 @@ IP Addr/FQDN of the webserver host
|
||||
|
||||
Port used by Apache
|
||||
|
||||
=item B<--proxyurl>
|
||||
|
||||
Proxy URL if any
|
||||
|
||||
=item B<--proto>
|
||||
|
||||
Protocol to use http or https, http is default
|
||||
@ -163,10 +156,6 @@ Specify this option if you access server-status page over hidden basic authentic
|
||||
|
||||
Threshold for HTTP timeout
|
||||
|
||||
=item B<--ssl-opt>
|
||||
|
||||
Set SSL Options (--ssl-opt="SSL_version => TLSv1" --ssl-opt="SSL_verify_mode => SSL_VERIFY_NONE").
|
||||
|
||||
=item B<--warning-*>
|
||||
|
||||
Warning Threshold. Can be: 'active', 'waiting', 'writing', 'reading'.
|
||||
|
@ -39,8 +39,7 @@ sub new {
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
$options{options}->add_options(arguments => {
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"port:s" => { name => 'port', },
|
||||
"proto:s" => { name => 'proto' },
|
||||
@ -49,9 +48,7 @@ sub new {
|
||||
"basic" => { name => 'basic' },
|
||||
"username:s" => { name => 'username' },
|
||||
"password:s" => { name => 'password' },
|
||||
"proxyurl:s" => { name => 'proxyurl' },
|
||||
"timeout:s" => { name => 'timeout' },
|
||||
"ssl-opt:s@" => { name => 'ssl_opt' },
|
||||
});
|
||||
foreach (@{$maps}) {
|
||||
$options{options}->add_options(arguments => {
|
||||
@ -60,7 +57,7 @@ sub new {
|
||||
});
|
||||
}
|
||||
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
|
||||
$self->{http} = centreon::plugins::http->new(output => $self->{output});
|
||||
$self->{http} = centreon::plugins::http->new(%options);
|
||||
return $self;
|
||||
}
|
||||
|
||||
@ -175,10 +172,6 @@ IP Addr/FQDN of the webserver host
|
||||
|
||||
Port used by Apache
|
||||
|
||||
=item B<--proxyurl>
|
||||
|
||||
Proxy URL if any
|
||||
|
||||
=item B<--proto>
|
||||
|
||||
Specify https if needed
|
||||
@ -211,10 +204,6 @@ Specify this option if you access server-status page over hidden basic authentic
|
||||
|
||||
Threshold for HTTP timeout
|
||||
|
||||
=item B<--ssl-opt>
|
||||
|
||||
Set SSL Options (--ssl-opt="SSL_version => TLSv1" --ssl-opt="SSL_verify_mode => SSL_VERIFY_NONE").
|
||||
|
||||
=item B<--warning-*>
|
||||
|
||||
Warning Threshold. Can be: 'accepts', 'handled', 'requests'.
|
||||
|
@ -33,8 +33,7 @@ sub new {
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
$options{options}->add_options(arguments => {
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"port:s" => { name => 'port', },
|
||||
"proto:s" => { name => 'proto' },
|
||||
@ -43,16 +42,14 @@ sub new {
|
||||
"basic" => { name => 'basic' },
|
||||
"username:s" => { name => 'username' },
|
||||
"password:s" => { name => 'password' },
|
||||
"proxyurl:s" => { name => 'proxyurl' },
|
||||
"warning:s" => { name => 'warning' },
|
||||
"critical:s" => { name => 'critical' },
|
||||
"timeout:s" => { name => 'timeout' },
|
||||
"ssl-opt:s@" => { name => 'ssl_opt' },
|
||||
"unknown-status:s" => { name => 'unknown_status', default => '' },
|
||||
"warning-status:s" => { name => 'warning_status' },
|
||||
"critical-status:s" => { name => 'critical_status', default => '%{http_code} < 200 or %{http_code} >= 300' },
|
||||
});
|
||||
$self->{http} = centreon::plugins::http->new(output => $self->{output});
|
||||
$self->{http} = centreon::plugins::http->new(%options);
|
||||
return $self;
|
||||
}
|
||||
|
||||
@ -140,18 +137,10 @@ Specify this option if you access server-status page over hidden basic authentic
|
||||
|
||||
(Use with --credentials)
|
||||
|
||||
=item B<--proxyurl>
|
||||
|
||||
Proxy URL if any
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Threshold for HTTP timeout
|
||||
|
||||
=item B<--ssl-opt>
|
||||
|
||||
Set SSL Options (--ssl-opt="SSL_version => TLSv1" --ssl-opt="SSL_verify_mode => SSL_VERIFY_NONE").
|
||||
|
||||
=item B<--unknown-status>
|
||||
|
||||
Threshold warning for http response code
|
||||
|
@ -34,10 +34,8 @@ sub new {
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.1';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
$options{options}->add_options(arguments => {
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"http-peer-addr:s" => { name => 'http_peer_addr' },
|
||||
"port:s" => { name => 'port', default => 8443 },
|
||||
"proto:s" => { name => 'proto', default => 'https' },
|
||||
"credentials" => { name => 'credentials' },
|
||||
@ -45,11 +43,7 @@ sub new {
|
||||
"username:s" => { name => 'username' },
|
||||
"password:s" => { name => 'password' },
|
||||
"legacy-password:s" => { name => 'legacy_password' },
|
||||
"proxyurl:s" => { name => 'proxyurl' },
|
||||
"proxypac:s" => { name => 'proxypac' },
|
||||
"timeout:s" => { name => 'timeout' },
|
||||
"ssl-opt:s@" => { name => 'ssl_opt' },
|
||||
"ssl:s" => { name => 'ssl' },
|
||||
"command:s" => { name => 'command' },
|
||||
"arg:s@" => { name => 'arg' },
|
||||
"unknown-status:s" => { name => 'unknown_status', default => '%{http_code} < 200 or %{http_code} >= 300' },
|
||||
@ -57,7 +51,7 @@ sub new {
|
||||
"critical-status:s" => { name => 'critical_status', default => '' },
|
||||
});
|
||||
|
||||
$self->{http} = centreon::plugins::http->new(output => $self->{output});
|
||||
$self->{http} = centreon::plugins::http->new(%options);
|
||||
return $self;
|
||||
}
|
||||
|
||||
@ -180,10 +174,6 @@ Query NSClient Rest API.
|
||||
|
||||
IP Addr/FQDN of the host
|
||||
|
||||
=item B<--http-peer-addr>
|
||||
|
||||
Set the address you want to connect (Useful if hostname is only a vhost. no ip resolve)
|
||||
|
||||
=item B<--port>
|
||||
|
||||
Port used (Default: 8443)
|
||||
@ -216,22 +206,10 @@ Specify this option if you access webpage over hidden basic authentication or yo
|
||||
|
||||
Specify password for old authentification system.
|
||||
|
||||
=item B<--proxyurl>
|
||||
|
||||
Proxy URL
|
||||
|
||||
=item B<--proxypac>
|
||||
|
||||
Proxy pac file (can be an url or local file)
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Threshold for HTTP timeout (Default: 5)
|
||||
|
||||
=item B<--ssl-opt>
|
||||
|
||||
Set SSL Options (--ssl-opt="SSL_version => TLSv1" --ssl-opt="SSL_verify_mode => SSL_VERIFY_NONE").
|
||||
|
||||
=item B<--command>
|
||||
|
||||
Set command.
|
||||
|
270
apps/openldap/ldap/mode/systemusage.pm
Normal file
270
apps/openldap/ldap/mode/systemusage.pm
Normal file
@ -0,0 +1,270 @@
|
||||
#
|
||||
# Copyright 2019 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package apps::openldap::ldap::mode::systemusage;
|
||||
|
||||
use base qw(centreon::plugins::templates::counter);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Digest::MD5 qw(md5_hex);
|
||||
use centreon::common::protocols::ldap::lib::ldap;
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'global', type => 0, message_separator => ' - ', skipped_code => { -10 => 1 } },
|
||||
{ name => 'operation', type => 0, cb_prefix_output => 'prefix_operation_output', skipped_code => { -10 => 1 } },
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{operation} = [];
|
||||
foreach ('search', 'add', 'bind', 'unbind', 'delete') {
|
||||
push @{$self->{maps_counters}->{operation}},
|
||||
{ label => 'op-' . $_, nlabel => 'system.operations.' . $_ . '.completed.count', set => {
|
||||
key_values => [ { name => 'operations_completed_' . $_, diff => 1 } ],
|
||||
output_template => $_ . ' %s',
|
||||
perfdatas => [
|
||||
{ label => 'operations_' . $_, value => 'operations_completed_' . $_ . '_absolute', template => '%.2f',
|
||||
min => 0 },
|
||||
],
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
$self->{maps_counters}->{global} = [
|
||||
{ label => 'con-current', nlabel => 'system.connections.current.count', set => {
|
||||
key_values => [ { name => 'connections_current' } ],
|
||||
output_template => 'Current connections %s',
|
||||
perfdatas => [
|
||||
{ label => 'connections_current', value => 'connections_current_absolute', template => '%s',
|
||||
min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'con-total', nlabel => 'system.connections.total.count', set => {
|
||||
key_values => [ { name => 'connections_total', diff => 1 } ],
|
||||
output_template => 'Total connections %s',
|
||||
perfdatas => [
|
||||
{ label => 'connections_total', value => 'connections_total_absolute', template => '%s',
|
||||
min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'threads-active', nlabel => 'system.threads.active.percentage', set => {
|
||||
key_values => [ { name => 'threads_active_prct' } ],
|
||||
output_template => 'Current active threads %.2f %%',
|
||||
perfdatas => [
|
||||
{ label => 'threads_active', value => 'threads_active_prct_absolute', template => '%.2f',
|
||||
min => 0, max => 100, unit => '%' },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'traffic', nlabel => 'system.traffic.bytespersecond', set => {
|
||||
key_values => [ { name => 'traffic', diff => 1 } ],
|
||||
output_change_bytes => 1, per_second => 1,
|
||||
output_template => 'traffic %s %s/s',
|
||||
perfdatas => [
|
||||
{ label => 'traffic', value => 'traffic_per_second', template => '%s',
|
||||
min => 0, unit => 'B/s', cast_int => 1 },
|
||||
],
|
||||
}
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
sub prefix_operation_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return 'Operation completed ';
|
||||
}
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments => {
|
||||
'hostname:s' => { name => 'hostname' },
|
||||
'search-base:s' => { name => 'search_base', default => 'cn=monitor' },
|
||||
'ldap-connect-options:s@' => { name => 'ldap_connect_options' },
|
||||
'ldap-starttls-options:s@' => { name => 'ldap_starttls_options' },
|
||||
'ldap-bind-options:s@' => { name => 'ldap_bind_options' },
|
||||
'tls' => { name => 'use_tls' },
|
||||
'username:s' => { name => 'username' },
|
||||
'password:s' => { name => 'password' },
|
||||
'timeout:s' => { name => 'timeout', default => '30' },
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::check_options(%options);
|
||||
|
||||
if (!defined($self->{option_results}->{hostname})) {
|
||||
$self->{output}->add_option_msg(short_msg => 'Please set the hostname option');
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (defined($self->{option_results}->{username}) && $self->{option_results}->{username} ne '' &&
|
||||
!defined($self->{option_results}->{password})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set --password option.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
}
|
||||
|
||||
sub ldap_error {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if ($options{code} == 1) {
|
||||
$self->{output}->output_add(
|
||||
severity => 'unknown',
|
||||
short_msg => $options{err_msg}
|
||||
);
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
}
|
||||
|
||||
sub search_monitor {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my ($ldap_handle, $code, $err_msg) = centreon::common::protocols::ldap::lib::ldap::connect(
|
||||
hostname => $self->{option_results}->{hostname},
|
||||
username => $self->{option_results}->{username},
|
||||
password => $self->{option_results}->{password},
|
||||
timeout => $self->{option_results}->{timeout},
|
||||
ldap_connect_options => $self->{option_results}->{ldap_connect_options},
|
||||
use_tls => $self->{option_results}->{use_tls},
|
||||
ldap_starttls_options => $self->{option_results}->{ldap_starttls_options},
|
||||
ldap_bind_options => $self->{option_results}->{ldap_bind_options},
|
||||
);
|
||||
$self->ldap_error(code => $code, err_msg => $err_msg);
|
||||
(my $search_result, $code, $err_msg) = centreon::common::protocols::ldap::lib::ldap::search(
|
||||
ldap_handle => $ldap_handle,
|
||||
search_base => $self->{option_results}->{search_base},
|
||||
search_filter => '(objectclass=*)',
|
||||
ldap_search_options => ['attrs=monitoredInfo', 'attrs=monitorCounter', 'attrs=MonitorOpCompleted'],
|
||||
);
|
||||
$self->ldap_error(code => $code, err_msg => $err_msg);
|
||||
centreon::common::protocols::ldap::lib::ldap::quit(ldap_handle => $ldap_handle);
|
||||
|
||||
return $search_result;
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{operation} = {};
|
||||
$self->{global} = {};
|
||||
my $search_result = $self->search_monitor();
|
||||
foreach my $entry ($search_result->entries()) {
|
||||
my $dn = $entry->dn();
|
||||
if ($dn =~ /cn=(Current|Total),cn=Connections/i) {
|
||||
$self->{global}->{'connections_' . lc($1)} = $entry->get_value('monitorCounter');
|
||||
} elsif ($dn =~ /cn=(.*?),cn=Operations/i) {
|
||||
$self->{operation}->{'operations_completed_' . lc($1)} = $entry->get_value('MonitorOpCompleted');
|
||||
} elsif ($dn =~ /cn=(Max|Active),cn=Threads/i) {
|
||||
$self->{global}->{'threads_' . lc($1)} = $entry->get_value('monitoredInfo');
|
||||
} elsif ($dn =~ /cn=Bytes,cn=Statistics/i) {
|
||||
$self->{global}->{traffic} = $entry->get_value('monitorCounter');
|
||||
}
|
||||
}
|
||||
|
||||
$self->{global}->{threads_active_prct} = $self->{global}->{threads_active} * 100 / $self->{global}->{threads_max};
|
||||
|
||||
$self->{cache_name} = "openldap_" . $self->{mode} . '_' . $self->{option_results}->{hostname} . '_' .
|
||||
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check system usage (connections, threads, requests).
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--hostname>
|
||||
|
||||
IP Addr/FQDN of the openldap host (required).
|
||||
|
||||
=item B<--search-base>
|
||||
|
||||
Set the DN that is the base object entry relative to the backend monitor (Default: cn=monitor).
|
||||
|
||||
=item B<--ldap-connect-options>
|
||||
|
||||
Add custom ldap connect options:
|
||||
|
||||
=over 16
|
||||
|
||||
=item B<Set SSL connection>
|
||||
|
||||
--ldap-connect-options='scheme=ldaps'
|
||||
|
||||
=item B<Set LDAP version 2>
|
||||
|
||||
--ldap-connect-options='version=2'
|
||||
|
||||
=back
|
||||
|
||||
=item B<--ldap-starttls-options>
|
||||
|
||||
Add custom start tls options (need --tls option):
|
||||
|
||||
=over 16
|
||||
|
||||
=item B<An example>
|
||||
|
||||
--ldap-starttls-options='verify=none'
|
||||
|
||||
=back
|
||||
|
||||
=item B<--ldap-bind-options>
|
||||
|
||||
Add custom bind options (can force noauth) (not really useful now).
|
||||
|
||||
=item B<--username>
|
||||
|
||||
Specify username for authentification (can be a DN)
|
||||
|
||||
=item B<--password>
|
||||
|
||||
Specify password for authentification
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Connection timeout in seconds (Default: 30)
|
||||
|
||||
=item B<--warning-*> B<--critical-*>
|
||||
|
||||
Thresholds.
|
||||
Can be: 'con-current', 'con-total', 'threads-active', 'traffic',
|
||||
'op-add', 'op-search', 'op-bind', 'op-unbind', 'op-delete'.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
@ -18,7 +18,7 @@
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package storage::hp::3par::7000::plugin;
|
||||
package apps::openldap::ldap::plugin;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
@ -29,18 +29,9 @@ sub new {
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$self->{version} = '0.1';
|
||||
%{$self->{modes}} = (
|
||||
'physicaldisk' => 'storage::hp::3par::7000::mode::physicaldisk',
|
||||
'psu' => 'storage::hp::3par::7000::mode::psu',
|
||||
'node' => 'storage::hp::3par::7000::mode::node',
|
||||
'battery' => 'storage::hp::3par::7000::mode::battery',
|
||||
'wsapi' => 'storage::hp::3par::7000::mode::wsapi',
|
||||
'cim' => 'storage::hp::3par::7000::mode::cim',
|
||||
'temperature' => 'storage::hp::3par::7000::mode::temperature',
|
||||
'storage' => 'storage::hp::3par::7000::mode::storage',
|
||||
'iscsi' => 'storage::hp::3par::7000::mode::iscsi',
|
||||
'volume' => 'storage::hp::3par::7000::mode::volume',
|
||||
'system-usage' => 'apps::openldap::ldap::mode::systemusage',
|
||||
);
|
||||
|
||||
return $self;
|
||||
@ -52,6 +43,6 @@ __END__
|
||||
|
||||
=head1 PLUGIN DESCRIPTION
|
||||
|
||||
Check HP 3par 7000 series in SSH.
|
||||
Check OpenLDAP through the monitor backend.
|
||||
|
||||
=cut
|
201
apps/openweathermap/restapi/custom/api.pm
Normal file
201
apps/openweathermap/restapi/custom/api.pm
Normal file
@ -0,0 +1,201 @@
|
||||
#
|
||||
# Copyright 2019 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package apps::openweathermap::restapi::custom::api;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::http;
|
||||
use JSON::XS;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = {};
|
||||
bless $self, $class;
|
||||
|
||||
if (!defined($options{output})) {
|
||||
print "Class Custom: Need to specify 'output' argument.\n";
|
||||
exit 3;
|
||||
}
|
||||
if (!defined($options{options})) {
|
||||
$options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument.");
|
||||
$options{output}->option_exit();
|
||||
}
|
||||
|
||||
if (!defined($options{noptions})) {
|
||||
$options{options}->add_options(arguments => {
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"url-path:s" => { name => 'url_path' },
|
||||
"port:s" => { name => 'port' },
|
||||
"proto:s" => { name => 'proto' },
|
||||
"api-token:s" => { name => 'api_token' },
|
||||
"timeout:s" => { name => 'timeout' },
|
||||
});
|
||||
}
|
||||
$options{options}->add_help(package => __PACKAGE__, sections => 'REST API OPTIONS', once => 1);
|
||||
|
||||
$self->{output} = $options{output};
|
||||
$self->{mode} = $options{mode};
|
||||
$self->{http} = centreon::plugins::http->new(%options);
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub set_options {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{option_results} = $options{option_results};
|
||||
}
|
||||
|
||||
sub set_defaults {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
foreach (keys %{$options{default}}) {
|
||||
if ($_ eq $self->{mode}) {
|
||||
for (my $i = 0; $i < scalar(@{$options{default}->{$_}}); $i++) {
|
||||
foreach my $opt (keys %{$options{default}->{$_}[$i]}) {
|
||||
if (!defined($self->{option_results}->{$opt}[$i])) {
|
||||
$self->{option_results}->{$opt}[$i] = $options{default}->{$_}[$i]->{$opt};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{hostname} = (defined($self->{option_results}->{hostname})) ? $self->{option_results}->{hostname} : 'api.openweathermap.org';
|
||||
$self->{port} = (defined($self->{option_results}->{port})) ? $self->{option_results}->{port} : 443;
|
||||
$self->{proto} = (defined($self->{option_results}->{proto})) ? $self->{option_results}->{proto} : 'https';
|
||||
$self->{url_path} = (defined($self->{option_results}->{url_path})) ? $self->{option_results}->{url_path} : '/data/2.5';
|
||||
$self->{timeout} = (defined($self->{option_results}->{timeout})) ? $self->{option_results}->{timeout} : 10;
|
||||
$self->{api_token} = (defined($self->{option_results}->{api_token})) ? $self->{option_results}->{api_token} : '';
|
||||
|
||||
if (!defined($self->{api_token}) || $self->{api_token} eq '') {
|
||||
$self->{output}->add_option_msg(short_msg => "Need to specify --api-token option.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub build_options_for_httplib {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{option_results}->{hostname} = $self->{hostname};
|
||||
$self->{option_results}->{timeout} = $self->{timeout};
|
||||
$self->{option_results}->{port} = $self->{port};
|
||||
$self->{option_results}->{proto} = $self->{proto};
|
||||
$self->{option_results}->{url_path} = $self->{url_path};
|
||||
$self->{option_results}->{warning_status} = '';
|
||||
$self->{option_results}->{critical_status} = '';
|
||||
}
|
||||
|
||||
sub settings {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->build_options_for_httplib();
|
||||
$self->{http}->add_header(key => 'Accept', value => 'application/json');
|
||||
|
||||
$self->{http}->set_options(%{$self->{option_results}});
|
||||
}
|
||||
|
||||
sub set_token {
|
||||
my ($self, %options) = @_;
|
||||
push @{$self->{get_param}}, 'APPID=' . $self->{api_token};
|
||||
}
|
||||
|
||||
sub request_api {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->set_token();
|
||||
$self->settings;
|
||||
|
||||
foreach my $get_param (@{$options{get_param}}) {
|
||||
push @{$self->{get_param}}, $get_param;
|
||||
}
|
||||
my $content = $self->{http}->request(
|
||||
url_path => $self->{url_path} . $options{url_path},
|
||||
get_param => \@{$self->{get_param}}
|
||||
);
|
||||
|
||||
my $decoded;
|
||||
eval {
|
||||
$decoded = JSON::XS->new->utf8->decode($content);
|
||||
};
|
||||
if ($@) {
|
||||
$self->{output}->add_option_msg(short_msg => "Cannot decode json response: $@");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (!defined($decoded->{code}) || $decoded->{code} != 200) {
|
||||
$self->{output}->output_add(long_msg => "Error message : " . $decoded->{errorDetails}, debug => 1);
|
||||
$self->{output}->add_option_msg(short_msg => "API return error code '" . $decoded->{result} . "' (add --debug option for detailed message)");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
return $decoded;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 NAME
|
||||
|
||||
OpenWeatherMap Rest API
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
OpenWeatherMap Rest API custom mode
|
||||
|
||||
=head1 REST API OPTIONS
|
||||
|
||||
OpenWeatherMap Rest API
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--hostname>
|
||||
|
||||
OpenWeatherMap API hostname (Default: 'api.openweathermap.org')
|
||||
|
||||
=item B<--port>
|
||||
|
||||
API port (Default: 443)
|
||||
|
||||
=item B<--proto>
|
||||
|
||||
Specify https if needed (Default: 'https')
|
||||
|
||||
=item B<--url-path>
|
||||
|
||||
API URL path (Default: '/data/2.5')
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Set HTTP timeout
|
||||
|
||||
=back
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
B<custom>.
|
||||
|
||||
=cut
|
189
apps/openweathermap/restapi/mode/cityweather.pm
Normal file
189
apps/openweathermap/restapi/mode/cityweather.pm
Normal file
@ -0,0 +1,189 @@
|
||||
#
|
||||
# Copyright 2019 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package apps::openweathermap::restapi::mode::cityweather;
|
||||
|
||||
use base qw(centreon::plugins::templates::counter);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold);
|
||||
|
||||
sub custom_status_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return sprintf("Weather: '%s'", $self->{result_values}->{weather});
|
||||
}
|
||||
|
||||
sub custom_status_calc {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{result_values}->{weather} = $options{new_datas}->{$self->{instance} . '_weather'};
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'city', type => 0, cb_prefix_output => 'prefix_city_output' }
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{city} = [
|
||||
{ label => 'weather', set => {
|
||||
key_values => [ { name => 'weather' } ],
|
||||
closure_custom_calc => $self->can('custom_status_calc'),
|
||||
closure_custom_output => $self->can('custom_status_output'),
|
||||
closure_custom_perfdata => sub { return 0; },
|
||||
closure_custom_threshold_check => \&catalog_status_threshold,
|
||||
}
|
||||
},
|
||||
{ label => 'temperature', nlabel => 'temperature.celsius', set => {
|
||||
key_values => [ { name => 'temperature' } ],
|
||||
output_template => 'Temperature: %d C',
|
||||
perfdatas => [
|
||||
{ label => 'temperature', value => 'temperature_absolute', template => '%d',
|
||||
unit => 'C' }
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'humidity', nlabel => 'humidity.percentage', set => {
|
||||
key_values => [ { name => 'humidity' } ],
|
||||
output_template => 'Humidity: %.2f%%',
|
||||
perfdatas => [
|
||||
{ label => 'humidity', value => 'humidity_absolute', template => '%.1f',
|
||||
min => 0, max => 100, unit => '%' }
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'clouds', nlabel => 'clouds.percentage', set => {
|
||||
key_values => [ { name => 'clouds' } ],
|
||||
output_template => 'Clouds: %.2f%%',
|
||||
perfdatas => [
|
||||
{ label => 'clouds', value => 'clouds_absolute', template => '%.1f',
|
||||
min => 0, max => 100, unit => '%' }
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'wind', nlabel => 'wind.speed.meterspersecond', set => {
|
||||
key_values => [ { name => 'wind' } ],
|
||||
output_template => 'Wind: %.2f m/s',
|
||||
perfdatas => [
|
||||
{ label => 'wind', value => 'wind_absolute', template => '%.1f',
|
||||
min => 0, unit => 'm/s' }
|
||||
],
|
||||
}
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
sub prefix_city_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return $self->{option_results}->{city_name} . " ";
|
||||
}
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments => {
|
||||
"city-name:s" => { name => 'city_name' },
|
||||
"warning-weather:s" => { name => 'warning_weather', default => '' },
|
||||
"critical-weather:s" => { name => 'critical_weather', default => '' },
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::check_options(%options);
|
||||
|
||||
$self->change_macros(macros => ['warning_weather', 'critical_weather']);
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $results = $options{custom}->request_api(
|
||||
url_path => "/weather?",
|
||||
get_param => ["q=" . $self->{option_results}->{city_name}]
|
||||
);
|
||||
|
||||
$self->{city} = {
|
||||
wind => $results->{wind}->{speed},
|
||||
humidity => $results->{main}->{humidity},
|
||||
temperature => $results->{main}->{temp} - 273.15,
|
||||
clouds => $results->{clouds}->{all},
|
||||
weather => @{$results->{weather}->[0]}{main}
|
||||
};
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check city weather
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--city-name>
|
||||
|
||||
City name (e.g London or ISO 3166 code like London,uk)
|
||||
|
||||
=item B<--warning-weather>
|
||||
|
||||
Set warning threshold for weather string desc (Default: '').
|
||||
Can used special variables like: %{weather}
|
||||
|
||||
=item B<--critical-weather>
|
||||
|
||||
Set critical threshold for weather string desc (Default: '').
|
||||
Can used special variables like: %{weather}
|
||||
Example :
|
||||
--critical-weather='%{weather} eq "Clouds'
|
||||
|
||||
=item B<--warning-*>
|
||||
|
||||
Set warning threshold for each metric gathered
|
||||
Can be :
|
||||
- temperature (Celsius)
|
||||
- humidity (%)
|
||||
- clouds (% coverage)
|
||||
- wind (speed m/s)
|
||||
|
||||
=item B<--critical-*>
|
||||
|
||||
Set critical threshold for each metric gathered
|
||||
Can be :
|
||||
- temperature (Celsius)
|
||||
- humidity (%)
|
||||
- clouds (% coverage)
|
||||
- wind (speed m/s)
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
55
apps/openweathermap/restapi/plugin.pm
Normal file
55
apps/openweathermap/restapi/plugin.pm
Normal file
@ -0,0 +1,55 @@
|
||||
#
|
||||
# Copyright 2019 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package apps::openweathermap::restapi::plugin;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use base qw(centreon::plugins::script_custom);
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '0.1';
|
||||
%{$self->{modes}} = (
|
||||
'city-weather' => 'apps::openweathermap::restapi::mode::cityweather',
|
||||
);
|
||||
|
||||
$self->{custom_modes}{api} = 'apps::openweathermap::restapi::custom::api';
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub init {
|
||||
my ( $self, %options ) = @_;
|
||||
|
||||
$self->SUPER::init(%options);
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 PLUGIN DESCRIPTION
|
||||
|
||||
Check Openweathermap data
|
||||
|
||||
=cut
|
@ -200,8 +200,7 @@ sub new {
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
$options{options}->add_options(arguments => {
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"port:s" => { name => 'port', },
|
||||
"proto:s" => { name => 'proto' },
|
||||
@ -210,12 +209,10 @@ sub new {
|
||||
"basic" => { name => 'basic' },
|
||||
"username:s" => { name => 'username' },
|
||||
"password:s" => { name => 'password' },
|
||||
"proxyurl:s" => { name => 'proxyurl' },
|
||||
"timeout:s" => { name => 'timeout', default => 30 },
|
||||
"ssl-opt:s@" => { name => 'ssl_opt' },
|
||||
});
|
||||
|
||||
$self->{http} = centreon::plugins::http->new(output => $self->{output});
|
||||
$self->{http} = centreon::plugins::http->new(%options);
|
||||
|
||||
return $self;
|
||||
}
|
||||
@ -262,10 +259,6 @@ IP Addr/FQDN of the webserver host
|
||||
|
||||
Port used by web server
|
||||
|
||||
=item B<--proxyurl>
|
||||
|
||||
Proxy URL if any
|
||||
|
||||
=item B<--proto>
|
||||
|
||||
Specify https if needed
|
||||
@ -298,10 +291,6 @@ Specify this option if you access server-status page over hidden basic authentic
|
||||
|
||||
Threshold for HTTP timeout (Default: 30)
|
||||
|
||||
=item B<--ssl-opt>
|
||||
|
||||
Set SSL Options (--ssl-opt="SSL_version => TLSv1" --ssl-opt="SSL_verify_mode => SSL_VERIFY_NONE").
|
||||
|
||||
=item B<--warning-*>
|
||||
|
||||
Threshold warning.
|
||||
|
@ -96,8 +96,7 @@ sub new {
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
$options{options}->add_options(arguments => {
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"port:s" => { name => 'port', },
|
||||
"proto:s" => { name => 'proto' },
|
||||
@ -106,12 +105,10 @@ sub new {
|
||||
"basic" => { name => 'basic' },
|
||||
"username:s" => { name => 'username' },
|
||||
"password:s" => { name => 'password' },
|
||||
"proxyurl:s" => { name => 'proxyurl' },
|
||||
"timeout:s" => { name => 'timeout', default => 30 },
|
||||
"ssl-opt:s@" => { name => 'ssl_opt' },
|
||||
});
|
||||
|
||||
$self->{http} = centreon::plugins::http->new(output => $self->{output});
|
||||
$self->{http} = centreon::plugins::http->new(%options);
|
||||
|
||||
return $self;
|
||||
}
|
||||
@ -159,10 +156,6 @@ IP Addr/FQDN of the webserver host
|
||||
|
||||
Port used by web server
|
||||
|
||||
=item B<--proxyurl>
|
||||
|
||||
Proxy URL if any
|
||||
|
||||
=item B<--proto>
|
||||
|
||||
Specify https if needed
|
||||
@ -195,10 +188,6 @@ Specify this option if you access server-status page over hidden basic authentic
|
||||
|
||||
Threshold for HTTP timeout (Default: 30)
|
||||
|
||||
=item B<--ssl-opt>
|
||||
|
||||
Set SSL Options (--ssl-opt="SSL_version => TLSv1" --ssl-opt="SSL_verify_mode => SSL_VERIFY_NONE").
|
||||
|
||||
=item B<--warning-*>
|
||||
|
||||
Threshold warning.
|
||||
|
@ -140,8 +140,7 @@ sub new {
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
$options{options}->add_options(arguments => {
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"port:s" => { name => 'port', },
|
||||
"proto:s" => { name => 'proto' },
|
||||
@ -150,11 +149,10 @@ sub new {
|
||||
"basic" => { name => 'basic' },
|
||||
"username:s" => { name => 'username' },
|
||||
"password:s" => { name => 'password' },
|
||||
"proxyurl:s" => { name => 'proxyurl' },
|
||||
"timeout:s" => { name => 'timeout', default => 5 },
|
||||
"ssl-opt:s@" => { name => 'ssl_opt' },
|
||||
});
|
||||
$self->{http} = centreon::plugins::http->new(output => $self->{output});
|
||||
|
||||
$self->{http} = centreon::plugins::http->new(%options);
|
||||
|
||||
return $self;
|
||||
}
|
||||
@ -202,10 +200,6 @@ IP Addr/FQDN of the webserver host
|
||||
|
||||
Port used by web server
|
||||
|
||||
=item B<--proxyurl>
|
||||
|
||||
Proxy URL if any
|
||||
|
||||
=item B<--proto>
|
||||
|
||||
Specify https if needed
|
||||
@ -238,10 +232,6 @@ Specify this option if you access server-status page over hidden basic authentic
|
||||
|
||||
Threshold for HTTP timeout (Default: 5)
|
||||
|
||||
=item B<--ssl-opt>
|
||||
|
||||
Set SSL Options (--ssl-opt="SSL_version => TLSv1" --ssl-opt="SSL_verify_mode => SSL_VERIFY_NONE").
|
||||
|
||||
=item B<--warning-*>
|
||||
|
||||
Threshold warning.
|
||||
|
@ -20,12 +20,87 @@
|
||||
|
||||
package apps::protocols::http::mode::expectedcontent;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
use base qw(centreon::plugins::templates::counter);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::http;
|
||||
use Time::HiRes qw(gettimeofday tv_interval);
|
||||
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold);
|
||||
|
||||
sub custom_content_threshold {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{instance_mode}->{content_status} = catalog_status_threshold($self, %options);
|
||||
return $self->{instance_mode}->{content_status};
|
||||
}
|
||||
|
||||
|
||||
sub custom_content_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $msg = 'HTTP test(s)';
|
||||
if (!$self->{output}->is_status(value => $self->{instance_mode}->{content_status}, compare => 'ok', litteral => 1)) {
|
||||
my $filter = $self->{instance_mode}->{option_results}->{lc($self->{instance_mode}->{content_status}) . '_content'};
|
||||
$filter =~ s/\$self->\{result_values\}->/%/g;
|
||||
$msg = sprintf("Content test [filter: '%s']", $filter);
|
||||
}
|
||||
|
||||
return $msg;
|
||||
}
|
||||
|
||||
sub custom_content_calc {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{result_values}->{content} = $options{new_datas}->{$self->{instance} . '_content'};
|
||||
$self->{result_values}->{code} = $options{new_datas}->{$self->{instance} . '_code'};
|
||||
$self->{result_values}->{header} = $options{new_datas}->{$self->{instance} . '_header'};
|
||||
$self->{result_values}->{first_header} = $options{new_datas}->{$self->{instance} . '_first_header'};
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'global', type => 0, skipped_code => { -10 => 1 } },
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{global} = [
|
||||
{ label => 'content', threshold => 0, set => {
|
||||
key_values => [ { name => 'content' }, { name => 'code' }, { name => 'first_header' }, { name => 'header' } ],
|
||||
closure_custom_output => $self->can('custom_content_output'),
|
||||
closure_custom_calc => $self->can('custom_content_calc'),
|
||||
closure_custom_perfdata => sub { return 0; },
|
||||
closure_custom_threshold_check => $self->can('custom_content_threshold'),
|
||||
}
|
||||
},
|
||||
{ label => 'size', display_ok => 0, set => {
|
||||
key_values => [ { name => 'size' } ],
|
||||
output_template => 'Content size : %s',
|
||||
perfdatas => [
|
||||
{ label => 'size', value => 'size_absolute', template => '%s', min => 0, unit => 'B' },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'time', display_ok => 0, set => {
|
||||
key_values => [ { name => 'time' } ],
|
||||
output_template => 'Response time : %.3fs',
|
||||
perfdatas => [
|
||||
{ label => 'time', value => 'time_absolute', template => '%.3f', min => 0, unit => 's' },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'extracted', display_ok => 0, set => {
|
||||
key_values => [ { name => 'extracted' } ],
|
||||
output_template => 'Extracted value : %s',
|
||||
perfdatas => [
|
||||
{ label => 'value', value => 'extracted_absolute', template => '%s' },
|
||||
],
|
||||
}
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
@ -33,27 +108,21 @@ sub new {
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.2';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
$options{options}->add_options(arguments => {
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"http-peer-addr:s" => { name => 'http_peer_addr' },
|
||||
"port:s" => { name => 'port', },
|
||||
"method:s" => { name => 'method' },
|
||||
"proto:s" => { name => 'proto' },
|
||||
"urlpath:s" => { name => 'url_path' },
|
||||
"credentials" => { name => 'credentials' },
|
||||
"basic" => { name => 'basic' },
|
||||
"ntlm" => { name => 'ntlm' }, # Deprecated
|
||||
"ntlmv2" => { name => 'ntlmv2' },
|
||||
"username:s" => { name => 'username' },
|
||||
"password:s" => { name => 'password' },
|
||||
"proxyurl:s" => { name => 'proxyurl' },
|
||||
"proxypac:s" => { name => 'proxypac' },
|
||||
"expected-string:s" => { name => 'expected_string' },
|
||||
"extracted-pattern:s" => { name => 'extracted_pattern' },
|
||||
"timeout:s" => { name => 'timeout' },
|
||||
"no-follow" => { name => 'no_follow', },
|
||||
"ssl:s" => { name => 'ssl', },
|
||||
"ssl-opt:s@" => { name => 'ssl_opt' },
|
||||
"cert-file:s" => { name => 'cert_file' },
|
||||
"key-file:s" => { name => 'key_file' },
|
||||
"cacert-file:s" => { name => 'cacert_file' },
|
||||
@ -66,91 +135,60 @@ sub new {
|
||||
"unknown-status:s" => { name => 'unknown_status' },
|
||||
"warning-status:s" => { name => 'warning_status' },
|
||||
"critical-status:s" => { name => 'critical_status' },
|
||||
"warning:s" => { name => 'warning' },
|
||||
"critical:s" => { name => 'critical' },
|
||||
"warning-size:s" => { name => 'warning_size' },
|
||||
"critical-size:s" => { name => 'critical_size' },
|
||||
"unknown-content:s" => { name => 'unknown_content', default => '' },
|
||||
"warning-content:s" => { name => 'warning_content', default => '' },
|
||||
"critical-content:s" => { name => 'critical_content', default => '' },
|
||||
});
|
||||
$self->{http} = centreon::plugins::http->new(output => $self->{output});
|
||||
|
||||
$self->{http} = centreon::plugins::http->new(%options);
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
$self->SUPER::check_options(%options);
|
||||
|
||||
if (!defined($self->{option_results}->{expected_string})) {
|
||||
$self->{output}->add_option_msg(short_msg => "You need to specify --expected-string option.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'warning-size', value => $self->{option_results}->{warning_size})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong warning-size threshold '" . $self->{option_results}->{warning_size} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'critical-size', value => $self->{option_results}->{critical_size})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong critical-size threshold '" . $self->{option_results}->{critical_size} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
# Legacy compat
|
||||
if (defined($self->{option_results}->{expected_string}) && $self->{option_results}->{expected_string} ne '') {
|
||||
$self->{option_results}->{critical_content} = "%{content} !~ /$self->{option_results}->{expected_string}/mi";
|
||||
}
|
||||
|
||||
$self->{http}->set_options(%{$self->{option_results}});
|
||||
$self->change_macros(macros => ['warning_content', 'critical_content', 'unknown_content']);
|
||||
}
|
||||
|
||||
sub run {
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $timing0 = [gettimeofday];
|
||||
my $webcontent = $self->{http}->request();
|
||||
my $timeelapsed = tv_interval($timing0, [gettimeofday]);
|
||||
|
||||
$self->{global} = {
|
||||
time => $timeelapsed,
|
||||
content => $webcontent,
|
||||
code => $self->{http}->get_code(),
|
||||
header => $self->{http}->get_header(),
|
||||
first_header => $self->{http}->get_first_header(),
|
||||
};
|
||||
|
||||
if (defined($self->{option_results}->{extracted_pattern}) && $self->{option_results}->{extracted_pattern} ne '' &&
|
||||
$webcontent =~ /$self->{option_results}->{extracted_pattern}/mi) {
|
||||
my $extracted = $1;
|
||||
if (defined($extracted) && $extracted =~ /(\d+([\.,]\d+)?)/) {
|
||||
$extracted =~ s/,/\./;
|
||||
$self->{global}->{extracted} = $extracted,
|
||||
}
|
||||
}
|
||||
|
||||
$self->{output}->output_add(long_msg => $webcontent);
|
||||
|
||||
if ($webcontent =~ /$self->{option_results}->{expected_string}/mi) {
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => sprintf("'%s' is present in content.", $self->{option_results}->{expected_string}));
|
||||
} else {
|
||||
$self->{output}->output_add(severity => 'CRITICAL',
|
||||
short_msg => sprintf("'%s' is not present in content.", $self->{option_results}->{expected_string}));
|
||||
}
|
||||
|
||||
# Time check
|
||||
my $exit = $self->{perfdata}->threshold_check(value => $timeelapsed,
|
||||
threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
||||
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => sprintf("Response time : %.3fs", $timeelapsed));
|
||||
}
|
||||
$self->{output}->perfdata_add(label => "time", unit => 's',
|
||||
value => sprintf('%.3f', $timeelapsed),
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
|
||||
min => 0);
|
||||
# Size check
|
||||
{
|
||||
require bytes;
|
||||
|
||||
my $content_size = bytes::length($webcontent);
|
||||
$exit = $self->{perfdata}->threshold_check(value => $content_size,
|
||||
threshold => [ { label => 'critical-size', exit_litteral => 'critical' }, { label => 'warning-size', exit_litteral => 'warning' } ]);
|
||||
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => sprintf("Content size : %s", $content_size));
|
||||
$self->{global}->{size} = bytes::length($webcontent);
|
||||
}
|
||||
$self->{output}->perfdata_add(label => "size", unit => 'B',
|
||||
value => $content_size,
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-size'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-size'),
|
||||
min => 0);
|
||||
}
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
1;
|
||||
@ -167,22 +205,10 @@ Check Webpage content
|
||||
|
||||
IP Addr/FQDN of the Webserver host
|
||||
|
||||
=item B<--http-peer-addr>
|
||||
|
||||
Set the address you want to connect (Useful if hostname is only a vhost. no ip resolve)
|
||||
|
||||
=item B<--port>
|
||||
|
||||
Port used by Webserver
|
||||
|
||||
=item B<--proxyurl>
|
||||
|
||||
Proxy URL
|
||||
|
||||
=item B<--proxypac>
|
||||
|
||||
Proxy pac file (can be an url or local file)
|
||||
|
||||
=item B<--method>
|
||||
|
||||
Specify http method used (Default: 'GET')
|
||||
@ -227,10 +253,6 @@ Threshold for HTTP timeout (Default: 5)
|
||||
|
||||
Do not follow http redirect
|
||||
|
||||
=item B<--ssl-opt>
|
||||
|
||||
Set SSL Options (--ssl-opt="SSL_version => TLSv1" --ssl-opt="SSL_verify_mode => SSL_VERIFY_NONE").
|
||||
|
||||
=item B<--cert-file>
|
||||
|
||||
Specify certificate to send to the webserver
|
||||
@ -267,6 +289,10 @@ Set POST params (Multiple option. Example: --post-param='key=value')
|
||||
|
||||
Save cookies in a file (Example: '/tmp/lwp_cookies.dat')
|
||||
|
||||
=item B<--extracted-pattern>
|
||||
|
||||
Set pattern to extracted a number (used --warning-extracted and --critical-extracted option).
|
||||
|
||||
=item B<--unknown-status>
|
||||
|
||||
Threshold warning for http response code (Default: '%{http_code} < 200 or %{http_code} >= 300')
|
||||
@ -279,11 +305,11 @@ Threshold warning for http response code
|
||||
|
||||
Threshold critical for http response code
|
||||
|
||||
=item B<--warning>
|
||||
=item B<--warning-time>
|
||||
|
||||
Threshold warning in seconds (Webpage response time)
|
||||
|
||||
=item B<--critical>
|
||||
=item B<--critical-time>
|
||||
|
||||
Threshold critical in seconds (Webpage response time)
|
||||
|
||||
@ -295,9 +321,28 @@ Threshold warning for content size
|
||||
|
||||
Threshold critical for content size
|
||||
|
||||
=item B<--expected-string>
|
||||
=item B<--warning-extracted>
|
||||
|
||||
Specify String to check on the Webpage
|
||||
Threshold warning for extracted value
|
||||
|
||||
=item B<--critical-extracted>
|
||||
|
||||
Threshold critical for extracted value
|
||||
|
||||
=item B<--unknown-content>
|
||||
|
||||
Set warning threshold for content page (Default: '').
|
||||
Can used special variables like: %{content}, %{header}, %{first_header}, %{code}
|
||||
|
||||
=item B<--warning-content>
|
||||
|
||||
Set warning threshold for status (Default: '').
|
||||
Can used special variables like: %{content}, %{header}, %{first_header}, %{code}
|
||||
|
||||
=item B<--critical-content>
|
||||
|
||||
Set critical threshold for content page (Default: '').
|
||||
Can used special variables like: %{content}, %{header}, %{first_header}, %{code}
|
||||
|
||||
=back
|
||||
|
||||
|
@ -35,29 +35,20 @@ sub new {
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.2';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"data:s" => { name => 'data' },
|
||||
"lookup:s@" => { name => 'lookup' },
|
||||
$options{options}->add_options(arguments => {
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"http-peer-addr:s" => { name => 'http_peer_addr' },
|
||||
"vhost:s" => { name => 'vhost' },
|
||||
"port:s" => { name => 'port', },
|
||||
"proto:s" => { name => 'proto' },
|
||||
"urlpath:s" => { name => 'url_path' },
|
||||
"credentials" => { name => 'credentials' },
|
||||
"basic" => { name => 'basic' },
|
||||
"ntlm" => { name => 'ntlm' }, # Deprecated
|
||||
"ntlmv2" => { name => 'ntlmv2' },
|
||||
"username:s" => { name => 'username' },
|
||||
"password:s" => { name => 'password' },
|
||||
"proxyurl:s" => { name => 'proxyurl' },
|
||||
"proxypac:s" => { name => 'proxypac' },
|
||||
"header:s@" => { name => 'header' },
|
||||
"get-param:s@" => { name => 'get_param' },
|
||||
"timeout:s" => { name => 'timeout', default => 10 },
|
||||
"ssl-opt:s@" => { name => 'ssl_opt' },
|
||||
"ssl:s" => { name => 'ssl', },
|
||||
"cert-file:s" => { name => 'cert_file' },
|
||||
"key-file:s" => { name => 'key_file' },
|
||||
"cacert-file:s" => { name => 'cacert_file' },
|
||||
@ -78,8 +69,13 @@ sub new {
|
||||
"format-warning:s" => { name => 'format_warning', default => '%{count} element(s) found' },
|
||||
"format-critical:s" => { name => 'format_critical', default => '%{count} element(s) found' },
|
||||
"format-unknown:s" => { name => 'format_unknown', default => '%{count} element(s) found' },
|
||||
"format-lookup:s" => { name => 'format_lookup'},
|
||||
"values-separator:s" => { name => 'values_separator', default => ', ' },
|
||||
"lookup-perfdatas-nagios:s" => { name => 'lookup_perfdatas_nagios'},
|
||||
"data:s" => { name => 'data' },
|
||||
"lookup:s@" => { name => 'lookup' },
|
||||
});
|
||||
|
||||
$self->{count} = 0;
|
||||
$self->{count_ok} = 0;
|
||||
$self->{count_warning} = 0;
|
||||
@ -92,7 +88,7 @@ sub new {
|
||||
$self->{values_string_warning} = [];
|
||||
$self->{values_string_critical} = [];
|
||||
$self->{values_string_unknown} = [];
|
||||
$self->{http} = centreon::plugins::http->new(output => $self->{output});
|
||||
$self->{http} = centreon::plugins::http->new(%options);
|
||||
return $self;
|
||||
}
|
||||
|
||||
@ -154,7 +150,12 @@ sub display_output {
|
||||
|
||||
foreach my $severity (('ok', 'warning', 'critical', 'unknown')) {
|
||||
next if (scalar(@{$self->{'values_' . $severity}}) == 0 && scalar(@{$self->{'values_string_' . $severity}}) == 0);
|
||||
my $format = $self->{option_results}->{'format_' . $severity};
|
||||
my $format = '';
|
||||
if(defined($self->{option_results}->{format_lookup}) && $self->{option_results}->{format_lookup} ne '') {
|
||||
$format = $self->{format_from_json};
|
||||
} else {
|
||||
$format = $self->{option_results}->{'format_' . $severity};
|
||||
}
|
||||
while ($format =~ /%\{(.*?)\}/g) {
|
||||
my $replace = '';
|
||||
if (ref($self->{$1}) eq 'ARRAY') {
|
||||
@ -169,24 +170,29 @@ sub display_output {
|
||||
}
|
||||
}
|
||||
|
||||
sub lookup {
|
||||
sub decode_json_response {
|
||||
my ($self, %options) = @_;
|
||||
my ($xpath, @values);
|
||||
|
||||
return if (defined($self->{json_response_decoded}));
|
||||
my $json = JSON->new;
|
||||
my $content;
|
||||
eval {
|
||||
$content = $json->decode($self->{json_response});
|
||||
$self->{json_response_decoded} = $json->decode($self->{json_response});
|
||||
};
|
||||
if ($@) {
|
||||
$self->{output}->add_option_msg(short_msg => "Cannot decode json response");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
}
|
||||
|
||||
sub lookup {
|
||||
my ($self, %options) = @_;
|
||||
my ($xpath, @values);
|
||||
|
||||
$self->decode_json_response();
|
||||
foreach my $xpath_find (@{$self->{option_results}->{lookup}}) {
|
||||
eval {
|
||||
my $jpath = JSON::Path->new($xpath_find);
|
||||
@values = $jpath->values($content);
|
||||
@values = $jpath->values($self->{json_response_decoded});
|
||||
};
|
||||
if ($@) {
|
||||
$self->{output}->add_option_msg(short_msg => "Cannot lookup: $@");
|
||||
@ -245,9 +251,59 @@ sub lookup {
|
||||
}
|
||||
}
|
||||
|
||||
if (defined($self->{option_results}->{format_lookup}) && $self->{option_results}->{format_lookup} ne '') {
|
||||
my $xpath_find = $self->{option_results}->{format_lookup};
|
||||
eval {
|
||||
my $jpath = JSON::Path->new($xpath_find);
|
||||
$self->{format_from_json} = $jpath->value($self->{json_response_decoded});
|
||||
};
|
||||
if ($@) {
|
||||
$self->{output}->add_option_msg(short_msg => "Cannot lookup output message: $@");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
$self->{output}->output_add(long_msg => "Lookup perfdatas XPath $xpath_find:");
|
||||
}
|
||||
|
||||
$self->display_output();
|
||||
}
|
||||
|
||||
sub lookup_perfdata_nagios {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return if (!defined($self->{option_results}->{lookup_perfdatas_nagios}) || $self->{option_results}->{lookup_perfdatas_nagios} eq '');
|
||||
|
||||
$self->decode_json_response();
|
||||
|
||||
my $perfdata_string;
|
||||
my $xpath_find = $self->{option_results}->{lookup_perfdatas_nagios};
|
||||
eval {
|
||||
my $jpath = JSON::Path->new($xpath_find);
|
||||
$perfdata_string = $jpath->value($self->{json_response_decoded});
|
||||
};
|
||||
if ($@) {
|
||||
$self->{output}->add_option_msg(short_msg => "Cannot lookup perfdatas: $@");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
$self->{output}->output_add(long_msg => "Lookup perfdatas XPath $xpath_find:");
|
||||
|
||||
my @metrics = split(/ /, $perfdata_string);
|
||||
foreach my $single_metric (@metrics) {
|
||||
my ($label, $perfdatas) = split(/=/, $single_metric);
|
||||
my ($value_w_unit, $warn, $crit, $min, $max) = split(/;/, $perfdatas);
|
||||
# separate the value from the unit
|
||||
my ($value, $unit) = $value_w_unit =~ /(^[0-9]+\.*\,*[0-9]*)(.*)/g;
|
||||
|
||||
$self->{output}->perfdata_add(label => $label, unit => $unit,
|
||||
value => $value,
|
||||
warning => $warn,
|
||||
critical => $crit,
|
||||
min => $min,
|
||||
max => $max);
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
@ -279,6 +335,8 @@ sub run {
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-time'),
|
||||
min => 0);
|
||||
|
||||
$self->lookup_perfdata_nagios();
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
@ -306,12 +364,23 @@ Set file with JSON request
|
||||
What to lookup in JSON response (JSON XPath string) (can be multiple)
|
||||
See: http://goessner.net/articles/JsonPath/
|
||||
|
||||
=item B<--lookup-perfdatas-nagios>
|
||||
|
||||
Take perfdatas from the JSON response (JSON XPath string)
|
||||
Chain must be formated in Nagios format.
|
||||
Ex : "rta=10.752ms;50.000;100.000;0; pl=0%;20;40;; rtmax=10.802ms;;;;"
|
||||
|
||||
=back
|
||||
|
||||
FORMAT OPTIONS:
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--format-lookup>
|
||||
|
||||
Take the output message from the JSON response (JSON XPath string)
|
||||
Override all the format options but substitute are still applied.
|
||||
|
||||
=item B<--format-ok>
|
||||
|
||||
Output format (Default: '%{count} element(s) found')
|
||||
@ -385,22 +454,10 @@ HTTP OPTIONS:
|
||||
|
||||
IP Addr/FQDN of the Webserver host
|
||||
|
||||
=item B<--http-peer-addr>
|
||||
|
||||
Set the address you want to connect (Useful if hostname is only a vhost. no ip resolve)
|
||||
|
||||
=item B<--port>
|
||||
|
||||
Port used by Webserver
|
||||
|
||||
=item B<--proxyurl>
|
||||
|
||||
Proxy URL
|
||||
|
||||
=item B<--proxypac>
|
||||
|
||||
Proxy pac file (can be an url or local file)
|
||||
|
||||
=item B<--proto>
|
||||
|
||||
Specify https if needed
|
||||
@ -437,10 +494,6 @@ Specify this option if you access webpage over ntlmv2 authentication (Use with -
|
||||
|
||||
Threshold for HTTP timeout (Default: 10)
|
||||
|
||||
=item B<--ssl-opt>
|
||||
|
||||
Set SSL Options (--ssl-opt="SSL_version => TLSv1" --ssl-opt="SSL_verify_mode => SSL_VERIFY_NONE").
|
||||
|
||||
=item B<--cert-file>
|
||||
|
||||
Specify certificate to send to the webserver
|
||||
|
@ -33,26 +33,19 @@ sub new {
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.1';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
$options{options}->add_options(arguments => {
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"http-peer-addr:s" => { name => 'http_peer_addr' },
|
||||
"port:s" => { name => 'port', },
|
||||
"method:s" => { name => 'method' },
|
||||
"proto:s" => { name => 'proto' },
|
||||
"urlpath:s" => { name => 'url_path' },
|
||||
"credentials" => { name => 'credentials' },
|
||||
"basic" => { name => 'basic' },
|
||||
"ntlm" => { name => 'ntlm' }, # Deprecated
|
||||
"ntlmv2" => { name => 'ntlmv2' },
|
||||
"username:s" => { name => 'username' },
|
||||
"password:s" => { name => 'password' },
|
||||
"proxyurl:s" => { name => 'proxyurl' },
|
||||
"proxypac:s" => { name => 'proxypac' },
|
||||
"timeout:s" => { name => 'timeout' },
|
||||
"no-follow" => { name => 'no_follow', },
|
||||
"ssl:s" => { name => 'ssl' },
|
||||
"ssl-opt:s@" => { name => 'ssl_opt' },
|
||||
"cert-file:s" => { name => 'cert_file' },
|
||||
"key-file:s" => { name => 'key_file' },
|
||||
"cacert-file:s" => { name => 'cacert_file' },
|
||||
@ -71,7 +64,7 @@ sub new {
|
||||
"critical-size:s" => { name => 'critical_size' },
|
||||
});
|
||||
|
||||
$self->{http} = centreon::plugins::http->new(output => $self->{output});
|
||||
$self->{http} = centreon::plugins::http->new(%options);
|
||||
return $self;
|
||||
}
|
||||
|
||||
@ -153,10 +146,6 @@ Check Webpage response and size.
|
||||
|
||||
IP Addr/FQDN of the webserver host
|
||||
|
||||
=item B<--http-peer-addr>
|
||||
|
||||
Set the address you want to connect (Useful if hostname is only a vhost. no ip resolve)
|
||||
|
||||
=item B<--port>
|
||||
|
||||
Port used by Webserver
|
||||
@ -197,14 +186,6 @@ Specify this option if you access webpage over hidden basic authentication or yo
|
||||
|
||||
Specify this option if you access webpage over ntlmv2 authentication (Use with --credentials and --port options)
|
||||
|
||||
=item B<--proxyurl>
|
||||
|
||||
Proxy URL
|
||||
|
||||
=item B<--proxypac>
|
||||
|
||||
Proxy pac file (can be an url or local file)
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Threshold for HTTP timeout (Default: 5)
|
||||
@ -213,10 +194,6 @@ Threshold for HTTP timeout (Default: 5)
|
||||
|
||||
Do not follow http redirect
|
||||
|
||||
=item B<--ssl-opt>
|
||||
|
||||
Set SSL Options (--ssl-opt="SSL_version => TLSv1" --ssl-opt="SSL_verify_mode => SSL_VERIFY_NONE").
|
||||
|
||||
=item B<--cert-file>
|
||||
|
||||
Specify certificate to send to the webserver
|
||||
|
@ -34,29 +34,22 @@ sub new {
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.2';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
$options{options}->add_options(arguments => {
|
||||
"service-soap:s" => { name => 'service_soap' },
|
||||
"data:s" => { name => 'data' },
|
||||
"lookup:s@" => { name => 'lookup' },
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"http-peer-addr:s" => { name => 'http_peer_addr' },
|
||||
"vhost:s" => { name => 'vhost' },
|
||||
"port:s" => { name => 'port', },
|
||||
"proto:s" => { name => 'proto' },
|
||||
"urlpath:s" => { name => 'url_path' },
|
||||
"credentials" => { name => 'credentials' },
|
||||
"basic" => { name => 'basic' },
|
||||
"ntlm" => { name => 'ntlm' }, # Deprecated
|
||||
"ntlmv2" => { name => 'ntlmv2' },
|
||||
"username:s" => { name => 'username' },
|
||||
"password:s" => { name => 'password' },
|
||||
"proxyurl:s" => { name => 'proxyurl' },
|
||||
"proxypac:s" => { name => 'proxypac' },
|
||||
"header:s@" => { name => 'header' },
|
||||
"timeout:s" => { name => 'timeout', default => 10 },
|
||||
"ssl-opt:s@" => { name => 'ssl_opt' },
|
||||
"ssl:s" => { name => 'ssl', },
|
||||
"cert-file:s" => { name => 'cert_file' },
|
||||
"key-file:s" => { name => 'key_file' },
|
||||
"cacert-file:s" => { name => 'cacert_file' },
|
||||
@ -87,7 +80,7 @@ sub new {
|
||||
$self->{values_string_ok} = [];
|
||||
$self->{values_string_warning} = [];
|
||||
$self->{values_string_critical} = [];
|
||||
$self->{http} = centreon::plugins::http->new(output => $self->{output});
|
||||
$self->{http} = centreon::plugins::http->new(%options);
|
||||
return $self;
|
||||
}
|
||||
|
||||
@ -165,8 +158,7 @@ sub check_encoding {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $charset;
|
||||
my $headers = $self->{http}->get_header();
|
||||
my $content_type = $headers->header('Content-Type');
|
||||
my ($content_type) = $self->{http}->get_header(name => 'Content-Type');
|
||||
if (defined($content_type) && $content_type =~ /charset\s*=\s*(\S+)/i) {
|
||||
$charset = $1;
|
||||
}
|
||||
@ -394,22 +386,10 @@ HTTP OPTIONS:
|
||||
|
||||
IP Addr/FQDN of the Webserver host
|
||||
|
||||
=item B<--http-peer-addr>
|
||||
|
||||
Set the address you want to connect (Useful if hostname is only a vhost. no ip resolve)
|
||||
|
||||
=item B<--port>
|
||||
|
||||
Port used by Webserver
|
||||
|
||||
=item B<--proxyurl>
|
||||
|
||||
Proxy URL
|
||||
|
||||
=item B<--proxypac>
|
||||
|
||||
Proxy pac file (can be an url or local file)
|
||||
|
||||
=item B<--proto>
|
||||
|
||||
Specify https if needed
|
||||
@ -446,10 +426,6 @@ Specify this option if you access webpage over ntlmv2 authentication (Use with -
|
||||
|
||||
Threshold for HTTP timeout (Default: 10)
|
||||
|
||||
=item B<--ssl-opt>
|
||||
|
||||
Set SSL Options (--ssl-opt="SSL_version => TLSv1" --ssl-opt="SSL_verify_mode => SSL_VERIFY_NONE").
|
||||
|
||||
=item B<--cert-file>
|
||||
|
||||
Specify certificate to send to the webserver
|
||||
@ -476,7 +452,7 @@ Set HTTP headers (Multiple option)
|
||||
|
||||
=item B<--unknown-status>
|
||||
|
||||
Threshold warning for http response code (Default: '%{http_code} < 200 or %{http_code} >= 300')
|
||||
Threshold unknown for http response code (Default: '%{http_code} < 200 or %{http_code} >= 300')
|
||||
|
||||
=item B<--warning-status>
|
||||
|
||||
|
@ -1,132 +0,0 @@
|
||||
#
|
||||
# Copyright 2019 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package apps::protocols::ldap::lib::ldap;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Net::LDAP;
|
||||
|
||||
my $ldap_handle;
|
||||
my $connected = 0;
|
||||
|
||||
sub quit {
|
||||
if ($connected == 1) {
|
||||
$ldap_handle->unbind;
|
||||
}
|
||||
}
|
||||
|
||||
sub search {
|
||||
my ($self, %options) = @_;
|
||||
my %ldap_search_options = ();
|
||||
|
||||
$ldap_search_options{base} = $self->{option_results}->{search_base};
|
||||
$ldap_search_options{filter} = $self->{option_results}->{search_filter};
|
||||
my $attrs;
|
||||
foreach my $option (@{$self->{option_results}->{ldap_search_options}}) {
|
||||
next if ($option !~ /^(.+?)=(.+)$/);
|
||||
if ($1 =~ /attrs/) {
|
||||
$attrs = [] if (!defined($attrs));
|
||||
push @$attrs, $2;
|
||||
} else {
|
||||
$ldap_search_options{$1} = $2;
|
||||
}
|
||||
}
|
||||
$ldap_search_options{attrs} = $attrs if (defined($attrs));
|
||||
my $search_result = $ldap_handle->search(%ldap_search_options);
|
||||
if ($search_result->code) {
|
||||
$self->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => 'Search operation error: ' . $search_result->error);
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
return $search_result;
|
||||
}
|
||||
|
||||
sub connect {
|
||||
my ($self, %options) = @_;
|
||||
my %ldap_connect_options = ();
|
||||
my %ldap_bind_options = ();
|
||||
|
||||
if (defined($self->{option_results}->{username}) && $self->{option_results}->{username} ne '' &&
|
||||
!defined($self->{option_results}->{password})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set --password option.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
my $connection_exit = defined($options{connection_exit}) ? $options{connection_exit} : 'unknown';
|
||||
$ldap_connect_options{timeout} = $self->{option_results}->{timeout} if (defined($self->{option_results}->{timeout}));
|
||||
foreach my $option (@{$self->{option_results}->{ldap_connect_options}}) {
|
||||
next if ($option !~ /^(.+?)=(.+)$/);
|
||||
$ldap_connect_options{$1} = $2;
|
||||
}
|
||||
|
||||
$ldap_handle = Net::LDAP->new($self->{option_results}->{hostname}, %ldap_connect_options);
|
||||
|
||||
if (!defined($ldap_handle)) {
|
||||
$self->{output}->output_add(severity => $connection_exit,
|
||||
short_msg => 'Unable to connect to LDAP: ' . $@);
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
# TLS Process
|
||||
if (defined($self->{option_results}->{use_tls})) {
|
||||
my %ldap_starttls_options = ();
|
||||
|
||||
foreach my $option (@{$self->{option_results}->{ldap_starttls_options}}) {
|
||||
next if ($option !~ /^(.+?)=(.+)$/);
|
||||
$ldap_starttls_options{$1} = $2;
|
||||
}
|
||||
|
||||
my $tls_result = $ldap_handle->start_tls(%ldap_starttls_options);
|
||||
if ($tls_result->code) {
|
||||
$self->{output}->output_add(severity => $connection_exit,
|
||||
short_msg => 'Start TLS operation error: ' . $tls_result->error);
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
}
|
||||
|
||||
# Bind process
|
||||
my $username;
|
||||
if (defined($self->{option_results}->{username}) && $self->{option_results}->{username} ne '') {
|
||||
$ldap_bind_options{password} = $self->{option_results}->{password};
|
||||
$username = $self->{option_results}->{username};
|
||||
}
|
||||
|
||||
foreach my $option (@{$self->{option_results}->{ldap_bind_options}}) {
|
||||
next if ($option !~ /^(.+?)=(.+)$/);
|
||||
$ldap_bind_options{$1} = $2;
|
||||
}
|
||||
|
||||
my $bind_result = $ldap_handle->bind($username, %ldap_bind_options);
|
||||
if ($bind_result->code) {
|
||||
$self->{output}->output_add(severity => $connection_exit,
|
||||
short_msg => 'Bind operation error: ' . $bind_result->error);
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
$connected = 1;
|
||||
}
|
||||
|
||||
1;
|
@ -25,7 +25,7 @@ use base qw(centreon::plugins::mode);
|
||||
use strict;
|
||||
use warnings;
|
||||
use Time::HiRes qw(gettimeofday tv_interval);
|
||||
use apps::protocols::ldap::lib::ldap;
|
||||
use centreon::common::protocols::ldap::lib::ldap;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
@ -33,19 +33,19 @@ sub new {
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"ldap-connect-options:s@" => { name => 'ldap_connect_options' },
|
||||
"ldap-starttls-options:s@" => { name => 'ldap_starttls_options' },
|
||||
"ldap-bind-options:s@" => { name => 'ldap_bind_options' },
|
||||
"tls" => { name => 'use_tls' },
|
||||
"username:s" => { name => 'username' },
|
||||
"password:s" => { name => 'password' },
|
||||
"warning:s" => { name => 'warning' },
|
||||
"critical:s" => { name => 'critical' },
|
||||
"timeout:s" => { name => 'timeout', default => '30' },
|
||||
$options{options}->add_options(arguments => {
|
||||
'hostname:s' => { name => 'hostname' },
|
||||
'ldap-connect-options:s@' => { name => 'ldap_connect_options' },
|
||||
'ldap-starttls-options:s@' => { name => 'ldap_starttls_options' },
|
||||
'ldap-bind-options:s@' => { name => 'ldap_bind_options' },
|
||||
'tls' => { name => 'use_tls' },
|
||||
'username:s' => { name => 'username' },
|
||||
'password:s' => { name => 'password' },
|
||||
'warning:s' => { name => 'warning' },
|
||||
'critical:s' => { name => 'critical' },
|
||||
'timeout:s' => { name => 'timeout', default => '30' },
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
@ -63,7 +63,13 @@ sub check_options {
|
||||
}
|
||||
|
||||
if (!defined($self->{option_results}->{hostname})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set the hostname option");
|
||||
$self->{output}->add_option_msg(short_msg => 'Please set the hostname option');
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
if (defined($self->{option_results}->{username}) && $self->{option_results}->{username} ne '' &&
|
||||
!defined($self->{option_results}->{password})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set --password option.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
}
|
||||
@ -73,16 +79,31 @@ sub run {
|
||||
|
||||
my $timing0 = [gettimeofday];
|
||||
|
||||
apps::protocols::ldap::lib::ldap::connect($self, connection_exit => 'critical');
|
||||
apps::protocols::ldap::lib::ldap::quit();
|
||||
my ($ldap_handle, $code, $err_msg) = centreon::common::protocols::ldap::lib::ldap::connect(
|
||||
hostname => $self->{option_results}->{hostname},
|
||||
username => $self->{option_results}->{username},
|
||||
password => $self->{option_results}->{password},
|
||||
timeout => $self->{option_results}->{timeout},
|
||||
ldap_connect_options => $self->{option_results}->{ldap_connect_options},
|
||||
use_tls => $self->{option_results}->{use_tls},
|
||||
ldap_starttls_options => $self->{option_results}->{ldap_starttls_options},
|
||||
ldap_bind_options => $self->{option_results}->{ldap_bind_options},
|
||||
);
|
||||
if ($code == 1) {
|
||||
$self->{output}->output_add(severity => 'critical',
|
||||
short_msg => $err_msg);
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
centreon::common::protocols::ldap::lib::ldap::quit(ldap_handle => $ldap_handle);
|
||||
|
||||
my $timeelapsed = tv_interval ($timing0, [gettimeofday]);
|
||||
|
||||
my $exit = $self->{perfdata}->threshold_check(value => $timeelapsed,
|
||||
threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => sprintf("Response time %.3f second(s)", $timeelapsed));
|
||||
$self->{output}->perfdata_add(label => "time", unit => 's',
|
||||
short_msg => sprintf('Response time %.3f second(s)', $timeelapsed));
|
||||
$self->{output}->perfdata_add(label => 'time', unit => 's',
|
||||
value => sprintf('%.3f', $timeelapsed),
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'));
|
||||
|
@ -20,12 +20,39 @@
|
||||
|
||||
package apps::protocols::ldap::mode::search;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
use base qw(centreon::plugins::templates::counter);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Time::HiRes qw(gettimeofday tv_interval);
|
||||
use apps::protocols::ldap::lib::ldap;
|
||||
use centreon::common::protocols::ldap::lib::ldap;
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'global', type => 0, skipped_code => { -10 => 1 } },
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{global} = [
|
||||
{ label => 'entries', nlabel => 'ldap.request.entries.count', set => {
|
||||
key_values => [ { name => 'entries' } ],
|
||||
output_template => 'Number of results returned: %s',
|
||||
perfdatas => [
|
||||
{ value => 'entries_absolute', template => '%s', min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'time', display_ok => 0, nlabel => 'ldap.request.time.second', set => {
|
||||
key_values => [ { name => 'time' } ],
|
||||
output_template => 'Response time : %.3fs',
|
||||
perfdatas => [
|
||||
{ label => 'time', value => 'time_absolute', template => '%.3f', min => 0, unit => 's' },
|
||||
],
|
||||
}
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
@ -33,80 +60,117 @@ sub new {
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"search-base:s" => { name => 'search_base' },
|
||||
"search-filter:s" => { name => 'search_filter' },
|
||||
"ldap-connect-options:s@" => { name => 'ldap_connect_options' },
|
||||
"ldap-starttls-options:s@" => { name => 'ldap_starttls_options' },
|
||||
"ldap-bind-options:s@" => { name => 'ldap_bind_options' },
|
||||
"ldap-search-options:s@" => { name => 'ldap_search_options' },
|
||||
"tls" => { name => 'use_tls' },
|
||||
"username:s" => { name => 'username' },
|
||||
"password:s" => { name => 'password' },
|
||||
"warning:s" => { name => 'warning' },
|
||||
"critical:s" => { name => 'critical' },
|
||||
"timeout:s" => { name => 'timeout', default => '30' },
|
||||
$options{options}->add_options(arguments => {
|
||||
'hostname:s' => { name => 'hostname' },
|
||||
'search-base:s' => { name => 'search_base' },
|
||||
'search-filter:s' => { name => 'search_filter' },
|
||||
'ldap-connect-options:s@' => { name => 'ldap_connect_options' },
|
||||
'ldap-starttls-options:s@' => { name => 'ldap_starttls_options' },
|
||||
'ldap-bind-options:s@' => { name => 'ldap_bind_options' },
|
||||
'ldap-search-options:s@' => { name => 'ldap_search_options' },
|
||||
'tls' => { name => 'use_tls' },
|
||||
'username:s' => { name => 'username' },
|
||||
'password:s' => { name => 'password' },
|
||||
'timeout:s' => { name => 'timeout', default => '30' },
|
||||
'display-entry:s' => { name => 'display_entry' },
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
$self->SUPER::check_options(%options);
|
||||
|
||||
if (!defined($self->{option_results}->{hostname})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set the hostname option");
|
||||
$self->{output}->add_option_msg(short_msg => 'Please set the hostname option');
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (defined($self->{option_results}->{username}) && $self->{option_results}->{username} ne '' &&
|
||||
!defined($self->{option_results}->{password})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set --password option.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (!defined($self->{option_results}->{search_base})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set the search-base option");
|
||||
$self->{output}->add_option_msg(short_msg => 'Please set the search-base option');
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (!defined($self->{option_results}->{search_filter})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set the search-filter option");
|
||||
$self->{output}->add_option_msg(short_msg => 'Please set the search-filter option');
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
$self->{option_results}->{ldap_search_options} = [] if (!defined($self->{option_results}->{ldap_search_options}));
|
||||
|
||||
if (defined($self->{option_results}->{display_entry}) && $self->{option_results}->{display_entry} ne '') {
|
||||
while ($self->{option_results}->{display_entry} =~ /%\{(.*?)\}/g) {
|
||||
push @{$self->{option_results}->{ldap_search_options}}, 'attrs=' . $1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
sub ldap_error {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if ($options{code} == 1) {
|
||||
$self->{output}->output_add(
|
||||
severity => 'unknown',
|
||||
short_msg => $options{err_msg}
|
||||
);
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
}
|
||||
|
||||
sub display_entries {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return if (!defined($self->{option_results}->{display_entry}) || $self->{option_results}->{display_entry} eq '');
|
||||
|
||||
foreach my $entry ($options{result}->entries()) {
|
||||
my $display = $self->{option_results}->{display_entry};
|
||||
while ($display =~ /%\{(.*?)\}/g) {
|
||||
my $attr = $1;
|
||||
my $value = $entry->get_value($attr);
|
||||
$value = '' if (!defined($value));
|
||||
$display =~ s/%\{$attr\}/$value/g;
|
||||
}
|
||||
|
||||
$self->{output}->output_add(long_msg => $display);
|
||||
}
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $timing0 = [gettimeofday];
|
||||
|
||||
apps::protocols::ldap::lib::ldap::connect($self);
|
||||
my $search_result = apps::protocols::ldap::lib::ldap::search($self);
|
||||
apps::protocols::ldap::lib::ldap::quit();
|
||||
my ($ldap_handle, $code, $err_msg) = centreon::common::protocols::ldap::lib::ldap::connect(
|
||||
hostname => $self->{option_results}->{hostname},
|
||||
username => $self->{option_results}->{username},
|
||||
password => $self->{option_results}->{password},
|
||||
timeout => $self->{option_results}->{timeout},
|
||||
ldap_connect_options => $self->{option_results}->{ldap_connect_options},
|
||||
use_tls => $self->{option_results}->{use_tls},
|
||||
ldap_starttls_options => $self->{option_results}->{ldap_starttls_options},
|
||||
ldap_bind_options => $self->{option_results}->{ldap_bind_options},
|
||||
);
|
||||
$self->ldap_error(code => $code, err_msg => $err_msg);
|
||||
(my $search_result, $code, $err_msg) = centreon::common::protocols::ldap::lib::ldap::search(
|
||||
ldap_handle => $ldap_handle,
|
||||
search_base => $self->{option_results}->{search_base},
|
||||
search_filter => $self->{option_results}->{search_filter},
|
||||
ldap_search_options => $self->{option_results}->{ldap_search_options},
|
||||
);
|
||||
$self->ldap_error(code => $code, err_msg => $err_msg);
|
||||
centreon::common::protocols::ldap::lib::ldap::quit(ldap_handle => $ldap_handle);
|
||||
|
||||
my $timeelapsed = tv_interval ($timing0, [gettimeofday]);
|
||||
$self->{global} = {
|
||||
time => tv_interval($timing0, [gettimeofday]),
|
||||
entries => scalar($search_result->entries)
|
||||
};
|
||||
|
||||
my $num_entries = scalar($search_result->entries);
|
||||
my $exit = $self->{perfdata}->threshold_check(value => $num_entries,
|
||||
threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => sprintf("Number of results returned: %s", $num_entries));
|
||||
|
||||
$self->{output}->perfdata_add(label => "time", unit => 's',
|
||||
value => sprintf('%.3f', $timeelapsed),
|
||||
min => 0);
|
||||
$self->{output}->perfdata_add(label => "entries",
|
||||
value => $num_entries,
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
|
||||
min => 0);
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
$self->display_entries(result => $search_result);
|
||||
}
|
||||
|
||||
1;
|
||||
@ -173,6 +237,10 @@ Add custom bind options (can force noauth) (not really useful now).
|
||||
|
||||
Add custom search options (can change the scope for example).
|
||||
|
||||
=item B<--display-entry>
|
||||
|
||||
Display ldap entries (with --verbose option) (Example: '%{cn} account locked')
|
||||
|
||||
=item B<--username>
|
||||
|
||||
Specify username for authentification (can be a DN)
|
||||
@ -185,11 +253,19 @@ Specify password for authentification
|
||||
|
||||
Connection timeout in seconds (Default: 30)
|
||||
|
||||
=item B<--warning>
|
||||
=item B<--warning-time>
|
||||
|
||||
Threshold warning in seconds
|
||||
|
||||
=item B<--critical-time>
|
||||
|
||||
Threshold critical in seconds
|
||||
|
||||
=item B<--warning-entries>
|
||||
|
||||
Threshold warning (number of results)
|
||||
|
||||
=item B<--critical>
|
||||
=item B<--critical-entries>
|
||||
|
||||
Threshold critical (number of results)
|
||||
|
||||
|
141
apps/protocols/nrpe/custom/nrpe.pm
Normal file
141
apps/protocols/nrpe/custom/nrpe.pm
Normal file
@ -0,0 +1,141 @@
|
||||
#
|
||||
# Copyright 2019 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package apps::protocols::nrpe::custom::nrpe;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::nrpe;
|
||||
|
||||
my %errors_num = (0 => 'OK', 1 => 'WARNING', 2 => 'CRITICAL', 3 => 'UNKNOWN');
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = {};
|
||||
bless $self, $class;
|
||||
|
||||
if (!defined($options{output})) {
|
||||
print "Class Custom: Need to specify 'output' argument.\n";
|
||||
exit 3;
|
||||
}
|
||||
if (!defined($options{options})) {
|
||||
$options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument.");
|
||||
$options{output}->option_exit();
|
||||
}
|
||||
|
||||
if (!defined($options{noptions})) {
|
||||
$options{options}->add_options(arguments => {
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
});
|
||||
}
|
||||
$options{options}->add_help(package => __PACKAGE__, sections => 'CUSTOM MODE OPTIONS', once => 1);
|
||||
|
||||
$self->{output} = $options{output};
|
||||
$self->{mode} = $options{mode};
|
||||
$self->{nrpe} = centreon::plugins::nrpe->new(%options);
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub set_options {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{option_results} = $options{option_results};
|
||||
}
|
||||
|
||||
sub set_defaults {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
foreach (keys %{$options{default}}) {
|
||||
if ($_ eq $self->{mode}) {
|
||||
for (my $i = 0; $i < scalar(@{$options{default}->{$_}}); $i++) {
|
||||
foreach my $opt (keys %{$options{default}->{$_}[$i]}) {
|
||||
if (!defined($self->{option_results}->{$opt}[$i])) {
|
||||
$self->{option_results}->{$opt}[$i] = $options{default}->{$_}[$i]->{$opt};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{hostname} = (defined($self->{option_results}->{hostname})) ? $self->{option_results}->{hostname} : '';
|
||||
|
||||
if (!defined($self->{hostname}) || $self->{hostname} eq '') {
|
||||
$self->{output}->add_option_msg(short_msg => "Need to specify --hostname option.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
$self->{nrpe}->check_options(option_results => $self->{option_results});
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub format_result {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my %result = (
|
||||
code => ($options{content}->{result_code} =~ /^[0-3]$/) ? $errors_num{$options{content}->{result_code}} : $options{content}->{result_code},
|
||||
message => $options{content}->{buffer},
|
||||
perf => []
|
||||
);
|
||||
return \%result;
|
||||
}
|
||||
|
||||
sub request {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my ($content) = $self->{nrpe}->request(check => $options{command}, arg => $options{arg});
|
||||
|
||||
my $result = $self->format_result(content => $content);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 NAME
|
||||
|
||||
NRPE protocol
|
||||
|
||||
=head1 CUSTOM MODE OPTIONS
|
||||
|
||||
NRPE protocol
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--hostname>
|
||||
|
||||
Remote hostname or IP address.
|
||||
|
||||
=back
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
B<custom>.
|
||||
|
||||
=cut
|
341
apps/protocols/nrpe/custom/nsclient.pm
Normal file
341
apps/protocols/nrpe/custom/nsclient.pm
Normal file
@ -0,0 +1,341 @@
|
||||
#
|
||||
# Copyright 2019 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package apps::protocols::nrpe::custom::nsclient;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::http;
|
||||
use URI::Encode;
|
||||
use JSON::XS;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = {};
|
||||
bless $self, $class;
|
||||
|
||||
if (!defined($options{output})) {
|
||||
print "Class Custom: Need to specify 'output' argument.\n";
|
||||
exit 3;
|
||||
}
|
||||
if (!defined($options{options})) {
|
||||
$options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument.");
|
||||
$options{output}->option_exit();
|
||||
}
|
||||
|
||||
if (!defined($options{noptions})) {
|
||||
$options{options}->add_options(arguments => {
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"port:s" => { name => 'port' },
|
||||
"proto:s" => { name => 'proto' },
|
||||
"credentials" => { name => 'credentials' },
|
||||
"basic" => { name => 'basic' },
|
||||
"username:s" => { name => 'username' },
|
||||
"password:s" => { name => 'password' },
|
||||
"legacy-password:s" => { name => 'legacy_password' },
|
||||
"timeout:s" => { name => 'timeout' },
|
||||
});
|
||||
}
|
||||
$options{options}->add_help(package => __PACKAGE__, sections => 'CUSTOM MODE OPTIONS', once => 1);
|
||||
|
||||
$self->{output} = $options{output};
|
||||
$self->{mode} = $options{mode};
|
||||
$self->{http} = centreon::plugins::http->new(%options);
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub set_options {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{option_results} = $options{option_results};
|
||||
}
|
||||
|
||||
sub set_defaults {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
foreach (keys %{$options{default}}) {
|
||||
if ($_ eq $self->{mode}) {
|
||||
for (my $i = 0; $i < scalar(@{$options{default}->{$_}}); $i++) {
|
||||
foreach my $opt (keys %{$options{default}->{$_}[$i]}) {
|
||||
if (!defined($self->{option_results}->{$opt}[$i])) {
|
||||
$self->{option_results}->{$opt}[$i] = $options{default}->{$_}[$i]->{$opt};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{hostname} = (defined($self->{option_results}->{hostname})) ? $self->{option_results}->{hostname} : '';
|
||||
$self->{port} = (defined($self->{option_results}->{port})) ? $self->{option_results}->{port} : 8443;
|
||||
$self->{proto} = (defined($self->{option_results}->{proto})) ? $self->{option_results}->{proto} : 'https';
|
||||
$self->{timeout} = (defined($self->{option_results}->{timeout})) ? $self->{option_results}->{timeout} : 10;
|
||||
$self->{username} = (defined($self->{option_results}->{username})) ? $self->{option_results}->{username} : undef;
|
||||
$self->{password} = (defined($self->{option_results}->{password})) ? $self->{option_results}->{password} : undef;
|
||||
$self->{legacy_password} = (defined($self->{option_results}->{legacy_password})) ? $self->{option_results}->{legacy_password} : undef;
|
||||
$self->{credentials} = (defined($self->{option_results}->{credentials})) ? 1 : undef;
|
||||
$self->{basic} = (defined($self->{option_results}->{basic})) ? 1 : undef;
|
||||
|
||||
if (!defined($self->{hostname}) || $self->{hostname} eq '') {
|
||||
$self->{output}->add_option_msg(short_msg => "Need to specify --hostname option.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub build_options_for_httplib {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{option_results}->{hostname} = $self->{hostname};
|
||||
$self->{option_results}->{timeout} = $self->{timeout};
|
||||
$self->{option_results}->{port} = $self->{port};
|
||||
$self->{option_results}->{proto} = $self->{proto};
|
||||
$self->{option_results}->{timeout} = $self->{timeout};
|
||||
$self->{option_results}->{warning_status} = '';
|
||||
$self->{option_results}->{critical_status} = '';
|
||||
$self->{option_results}->{unknown_status} = '%{http_code} < 200 or %{http_code} >= 300';
|
||||
}
|
||||
|
||||
sub settings {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->build_options_for_httplib();
|
||||
if (defined($self->{legacy_password}) && $self->{legacy_password} ne '') {
|
||||
$self->{http}->add_header(key => 'password', value => $self->{legacy_password});
|
||||
}
|
||||
$self->{http}->set_options(%{$self->{option_results}});
|
||||
}
|
||||
|
||||
# Two kind of outputs.
|
||||
# 1-
|
||||
# {
|
||||
# "header": {
|
||||
# "source_id": ""
|
||||
# },
|
||||
# "payload": [{
|
||||
# "command": "check_centreon_plugins",
|
||||
# "lines": [{
|
||||
# "message": "OK: Reboot Pending : False | 'value1'=10;;;; 'value2'=10;;;;\r\nlong1\r\nlong2"
|
||||
# }],
|
||||
# "result": "OK"
|
||||
# }]
|
||||
# }
|
||||
# 2- Can be also "int_value".
|
||||
# {
|
||||
# "header": {
|
||||
# "source_id": ""
|
||||
# },
|
||||
# "payload": [{
|
||||
# "command": "check_drivesize",
|
||||
# "lines": [{
|
||||
# "message": "OK All 1 drive(s) are ok",
|
||||
# "perf": [{
|
||||
# "alias": "C",
|
||||
# "float_value": {
|
||||
# "critical": 44.690621566027403,
|
||||
# "maximum": 49.656246185302734,
|
||||
# "minimum": 0.00000000000000000,
|
||||
# "unit": "GB",
|
||||
# "value": 21.684593200683594,
|
||||
# "warning": 39.724996947683394
|
||||
# }
|
||||
# },
|
||||
# {
|
||||
# "alias": "C",
|
||||
# "float_value": {
|
||||
# "critical": 90.000000000000000,
|
||||
# "maximum": 100.00000000000000,
|
||||
# "minimum": 0.00000000000000000,
|
||||
# "unit": "%",
|
||||
# "value": 44.000000000000000,
|
||||
# "warning": 80.000000000000000
|
||||
# }
|
||||
# }
|
||||
# ]
|
||||
# }],
|
||||
# "result": "OK"
|
||||
# }]
|
||||
# }
|
||||
|
||||
sub output_perf {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my %result = (
|
||||
code => $options{result},
|
||||
message => $options{data}->{message}
|
||||
);
|
||||
|
||||
foreach (@{$options{data}->{perf}}) {
|
||||
my $perf = defined($_->{float_value}) ? $_->{float_value} : $_->{int_value};
|
||||
my $printf_format = '%d';
|
||||
$printf_format = '%.3f' if (defined($_->{float_value}));
|
||||
|
||||
push @{$result{perf}}, {
|
||||
label => $_->{alias},
|
||||
unit => $perf->{unit},
|
||||
value => sprintf($printf_format, $perf->{value}),
|
||||
warning => defined($perf->{warning}) ? sprintf($printf_format, $perf->{warning}) : undef,
|
||||
critical => defined($perf->{critical}) ? sprintf($printf_format, $perf->{critical}) : undef,
|
||||
min => defined($perf->{minimum}) ? sprintf($printf_format, $perf->{minimum}) : undef,
|
||||
max => defined($perf->{maximum}) ? sprintf($printf_format, $perf->{maximum}) : undef,
|
||||
};
|
||||
}
|
||||
return \%result;
|
||||
}
|
||||
|
||||
sub output_noperf {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my %result = (
|
||||
code => $options{result},
|
||||
message => $options{data}->{message},
|
||||
perf => []
|
||||
);
|
||||
return \%result;
|
||||
}
|
||||
|
||||
sub format_result {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $decoded;
|
||||
eval {
|
||||
$decoded = decode_json($options{content});
|
||||
};
|
||||
if ($@) {
|
||||
$self->{output}->output_add(long_msg => $options{content}, debug => 1);
|
||||
$self->{output}->add_option_msg(short_msg => "Cannot decode response (add --debug option to display returned content)");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
my $entry = $decoded->{payload}->[0];
|
||||
$entry->{lines}->[0]->{message} =~ s/\r//msg;
|
||||
if (defined($entry->{lines}->[0]->{perf})) {
|
||||
return $self->output_perf(result => $entry->{result}, data => $entry->{lines}->[0]);
|
||||
} else {
|
||||
return $self->output_noperf(result => $entry->{result}, data => $entry->{lines}->[0]);
|
||||
}
|
||||
}
|
||||
|
||||
sub request {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->settings();
|
||||
|
||||
my $uri = URI::Encode->new({encode_reserved => 1});
|
||||
my ($encoded_args, $append) = ('', '');
|
||||
if (defined($options{arg})) {
|
||||
foreach (@{$options{arg}}) {
|
||||
$encoded_args .= $append . $uri->encode($_);
|
||||
$append = '&';
|
||||
}
|
||||
}
|
||||
|
||||
my ($content) = $self->{http}->request(url_path => '/query/' . $options{command} . '?' . $encoded_args);
|
||||
if (!defined($content) || $content eq '') {
|
||||
$self->{output}->add_option_msg(short_msg => "API returns empty content [code: '" . $self->{http}->get_code() . "'] [message: '" . $self->{http}->get_message() . "']");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
$self->{output}->output_add(long_msg => "nsclient return = " . $content, debug => 1);
|
||||
|
||||
my $result = $self->format_result(content => $content);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 NAME
|
||||
|
||||
NSClient++ Rest API
|
||||
|
||||
=head1 CUSTOM MODE OPTIONS
|
||||
|
||||
NSClient++ Rest API
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--hostname>
|
||||
|
||||
Remote hostname or IP address.
|
||||
|
||||
=item B<--port>
|
||||
|
||||
Port used (Default: 8443)
|
||||
|
||||
=item B<--proto>
|
||||
|
||||
Specify https if needed (Default: 'https')
|
||||
|
||||
=item B<--credentials>
|
||||
|
||||
Specify this option if you access webpage with authentication
|
||||
|
||||
=item B<--username>
|
||||
|
||||
Specify username for authentication (Mandatory if --credentials is specified)
|
||||
|
||||
=item B<--password>
|
||||
|
||||
Specify password for authentication (Mandatory if --credentials is specified)
|
||||
|
||||
=item B<--basic>
|
||||
|
||||
Specify this option if you access webpage over basic authentication and don't want a '401 UNAUTHORIZED' error to be logged on your webserver.
|
||||
|
||||
Specify this option if you access webpage over hidden basic authentication or you'll get a '404 NOT FOUND' error.
|
||||
|
||||
(Use with --credentials)
|
||||
|
||||
=item B<--legacy-password>
|
||||
|
||||
Specify password for old authentication system.
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Set timeout in seconds (Default: 10).
|
||||
|
||||
=item B<--unknown-status>
|
||||
|
||||
Threshold warning for http response code.
|
||||
(Default: '%{http_code} < 200 or %{http_code} >= 300')
|
||||
|
||||
=item B<--warning-status>
|
||||
|
||||
Threshold warning for http response code.
|
||||
|
||||
=item B<--critical-status>
|
||||
|
||||
Threshold critical for http response code.
|
||||
|
||||
=back
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
B<custom>.
|
||||
|
||||
=cut
|
116
apps/protocols/nrpe/mode/query.pm
Normal file
116
apps/protocols/nrpe/mode/query.pm
Normal file
@ -0,0 +1,116 @@
|
||||
#
|
||||
# Copyright 2019 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package apps::protocols::nrpe::mode::query;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments => {
|
||||
"command:s" => { name => 'command' },
|
||||
"arg:s@" => { name => 'arg' },
|
||||
"sanitize-message:s" => { name => 'sanitize_message' },
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq '') {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set --command option");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
}
|
||||
|
||||
sub sanitize_message {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{display_options}->{nolabel} = 1;
|
||||
return $options{message} unless (defined($self->{option_results}->{sanitize_message}));
|
||||
|
||||
my $message = $options{message};
|
||||
foreach my $code (('OK', 'WARNING', 'CRITICAL', 'UNKNOWN')) {
|
||||
foreach my $separator (('-', ':')) {
|
||||
if ($message =~ /^\w+\s*$code\s*$separator\s*(.*)$/) {
|
||||
delete $self->{display_options}->{nolabel};
|
||||
return $1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $message;
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $result = $options{custom}->request(
|
||||
command => $self->{option_results}->{command},
|
||||
arg => $self->{option_results}->{arg}
|
||||
);
|
||||
|
||||
$self->{output}->output_add(
|
||||
severity => $result->{code},
|
||||
short_msg => $self->sanitize_message(message => $result->{message})
|
||||
);
|
||||
|
||||
foreach (@{$result->{perf}}) {
|
||||
$self->{output}->perfdata_add(%{$_});
|
||||
}
|
||||
$self->{display_options}->{force_ignore_perfdata} = 1 if (scalar(@{$result->{perf}}) == 0);
|
||||
|
||||
$self->{output}->display(%{$self->{display_options}});
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Trigger commands against NRPE/NSClient agent.
|
||||
|
||||
=item B<--command>
|
||||
|
||||
Set command.
|
||||
|
||||
=item B<--arg>
|
||||
|
||||
Set arguments (Multiple option. Example: --arg='arg1' --arg='arg2').
|
||||
|
||||
=item B<--sanitize-message>
|
||||
|
||||
Sanitize message by removing heading code and
|
||||
separator from returned message (ie "OK - ").
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
50
apps/protocols/nrpe/plugin.pm
Normal file
50
apps/protocols/nrpe/plugin.pm
Normal file
@ -0,0 +1,50 @@
|
||||
#
|
||||
# Copyright 2019 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package apps::protocols::nrpe::plugin;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use base qw(centreon::plugins::script_custom);
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '0.1';
|
||||
%{$self->{modes}} = (
|
||||
'query' => 'apps::protocols::nrpe::mode::query',
|
||||
);
|
||||
|
||||
$self->{custom_modes}{nrpe} = 'apps::protocols::nrpe::custom::nrpe';
|
||||
$self->{custom_modes}{nsclient} = 'apps::protocols::nrpe::custom::nsclient';
|
||||
return $self;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 PLUGIN DESCRIPTION
|
||||
|
||||
Trigger commands against NRPE/NSClient agent.
|
||||
|
||||
=cut
|
179
apps/protocols/snmp/mode/responsetime.pm
Normal file
179
apps/protocols/snmp/mode/responsetime.pm
Normal file
@ -0,0 +1,179 @@
|
||||
#
|
||||
# Copyright 2019 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package apps::protocols::snmp::mode::responsetime;
|
||||
|
||||
use base qw(centreon::plugins::templates::counter);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Time::HiRes qw(gettimeofday tv_interval);
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'global', type => 0, cb_prefix_output => 'prefix_output' },
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{global} = [
|
||||
{ label => 'rta', set => {
|
||||
key_values => [ { name => 'rta' } ],
|
||||
output_template => 'rta %.3fms',
|
||||
perfdatas => [
|
||||
{ label => 'rta', value => 'rta_absolute', template => '%.3f', min => 0, unit => 'ms' },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'rtmax', display_ok => 0, set => {
|
||||
key_values => [ { name => 'rtmax' } ],
|
||||
perfdatas => [
|
||||
{ label => 'rtmax', value => 'rtmax_absolute', template => '%.3f', min => 0, unit => 'ms' },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'rtmin', display_ok => 0, set => {
|
||||
key_values => [ { name => 'rtmin' } ],
|
||||
perfdatas => [
|
||||
{ label => 'rtmin', value => 'rtmin_absolute', template => '%.3f', min => 0, unit => 'ms' },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'pl', set => {
|
||||
key_values => [ { name => 'pl' } ],
|
||||
output_template => 'lost %s%%',
|
||||
perfdatas => [
|
||||
{ label => 'pl', value => 'pl_absolute', template => '%s', min => 0, max => 100, unit => '%' },
|
||||
],
|
||||
}
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
sub prefix_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "SNMP Agent ";
|
||||
}
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments => {
|
||||
"timeout:s" => { name => 'timeout' },
|
||||
"packets:s" => { name => 'packets' },
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::check_options(%options);
|
||||
|
||||
$self->{option_timeout} = 5;
|
||||
$self->{option_packets} = 5;
|
||||
if (defined($self->{option_results}->{timeout}) && $self->{option_results}->{timeout} =~ /(\d+)/) {
|
||||
$self->{option_timeout} = $1;
|
||||
}
|
||||
if (defined($self->{option_results}->{packets}) && $self->{option_results}->{packets} =~ /(\d+)/) {
|
||||
$self->{option_packets} = $1;
|
||||
}
|
||||
|
||||
$options{snmp}->set_snmp_connect_params(Timeout => $self->{option_timeout} * (10**6));
|
||||
$options{snmp}->set_snmp_connect_params(Retries => 0);
|
||||
$options{snmp}->set_snmp_params(subsetleef => 1);
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $sysDescr = ".1.3.6.1.2.1.1.1.0";
|
||||
my $total_time_elapsed = 0;
|
||||
my $max_time_elapsed = 0;
|
||||
my $min_time_elapsed = 0;
|
||||
my $total_packet_lost = 0;
|
||||
for (my $i = 0; $i < $self->{option_packets}; $i++) {
|
||||
my $timing0 = [gettimeofday];
|
||||
my $return = $options{snmp}->get_leef(oids => [$sysDescr], nothing_quit => 0, dont_quit => 1);
|
||||
my $timeelapsed = tv_interval($timing0, [gettimeofday]);
|
||||
|
||||
if (!defined($return)) {
|
||||
$total_packet_lost++;
|
||||
} else {
|
||||
$total_time_elapsed += $timeelapsed;
|
||||
$max_time_elapsed = $timeelapsed if ($timeelapsed > $max_time_elapsed);
|
||||
$min_time_elapsed = $timeelapsed if ($timeelapsed < $min_time_elapsed || $min_time_elapsed == 0);
|
||||
}
|
||||
}
|
||||
|
||||
$self->{global} = {
|
||||
rta => $total_time_elapsed * 1000 / $self->{option_packets},
|
||||
rtmax => $max_time_elapsed * 1000,
|
||||
rtmin => $min_time_elapsed * 1000,
|
||||
pl => int($total_packet_lost * 100 / $self->{option_packets}),
|
||||
};
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check SNMP agent response time.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--filter-counters>
|
||||
|
||||
Only display some counters (regexp can be used).
|
||||
Example : --filter-counters='rta'
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Set timeout in seconds (Default: 5).
|
||||
|
||||
=item B<--packets>
|
||||
|
||||
Number of packets to send (Default: 5).
|
||||
|
||||
=item B<--warning-rta>
|
||||
|
||||
Response time threshold warning in milliseconds
|
||||
|
||||
=item B<--critical-rta>
|
||||
|
||||
Response time threshold critical in milliseconds
|
||||
|
||||
=item B<--warning-pl>
|
||||
|
||||
Packets lost threshold warning in %
|
||||
|
||||
=item B<--critical-pl>
|
||||
|
||||
Packets lost threshold critical in %
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
@ -33,6 +33,7 @@ sub new {
|
||||
%{$self->{modes}} = (
|
||||
'dynamic-command' => 'snmp_standard::mode::dynamiccommand',
|
||||
'numeric-value' => 'snmp_standard::mode::numericvalue',
|
||||
'response-time' => 'apps::protocols::snmp::mode::responsetime',
|
||||
'string-value' => 'snmp_standard::mode::stringvalue',
|
||||
'uptime' => 'snmp_standard::mode::uptime',
|
||||
);
|
||||
|
@ -34,8 +34,7 @@ sub new {
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
$options{options}->add_options(arguments => {
|
||||
"scenario:s" => { name => 'scenario' },
|
||||
"warning:s" => { name => 'warning' },
|
||||
"critical:s" => { name => 'critical' },
|
||||
@ -55,7 +54,7 @@ sub check_options {
|
||||
# {"cmd": "open", "options": { "Host": "10.0.0.1", "Port": "23", "Timeout": "30" } },
|
||||
# {"cmd": "login", "options": { "Name": "admin", "Password": "pass", "Timeout": "5" } },
|
||||
# {"cmd": "waitfor", "options": { "Match": "/string/", "Timeout": "5" } },
|
||||
# {"cmd": "put", "options": { "String": "/mystring/", "Timeout": "5" } },
|
||||
# {"cmd": "put", "options": { "String": "mystring", "Timeout": "5" } },
|
||||
# {"cmd": "close" }
|
||||
#]
|
||||
if (!defined($self->{option_results}->{scenario})) {
|
||||
|
262
apps/protocols/tftp/mode/commands.pm
Normal file
262
apps/protocols/tftp/mode/commands.pm
Normal file
@ -0,0 +1,262 @@
|
||||
#
|
||||
# Copyright 2019 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package apps::protocols::tftp::mode::commands;
|
||||
|
||||
use base qw(centreon::plugins::templates::counter);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold);
|
||||
use Net::TFTP;
|
||||
use Time::HiRes qw(gettimeofday tv_interval);
|
||||
|
||||
sub custom_status_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $msg = "status '" . $self->{result_values}->{status} . "'";
|
||||
return $msg;
|
||||
}
|
||||
|
||||
sub custom_status_calc {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'};
|
||||
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'command', type => 1, cb_prefix_output => 'prefix_command_output', message_multiple => 'All commands are ok' }
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{command} = [
|
||||
{ label => 'status', threshold => 0, set => {
|
||||
key_values => [ { name => 'status' }, { name => 'display' } ],
|
||||
closure_custom_calc => $self->can('custom_status_calc'),
|
||||
closure_custom_output => $self->can('custom_status_output'),
|
||||
closure_custom_perfdata => sub { return 0; },
|
||||
closure_custom_threshold_check => \&catalog_status_threshold
|
||||
}
|
||||
},
|
||||
{ label => 'time', display_ok => 0, set => {
|
||||
key_values => [ { name => 'timeelapsed' }, { name => 'display' } ],
|
||||
output_template => 'response time %.3fs',
|
||||
perfdatas => [
|
||||
{ label => 'time', value => 'timeelapsed_absolute', template => '%.3f',
|
||||
min => 0, unit => 's', label_extra_instance => 1, instance_use => 'display_absolute' },
|
||||
],
|
||||
}
|
||||
},
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments => {
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"port:s" => { name => 'port', default => 69 },
|
||||
"timeout:s" => { name => 'timeout', default => 5 },
|
||||
"retries:s" => { name => 'retries', default => 5 },
|
||||
"block-size:s" => { name => 'block_size', default => 512 },
|
||||
"warning-status:s" => { name => 'warning_status', default => '' },
|
||||
"critical-status:s" => { name => 'critical_status', default => '%{status} ne "ok"' },
|
||||
"command:s@" => { name => 'command' },
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::check_options(%options);
|
||||
|
||||
$self->change_macros(macros => ['warning_status', 'critical_status']);
|
||||
|
||||
if (!defined($self->{option_results}->{hostname}) || $self->{option_results}->{hostname} eq '') {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set the --hostname option");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
$self->{option_results}->{command} = []
|
||||
if (!defined($self->{option_results}->{command}));
|
||||
}
|
||||
|
||||
sub prefix_command_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Command '" . $options{instance_value}->{display} . "' ";
|
||||
}
|
||||
|
||||
sub put_command {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $status = 'ok';
|
||||
if (!$options{tftp}->put($options{localfile}, $options{remotefile})) {
|
||||
$status = $options{tftp}->error;
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
sub get_command {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my ($status, $stdout);
|
||||
{
|
||||
local *STDOUT;
|
||||
open STDOUT, '>', \$stdout;
|
||||
|
||||
if (!$options{tftp}->get($options{remotefile}, \*STDOUT)) {
|
||||
$status = $options{tftp}->error;
|
||||
} else {
|
||||
$status = 'ok';
|
||||
}
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $tftp = Net::TFTP->new(
|
||||
$self->{option_results}->{hostname},
|
||||
Timeout => $self->{option_results}->{timeout},
|
||||
Retries => $self->{option_results}->{retries},
|
||||
Port => $self->{option_results}->{port},
|
||||
BlockSize => $self->{option_results}->{block_size},
|
||||
);
|
||||
|
||||
$self->{command} = {};
|
||||
my $i = 0;
|
||||
foreach (@{$self->{option_results}->{command}}) {
|
||||
my ($label, $command, $arg1, $arg2) = split /,/;
|
||||
|
||||
if (!defined($command) || $command !~ /(put|get)/) {
|
||||
$self->{output}->add_option_msg(short_msg => "Unknown command. Please use 'get' or 'put' command name");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
$i++;
|
||||
$command = $1;
|
||||
$label = $i
|
||||
if (!defined($label) || $label eq '');
|
||||
if (!defined($arg1) || $arg1 eq '') {
|
||||
$self->{output}->add_option_msg(short_msg => "Unknown first argument. first argument is required.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
if ($command eq 'put' && (!defined($arg2) || $arg2 eq '')) {
|
||||
$self->{output}->add_option_msg(short_msg => "Unknown second argument. second argument is required for 'put' command.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
my $status;
|
||||
my $timing0 = [gettimeofday];
|
||||
if ($command eq 'put') {
|
||||
$status = $self->put_command(tftp => $tftp, localfile => $arg1, remotefile => $arg2);
|
||||
} else {
|
||||
$status = $self->get_command(tftp => $tftp, remotefile => $arg1);
|
||||
}
|
||||
my $timeelapsed = tv_interval($timing0, [gettimeofday]);
|
||||
|
||||
$self->{command}->{$i} = {
|
||||
display => $label,
|
||||
status => $status,
|
||||
timeelapsed => $timeelapsed,
|
||||
};
|
||||
}
|
||||
|
||||
if (scalar(keys %{$self->{command}}) <= 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "No command found.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check tftp commands.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--hostname>
|
||||
|
||||
TFTP server name (required).
|
||||
|
||||
=item B<--port>
|
||||
|
||||
TFTP port (Default: 69).
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
TFTP timeout in seconds (Default: 5).
|
||||
|
||||
=item B<--retries>
|
||||
|
||||
TFTP number of retries (Default: 5).
|
||||
|
||||
=item B<--block-size>
|
||||
|
||||
TFTP size of blocks to use in the transfer (Default: 512).
|
||||
|
||||
=item B<--filter-counters>
|
||||
|
||||
Only display some counters (regexp can be used).
|
||||
Example: --filter-counters='^status$'
|
||||
|
||||
=item B<--warning-status>
|
||||
|
||||
Set warning threshold for status (Default: '').
|
||||
Can used special variables like: %{status}, %{display}
|
||||
|
||||
=item B<--critical-status>
|
||||
|
||||
Set critical threshold for status (Default: '%{status} ne "ok"').
|
||||
Can used special variables like: %{status}, %{display}
|
||||
|
||||
=item B<--warning-time>
|
||||
|
||||
Threshold warning.
|
||||
|
||||
=item B<--critical-time>
|
||||
|
||||
Threshold critical.
|
||||
|
||||
=item B<--command>
|
||||
|
||||
TFP command.
|
||||
Example: --command='labeldisplay,get,remotefile' --command='labeldisplay2,put,localfile,remotefile"
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
48
apps/protocols/tftp/plugin.pm
Normal file
48
apps/protocols/tftp/plugin.pm
Normal file
@ -0,0 +1,48 @@
|
||||
#
|
||||
# Copyright 2019 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package apps::protocols::tftp::plugin;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use base qw(centreon::plugins::script_simple);
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '0.1';
|
||||
%{$self->{modes}} = (
|
||||
'commands' => 'apps::protocols::tftp::mode::commands',
|
||||
);
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 PLUGIN DESCRIPTION
|
||||
|
||||
Check an TFTP server.
|
||||
|
||||
=cut
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user