Merge remote-tracking branch 'origin/master' into (wip)parity-blockchain-monitoring

get per_minute option
This commit is contained in:
Lotfi zaouche 2020-05-20 08:10:05 +00:00
commit 703a7f201a
336 changed files with 22942 additions and 3475 deletions

View File

@ -1,3 +1,5 @@
properties([buildDiscarder(logRotator(numToKeepStr: '50'))])
stage('Source') {
node {
sh 'setup_centreon_build.sh'

View File

@ -31,8 +31,7 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold)
sub custom_status_output {
my ($self, %options) = @_;
my $msg = sprintf("Updates status is '%s'", $self->{result_values}->{status});
return $msg;
return sprintf("Updates status is '%s'", $self->{result_values}->{status});
}
sub custom_status_calc {
@ -45,26 +44,34 @@ sub custom_status_calc {
sub custom_last_perfdata {
my ($self, %options) = @_;
$self->{output}->perfdata_add(label => 'last_server_update',
value => $self->{result_values}->{diff},
unit => 's',
min => 0);
$self->{output}->perfdata_add(
label => 'last_server_update',
value => $self->{result_values}->{diff},
unit => 's',
min => 0
);
}
sub custom_last_threshold {
my ($self, %options) = @_;
my $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{diff},
threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' },
{ label => 'warning-' . $self->{label}, exit_litteral => 'warning' } ]);
my $exit = $self->{perfdata}->threshold_check(
value => $self->{result_values}->{diff},
threshold => [
{ label => 'critical-' . $self->{label}, exit_litteral => 'critical' },
{ label => 'warning-' . $self->{label}, exit_litteral => 'warning' }
]
);
return $exit;
}
sub custom_last_output {
my ($self, %options) = @_;
my $msg = sprintf("Last server update: %s [%s]", centreon::plugins::misc::change_seconds(value => $self->{result_values}->{diff}), $self->{result_values}->{date_time});
return $msg;
return sprintf(
'Last server update: %s [%s]',
centreon::plugins::misc::change_seconds(value => $self->{result_values}->{diff}), $self->{result_values}->{date_time}
);
}
sub custom_last_calc {
@ -80,7 +87,7 @@ sub custom_last_calc {
hour => $4,
minute => $5,
second => $6,
%{$self->{tz}}
%{$self->{instance_mode}->{tz}}
);
$self->{result_values}->{diff} = time() - $dt->epoch;
$self->{result_values}->{date_time} = $dt->datetime();
@ -93,7 +100,7 @@ sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0, message_separator => ' - ' },
{ name => 'global', type => 0, message_separator => ' - ' }
];
$self->{maps_counters}->{global} = [
@ -102,7 +109,7 @@ sub set_counters {
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,
closure_custom_threshold_check => \&catalog_status_threshold
}
},
{ label => 'last-server-update', set => {
@ -110,17 +117,17 @@ sub set_counters {
closure_custom_calc => $self->can('custom_last_calc'),
closure_custom_output => $self->can('custom_last_output'),
closure_custom_threshold_check => $self->can('custom_last_threshold'),
closure_custom_perfdata => $self->can('custom_last_perfdata'),
closure_custom_perfdata => $self->can('custom_last_perfdata')
}
},
{ label => 'not-updated', set => {
key_values => [ { name => 'hostsNotUpdated' } ],
output_template => '%d host(s) not up to date',
perfdatas => [
{ label => 'not_updated', value => 'hostsNotUpdated_absolute', template => '%d', min => 0 },
],
{ label => 'not_updated', value => 'hostsNotUpdated_absolute', template => '%d', min => 0 }
]
}
},
}
];
}
@ -129,12 +136,12 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$options{options}->add_options(arguments =>
{
"warning-status:s" => { name => 'warning_status', default => '%{status} =~ /Warning/i' },
"critical-status:s" => { name => 'critical_status', default => '%{status} =~ /Critical/i' },
"timezone:s" => { name => 'timezone', default => 'GMT' },
});
$options{options}->add_options(arguments => {
'warning-status:s' => { name => 'warning_status', default => '%{status} =~ /Warning/i' },
'critical-status:s' => { name => 'critical_status', default => '%{status} =~ /Critical/i' },
'timezone:s' => { name => 'timezone', default => 'GMT' }
});
return $self;
}
@ -146,12 +153,12 @@ sub check_options {
$self->change_macros(macros => ['warning_status', 'critical_status']);
}
my %map_status = (
my $map_status = {
0 => 'OK',
1 => 'Info',
2 => 'Warning',
3 => 'Critical',
);
3 => 'Critical'
};
my $oid_updatesStatus = '.1.3.6.1.4.1.23668.1093.1.2.1';
my $oid_lastServerUpdateTime = '.1.3.6.1.4.1.23668.1093.1.2.3';
@ -160,14 +167,16 @@ my $oid_hostsNotUpdated = '.1.3.6.1.4.1.23668.1093.1.2.4';
sub manage_selection {
my ($self, %options) = @_;
my $snmp_result = $options{snmp}->get_leef(oids => [ $oid_updatesStatus, $oid_lastServerUpdateTime,
$oid_hostsNotUpdated ],
nothing_quit => 1);
$self->{global} = {};
my $snmp_result = $options{snmp}->get_leef(
oids => [
$oid_updatesStatus, $oid_lastServerUpdateTime,
$oid_hostsNotUpdated
],
nothing_quit => 1
);
$self->{global} = {
updatesStatus => $map_status{$snmp_result->{$oid_updatesStatus}},
updatesStatus => $map_status->{$snmp_result->{$oid_updatesStatus}},
lastServerUpdateTime => $snmp_result->{$oid_lastServerUpdateTime},
hostsNotUpdated => $snmp_result->{$oid_hostsNotUpdated},
};

View File

@ -0,0 +1,183 @@
#
# Copyright 2020 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::bluemind::local::custom::api;
use strict;
use warnings;
use centreon::plugins::ssh;
use centreon::plugins::misc;
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' },
'timeout:s' => { name => 'timeout', default => 30 },
'sudo' => { name => 'sudo' },
'command:s' => { name => 'command' },
'command-path:s' => { name => 'command_path' },
'command-options:s' => { name => 'command_options' }
});
}
$options{options}->add_help(package => __PACKAGE__, sections => 'BLUEMIND OPTIONS', once => 1);
$self->{output} = $options{output};
$self->{mode} = $options{mode};
$self->{ssh} = centreon::plugins::ssh->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 get_hostname {
my ($self, %options) = @_;
return defined($self->{option_results}->{hostname}) ? $self->{option_results}->{hostname} : 'local';
}
sub check_options {
my ($self, %options) = @_;
if (defined($self->{option_results}->{hostname}) && $self->{option_results}->{hostname} ne '') {
$self->{ssh}->check_options(option_results => $self->{option_results});
}
return 0;
}
sub execute_command {
my ($self, %options) = @_;
my $content;
if (defined($self->{option_results}->{hostname}) && $self->{option_results}->{hostname} ne '') {
($content) = $self->{ssh}->execute(
hostname => $self->{option_results}->{hostname},
command => defined($self->{option_results}->{command}) && $self->{option_results}->{command} ne '' ? $self->{option_results}->{command} : $options{command},
command_path => $self->{option_results}->{command_path},
command_options => defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '' ? $self->{option_results}->{command_options} : undef,
timeout => $self->{option_results}->{timeout},
sudo => $self->{option_results}->{sudo}
);
} else {
($content) = centreon::plugins::misc::execute(
output => $self->{output},
options => { timeout => $self->{option_results}->{timeout} },
sudo => $self->{option_results}->{sudo},
command => defined($self->{option_results}->{command}) && $self->{option_results}->{command} ne '' ? $self->{option_results}->{command} : $options{command},
command_path => $self->{option_results}->{command_path},
command_options => defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '' ? $self->{option_results}->{command_options} : undef
);
}
my $results = {};
foreach (split /\n/, $content) {
next if (! /$options{filter}/);
my ($key, $value_str) = split /\s/;
foreach my $value (split /,/, $value_str) {
my ($field1, $field2) = split /=/, $value;
$results->{$key}->{$field1} = $field2;
}
}
return $results;
}
1;
__END__
=head1 NAME
bluemind
=head1 SYNOPSIS
bluemind
=head1 BLUEMIND OPTIONS
=over 8
=item B<--hostname>
Hostname to query.
=item B<--timeout>
Timeout in seconds for the command (Default: 30).
=item B<--sudo>
Use 'sudo' to execute the command.
=item B<--command>
Command to get information. Used it you have output in a file.
=item B<--command-path>
Command path.
=item B<--command-options>
Command options.
=back
=head1 DESCRIPTION
B<custom>.
=cut

View File

@ -0,0 +1,158 @@
#
# Copyright 2020 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::bluemind::local::mode::core;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
use bigint;
sub prefix_core_output {
my ($self, %options) = @_;
return 'Main engine ';
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'bm_core', type => 0, cb_prefix_output => 'prefix_core_output' }
];
$self->{maps_counters}->{bm_core} = [
{ label => 'calls-received-success', nlabel => 'core.calls.received.success.count', display_ok => 0, set => {
key_values => [ { name => 'calls_success', diff => 1 } ],
output_template => 'success calls received: %s',
perfdatas => [
{ value => 'calls_success_absolute', template => '%s', min => 0 }
]
}
},
{ label => 'calls-received-failed', nlabel => 'core.calls.received.failure.count', set => {
key_values => [ { name => 'calls_failure', diff => 1 } ],
output_template => 'failure calls received: %s',
perfdatas => [
{ value => 'calls_failure_absolute', template => '%s', min => 0 }
]
}
},
{ label => 'heartbeat-broadcast', nlabel => 'core.heartbeat.broadcast.running.count', display_ok => 0, set => {
key_values => [ { name => 'heartbeat_broadcast', diff => 1 } ],
output_template => 'broadcast heartbeat running: %s',
perfdatas => [
{ value => 'heartbeat_broadcast_absolute', template => '%s', min => 0 }
]
}
},
{ label => 'directory-cluster-events', nlabel => 'core.directory.cluster.events.count', display_ok => 0, set => {
key_values => [ { name => 'cluster_events', diff => 1 } ],
output_template => 'directory cluster events: %s',
perfdatas => [
{ value => 'cluster_events_absolute', template => '%s', min => 0 }
]
}
},
{ label => 'request-handling-total', nlabel => 'core.request.handling.total.milliseconds', set => {
key_values => [ { name => 'request_handling_time_total', diff => 1 } ],
output_template => 'total request handling: %s ms',
perfdatas => [
{ value => 'request_handling_time_total_absolute', template => '%s', min => 0, unit => 'ms' }
]
}
},
{ label => 'request-handling-mean', nlabel => 'core.request.handling.mean.milliseconds', display_ok => 0, set => {
key_values => [ { name => 'request_handling_time_mean' } ],
output_template => 'mean request handling: %s ms',
perfdatas => [
{ value => 'request_handling_time_mean_absolute', template => '%s', min => 0, unit => 'ms' }
]
}
}
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
});
return $self;
}
sub manage_selection {
my ($self, %options) = @_;
# bm-core.heartbeat.broadcast,state=core.state.running,meterType=Counter count=1854550
# bm-core.handlingDuration,meterType=Timer count=695244256,totalTime=1911292590914929,mean=2749095
# bm-core.callsCount,status=failure,meterType=Counter count=97
# bm-core.callsCount,status=success,meterType=Counter count=125244086
# bm-core.directory.cluster.events,meterType=Counter count=14300
my $result = $options{custom}->execute_command(
command => 'curl --unix-socket /var/run/bm-metrics/metrics-bm-core.sock http://127.0.0.1/metrics',
filter => 'bm-core\.heartbeat\.broadcast|bm-core\.handlingDuration|bm-core\.callsCount|bm-core\.directory\.cluster\.events'
);
$self->{bm_core} = {};
foreach (keys %$result) {
$self->{bm_core}->{'calls_' . $1} = $result->{$_}->{count} if (/bm-core.callsCount.*status=(failure|success)/);
$self->{bm_core}->{cluster_events} = $result->{$_}->{count} if (/bm-core\.directory\.cluster\.events/);
if (/bm-core\.handlingDuration/) { # in nanoseconds
$self->{bm_core}->{request_handling_time_total} = $result->{$_}->{totalTime} / 1000000;
$self->{bm_core}->{request_handling_time_mean} = $result->{$_}->{mean} / 1000000;
}
$self->{bm_core}->{heartbeat_broadcast} = $result->{$_}->{count} if (/bm-core\.heartbeat\.broadcast.*running/);
}
$self->{cache_name} = 'bluemind_' . $self->{mode} . '_' . $options{custom}->get_hostname() . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
}
1;
__END__
=head1 MODE
Check main bluemind engine.
=over 8
=item B<--filter-counters>
Only display some counters (regexp can be used).
Example: --filter-counters='^calls'
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'calls-received-success', 'calls-received-failed',
'heartbeat-broadcast', 'directory-cluster-events',
'request-handling-total', 'request-handling-mean'.
=back
=cut

View File

@ -0,0 +1,128 @@
#
# Copyright 2020 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::bluemind::local::mode::eas;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
use bigint;
sub prefix_eas_output {
my ($self, %options) = @_;
return 'Mobile connection service ';
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'bm_eas', type => 0, cb_prefix_output => 'prefix_eas_output' }
];
$self->{maps_counters}->{bm_eas} = [
{ label => 'responses-size-total', nlabel => 'eas.responses.size.total.bytes', display_ok => 0, set => {
key_values => [ { name => 'response_size', diff => 1 } ],
output_template => 'total responses size: %s %s',
output_change_bytes => 1,
perfdatas => [
{ value => 'response_size_absolute', template => '%s', min => 0, unit => 'B' }
]
}
},
{ label => 'execution-total', nlabel => 'eas.execution.total.milliseconds', display_ok => 0, set => {
key_values => [ { name => 'execution_total', diff => 1 } ],
output_template => 'total execution: %s ms',
perfdatas => [
{ value => 'execution_total_absolute', template => '%s', min => 0, unit => 'ms' }
]
}
},
{ label => 'execution-mean', nlabel => 'eas.execution.mean.milliseconds', set => {
key_values => [ { name => 'execution_mean' } ],
output_template => 'mean execution: %s ms',
perfdatas => [
{ value => 'execution_mean_absolute', template => '%s', min => 0, unit => 'ms' }
]
}
}
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
});
return $self;
}
sub manage_selection {
my ($self, %options) = @_;
# bm-eas.executionTime,meterType=Timer count=23865528,totalTime=48394780739993049,mean=2027811022
# bm-eas.responseSize,meterType=DistSum count=31508001,totalAmount=736453775233,mean=23373
my $result = $options{custom}->execute_command(
command => 'curl --unix-socket /var/run/bm-metrics/metrics-bm-eas.sock http://127.0.0.1/metrics',
filter => 'executionTime|responseSize'
);
$self->{bm_eas} = {};
foreach (keys %$result) {
$self->{bm_eas}->{response_size} = $result->{$_}->{totalAmount} if (/bm-eas.responseSize/);
if (/bm-eas\.executionTime/) {
$self->{bm_eas}->{execution_total} = $result->{$_}->{totalTime} / 100000;
$self->{bm_eas}->{execution_mean} = $result->{$_}->{mean} / 100000;
}
}
$self->{cache_name} = 'bluemind_' . $self->{mode} . '_' . $options{custom}->get_hostname() . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
}
1;
__END__
=head1 MODE
Check mobile connection service.
=over 8
=item B<--filter-counters>
Only display some counters (regexp can be used).
Example: --filter-counters='^execution'
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'responses-size-total', 'execution-total', 'execution-mean'.
=back
=cut

View File

@ -0,0 +1,205 @@
#
# Copyright 2020 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::bluemind::local::mode::hps;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
use bigint;
sub prefix_hps_output {
my ($self, %options) = @_;
return 'Authentication service ';
}
sub prefix_upstream_output {
my ($self, %options) = @_;
return "Upstream '" . $options{instance_value}->{display} . "' ";
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'bm_hps', type => 0, cb_prefix_output => 'prefix_hps_output' },
{ name => 'bm_hps_upstream', type => 1, cb_prefix_output => 'prefix_upstream_output', message_multiple => 'All upstreams are ok' }
];
$self->{maps_counters}->{bm_hps} = [
{ label => 'authentication-success', nlabel => 'hps.authentication.success.count', display_ok => 0, set => {
key_values => [ { name => 'auth_success', diff => 1 } ],
output_template => 'success authentication: %s',
perfdatas => [
{ value => 'auth_success_absolute', template => '%s', min => 0 }
]
}
},
{ label => 'authentication-failure', nlabel => 'hps.authentication.failure.count', set => {
key_values => [ { name => 'auth_failure', diff => 1 } ],
output_template => 'failure authentication: %s',
perfdatas => [
{ value => 'auth_failure_absolute', template => '%s', min => 0 }
]
}
},
{ label => 'requests-protected', nlabel => 'hps.requests.protected.count', display_ok => 0, set => {
key_values => [ { name => 'requests_protected', diff => 1 } ],
output_template => 'protected requests: %s',
perfdatas => [
{ value => 'requests_protected_absolute', template => '%s', min => 0 }
]
}
},
{ label => 'requests-maintenance', nlabel => 'hps.requests.maintenance.count', set => {
key_values => [ { name => 'requests_maintenance', diff => 1 } ],
output_template => 'maintenance requests: %s',
perfdatas => [
{ value => 'requests_maintenance_absolute', template => '%s', min => 0 }
]
}
}
];
$self->{maps_counters}->{bm_hps_upstream} = [
{ label => 'upstream-requests-time-total', nlabel => 'hps.upstream.requests.time.milliseconds', display_ok => 0, set => {
key_values => [ { name => 'requests_time_total', diff => 1 }, { name => 'display' } ],
output_template => 'total requests time: %s ms',
perfdatas => [
{ value => 'requests_time_total_absolute', template => '%s', min => 0, unit => 'ms', label_extra_instance => 1 }
]
}
},
{ label => 'upstream-requests-time-mean', nlabel => 'hps.upstream.requests.time.mean.milliseconds', set => {
key_values => [ { name => 'requests_time_mean' }, { name => 'display' } ],
output_template => 'mean requests time: %s ms',
perfdatas => [
{ value => 'requests_time_mean_absolute', template => '%s', min => 0, unit => 'ms', label_extra_instance => 1 }
]
}
},
{ label => 'upstream-requests-size-total', nlabel => 'hps.upstream.requests.size.total.bytes', display_ok => 0, set => {
key_values => [ { name => 'requests_size', diff => 1 } ],
output_template => 'total requests size: %s %s',
output_change_bytes => 1,
perfdatas => [
{ value => 'requests_size_absolute', template => '%s', min => 0, unit => 'B' }
]
}
},
{ label => 'upstream-requests-total', nlabel => 'hps.upstream.requests.total.count', display_ok => 0, set => {
key_values => [ { name => 'requests', diff => 1 } ],
output_template => 'total requests: %s',
perfdatas => [
{ value => 'requests_absolute', template => '%s', min => 0 }
]
}
}
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
'filter-upstream:s' => { name => 'filter_upstream' }
});
return $self;
}
sub manage_selection {
my ($self, %options) = @_;
# bm-hps.authCount,status=failure,meterType=Counter count=855
# bm-hps.authCount,status=success,meterType=Counter count=11957
# bm-hps.ftlTemplates.requests,meterType=Counter count=23064
# bm-hps.requestsCount,kind=protected,meterType=Counter count=3080815
# bm-hps.requestsCount,kind=maintenance,meterType=Counter count=1
# bm-hps.upstreamRequestSize,path=/login,meterType=DistSum count=331977,totalAmount=0,mean=0
# bm-hps.upstreamRequestTime,path=/login,meterType=Timer count=37864,totalTime=70405376220,mean=1859427
# bm-hps.upstreamRequestsCount,path=/login,meterType=Counter count=1383
my $result = $options{custom}->execute_command(
command => 'curl --unix-socket /var/run/bm-metrics/metrics-bm-hps.sock http://127.0.0.1/metrics',
filter => 'authCount|ftlTemplates\.requests|requestsCount|upstreamRequestSize|upstreamRequestTime|upstreamRequestsCount'
);
$self->{bm_hps} = {};
$self->{bm_hps_upstream} = {};
foreach (keys %$result) {
$self->{bm_hps}->{'auth_' . $1} = $result->{$_}->{count} if (/bm-hps\.authCount.*status=(failure|success)/);
$self->{bm_hps}->{'requests_' . $1} = $result->{$_}->{count} if (/bm-hps\.requestsCount.*kind=(maintenance|protected)/);
if (/bm-hps\.upstreamRequestTime.*path=(.*?),/) {
my $upstream = $1;
if (defined($self->{option_results}->{filter_upstream}) && $self->{option_results}->{filter_upstream} ne '' &&
$upstream !~ /$self->{option_results}->{filter_upstream}/) {
$self->{output}->output_add(long_msg => "skipping upstream '" . $upstream . "': no matching filter.", debug => 1);
next;
}
$self->{bm_hps_upstream}->{$upstream} = {
display => $upstream,
requests_time_total => $result->{$_}->{totalTime} / 100000,
requests_time_mean => $result->{$_}->{mean} / 100000,
requests_size => $result->{"bm-hps.upstreamRequestSize,path=$upstream,meterType=DistSum"}->{totalAmount},
requests => $result->{"bm-hps.upstreamRequestsCount,path=$upstream,meterType=Counter"}->{count}
};
}
}
$self->{cache_name} = 'bluemind_' . $self->{mode} . '_' . $options{custom}->get_hostname() . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
}
1;
__END__
=head1 MODE
Check authentication service.
=over 8
=item B<--filter-counters>
Only display some counters (regexp can be used).
Example: --filter-counters='maintenance'
=item B<--filter-upstream>
Filter upstream name (can be a regexp).
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'authentication-success', 'authentication-failure', 'requests-protected',
'requests-maintenance', 'upstream-requests-time-total', 'upstream-requests-time-mean',
'upstream-requests-size-total, 'upstream-requests-total'.
=back
=cut

View File

@ -0,0 +1,96 @@
#
# Copyright 2020 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::bluemind::local::mode::ips;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
sub prefix_ips_output {
my ($self, %options) = @_;
return 'IMAP operations tracking ';
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'bm_ips', type => 0, cb_prefix_output => 'prefix_ips_output' }
];
$self->{maps_counters}->{bm_ips} = [
{ label => 'connections-active', nlabel => 'ips.connections.active.count', set => {
key_values => [ { name => 'active_connections' } ],
output_template => 'active connections: %s',
perfdatas => [
{ value => 'active_connections_absolute', template => '%s', min => 0 }
]
}
}
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
});
return $self;
}
sub manage_selection {
my ($self, %options) = @_;
# bm-ips.activeConnections,meterType=Gauge value=718
my $result = $options{custom}->execute_command(
command => 'curl --unix-socket /var/run/bm-metrics/metrics-bm-ips.sock http://127.0.0.1/metrics',
filter => 'activeConnections'
);
$self->{bm_ips} = {};
foreach (keys %$result) {
$self->{bm_ips}->{active_connections} = $result->{$_}->{value} if (/bm-ips\.activeConnections/);
}
}
1;
__END__
=head1 MODE
Check IMAP operations tracking.
=over 8
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'active-connections'.
=back
=cut

View File

@ -0,0 +1,191 @@
#
# Copyright 2020 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::bluemind::local::mode::lmtpd;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
use bigint;
sub prefix_lmtpd_output {
my ($self, %options) = @_;
return 'Email delivery service ';
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'bm_lmtpd', type => 0, cb_prefix_output => 'prefix_lmtpd_output' }
];
$self->{maps_counters}->{bm_lmtpd} = [
{ label => 'connections-active', nlabel => 'lmtpd.connections.active.count', set => {
key_values => [ { name => 'active_connections' } ],
output_template => 'active connections: %s',
perfdatas => [
{ value => 'active_connections_absolute', template => '%s', min => 0 }
]
}
},
{ label => 'connections-total', nlabel => 'lmtpd.connections.total.count', display_ok => 0, set => {
key_values => [ { name => 'connections', diff => 1 } ],
output_template => 'total connections: %s',
perfdatas => [
{ value => 'connections_absolute', template => '%s', min => 0 }
]
}
},
{ label => 'deliveries-success', nlabel => 'lmtpd.deliveries.success.count', display_ok => 0, set => {
key_values => [ { name => 'deliveries_ok', diff => 1 } ],
output_template => 'success deliveries: %s',
perfdatas => [
{ value => 'deliveries_ok_absolute', template => '%s', min => 0 }
]
}
},
{ label => 'deliveries-failure', nlabel => 'lmtpd.deliveries.failure.count', display_ok => 0, set => {
key_values => [ { name => 'deliveries_ko', diff => 1 } ],
output_template => 'failure deliveries: %s',
perfdatas => [
{ value => 'deliveries_ko_absolute', template => '%s', min => 0 }
]
}
},
{ label => 'emails-size-total', nlabel => 'lmtpd.emails.size.total.bytes', display_ok => 0, set => {
key_values => [ { name => 'email_size', diff => 1 } ],
output_template => 'total emails size: %s %s',
output_change_bytes => 1,
perfdatas => [
{ value => 'email_size_absolute', template => '%s', min => 0, unit => 'B' }
]
}
},
{ label => 'sessions-duration-total', nlabel => 'lmtpd.sessions.duration.total.milliseconds', set => {
key_values => [ { name => 'session_duration_total', diff => 1 } ],
output_template => 'total sessions duration: %s ms',
perfdatas => [
{ value => 'session_duration_total_absolute', template => '%s', min => 0, unit => 'ms' }
]
}
},
{ label => 'sessions-duration-mean', nlabel => 'lmtpd.sessions.duration.mean.milliseconds', set => {
key_values => [ { name => 'session_duration_mean' } ],
output_template => 'mean sessions duration: %s ms',
perfdatas => [
{ value => 'session_duration_mean_absolute', template => '%s', min => 0, unit => 'ms' }
]
}
},
{ label => 'traffic-transport-latency-total', nlabel => 'lmtpd.traffic.transport.latency.total.milliseconds', set => {
key_values => [ { name => 'traffic_latency_total', diff => 1 } ],
output_template => 'total traffic transport latency: %s ms',
perfdatas => [
{ value => 'traffic_latency_total_absolute', template => '%s', min => 0, unit => 'ms' }
]
}
},
{ label => 'traffic-transport-latency-mean', nlabel => 'lmtpd.traffic.transport.latency.mean.milliseconds', set => {
key_values => [ { name => 'traffic_latency_mean' } ],
output_template => 'mean traffic transport latency: %s ms',
perfdatas => [
{ value => 'traffic_latency_mean_absolute', template => '%s', min => 0, unit => 'ms' }
]
}
}
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
});
return $self;
}
sub manage_selection {
my ($self, %options) = @_;
# bm-lmtpd.activeConnections,meterType=Gauge value=0
# bm-lmtpd.connectionCount,meterType=Counter count=1236057
# bm-lmtpd.deliveries,status=ko,meterType=Counter count=410
# bm-lmtpd.deliveries,status=ok,meterType=Counter count=1390933
# bm-lmtpd.emailSize,meterType=DistSum count=5020456,totalAmount=1170102671020,mean=233067
# bm-lmtpd.sessionDuration,meterType=Timer count=4941893,totalTime=1052591049892285,mean=212993492
# bm-lmtpd.traffic.transportLatency,meterType=Timer count=5017208,totalTime=272844528075000000,mean=54381745400
my $result = $options{custom}->execute_command(
command => 'curl --unix-socket /var/run/bm-metrics/metrics-bm-lmtpd.sock http://127.0.0.1/metrics',
filter => 'activeConnections|connectionCount|deliveries|emailSize|sessionDuration|traffic\.transportLatency'
);
$self->{bm_lmtpd} = {};
foreach (keys %$result) {
$self->{bm_lmtpd}->{'deliveries_' . $1} = $result->{$_}->{count} if (/bm-lmtpd\.deliveries.*status=(ok|ko)/);
$self->{bm_lmtpd}->{active_connections} = $result->{$_}->{value} if (/bm-lmtpd\.activeConnections/);
$self->{bm_lmtpd}->{connections} = $result->{$_}->{count} if (/bm-lmtpd\.connectionCount/);
$self->{bm_lmtpd}->{email_size} = $result->{$_}->{totalAmount} if (/bm-lmtpd\.emailSize/);
if (/bm-lmtpd\.sessionDuration/) {
$self->{bm_lmtpd}->{session_duration_total} = $result->{$_}->{totalTime} / 100000;
$self->{bm_lmtpd}->{session_duration_mean} = $result->{$_}->{mean} / 100000;
}
if (/bm-lmtpd\.traffic\.transportLatency/) {
$self->{bm_lmtpd}->{traffic_latency_total} = $result->{$_}->{totalTime} / 100000;
$self->{bm_lmtpd}->{traffic_latency_mean} = $result->{$_}->{mean} / 100000;
}
}
$self->{cache_name} = 'bluemind_' . $self->{mode} . '_' . $options{custom}->get_hostname() . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
}
1;
__END__
=head1 MODE
Check email delivery service.
=over 8
=item B<--filter-counters>
Only display some counters (regexp can be used).
Example: --filter-counters='^deliveries'
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'connections-active', 'connections-total',
'deliveries-success', 'deliveries-failure', 'emails-size-total',
'sessions-duration-total', 'sessions-duration-mean', 'traffic-transport-latency-total',
'traffic-transport-latency-mean'.
=back
=cut

View File

@ -0,0 +1,168 @@
#
# Copyright 2020 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::bluemind::local::mode::milter;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
use bigint;
sub prefix_milter_output {
my ($self, %options) = @_;
return 'Milter service ';
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'bm_milter', type => 0, cb_prefix_output => 'prefix_milter_output' }
];
$self->{maps_counters}->{bm_milter} = [
{ label => 'connections-total', nlabel => 'milter.connections.total.count', set => {
key_values => [ { name => 'connections', diff => 1 } ],
output_template => 'total connections: %s',
perfdatas => [
{ value => 'connections_absolute', template => '%s', min => 0 }
]
}
},
{ label => 'traffic-class-inbound', nlabel => 'milter.traffic.class.inbound.count', display_ok => 0, set => {
key_values => [ { name => 'traffic_class_inbound', diff => 1 } ],
output_template => 'traffic class inbound: %s',
perfdatas => [
{ value => 'traffic_class_inbound_absolute', template => '%s', min => 0 }
]
}
},
{ label => 'traffic-class-outbound', nlabel => 'milter.traffic.class.outbound.count', display_ok => 0, set => {
key_values => [ { name => 'traffic_class_outbound', diff => 1 } ],
output_template => 'traffic class outbound: %s',
perfdatas => [
{ value => 'traffic_class_outbound_absolute', template => '%s', min => 0 }
]
}
},
{ label => 'traffic-size-inbound', nlabel => 'milter.traffic.size.inbound.bytes', display_ok => 0, set => {
key_values => [ { name => 'traffic_size_inbound', diff => 1 } ],
output_template => 'traffic size inbound: %s %s',
output_change_bytes => 1,
perfdatas => [
{ value => 'traffic_size_inbound_absolute', template => '%s', min => 0, unit => 'B' }
]
}
},
{ label => 'traffic-size-outbound', nlabel => 'milter.traffic.size.outbound.bytes', display_ok => 0, set => {
key_values => [ { name => 'traffic_size_outbound', diff => 1 } ],
output_template => 'traffic size outbound: %s %s',
output_change_bytes => 1,
perfdatas => [
{ value => 'traffic_size_outbound_absolute', template => '%s', min => 0, unit => 'B' }
]
}
},
{ label => 'sessions-duration-total', nlabel => 'milter.sessions.duration.total.milliseconds', display_ok => 0, set => {
key_values => [ { name => 'session_duration_total', diff => 1 } ],
output_template => 'total sessions duration: %s ms',
perfdatas => [
{ value => 'session_duration_total_absolute', template => '%s', min => 0, unit => 'ms' }
]
}
},
{ label => 'sessions-duration-mean', nlabel => 'milter.sessions.duration.mean.milliseconds', set => {
key_values => [ { name => 'session_duration_mean' } ],
output_template => 'mean sessions duration: %s ms',
perfdatas => [
{ value => 'session_duration_mean_absolute', template => '%s', min => 0, unit => 'ms' }
]
}
}
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
});
return $self;
}
sub manage_selection {
my ($self, %options) = @_;
# bm-milter.connectionsCount,meterType=Counter count=2017123
# bm-milter.sessionDuration,meterType=Timer count=11553431,totalTime=21943249233042775,mean=1899284224
# bm-milter.traffic.class,type=INBOUND,meterType=Counter count=1289087
# bm-milter.traffic.class,type=OUTBOUND,meterType=Counter count=415711
# bm-milter.traffic.size,type=INBOUND,meterType=Counter count=29063863392
# bm-milter.traffic.size,type=OUTBOUND,meterType=Counter count=10763275492
my $result = $options{custom}->execute_command(
command => 'curl --unix-socket /var/run/bm-metrics/metrics-bm-milter.sock http://127.0.0.1/metrics',
filter => 'connectionsCount|sessionDuration|traffic\.class|traffic\.size'
);
$self->{bm_milter} = {};
foreach (keys %$result) {
$self->{bm_milter}->{'traffic_class_' . lc($1)} = $result->{$_}->{count} if (/bm-milter\.traffic\.class.*type=(INBOUND|OUTBOUND)/i);
$self->{bm_milter}->{'traffic_size_' . lc($1)} = $result->{$_}->{count} if (/bm-milter\.traffic\.size.*type=(INBOUND|OUTBOUND)/i);
$self->{bm_milter}->{connections} = $result->{$_}->{count} if (/bm-milter\.connectionsCount/);
if (/bm-milter\.sessionDuration/) {
$self->{bm_milter}->{session_duration_total} = $result->{$_}->{totalTime} / 100000;
$self->{bm_milter}->{session_duration_mean} = $result->{$_}->{mean} / 100000;
}
}
$self->{cache_name} = 'bluemind_' . $self->{mode} . '_' . $options{custom}->get_hostname() . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
}
1;
__END__
=head1 MODE
Check milter service.
=over 8
=item B<--filter-counters>
Only display some counters (regexp can be used).
Example: --filter-counters='^deliveries'
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'connections-total', 'traffic-class-inbound', 'traffic-class-outbound',
'traffic-size-inbound', 'traffic-size-outbound', 'sessions-duration-total', 'sessions-duration-mean' .
=back
=cut

View File

@ -0,0 +1,152 @@
#
# Copyright 2020 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::bluemind::local::mode::webserver;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
use bigint;
sub prefix_webserver_output {
my ($self, %options) = @_;
return 'Web application server ';
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'bm_webserver', type => 0, cb_prefix_output => 'prefix_webserver_output' },
];
$self->{maps_counters}->{bm_webserver} = [
{ label => 'requests-time-total', nlabel => 'webserver.requests.time.milliseconds', display_ok => 0, set => {
key_values => [ { name => 'requests_time_total', diff => 1 } ],
output_template => 'total requests time: %s ms',
perfdatas => [
{ value => 'requests_time_total_absolute', template => '%s', min => 0, unit => 'ms' }
]
}
},
{ label => 'requests-time-mean', nlabel => 'webserver.requests.time.mean.milliseconds', set => {
key_values => [ { name => 'requests_time_mean' } ],
output_template => 'mean requests time: %s ms',
perfdatas => [
{ value => 'requests_time_mean_absolute', template => '%s', min => 0, unit => 'ms' }
]
}
},
{ label => 'requests-total', nlabel => 'webserver.requests.total.count', set => {
key_values => [ { name => 'requests', diff => 1 } ],
output_template => 'total requests: %s',
perfdatas => [
{ value => 'requests_absolute', template => '%s', min => 0 }
]
}
},
{ label => 'requests-status-200', nlabel => 'webserver.requests.status.200.count', display_ok => 0, set => {
key_values => [ { name => 'requests_200', diff => 1 } ],
output_template => 'total 200 requests: %s',
perfdatas => [
{ value => 'requests_200_absolute', template => '%s', min => 0 }
]
}
},
{ label => 'requests-status-304', nlabel => 'webserver.requests.status.304.count', display_ok => 0, set => {
key_values => [ { name => 'requests_304', diff => 1 } ],
output_template => 'total 304 requests: %s',
perfdatas => [
{ value => 'requests_304_absolute', template => '%s', min => 0 }
]
}
}
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
});
return $self;
}
sub manage_selection {
my ($self, %options) = @_;
# bm-webserver.appCache.requestTime,meterType=Timer count=91005,totalTime=46688008481,mean=513026
# bm-webserver.appCache.requests,meterType=Counter count=8552
# bm-webserver.staticFile.requests,status=200,meterType=Counter count=318881
# bm-webserver.staticFile.requests,status=304,meterType=Counter count=3485778
my $result = $options{custom}->execute_command(
command => 'curl --unix-socket /var/run/bm-metrics/metrics-bm-webserver.sock http://127.0.0.1/metrics',
filter => 'appCache|staticFile\.requests'
);
$self->{bm_webserver} = {};
foreach (keys %$result) {
$self->{bm_webserver}->{'requests_' . $1} = $result->{$_}->{count} if (/bm-webserver\.staticFile\.requests.*,status=(200|304)/);
$self->{bm_webserver}->{requests} = $result->{$_}->{count} if (/bm-webserver\.appCache\.requests/);
if (/bm-webserver\.appCache\.requestTime/) {
$self->{bm_webserver}->{requests_time_total} = $result->{$_}->{totalTime} / 100000;
$self->{bm_webserver}->{requests_time_mean} = $result->{$_}->{mean} / 100000;
}
}
$self->{cache_name} = 'bluemind_' . $self->{mode} . '_' . $options{custom}->get_hostname() . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
}
1;
__END__
=head1 MODE
Check web application server.
=over 8
=item B<--filter-counters>
Only display some counters (regexp can be used).
Example: --filter-counters='requests-time-mean'
=item B<--filter-upstream>
Filter upstream name (can be a regexp).
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'requests-time-total', 'requests-time-mean', 'requests-total',
'requests-status-200', 'requests-status-304'.
=back
=cut

View File

@ -0,0 +1,115 @@
#
# Copyright 2020 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::bluemind::local::mode::xmpp;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
use bigint;
sub prefix_xmpp_output {
my ($self, %options) = @_;
return 'Instant messaging service ';
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'bm_xmpp', type => 0, cb_prefix_output => 'prefix_xmpp_output' }
];
$self->{maps_counters}->{bm_xmpp} = [
{ label => 'packets-all', nlabel => 'xmpp.packets.all.count', set => {
key_values => [ { name => 'packets_all', diff => 1 } ],
output_template => 'all packets sent: %s',
perfdatas => [
{ value => 'packets_all_absolute', template => '%s', min => 0 }
]
}
},
{ label => 'packets-chat', nlabel => 'xmpp.packets.chat.count', display_ok => 0, set => {
key_values => [ { name => 'packets_chat', diff => 1 } ],
output_template => 'chat packets sent: %s',
perfdatas => [
{ value => 'packets_chat_absolute', template => '%s', min => 0 }
]
}
}
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
});
return $self;
}
sub manage_selection {
my ($self, %options) = @_;
# bm-xmpp.packetsCount,type=all,meterType=Counter count=517791
# bm-xmpp.packetsCount,type=chat,meterType=Counter count=12
my $result = $options{custom}->execute_command(
command => 'curl --unix-socket /var/run/bm-metrics/metrics-bm-xmpp.sock http://127.0.0.1/metrics',
filter => 'packetsCount'
);
$self->{bm_xmpp} = {};
foreach (keys %$result) {
$self->{bm_xmpp}->{'packets_' . $1} = $result->{$_}->{count} if (/bm-xmpp\.packetsCount.*type=(all|chat)/);
}
$self->{cache_name} = 'bluemind_' . $self->{mode} . '_' . $options{custom}->get_hostname() . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
}
1;
__END__
=head1 MODE
Check instant messaging service.
=over 8
=item B<--filter-counters>
Only display some counters (regexp can be used).
Example: --filter-counters='chat'
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'packets-all', 'packets-chat'.
=back
=cut

View File

@ -0,0 +1,58 @@
#
# Copyright 2020 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::bluemind::local::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} = {
'core' => 'apps::bluemind::local::mode::core',
'eas' => 'apps::bluemind::local::mode::eas',
'hps' => 'apps::bluemind::local::mode::hps',
'ips' => 'apps::bluemind::local::mode::ips',
'lmtpd' => 'apps::bluemind::local::mode::lmtpd',
'milter' => 'apps::bluemind::local::mode::milter',
'webserver' => 'apps::bluemind::local::mode::webserver',
'xmpp' => 'apps::bluemind::local::mode::xmpp'
};
$self->{custom_modes}{api} = 'apps::bluemind::local::custom::api';
return $self;
}
1;
__END__
=head1 PLUGIN DESCRIPTION
Check BlueMind through bm-metrics sockets
=cut

View File

@ -1,211 +0,0 @@
#
# Copyright 2020 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::bluemind::mode::incoming;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::plugins::http;
use centreon::plugins::statefile;
use JSON;
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$options{options}->add_options(arguments => {
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port', default => '8086'},
"proto:s" => { name => 'proto' },
"urlpath:s" => { name => 'url_path', default => "/db" },
"database:s" => { name => 'database' },
"username:s" => { name => 'username' },
"password:s" => { name => 'password' },
"timeout:s" => { name => 'timeout' },
"warning:s" => { name => 'warning' },
"critical:s" => { name => 'critical' },
});
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
$self->{http} = centreon::plugins::http->new(%options);
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();
}
if (!defined($self->{option_results}->{database})) {
$self->{output}->add_option_msg(short_msg => "Please set the database option");
$self->{output}->option_exit();
}
if ((!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) {
$self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= option");
$self->{output}->option_exit();
}
my $query = 'select sum("success") as "success_sum", sum("failure") as "failure_sum" from lmtpd.deliveries where time > '.$old_timestamp.'s and time < now()';
$self->{option_results}->{url_path} = $self->{option_results}->{url_path}."/".$self->{option_results}->{database}."/series";
$self->{option_results}->{get_param} = [];
push @{$self->{option_results}->{get_param}}, "q=" . $query, "p=" . $self->{option_results}->{password}, "u=" . $self->{option_results}->{username};
$self->{http}->set_options(%{$self->{option_results}});
$self->{statefile_value}->check_options(%options);
}
sub run {
my ($self, %options) = @_;
$self->{statefile_value}->read(statefile => 'bluemind_' . $self->{option_results}->{hostname} . '_' . $self->{http}->get_port() . '_' . $self->{mode});
my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
my $new_datas = {};
$new_datas->{last_timestamp} = time();
$self->{statefile_value}->write(data => $new_datas);
if (!defined($old_timestamp)) {
$self->{output}->output_add(severity => 'OK',
short_msg => "Buffer creation...");
$self->{output}->display();
$self->{output}->exit();
}
my $jsoncontent = $self->{http}->request();
my $json = JSON->new;
my $webcontent;
eval {
$webcontent = $json->decode($jsoncontent);
};
if ($@) {
$self->{output}->add_option_msg(short_msg => "Cannot decode json response");
$self->{output}->option_exit();
}
my $hwebcontent;
for my $ref (@{ $webcontent }) {
my $name = $ref->{name};
my @columns = @{ $ref->{columns} };
for my $points (@{ $ref->{points} }) {
my %hash;
@hash{ @columns } = @$points;
push @{ $hwebcontent->{$name} }, \%hash;
}
}
my $success_incoming_mails = defined($hwebcontent->{qw(lmtpd.deliveries)}->[0]->{success_sum}) ? $hwebcontent->{qw(lmtpd.deliveries)}->[0]->{success_sum} : '0';
my $failure_incoming_mails = defined($hwebcontent->{qw(lmtpd.deliveries)}->[0]->{failure_sum}) ? $hwebcontent->{qw(lmtpd.deliveries)}->[0]->{failure_sum} : '0';
# If not present: failure and success incoming mails are 0
if (!defined($success_incoming_mails)) {
$success_incoming_mails = 0;
}
if (!defined($failure_incoming_mails)) {
$failure_incoming_mails = 0;
}
my $exit = $self->{perfdata}->threshold_check(value => $failure_incoming_mails, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Success Incoming Mails: %d - Failure Incoming Mails: %d",$success_incoming_mails,$failure_incoming_mails));
$self->{output}->perfdata_add(label => 'success',
value => sprintf("%d", $success_incoming_mails),
min => 0,
);
$self->{output}->perfdata_add(label => 'failure',
value => sprintf("%d", $failure_incoming_mails),
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();
}
1;
__END__
=head1 MODE
Check Bluemind incoming_mails (success and failure)
=over 8
=item B<--hostname>
IP Addr/FQDN of the Bluemind host
=item B<--port>
Port used by InfluxDB API (Default: '8086')
=item B<--proto>
Specify https if needed (Default: 'http')
=item B<--urlpath>
Set path to get influxdb information (Default: '/db')
=item B<--database>
InfluxDB Database name
=item B<--username>
Specify username for API authentification
=item B<--password>
Specify password for API authentification
=item B<--timeout>
Threshold for HTTP timeout (Default: 5)
=item B<--warning>
Warning Threshold for failure incoming mails
=item B<--critical>
Critical Threshold for failure incoming mails
=back
=cut

View File

@ -323,7 +323,12 @@ sub manage_selection {
$self->{vmetrics}->{$vcurve}->{aggregated_value} = sprintf(
$config_data->{formatting}->{printf_metric_value},
max(@{$self->{vmetrics}->{$vcurve}->{values}})) if ($config_data->{virtualcurve}->{$vcurve}->{aggregation} eq 'max');
$self->{vmetrics}->{$vcurve}->{aggregated_value} = eval "$self->{vmetrics}->{$vcurve}->{aggregated_value} $config_data->{virtualcurve}->{$vcurve}->{custom}" if (defined($config_data->{virtualcurve}->{$vcurve}->{custom}));
if ($config_data->{virtualcurve}->{$vcurve}->{aggregation} eq 'none') {
$self->{vmetrics}->{$vcurve}->{aggregated_value} = ($config_data->{virtualcurve}->{$vcurve}->{aggregation} eq 'none' && defined($config_data->{virtualcurve}->{$vcurve}->{custom})) ?
eval "$config_data->{virtualcurve}->{$vcurve}->{custom}" :
eval "$self->{vmetrics}->{$vcurve}->{aggregated_value} $config_data->{virtualcurve}->{$vcurve}->{custom}";
}
$self->{vmetrics}->{$vcurve}->{unit} = (defined($config_data->{virtualcurve}->{$vcurve}->{unit})) ? $config_data->{virtualcurve}->{$vcurve}->{unit} : '';
$self->{vmetrics}->{$vcurve}->{min} = (defined($config_data->{virtualcurve}->{$vcurve}->{min})) ? $config_data->{virtualcurve}->{$vcurve}->{min} : '';

View File

@ -0,0 +1,264 @@
#
# Copyright 2020 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::hddtemp::custom::cli;
use strict;
use warnings;
use centreon::plugins::ssh;
use centreon::plugins::misc;
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' },
'timeout:s' => { name => 'timeout', default => 45 },
'command-drives:s' => { name => 'command_drives' },
'command-path-drives:s' => { name => 'command_path_drives' },
'command-options-drives:s' => { name => 'command_options_drives' },
'command-hddtemp:s' => { name => 'command_hddtemp' },
'command-path-hddtemp:s' => { name => 'command_path_hddtemp' },
'command-options-hddtemp:s' => { name => 'command_options_hddtemp' },
'sudo:s' => { name => 'sudo' }
});
}
$options{options}->add_help(package => __PACKAGE__, sections => 'CLI OPTIONS', once => 1);
$self->{output} = $options{output};
$self->{mode} = $options{mode};
$self->{ssh} = centreon::plugins::ssh->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) = @_;
if (defined($self->{option_results}->{hostname}) && $self->{option_results}->{hostname} ne '') {
$self->{ssh}->check_options(option_results => $self->{option_results});
}
return 0;
}
sub list_drives {
my ($self, %options) = @_;
my $stdout;
if (defined($self->{option_results}->{hostname}) && $self->{option_results}->{hostname} ne '') {
($stdout) = $self->{ssh}->execute(
hostname => $self->{option_results}->{hostname},
command => defined($self->{option_results}->{command_drives}) && $self->{option_results}->{command_drives} ne '' ? $self->{option_results}->{command_drives} : 'lsblk',
command_path => $self->{option_results}->{command_path_drives},
command_options => defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options_drives} ne '' ? $self->{option_results}->{command_options_drives} : '-I 8 -d -o NAME -p -n',
timeout => $self->{option_results}->{timeout}
);
} else {
($stdout) = centreon::plugins::misc::execute(
output => $self->{output},
options => { timeout => $self->{option_results}->{timeout} },
command => defined($self->{option_results}->{command_drives}) && $self->{option_results}->{command_drives} ne '' ? $self->{option_results}->{command_drives} : 'lsblk',
command_path => $self->{option_results}->{command_path_drives},
command_options => defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options_drives} ne '' ? $self->{option_results}->{command_options_drives} : '-I 8 -d -o NAME -p -n'
);
}
$self->{output}->output_add(long_msg => "command response: $stdout", debug => 1);
my $drives = {};
$drives->{$_} = {} foreach (split /\n/, $stdout);
return $drives;
}
sub get_drives_information {
my ($self, %options) = @_;
my $drives = $self->list_drives();
my $cmd_options = '-u C ' . join(' ', keys %$drives);
my ($stdout, $exit_code);
if (defined($self->{option_results}->{hostname}) && $self->{option_results}->{hostname} ne '') {
($stdout, $exit_code) = $self->{ssh}->execute(
hostname => $self->{option_results}->{hostname},
sudo => $self->{option_results}->{sudo},
command => defined($self->{option_results}->{command_hddtemp}) && $self->{option_results}->{command_hddtemp} ne '' ? $self->{option_results}->{command_hddtemp} : 'hddtemp',
command_path => $self->{option_results}->{command_path_hddtemp},
command_options => defined($self->{option_results}->{command_options_hddtemp}) && $self->{option_results}->{command_options_hddtemp} ne '' ? $self->{option_results}->{command_options_hddtemp} : $cmd_options,
timeout => $self->{option_results}->{timeout},
no_quit => 1
);
} else {
($stdout, $exit_code) = centreon::plugins::misc::execute(
output => $self->{output},
options => { timeout => $self->{option_results}->{timeout} },
sudo => $self->{option_results}->{sudo},
command => defined($self->{option_results}->{command_hddtemp}) && $self->{option_results}->{command_hddtemp} ne '' ? $self->{option_results}->{command_hddtemp} : 'hddtemp',
command_path => $self->{option_results}->{command_path_hddtemp},
command_options => defined($self->{option_results}->{command_options_hddtemp}) && $self->{option_results}->{command_options_hddtemp} ne '' ? $self->{option_results}->{command_options_hddtemp} : $cmd_options . ' 2> /dev/null',
no_quit => 1,
);
}
# exit values can be: 0/1. Need root permissions.
if ($exit_code != 0 && $exit_code != 1) {
$self->{output}->add_option_msg(short_msg => sprintf('command execution error [exit code: %s]', $exit_code));
$self->{output}->option_exit();
}
# OK:
# /dev/sda: SanDisk ...: 32 C
# ERROR:
# message on stderr. So if we don't catch stderr and we have nothing, surely error. for example:
# /dev/sda: open: Permission denied
# UNKNOWN:
# /dev/sda: SanDisk ...: no sensor
# SLEEP:
# /dev/sda: SanDisk ...: drive is sleeping
# NOSENSOR:
# /dev/sda: SanDisk ...: drive supported, but it doesn't have a temperature sensor
# NOT_APPLICABLE:
# /dev/sda: SanDisk ...: misc message
foreach my $name (keys %$drives) {
if ($stdout =~ /^$name:.*?:\s+(\d+).*?C/m) {
$drives->{$name}->{status} = 'ok';
$drives->{$name}->{temperature_unit} = 'C';
$drives->{$name}->{temperature} = $1;
} elsif ($stdout =~ /^$name:.*?:\s+(.*)$/m) {
my $message = $1;
$drives->{$name}->{status} = 'notApplicable';
$drives->{$name}->{status} = 'unknown' if ($message =~ /no sensor/i);
$drives->{$name}->{status} = 'driveSleep' if ($message =~ /drive is sleeping/i);
$drives->{$name}->{status} = 'noSensor' if ($message =~ /drive supported, but it doesn't have a temperature sensor/i);
} else {
$drives->{$name}->{status} = 'error';
}
}
return $drives;
}
1;
__END__
=head1 NAME
ssh
=head1 SYNOPSIS
my ssh
=head1 CLI OPTIONS
=over 8
=item B<--hostname>
Hostname to query (ssh mode).
=item B<--timeout>
Timeout in seconds for the command (Default: 45).
=item You can override command for drives listing.
By default, we use 'lsblk -I 8 -d -o NAME -p -n':
=over 16
=item B<--command-drives>
Command to get information. Used it you have output in a file.
=item B<--command-path-drives>
Command path.
=item B<--command-options-drives>
Command options.
=back
=item You can override command hddtemp used.
By default, we use 'hddtemp -u C /dev/sda /dev/sdb ...' built with the result of drives command:
=over 16
=item B<--command-hddtemp>
Command to get information. Used it you have output in a file.
=item B<--command-path-hddtemp>
Command path.
=item B<--command-options-hddtemp>
Command options.
=item B<--sudo>
Sudo hddtemp command.
=back
=back
=head1 DESCRIPTION
B<custom>.
=cut

View File

@ -0,0 +1,198 @@
#
# Copyright 2020 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::hddtemp::custom::tcp;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
use IO::Socket;
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' },
'timeout:s' => { name => 'timeout' }
});
}
$options{options}->add_help(package => __PACKAGE__, sections => 'CUSTOM TCP 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) = @_;
$self->{hostname} = (defined($self->{option_results}->{hostname})) ? $self->{option_results}->{hostname} : '';
$self->{port} = (defined($self->{option_results}->{port})) && $self->{option_results}->{port} =~ /(\d+)/ ? $1 : 7634;
$self->{timeout} = (defined($self->{option_results}->{timeout})) && $self->{option_results}->{timeout} =~ /(\d+)/ ? $1 : 30;
if ($self->{hostname} eq '') {
$self->{output}->add_option_msg(short_msg => 'Need to specify --hostname option.');
$self->{output}->option_exit();
}
return 0;
}
sub get_hddtemp_drives {
my ($self, %options) = @_;
my $socket = new IO::Socket::INET(
Proto => 'tcp',
PeerAddr => $self->{hostname},
PeerPort => $self->{port},
Timeout => $self->{timeout}
);
if (!defined($socket)) {
$self->{output}->add_option_msg(short_msg => "could not connect: $@");
$self->{output}->option_exit();
}
my $line;
eval {
local $SIG{ALRM} = sub { die 'Timeout'; };
alarm($self->{timeout});
$line = <$socket>;
alarm(0);
};
$socket->shutdown(2);
if ($@) {
$self->{output}->add_option_msg(short_msg => 'cannot get informations: ' . $@);
$self->{output}->option_exit();
}
return $line;
}
sub list_drives {
my ($self, %options) = @_;
my $line = $self->get_hddtemp_drives();
my $drives = {};
while ($line =~ /\|(.*?)\|(.*?)\|(.*?)\|(.*?)\|/msg) {
$drives->{$1} = {};
}
return $drives;
}
sub get_drives_information {
my ($self, %options) = @_;
my $line = $self->get_hddtemp_drives();
#|/dev/sda|SanDisk ....|33|C|
#|/dev/sda|Scan .... |NA|*|
my $mapping_errors = {
NA => 'notApplicable',
UNK => 'unknown',
NOS => 'noSensor',
SLP => 'driveSleep',
ERR => 'error'
};
my $drives = {};
while ($line =~ /\|(.*?)\|(.*?)\|(.*?)\|(.*?)\|/msg) {
my ($name, $value, $unit) = ($1, $3, $4);
if ($value =~ /\d+/) {
$drives->{$name} = { temperature => $value, temperature_unit => $unit, status => 'ok' };
} else {
$drives->{$name} = { status => $mapping_errors->{$value} };
}
}
return $drives;
}
1;
__END__
=head1 NAME
Hddtemp
=head1 CUSTOM TCP OPTIONS
Hddtemp tcp
=over 8
=item B<--hostname>
Hostname or IP address.
=item B<--port>
Port used (Default: 7634)
=item B<--timeout>
Set timeout in seconds (Default: 30).
=back
=head1 DESCRIPTION
B<custom>.
=cut

View File

@ -1,184 +0,0 @@
#
# Copyright 2020 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::hddtemp::local::mode::temperature;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::plugins::misc;
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$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 => 30 },
"sudo" => { name => 'sudo' },
"command:s" => { name => 'command', default => 'hddtemp' },
"command-path:s" => { name => 'command_path', default => '/usr/sbin' },
"command-options:s" => { name => 'command_options', default => '-u' },
"warning:s" => { name => 'warning' },
"critical:s" => { name => 'critical' },
"disks:s" => { name => 'disks' },
"unit:s" => { name => 'unit', default => 'C' }
});
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->{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->{critical} . "'.");
$self->{output}->option_exit();
}
if (!defined($self->{option_results}->{disks}) || $self->{option_results}->{disks} eq '') {
$self->{output}->add_option_msg(short_msg => "Need to specify hdd (ex. /dev/sda).");
$self->{output}->option_exit();
}
#### Create command_options
if (defined($self->{option_results}->{unit})) {
$self->{option_results}->{command_options} .= $self->{option_results}->{unit};
}
$self->{option_results}->{command_options} .= ' ' . $self->{option_results}->{disks};
$self->{option_results}->{command_options} .= ' 2>&1';
}
sub run {
my ($self, %options) = @_;
my $total_size = 0;
my $stdout = 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 => $self->{option_results}->{command_options});
$self->{output}->output_add(severity => 'OK',
short_msg => "All temperatures are ok.");
foreach (split(/\n/, $stdout)) {
next if (!/(.*): (.*): ([0-9]*)/);
my ($disk, $model, $temp) = ($1, $2, $3);
my $exit_code = $self->{perfdata}->threshold_check(value => $temp,
threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
$self->{output}->output_add(long_msg => sprintf("%s: %s", $disk, $temp . '°' . $self->{option_results}->{unit}));
if (!$self->{output}->is_status(litteral => 1, value => $exit_code, compare => 'ok')) {
$self->{output}->output_add(severity => $exit_code,
short_msg => sprintf("'%s' temp is %s", $disk, $temp . '°' . $self->{option_results}->{unit}));
}
$self->{output}->perfdata_add(label => $disk, unit => $self->{option_results}->{unit},
value => $temp,
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();
}
1;
__END__
=head1 MODE
Check hdd temperature with hddtemp.
=over 8
=item B<--disks>
Disks to check (ex: /dev/sda)
=item B<--unit>
Temperature unit (default: C).
=item B<--warning>
Threshold warning in °.
=item B<--critical>
Threshold critical in °.
=item B<--remote>
Execute command remotely in 'ssh'.
=item B<--hostname>
Hostname to query (need --remote).
=item B<--ssh-option>
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
=item B<--ssh-path>
Specify ssh command path (default: none)
=item B<--ssh-command>
Specify ssh command (default: 'ssh'). Useful to use 'plink'.
=item B<--timeout>
Timeout in seconds for the command (Default: 30).
=item B<--sudo>
Use 'sudo' to execute the command.
=item B<--command>
Command to get information (Default: 'hddtemp').
Can be changed if you have output in a file.
=item B<--command-path>
Command path (Default: '/usr/sbin').
=item B<--command-options>
Command options (Default: '-u').
=back
=cut

View File

@ -0,0 +1,97 @@
#
# Copyright 2020 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::hddtemp::mode::listdrives;
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;
$options{options}->add_options(arguments => {});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
}
sub manage_selection {
my ($self, %options) = @_;
return $options{custom}->list_drives();
}
sub run {
my ($self, %options) = @_;
my $drives = $self->manage_selection(%options);
foreach (sort keys %$drives) {
$self->{output}->output_add(long_msg =>
sprintf(
'[name = %s]',
$_
)
);
}
$self->{output}->output_add(
severity => 'OK',
short_msg => 'List drives:'
);
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
$self->{output}->exit();
}
sub disco_format {
my ($self, %options) = @_;
$self->{output}->add_disco_format(elements => ['name']);
}
sub disco_show {
my ($self, %options) = @_;
my $drives = $self->manage_selection(%options);
foreach (sort keys %$drives) {
$self->{output}->add_disco_entry(name => $_);
}
}
1;
__END__
=head1 MODE
List queues.
=over 8
=back
=cut

View File

@ -0,0 +1,169 @@
#
# Copyright 2020 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::hddtemp::mode::temperatures;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc);
sub custom_status_output {
my ($self, %options) = @_;
return sprintf(
'status: %s',
$self->{result_values}->{status},
);
}
sub custom_temperature_output {
my ($self, %options) = @_;
return sprintf('temperature: %s %s',
$self->{result_values}->{temperature_absolute},
$self->{result_values}->{temperature_unit_absolute}
);
}
sub custom_temperature_perfdata {
my ($self, %options) = @_;
$self->{output}->perfdata_add(
nlabel => 'drive.temperature.' . ($self->{result_values}->{temperature_unit_absolute} eq 'C' ? 'celsius' : 'fahrenheit'),
instances => $self->{result_values}->{display_absolute},
unit => $self->{result_values}->{temperature_unit_absolute},
value => $self->{result_values}->{temperature_absolute},
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}),
);
}
sub prefix_drive_output {
my ($self, %options) = @_;
return "Drive '" . $options{instance_value}->{display} . "' ";
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'drives', type => 1, cb_prefix_output => 'prefix_drive_output', skipped_code => { -10 => 1 } }
];
$self->{maps_counters}->{drives} = [
{ label => 'status', threshold => 0, set => {
key_values => [ { name => 'status' }, { name => 'display' } ],
closure_custom_calc => \&catalog_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', set => {
key_values => [ { name => 'temperature' }, { name => 'temperature_unit' }, { name => 'display' } ],
closure_custom_output => $self->can('custom_temperature_output'),
closure_custom_perfdata => $self->can('custom_temperature_perfdata')
}
}
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
'filter-name:s' => { name => 'filter_name' },
'unknown-status:s' => { name => 'unknown_status', default => '' },
'warning-status:s' => { name => 'warning_status', default => '' },
'critical-status:s' => { name => 'critical_status', default => '%{status} !~ /ok/i' }
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']);
}
sub manage_selection {
my ($self, %options) = @_;
my $results = $options{custom}->get_drives_information();
$self->{drives} = {};
foreach (keys %$results) {
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
$_ !~ /$self->{option_results}->{filter_name}/) {
$self->{output}->output_add(long_msg => "skipping drive '" . $_ . "': no matching filter.", debug => 1);
next;
}
$self->{drives}->{$_} = {
display => $_,
%{$results->{$_}}
};
}
}
1;
__END__
=head1 MODE
Check drive temperatures.
=over 8
=item B<--filter-name>
Filter drive name (Can use regexp).
=item B<--unknown-status>
Set unknown threshold for status.
Can used special variables like: %{status}, %{display}
=item B<--warning-status>
Set warning threshold for status.
Can used special variables like: %{status}, %{display}
=item B<--critical-status>
Set critical threshold for status (Default: '%{status} !~ /ok/i').
Can used special variables like: %{status}, %{display}
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'temperature'.
=back
=cut

View File

@ -0,0 +1,54 @@
#
# Copyright 2020 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::hddtemp::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}} = (
'list-drives' => 'apps::hddtemp::mode::listdrives',
'temperatures' => 'apps::hddtemp::mode::temperatures'
);
$self->{custom_modes}{tcp} = 'apps::hddtemp::custom::tcp';
$self->{custom_modes}{cli} = 'apps::hddtemp::custom::cli';
return $self;
}
1;
__END__
=head1 PLUGIN DESCRIPTION
Check drives temperature with hddtemp.
Two custom modes availables:
'tcp' (remotely with hddtemp in daemon mode)
'command' (with hddtemp command. you can execute locally or through ssh).
=cut

View File

@ -1,160 +0,0 @@
#
# Copyright 2020 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::hddtemp::remote::mode::listdrives;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
use IO::Socket;
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$options{options}->add_options(arguments =>
{
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port', default => '7634' },
"timeout:s" => { name => 'timeout', default => '10' },
"filter-name:s" => { name => 'filter_name', },
});
$self->{result} = {};
$self->{hostname} = undef;
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
if (!defined($self->{option_results}->{hostname})) {
$self->{output}->add_option_msg(short_msg => "Please set the hostname option");
$self->{output}->option_exit();
}
}
sub manage_selection {
my ($self, %options) = @_;
my $oSocketConn = new IO::Socket::INET ( Proto => 'tcp',
PeerAddr => $self->{option_results}->{hostname},
PeerPort => $self->{option_results}->{port},
Timeout => $self->{option_results}->{timeout},
);
if (!defined($oSocketConn)) {
$self->{output}->add_option_msg(short_msg => "Could not connect.");
$self->{output}->option_exit();
}
#|/dev/sda|SD280813AS|35|C|#|/dev/sdb|ST2000CD005-1CH134|35|C|
my $line;
eval {
local $SIG{ALRM} = sub { die "Timeout by signal ALARM\n"; };
alarm(10);
$line = <$oSocketConn>;
alarm(0);
};
$oSocketConn->shutdown(2);
if ($@) {
$self->{output}->add_option_msg(short_msg => "Cannot get informations.");
$self->{output}->option_exit();
}
while ($line =~ /\|([^|]+)\|([^|]+)\|([^|]+)\|(C|F)\|/g) {
my ($drive, $serial, $temperature, $unit) = ($1, $2, $3, $4);
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
$drive !~ /$self->{option_results}->{filter_name}/) {
$self->{output}->output_add(long_msg => "Skipping drive '" . $drive . "': no matching filter name");
next;
}
$self->{result}->{$drive} = {serial => $serial, temperature => $temperature, unit => $unit};
}
}
sub run {
my ($self, %options) = @_;
$self->manage_selection();
foreach my $name (sort(keys %{$self->{result}})) {
$self->{output}->output_add(long_msg => "'" . $name . "' [temperature = " . $self->{result}->{$name}->{temperature} . $self->{result}->{$name}->{unit} . ']');
}
$self->{output}->output_add(severity => 'OK',
short_msg => 'List Drives:');
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
$self->{output}->exit();
}
sub disco_format {
my ($self, %options) = @_;
$self->{output}->add_disco_format(elements => ['name', 'temperature']);
}
sub disco_show {
my ($self, %options) = @_;
$self->manage_selection();
foreach my $name (sort(keys %{$self->{result}})) {
$self->{output}->add_disco_entry(name => $name,
temperature => $self->{result}->{$name}->{temperature}
);
}
}
1;
__END__
=head1 MODE
List HDDTEMP Harddrives
=over 8
=item B<--hostname>
IP Address or FQDN of the Server
=item B<--port>
Port used by Hddtemp (Default: 7634)
=item B<--timeout>
Set Timeout for Socketconnect
=item B<--filter-name>
Filter Harddrive name (regexp can be used).
=back
=cut

View File

@ -1,210 +0,0 @@
#
# Copyright 2020 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::hddtemp::remote::mode::temperature;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
use IO::Socket;
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$options{options}->add_options(arguments => {
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port', default => '7634' },
"timeout:s" => { name => 'timeout', default => '10' },
"name:s" => { name => 'name' },
"warning:s" => { name => 'warning' },
"critical:s" => { name => 'critical' },
"regexp" => { name => 'use_regexp' },
"regexp-isensitive" => { name => 'use_regexpi' },
});
$self->{result} = {};
$self->{hostname} = undef;
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
if (!defined($self->{option_results}->{hostname})) {
$self->{output}->add_option_msg(short_msg => "Please set the hostname 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();
}
}
sub manage_selection {
my ($self, %options) = @_;
my $oSocketConn = new IO::Socket::INET (
Proto => 'tcp',
PeerAddr => $self->{option_results}->{hostname},
PeerPort => $self->{option_results}->{port},
Timeout => $self->{option_results}->{timeout},
);
if (!defined($oSocketConn)) {
$self->{output}->add_option_msg(short_msg => "Could not connect.");
$self->{output}->option_exit();
}
#|/dev/sda|SD280813AS|35|C|#|/dev/sdb|ST2000CD005-1CH134|35|C|
my $line;
eval {
local $SIG{ALRM} = sub { die "Timeout by signal ALARM\n"; };
alarm(10);
$line = <$oSocketConn>;
alarm(0);
};
$oSocketConn->shutdown(2);
if ($@) {
$self->{output}->add_option_msg(short_msg => "Cannot get informations.");
$self->{output}->option_exit();
}
while ($line =~ /\|([^|]+)\|([^|]+)\|([^|]+)\|(C|F)\|/g) {
my ($drive, $serial, $temperature, $unit) = ($1, $2, $3, $4);
next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi})
&& $drive !~ /$self->{option_results}->{name}/i);
next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
&& $drive !~ /$self->{option_results}->{name}/);
next if (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
&& $drive ne $self->{option_results}->{name});
$self->{result}->{$drive} = {serial => $serial, temperature => $temperature, unit => $unit};
}
if (scalar(keys %{$self->{result}}) <= 0) {
if (defined($self->{option_results}->{name})) {
$self->{output}->add_option_msg(short_msg => "No drives found for name '" . $self->{option_results}->{name} . "'.");
} else {
$self->{output}->add_option_msg(short_msg => "No drives found.");
}
$self->{output}->option_exit();
}
}
sub run {
my ($self, %options) = @_;
$self->manage_selection();
if (!defined($self->{option_results}->{name}) || defined($self->{option_results}->{use_regexp})) {
$self->{output}->output_add(severity => 'OK',
short_msg => 'All Harddrive Temperatures are ok.');
};
foreach my $name (sort(keys %{$self->{result}})) {
my $exit = $self->{perfdata}->threshold_check(value => $self->{result}->{$name}->{temperature}, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
$self->{output}->output_add(long_msg => sprintf("Harddrive '%s' Temperature : %s%s",
$name,
$self->{result}->{$name}->{temperature},
$self->{result}->{$name}->{unit}));
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1) || (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp}))) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Harddrive '%s' Temperature : %s%s",
$name,
$self->{result}->{$name}->{temperature},
$self->{result}->{$name}->{unit}));
}
my $extra_label;
$extra_label = '_' . $name if (!defined($self->{option_results}->{name}) || defined($self->{option_results}->{use_regexp}));
$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
);
};
$self->{output}->display();
$self->{output}->exit();
};
1;
__END__
=head1 MODE
Check HDDTEMP Temperature by Socket Connect
=over 8
=item B<--hostname>
IP Address or FQDN of the Server
=item B<--port>
Port used by Hddtemp (Default: 7634)
=item B<--timeout>
Set Timeout for Socketconnect
=item B<--warning>
Warning Threshold for Temperature
=item B<--critical>
Critical Threshold for Temperature
=item B<--name>
Set the Harddrive name (empty means 'check all Harddrives')
=item B<--regexp>
Allows to use regexp to filter Harddrive (with option --name).
=item B<--regexp-isensitive>
Allows to use regexp non case-sensitive (with --regexp).
=back
=cut

View File

@ -77,12 +77,11 @@ sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
bless $self, $class;
$options{options}->add_options(arguments =>
{
"filter-name:s" => { name => 'filter_name', default => '(/select|/update)$' },
});
$options{options}->add_options(arguments => {
'filter-name:s' => { name => 'filter_name', default => '(/select|/update)$' }
});
return $self;
}

View File

@ -0,0 +1,323 @@
#
# Copyright 2020 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::mq::activemq::jmx::mode::brokers;
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 => 'brokers', type => 3, cb_prefix_output => 'prefix_broker_output', cb_long_output => 'broker_long_output', indent_long_output => ' ', message_multiple => 'All brokers are ok',
group => [
{ name => 'global', type => 0, skipped_code => { -10 => 1 } },
{ name => 'queue', display_long => 1, cb_prefix_output => 'prefix_queue_output', message_multiple => 'All queues are ok', type => 1, skipped_code => { -10 => 1 } },
{ name => 'topic', display_long => 1, cb_prefix_output => 'prefix_topic_output', message_multiple => 'All topics are ok', type => 1, skipped_code => { -10 => 1 } }
]
}
];
$self->{maps_counters}->{global} = [
{ label => 'store-usage', nlabel => 'broker.store.usage.percentage', set => {
key_values => [ { name => 'StorePercentUsage' }, { name => 'display' } ],
output_template => 'store usage: %.2f %%',
perfdatas => [
{ value => 'StorePercentUsage_absolute', template => '%.2f', unit => '%', min => 0, max => 100, label_extra_instance => 1 }
]
}
},
{ label => 'temporary-usage', nlabel => 'broker.temporary.usage.percentage', set => {
key_values => [ { name => 'TempPercentUsage' }, { name => 'display' } ],
output_template => 'temporary usage: %.2f %%',
perfdatas => [
{ value => 'TempPercentUsage_absolute', template => '%.2f', unit => '%', min => 0, max => 100, label_extra_instance => 1 }
]
}
},
{ label => 'memory-usage', nlabel => 'broker.memory.usage.percentage', set => {
key_values => [ { name => 'MemoryPercentUsage' }, { name => 'display' } ],
output_template => 'memory usage: %.2f %%',
perfdatas => [
{ value => 'MemoryPercentUsage_absolute', template => '%.2f', unit => '%', min => 0, max => 100, label_extra_instance => 1 }
]
}
}
];
foreach (('queue', 'topic')) {
$self->{maps_counters}->{$_} = [
{ label => $_ . '-average-enqueue-time', nlabel => 'broker.' . $_ . '.average.enqueue.time.milliseconds', set => {
key_values => [ { name => 'AverageEnqueueTime' }, { name => 'display' } ],
output_template => 'average time messages remained enqueued: %.3f ms',
perfdatas => [
{ value => 'AverageEnqueueTime_absolute',
template => '%.3f', unit => 'ms', min => 0, label_extra_instance => 1 }
]
}
},
{ label => $_ . '-consumers-connected', nlabel => 'broker.' . $_ . '.consumers.connected.count', set => {
key_values => [ { name => 'ConsumerCount' }, { name => 'display' } ],
output_template => 'consumers connected: %s',
perfdatas => [
{ value => 'ConsumerCount_absolute',
template => '%s', min => 0, label_extra_instance => 1 }
]
}
},
{ label => $_ . '-producers-connected', nlabel => 'broker.' . $_ . '.producers.connected.count', display_ok => 0, set => {
key_values => [ { name => 'ProducerCount' }, { name => 'display' } ],
output_template => 'producers connected: %s',
perfdatas => [
{ value => 'ProducerCount_absolute',
template => '%s', min => 0, label_extra_instance => 1 }
]
}
},
{ label => $_ . '-memory-usage', nlabel => 'broker.' . $_ . '.memory.usage.percentage', display_ok => 0, set => {
key_values => [ { name => 'MemoryPercentUsage' }, { name => 'display' } ],
output_template => 'memory usage: %.2f %%',
perfdatas => [
{ value => 'MemoryPercentUsage_absolute',
template => '%.2f', unit => '%', min => 0, max => 100, label_extra_instance => 1 }
]
}
},
{ label => $_ . '-size', nlabel => 'broker.' . $_ . '.size.count', set => {
key_values => [ { name => 'QueueSize' }, { name => 'display' } ],
output_template => 'queue size: %s',
perfdatas => [
{ value => 'QueueSize_absolute',
template => '%s', min => 0, label_extra_instance => 1 }
]
}
},
{ label => $_ . '-messages-enqueued', nlabel => 'broker.' . $_ . '.messages.enqueued.count', display_ok => 0, set => {
key_values => [ { name => 'EnqueueCount', diff => 1 }, { name => 'display' } ],
output_template => 'messages enqueued: %s',
perfdatas => [
{ value => 'EnqueueCount_absolute',
template => '%s', min => 0, label_extra_instance => 1 }
]
}
},
{ label => $_ . '-messages-dequeued', nlabel => 'broker.' . $_ . '.messages.dequeue.count', display_ok => 0, set => {
key_values => [ { name => 'DequeueCount', diff => 1 }, { name => 'display' } ],
output_template => 'messages dequeued: %s',
perfdatas => [
{ value => 'DequeueCount_absolute',
template => '%s', min => 0, label_extra_instance => 1 }
]
}
},
{ label => $_ . '-messages-expired', nlabel => 'broker.' . $_ . '.messages.expired.count', display_ok => 0, set => {
key_values => [ { name => 'ExpiredCount', diff => 1 }, { name => 'display' } ],
output_template => 'messages expired: %s',
perfdatas => [
{ value => 'ExpiredCount_absolute',
template => '%s', min => 0, label_extra_instance => 1 }
]
}
},
{ label => $_ . '-messages-inflighted', nlabel => 'broker.' . $_ . '.messages.inflighted.count', display_ok => 0, set => {
key_values => [ { name => 'InFlightCount', diff => 1 }, { name => 'display' } ],
output_template => 'messages in-flighted: %s',
perfdatas => [
{ value => 'InFlightCount_absolute',
template => '%s', min => 0, label_extra_instance => 1 }
]
}
},
{ label => $_ . '-messages-size-average', nlabel => 'broker.' . $_ . '.messages.size.average.bytes', display_ok => 0, set => {
key_values => [ { name => 'AverageMessageSize' }, { name => 'display' } ],
output_template => 'average messages size: %s %s',
output_change_bytes => 1,
perfdatas => [
{ value => 'AverageMessageSize_absolute',
template => '%s', unit => 'B', min => 0, label_extra_instance => 1 }
]
}
}
];
}
}
sub broker_long_output {
my ($self, %options) = @_;
return "checking broker '" . $options{instance_value}->{display} . "'";
}
sub prefix_broker_output {
my ($self, %options) = @_;
return "Broker '" . $options{instance_value}->{display} . "' ";
}
sub prefix_queue_output {
my ($self, %options) = @_;
return "queue '" . $options{instance_value}->{display} . "' ";
}
sub prefix_topic_output {
my ($self, %options) = @_;
return "topic '" . $options{instance_value}->{display} . "' ";
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
'filter-broker-name:s' => { name => 'filter_broker_name' },
'filter-destination-name:s' => { name => 'filter_destination_name' },
'filter-destination-type:s' => { name => 'filter_destination_type' }
});
return $self;
}
sub manage_selection {
my ($self, %options) = @_;
my $request = [
{
mbean => 'org.apache.activemq:brokerName=*,destinationName=*,destinationType=*,type=Broker',
attributes => [
{ name => 'AverageEnqueueTime' }, { name => 'ConsumerCount' },
{ name => 'ProducerCount' }, { name => 'MemoryPercentUsage' },
{ name => 'QueueSize' }, { name => 'EnqueueCount' },
{ name => 'DequeueCount' }, { name => 'ExpiredCount' },
{ name => 'InFlightCount' }, { name => 'AverageMessageSize' }
]
},
{
mbean => 'org.apache.activemq:brokerName=*,type=Broker',
attributes => [
{ name => 'StorePercentUsage' }, { name => 'TempPercentUsage' },
{ name => 'MemoryPercentUsage' }
]
}
];
my $result = $options{custom}->get_attributes(request => $request, nothing_quit => 1);
$self->{cache_name} = 'activemq_' . $self->{mode} . '_' . md5_hex($options{custom}->get_connection_info()) . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' .
(defined($self->{option_results}->{filter_broker_name}) ? md5_hex($self->{option_results}->{filter_broker_name}) : md5_hex('all')) . '_' .
(defined($self->{option_results}->{filter_destination_name}) ? md5_hex($self->{option_results}->{filter_destination_name}) : md5_hex('all')) . '_' .
(defined($self->{option_results}->{filter_destination_type}) ? md5_hex($self->{option_results}->{filter_destination_type}) : md5_hex('all'));
$self->{brokers} = {};
foreach my $mbean (keys %$result) {
next if ($mbean !~ /org.apache.activemq:brokerName=(.*?),(?:destinationName=(.*?),destinationType=(.*?),|type=Broker)/);
my ($broker_name, $destination_name, $destination_type) = ($1, $2, $3);
if (defined($self->{option_results}->{filter_broker_name}) && $self->{option_results}->{filter_broker_name} ne '' &&
$broker_name !~ /$self->{option_results}->{filter_broker_name}/) {
$self->{output}->output_add(long_msg => "skipping '" . $broker_name . "': no matching filter.", debug => 1);
next;
}
if (defined($self->{option_results}->{filter_destination_type}) && $self->{option_results}->{filter_destination_type} ne '' &&
$destination_type !~ /$self->{option_results}->{filter_destination_type}/) {
$self->{output}->output_add(long_msg => "skipping '" . $broker_name . "': no matching filter.", debug => 1);
next;
}
if (!defined($self->{brokers}->{$broker_name})) {
$self->{brokers}->{$broker_name} = {
display => $broker_name,
queue => {},
topic => {}
};
}
if (defined($destination_name)) {
my $type = lc($destination_type);
next if ($type ne 'topic' && $type ne 'queue');
if (defined($self->{option_results}->{filter_destination_name}) && $self->{option_results}->{filter_destination_name} ne '' &&
$destination_name !~ /$self->{option_results}->{filter_destination_name}/) {
$self->{output}->output_add(long_msg => "skipping '" . $destination_name . "': no matching filter.", debug => 1);
next;
}
$self->{brokers}->{$broker_name}->{$type}->{$destination_name} = {
display => $destination_name,
%{$result->{$mbean}}
};
} else {
$self->{brokers}->{$broker_name}->{global} = {
display => $broker_name,
%{$result->{$mbean}}
};
}
}
if (scalar(keys %{$self->{brokers}}) <= 0) {
$self->{output}->output_add(short_msg => 'no brokers found');
}
}
1;
__END__
=head1 MODE
Check brokers.
=over 8
=item B<--filter-broker-name>
Filter broker name (Can be a regexp).
=item B<--filter-destination-name>
Filter destination name (Can be a regexp).
=item B<--filter-destination-type>
Filter destination type (Can be a regexp).
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'store-usage' (%), 'temporary-usage' (%), 'memory-usage' (%),
'queue-average-enqueue-time' (ms), 'queue-consumers-connected',
'queue-producers-connected', 'queue-memory-usage' (%), 'queue-size',
'queue-messages-enqueued', 'queue-messages-dequeued', 'queue-messages-expired',
'queue-messages-inflighted',
'topic-average-enqueue-time' (ms), 'topic-consumers-connected',
'topic-producers-connected', 'topic-memory-usage' (%), 'topic-size',
'topic-messages-enqueued', 'topic-messages-dequeued', 'topic-messages-expired',
'topic-messages-inflighted'.
=back
=cut

View File

@ -0,0 +1,116 @@
#
# Copyright 2020 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::mq::activemq::jmx::mode::listbrokers;
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;
$options{options}->add_options(arguments => {
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
}
sub manage_selection {
my ($self, %options) = @_;
my $request = [
{
mbean => 'org.apache.activemq:brokerName=*,type=Broker',
attributes => [
{ name => 'BrokerName' }
]
}
];
my $datas = $options{custom}->get_attributes(request => $request);
my $results = {};
foreach (keys %$datas) {
$results->{$datas->{$_}->{BrokerName}} = { name => $datas->{$_}->{BrokerName} };
}
return $results;
}
sub run {
my ($self, %options) = @_;
my $results = $self->manage_selection(custom => $options{custom});
foreach (sort keys %$results) {
$self->{output}->output_add(
long_msg => sprintf(
'[name = %s]',
$_
)
);
}
$self->{output}->output_add(
severity => 'OK',
short_msg => 'List brokers:'
);
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
$self->{output}->exit();
}
sub disco_format {
my ($self, %options) = @_;
$self->{output}->add_disco_format(elements => ['name']);
}
sub disco_show {
my ($self, %options) = @_;
my $results = $self->manage_selection(custom => $options{custom});
foreach (sort keys %$results) {
$self->{output}->add_disco_entry(
name => $_
);
}
}
1;
__END__
=head1 MODE
List brokers.
=over 8
=back
=cut

View File

@ -18,33 +18,33 @@
# limitations under the License.
#
package apps::bluemind::plugin;
package apps::mq::activemq::jmx::plugin;
use strict;
use warnings;
use base qw(centreon::plugins::script_simple);
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}} = (
'incoming' => 'apps::bluemind::mode::incoming',
'brokers' => 'apps::mq::activemq::jmx::mode::brokers',
'list-brokers' => 'apps::mq::activemq::jmx::mode::listbrokers'
);
$self->{custom_modes}{jolokia} = 'centreon::common::protocols::jmx::custom::jolokia';
return $self;
}
1;
__END__
=head1 PLUGIN DESCRIPTION
Check BlueMind through InfluxDB API
Check ActiveMQ in JMX. Need Jolokia agent.
=cut

View File

@ -25,7 +25,6 @@ use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::plugins::http;
use URI::Encode;
use JSON::XS;
sub new {

View File

@ -0,0 +1,211 @@
#
# Copyright 2020 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::mq::vernemq::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 => {
'api-key:s' => { name => 'api_key' },
'hostname:s' => { name => 'hostname' },
'port:s' => { name => 'port' },
'proto:s' => { name => 'proto' },
'timeout:s' => { name => 'timeout' },
'unknown-http-status:s' => { name => 'unknown_http_status' },
'warning-http-status:s' => { name => 'warning_http_status' },
'critical-http-status:s' => { name => 'critical_http_status' }
});
}
$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} : '';
$self->{port} = (defined($self->{option_results}->{port})) ? $self->{option_results}->{port} : 8888;
$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->{api_key} = (defined($self->{option_results}->{api_key})) ? $self->{option_results}->{api_key} : undef;
$self->{unknown_http_status} = (defined($self->{option_results}->{unknown_http_status})) ? $self->{option_results}->{unknown_http_status} : '%{http_code} < 200 or %{http_code} >= 300';
$self->{warning_http_status} = (defined($self->{option_results}->{warning_http_status})) ? $self->{option_results}->{warning_http_status} : '';
$self->{critical_http_status} = (defined($self->{option_results}->{critical_http_status})) ? $self->{option_results}->{critical_http_status} : '';
if (!defined($self->{hostname}) || $self->{hostname} eq '') {
$self->{output}->add_option_msg(short_msg => "Need to specify --hostname option.");
$self->{output}->option_exit();
}
if (!defined($self->{api_key}) || $self->{api_key} eq '') {
$self->{output}->add_option_msg(short_msg => "Need to specify --api-key option.");
$self->{output}->option_exit();
}
return 0;
}
sub build_options_for_httplib {
my ($self, %options) = @_;
$self->{option_results}->{hostname} = $self->{api_key} . '@' . $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};
}
sub settings {
my ($self, %options) = @_;
return if (defined($self->{settings_done}));
$self->build_options_for_httplib();
$self->{http}->add_header(key => 'Accept', value => 'application/json');
$self->{http}->add_header(key => 'Content-Type', value => 'application/json');
$self->{http}->set_options(%{$self->{option_results}});
$self->{settings_done} = 1;
}
sub get_hostname {
my ($self, %options) = @_;
return $self->{hostname};
}
sub get_port {
my ($self, %options) = @_;
return $self->{port};
}
sub request_api {
my ($self, %options) = @_;
$self->settings();
my $content = $self->{http}->request(
method => defined($options{method}) ? $options{method} : 'GET',
url_path => '/api/v1' . $options{endpoint},
unknown_status => $self->{unknown_http_status},
warning_status => $self->{warning_http_status},
critical_status => $self->{critical_http_status}
);
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();
}
my $decoded;
eval {
$decoded = JSON::XS->new->utf8->decode($content);
};
if ($@) {
$self->{output}->add_option_msg(short_msg => "Cannot decode response (add --debug option to display returned content)");
$self->{output}->option_exit();
}
return $decoded;
}
1;
__END__
=head1 NAME
VerneMQ Rest API
=head1 REST API OPTIONS
VerneMQ Rest API
=over 8
=item B<--hostname>
Set hostname.
=item B<--port>
Port used (Default: 8888)
=item B<--proto>
Specify https if needed (Default: 'http')
=item B<--api-key>
VerneMQ API Token.
=item B<--timeout>
Set timeout in seconds (Default: 10).
=back
=head1 DESCRIPTION
B<custom>.
=cut

View File

@ -0,0 +1,165 @@
#
# Copyright 2020 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::mq::vernemq::restapi::mode::clusters;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc);
sub custom_status_output {
my ($self, %options) = @_;
return 'status: ' . $self->{result_values}->{status};
}
sub prefix_cluster_output {
my ($self, %options) = @_;
return "Cluster '" . $options{instance_value}->{display} . "' ";
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0 },
{ name => 'clusters', type => 1, cb_prefix_output => 'prefix_cluster_output', message_multiple => 'All clusters are ok', skipped_code => { -10 => 1 } },
];
$self->{maps_counters}->{global} = [
{ label => 'running', nlabel => 'clusters.running.count', display_ok => 0, set => {
key_values => [ { name => 'running' } ],
output_template => 'current clusters running: %s',
perfdatas => [
{ value => 'running_absolute', template => '%s', min => 0 }
]
}
},
{ label => 'notrunning', nlabel => 'clusters.notrunning.count', display_ok => 0, set => {
key_values => [ { name => 'notrunning' } ],
output_template => 'current clusters not running: %s',
perfdatas => [
{ value => 'notrunning_absolute', template => '%s', min => 0 }
]
}
}
];
$self->{maps_counters}->{clusters} = [
{ label => 'status', threshold => 0, set => {
key_values => [ { name => 'status' }, { name => 'display' } ],
closure_custom_calc => \&catalog_status_calc,
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold
}
}
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
'filter-name:s' => { name => 'filter_name' },
'unknown-status:s' => { name => 'unknown_status', default => '' },
'warning-status:s' => { name => 'warning_status', default => '' },
'critical-status:s' => { name => 'critical_status', default => '%{status} eq "notRunning"' },
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$self->change_macros(macros => ['warning_status', 'critical_status', 'unknown_status']);
}
sub manage_selection {
my ($self, %options) = @_;
my $clusters = $options{custom}->request_api(endpoint => '/cluster/show');
$self->{global} = { running => 0, notrunning => 0 };
$self->{clusters} = {};
foreach (@{$clusters->{table}}) {
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
$_->{Node} !~ /$self->{option_results}->{filter_name}/) {
$self->{output}->output_add(long_msg => "skipping cluster '" . $_->{Node} . "': no matching filter.", debug => 1);
next;
}
$_->{Running} ? $self->{global}->{running}++ : $self->{global}->{notrunning}++;
$self->{clusters}->{$_->{Node}} = {
display => $_->{Node},
status => $_->{Running} ? 'running' : 'notRunning'
};
}
if (scalar(keys %{$self->{clusters}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No cluster found");
$self->{output}->option_exit();
}
}
1;
__END__
=head1 MODE
Check clusters.
=over 8
=item B<--filter-name>
Filter cluster name (can be a regexp).
=item B<--unknown-status>
Set unknown threshold for status.
Can used special variables like: %{status}, %{display}
=item B<--warning-status>
Set warning threshold for status.
Can used special variables like: %{status}, %{display}
=item B<--critical-status>
Set critical threshold for status (Default: '%{status} eq "notRunning"').
Can used special variables like: %{status}, %{display}
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'running', 'notrunning'.
=back
=cut

View File

@ -0,0 +1,165 @@
#
# Copyright 2020 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::mq::vernemq::restapi::mode::listeners;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc);
sub custom_status_output {
my ($self, %options) = @_;
return 'status: ' . $self->{result_values}->{status};
}
sub prefix_listener_output {
my ($self, %options) = @_;
return "Listener '" . $options{instance_value}->{display} . "' ";
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0 },
{ name => 'listeners', type => 1, cb_prefix_output => 'prefix_listener_output', message_multiple => 'All listeners are ok', skipped_code => { -10 => 1 } },
];
$self->{maps_counters}->{global} = [
{ label => 'running', nlabel => 'listeners.running.count', display_ok => 0, set => {
key_values => [ { name => 'running' } ],
output_template => 'current listeners running: %s',
perfdatas => [
{ value => 'running_absolute', template => '%s', min => 0 }
]
}
},
{ label => 'notrunning', nlabel => 'listeners.notrunning.count', display_ok => 0, set => {
key_values => [ { name => 'notrunning' } ],
output_template => 'current listeners not running: %s',
perfdatas => [
{ value => 'notrunning_absolute', template => '%s', min => 0 }
]
}
}
];
$self->{maps_counters}->{listeners} = [
{ label => 'status', threshold => 0, set => {
key_values => [ { name => 'status' }, { name => 'display' } ],
closure_custom_calc => \&catalog_status_calc,
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold
}
}
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
'filter-type:s' => { name => 'filter_type' },
'unknown-status:s' => { name => 'unknown_status', default => '' },
'warning-status:s' => { name => 'warning_status', default => '' },
'critical-status:s' => { name => 'critical_status', default => '%{status} ne "running"' },
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$self->change_macros(macros => ['warning_status', 'critical_status', 'unknown_status']);
}
sub manage_selection {
my ($self, %options) = @_;
my $clusters = $options{custom}->request_api(endpoint => '/listener/show');
$self->{global} = { running => 0, notrunning => 0 };
$self->{listeners} = {};
foreach (@{$clusters->{table}}) {
if (defined($self->{option_results}->{filter_type}) && $self->{option_results}->{filter_type} ne '' &&
$_->{type} !~ /$self->{option_results}->{filter_type}/) {
$self->{output}->output_add(long_msg => "skipping listeners '" . $_->{type} . "': no matching filter.", debug => 1);
next;
}
$_->{status} eq 'running' ? $self->{global}->{running}++ : $self->{global}->{notrunning}++;
$self->{listeners}->{$_->{type}} = {
display => $_->{type},
status => $_->{status}
};
}
if (scalar(keys %{$self->{listeners}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No listener found");
$self->{output}->option_exit();
}
}
1;
__END__
=head1 MODE
Check listeners.
=over 8
=item B<--filter-type>
Filter listener type (can be a regexp).
=item B<--unknown-status>
Set unknown threshold for status.
Can used special variables like: %{status}, %{display}
=item B<--warning-status>
Set warning threshold for status.
Can used special variables like: %{status}, %{display}
=item B<--critical-status>
Set critical threshold for status (Default: '%{status} ne "running"').
Can used special variables like: %{status}, %{display}
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'running', 'notrunning'.
=back
=cut

View File

@ -0,0 +1,100 @@
#
# Copyright 2020 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::mq::vernemq::restapi::mode::plugins;
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, skipped_code => { -10 => 1 } }
];
$self->{maps_counters}->{global} = [
{ label => 'total', nlabel => 'plugins.total.count', set => {
key_values => [ { name => 'total' } ],
output_template => 'current total plugins: %s',
perfdatas => [
{ value => 'total_absolute', template => '%s', min => 0 }
]
}
}
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
'filter-name:s' => { name => 'filter_name' }
});
return $self;
}
sub manage_selection {
my ($self, %options) = @_;
my $plugins = $options{custom}->request_api(
endpoint => '/plugin/show'
);
$self->{global} = { total => 0 };
foreach (@{$plugins->{table}}) {
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
$_->{Plugin} !~ /$self->{option_results}->{filter_name}/) {
$self->{output}->output_add(long_msg => "skipping plugin '" . $_->{Plugin} . "': no matching filter.", debug => 1);
next;
}
$self->{output}->output_add(long_msg => "plugin '" . $_->{Plugin} . "'");
$self->{global}->{total}++;
}
}
1;
__END__
=head1 MODE
Check plugins.
=over 8
=item B<--filter-name>
Filter plugin name (can be a regexp).
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'total'.
=back
=cut

View File

@ -0,0 +1,103 @@
#
# Copyright 2020 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::mq::vernemq::restapi::mode::sessions;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
sub prefix_session_output {
my ($self, %options) = @_;
return 'Sessions ';
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0, cb_prefix_output => 'prefix_session_output', skipped_code => { -10 => 1 } }
];
$self->{maps_counters}->{global} = [
{ label => 'online', nlabel => 'sessions.online.count', set => {
key_values => [ { name => 'online' } ],
output_template => 'current online: %s',
perfdatas => [
{ value => 'online_absolute', template => '%s', min => 0 }
]
}
},
{ label => 'total', nlabel => 'sessions.total.count', set => {
key_values => [ { name => 'total' } ],
output_template => 'current total: %s',
perfdatas => [
{ value => 'total_absolute', template => '%s', min => 0 }
]
}
}
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
});
return $self;
}
sub manage_selection {
my ($self, %options) = @_;
my $sessions = $options{custom}->request_api(
endpoint => '/session/show'
);
$self->{global} = { total => 0, online => 0 };
foreach (@{$sessions->{table}}) {
$self->{global}->{online}++ if ($_->{is_online});
$self->{global}->{total}++;
}
}
1;
__END__
=head1 MODE
Check sessions.
=over 8
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'total', 'online'.
=back
=cut

View File

@ -0,0 +1,52 @@
#
# Copyright 2020 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::mq::vernemq::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} } = (
'clusters' => 'apps::mq::vernemq::restapi::mode::clusters',
'listeners' => 'apps::mq::vernemq::restapi::mode::listeners',
'plugins' => 'apps::mq::vernemq::restapi::mode::plugins',
'sessions' => 'apps::mq::vernemq::restapi::mode::sessions'
);
$self->{custom_modes}{api} = 'apps::mq::vernemq::restapi::custom::api';
return $self;
}
1;
__END__
=head1 PLUGIN DESCRIPTION
Check VerneMQ using Rest API.
=cut

View File

@ -0,0 +1,347 @@
#
# Copyright 2020 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::mulesoft::restapi::custom::api;
use strict;
use warnings;
use DateTime;
use centreon::plugins::http;
use centreon::plugins::statefile;
use JSON::XS;
use URI::Encode;
use Digest::MD5 qw(md5_hex);
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 => {
'api-username:s' => { name => 'api_username' },
'api-password:s' => { name => 'api_password' },
'environment-id:s' => { name => 'environment_id' },
'organization-id:s' => { name => 'organization_id' },
'hostname:s' => { name => 'hostname' },
'port:s' => { name => 'port' },
'proto:s' => { name => 'proto' },
'timeout:s' => { name => 'timeout' },
'reload-cache-time:s' => { name => 'reload_cache_time' },
'authent-endpoint:s' => { name => 'authent_endpoint'},
'monitoring-endpoint:s' => { name => 'monitoring_endpoint'},
});
}
$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);
$self->{cache} = centreon::plugins::statefile->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} : 'eu1.anypoint.mulesoft.com';
$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->{timeout} = (defined($self->{option_results}->{timeout})) ? $self->{option_results}->{timeout} : 10;
$self->{authent_endpoint} = (defined($self->{option_results}->{authent_endpoint})) ? $self->{option_results}->{authent_endpoint} : '/accounts/login';
$self->{monitoring_endpoint} = (defined($self->{option_results}->{monitoring_endpoint})) ? $self->{option_results}->{monitoring_endpoint} : '/hybrid/api/v1';
$self->{api_username} = (defined($self->{option_results}->{api_username})) ? $self->{option_results}->{api_username} : '';
$self->{api_password} = (defined($self->{option_results}->{api_password})) ? $self->{option_results}->{api_password} : '';
$self->{environment_id} = (defined($self->{option_results}->{environment_id})) ? $self->{option_results}->{environment_id} : '';
$self->{organization_id} = (defined($self->{option_results}->{organization_id})) ? $self->{option_results}->{organization_id} : '';
$self->{reload_cache_time} = (defined($self->{option_results}->{reload_cache_time})) ? $self->{option_results}->{reload_cache_time} : 180;
$self->{cache}->check_options(option_results => $self->{option_results});
if (!defined($self->{environment_id}) || $self->{environment_id} eq '' || !defined($self->{organization_id}) || $self->{organization_id} eq '' ) {
$self->{output}->add_option_msg(short_msg => "--environment-id and --organization-id must be set");
$self->{output}->option_exit();
}
if (!defined($self->{api_username}) || $self->{api_username} eq '' || !defined($self->{api_password}) || $self->{api_password} eq '' ) {
$self->{output}->add_option_msg(short_msg => "--api-username and --api-password must be set");
$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} > 400';
}
sub settings {
my ($self, %options) = @_;
$self->build_options_for_httplib();
$self->{http}->add_header(key => 'Accept', value => 'application/json');
$self->{http}->add_header(key => 'Content-Type', value => $options{content_type});
$self->{http}->add_header(key => 'Authorization', value => 'Bearer ' . $self->{access_token}) if (defined($self->{access_token}));
$self->{http}->add_header(key => 'X-ANYPNT-ENV-ID', value => $self->{environment_id}) if (defined $options{environment_header});
$self->{http}->add_header(key => 'X-ANYPNT-ORG-ID', value => $self->{organization_id}) if (defined $options{organization_header});
$self->{http}->set_options(%{$self->{option_results}});
}
sub get_access_token {
my ($self, %options) = @_;
my $has_cache_file = $options{statefile}->read(statefile => 'mulesoft_api_' . md5_hex($self->{hostname}) . '_' . md5_hex($self->{api_username}));
my $expires_on = $options{statefile}->get(name => 'expires_on');
my $access_token = $options{statefile}->get(name => 'access_token');
if ( $has_cache_file == 0 || !defined($access_token) || (($expires_on - time()) < 10) ) {
my $login = { username => $self->{api_username}, password => $self->{api_password} };
my $post_json = JSON::XS->new->utf8->encode($login);
$self->settings(content_type => 'application/json');
my $content = $self->{http}->request(
method => 'POST',
query_form_post => $post_json,
url_path => $self->{authent_endpoint}
);
if (!defined($content) || $content eq '') {
$self->{output}->add_option_msg(short_msg => "Authentication endpoint returns empty content [code: '" . $self->{http}->get_code() . "'] [message: '" . $self->{http}->get_message() . "']");
$self->{output}->option_exit();
}
my $decoded;
eval {
$decoded = JSON::XS->new->utf8->decode($content);
};
if ($@) {
$self->{output}->output_add(long_msg => $content, debug => 1);
$self->{output}->add_option_msg(short_msg => "Cannot decode response (add --debug option to display returned content)");
$self->{output}->option_exit();
}
if (defined($decoded->{error_code})) {
$self->{output}->output_add(long_msg => "Error message : " . $decoded->{error}, debug => 1);
$self->{output}->add_option_msg(short_msg => "Authentication endpoint returns error code '" . $decoded->{error_code} . "' (add --debug option for detailed message)");
$self->{output}->option_exit();
}
$access_token = $decoded->{access_token};
my $datas = { last_timestamp => time(), access_token => $decoded->{access_token}, expires_on => time() + 3600 };
$options{statefile}->write(data => $datas);
}
return $access_token;
}
sub request_api {
my ($self, %options) = @_;
if (!defined($self->{access_token})) {
$self->{access_token} = $self->get_access_token(statefile => $self->{cache});
}
$self->settings(content_type => 'application/x-www-form-urlencoded', environment_header => 1, organization_header => 1);
$self->{output}->output_add(long_msg => "URL: '" . $self->{proto} . '://' . $self->{hostname} . ':' . $self->{port} .
$options{url_path} . "'", debug => 1);
my $content = $self->{http}->request(%options);
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();
}
my $decoded;
eval {
$decoded = JSON::XS->new->utf8->decode($content);
};
if ($@) {
$self->{output}->output_add(long_msg => $content, debug => 1);
$self->{output}->add_option_msg(short_msg => "Cannot decode response (add --debug option to display returned content)");
$self->{output}->option_exit();
}
if (defined($decoded->{error_code})) {
$self->{output}->output_add(long_msg => "Error message : " . $decoded->{error}, debug => 1);
$self->{output}->add_option_msg(short_msg => "API returns error code '" . $decoded->{error_code} . "' (add --debug option for detailed message)");
$self->{output}->option_exit();
}
return $decoded;
}
sub list_applications {
my ($self, %options) = @_;
my $url_path = $self->{monitoring_endpoint} . '/applications';
my $response = $self->request_api(method => 'GET', url_path => $url_path);
return $response->{data};
}
sub get_application_status {
my ($self, %options) = @_;
my $url_path = $self->{monitoring_endpoint} . '/applications/' . $options{applicationId};
my $response = $self->request_api(method => 'GET', url_path => $url_path);
return $response->{data};
}
sub list_servers {
my ($self, %options) = @_;
my $url_path = $self->{monitoring_endpoint} . '/servers/';
my $response = $self->request_api(method => 'GET', url_path => $url_path);
return $response->{data};
}
sub get_server_status {
my ($self, %options) = @_;
my $url_path = $self->{monitoring_endpoint} . '/servers/' . $options{serverId};
my $response = $self->request_api(method => 'GET', url_path => $url_path);
return $response->{data};
}
sub list_clusters {
my ($self, %options) = @_;
my $url_path = $self->{monitoring_endpoint} . '/clusters/';
my $response = $self->request_api(method => 'GET', url_path => $url_path);
return $response->{data};
}
sub cache_hosts {
my ($self, %options) = @_;
$self->{cache_hosts} = centreon::plugins::statefile->new(%options);
$self->{cache_hosts}->check_options(option_results => $self->{option_results});
my $has_cache_file = $self->{cache_hosts}->read(statefile => 'cache_ovirt_hosts_' . md5_hex($self->{hostname}) . '_' . md5_hex($self->{api_username}));
my $timestamp_cache = $self->{cache_hosts}->get(name => 'last_timestamp');
my $hosts = $self->{cache_hosts}->get(name => 'hosts');
if ($has_cache_file == 0 || !defined($timestamp_cache) || ((time() - $timestamp_cache) > (($self->{reload_cache_time}) * 60))) {
$hosts = [];
my $datas = { last_timestamp => time(), hosts => $hosts };
my $list = $self->list_hosts();
foreach (@{$list}) {
push @{$hosts}, { id => $_->{id}, name => $_->{name} };
}
$self->{cache_hosts}->write(data => $datas);
}
return $hosts;
}
1;
__END__
=head1 NAME
Mulesoft Rest API
=head1 REST API OPTIONS
Mulesoft Rest API
=over 8
=item B<--hostname>
Mulesoft API hostname (Default: anypoint.mulesoft.com).
=item B<--port>
Port used (Default: 443)
=item B<--proto>
Specify https if needed (Default: 'https')
=item B<--api-username>
Mulesoft API username (mandatory).
=item B<--api-password>
Mulesoft API password (mandatory).
=item B<--environment-id>
Mulesoft API Environment ID (mandatory).
=item B<--organization-id>
Mulesoft API Organization ID (mandatory).
=item B<--timeout>
Set timeout in seconds (Default: 10).
=back
=head1 DESCRIPTION
B<custom>.
=cut

View File

@ -0,0 +1,182 @@
#
# Copyright 2020 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::mulesoft::restapi::mode::applications;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc);
sub custom_status_output {
my ($self, %options) = @_;
return sprintf('Id: %s, Status: %s', $self->{result_values}->{id}, $self->{result_values}->{status});
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0, cb_prefix_output => 'prefix_global_output' },
{ name => 'applications', type => 1, cb_prefix_output => 'prefix_application_output', message_multiple => 'All applications are ok' }
];
$self->{maps_counters}->{global} = [
{ label => 'total', nlabel => 'mulesoft.applications.total.count', set => {
key_values => [ { name => 'total' } ],
output_template => "Total : %s",
perfdatas => [ { value => 'total_absolute', template => '%d', min => 0 } ]
}
},
{ label => 'started', nlabel => 'mulesoft.applications.status.started.count', set => {
key_values => [ { name => 'started' } ],
output_template => "Started : %s",
perfdatas => [ { value => 'started_absolute', template => '%d', min => 0 } ]
}
},
{ label => 'stopped', nlabel => 'mulesoft.applications.status.stopped.count', set => {
key_values => [ { name => 'stopped' } ],
output_template => "Stopped : %s",
perfdatas => [ { value => 'stopped_absolute', template => '%d', min => 0 } ]
}
},
{ label => 'failed', nlabel => 'mulesoft.applications.status.failed.count', set => {
key_values => [ { name => 'failed' } ],
output_template => "Failed : %s",
perfdatas => [ { value => 'failed_absolute', template => '%d', min => 0 } ]
}
}
];
$self->{maps_counters}->{applications} = [
{ label => 'status', threshold => 0, set => {
key_values => [ { name => 'id' }, { name => 'status' }, { name => 'name'}, { name => 'display' } ],
closure_custom_calc => \&catalog_status_calc,
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold
}
}
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$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 => '' }
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$self->change_macros(macros => ['warning_status', 'critical_status']);
}
sub prefix_global_output {
my ($self, %options) = @_;
return "Total applications ";
}
sub prefix_application_output {
my ($self, %options) = @_;
return "Application '" . $options{instance_value}->{name} . "' ";
}
sub manage_selection {
my ($self, %options) = @_;
$self->{global} = { started => 0, stopped => 0, failed => 0 };
$self->{applications} = {};
my $result = $options{custom}->list_applications();
foreach my $application (@{$result}) {
next if ( defined($self->{option_results}->{filter_name})
&& $self->{option_results}->{filter_name} ne ''
&& $application->{name} !~ /$self->{option_results}->{filter_name}/ );
$self->{applications}->{$application} = {
display => $application,
id => $application->{id},
name => $application->{name},
status => $application->{lastReportedStatus},
};
$self->{global}->{started}++ if $application->{lastReportedStatus} =~ m/STARTED/;
$self->{global}->{stopped}++ if $application->{lastReportedStatus} =~ m/STOPPED/;
$self->{global}->{failed}++ if $application->{lastReportedStatus} =~ m/FAILED/;
}
if (scalar(keys %{$self->{applications}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No application found.");
$self->{output}->option_exit();
}
$self->{global}->{total} = scalar (keys %{$self->{applications}});
}
1;
__END__
=head1 MODE
Check Mulesoft Anypoint Applications status.
Example:
perl centreon_plugins.pl --plugin=apps::mulesoft::restapi::plugin --mode=applications
--environment-id='1234abc-56de-78fg-90hi-1234abcdefg' --organization-id='1234abcd-56ef-78fg-90hi-1234abcdefg'
--api-username='myapiuser' --api-password='myapipassword' --verbose
More information on'https://anypoint.mulesoft.com/exchange/portals/anypoint-platform/'.
=over 8
=item B<--filter-name>
Filter by application name (Regexp can be used).
Example: --filter-name='^application1$'
=item B<--warning-status>
Set warning threshold for status (Default: '').
Threshold can be matched on %{name}, %{id} or %{status} and Regexp can be used.
Typical syntax: --warning-status='%{status} ne "STARTED"'
=item B<--critical-status>
Set warning threshold for status (Default: '').
Threshold can be matched on %{name}, %{id} or %{status} and Regexp can be used.
Typical syntax: --critical-status='%{status} ~= m/FAILED/'
=back
=cut

View File

@ -0,0 +1,181 @@
#
# Copyright 2020 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and cluster 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::mulesoft::restapi::mode::clusters;
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 my $msg = sprintf('Id: %s, Status: %s', $self->{result_values}->{id}, $self->{result_values}->{status});
}
sub custom_status_calc {
my ($self, %options) = @_;
$self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'};
$self->{result_values}->{id} = $options{new_datas}->{$self->{instance} . '_id'};
return 0;
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0, cb_prefix_output => 'prefix_global_output' },
{ name => 'clusters', type => 1, cb_prefix_output => 'prefix_cluster_output', message_multiple => 'All clusters are ok' }
];
$self->{maps_counters}->{global} = [
{ label => 'total', nlabel => 'mulesoft.clusters.total.count', set => {
key_values => [ { name => 'total' } ],
output_template => "Total : %s",
perfdatas => [ { value => 'total_absolute', template => '%d', min => 0 } ],
}
},
{ label => 'running', nlabel => 'mulesoft.clusters.status.running.count', set => {
key_values => [ { name => 'running' } ],
output_template => "Running : %s",
perfdatas => [ { value => 'running_absolute', template => '%d', min => 0 } ]
}
},
{ label => 'disconnected', nlabel => 'mulesoft.clusters.status.disconnected.count', set => {
key_values => [ { name => 'disconnected' } ],
output_template => "Disconnected : %s",
perfdatas => [ { value => 'disconnected_absolute', template => '%d', min => 0 } ]
}
}
];
$self->{maps_counters}->{clusters} = [
{ label => 'status', threshold => 0, set => {
key_values => [ { name => 'id' }, { name => 'status' }, { name => 'name'}, { 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,
}
},
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$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 => '' },
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$self->change_macros(macros => ['warning_status', 'critical_status']);
}
sub prefix_global_output {
my ($self, %options) = @_;
return "Total clusters ";
}
sub prefix_cluster_output {
my ($self, %options) = @_;
return "cluster '" . $options{instance_value}->{name} . "' ";
}
sub manage_selection {
my ($self, %options) = @_;
$self->{global} = { started => 0, stopped => 0, failed => 0 };
$self->{clusters} = {};
my $result = $options{custom}->list_clusters();
foreach my $cluster (@{$result}) {
next if ( defined($self->{option_results}->{filter_name})
&& $self->{option_results}->{filter_name} ne ''
&& $cluster->{name} !~ /$self->{option_results}->{filter_name}/ );
$self->{clusters}->{$cluster} = {
display => $cluster,
id => $cluster->{id},
name => $cluster->{name},
status => $cluster->{status},
};
$self->{global}->{running}++ if $cluster->{status} =~ m/RUNNING/;
$self->{global}->{disconnected}++ if $cluster->{status} =~ m/DISCONNECTED/;
}
if (scalar(keys %{$self->{clusters}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No cluster found.");
$self->{output}->option_exit();
}
$self->{global}->{total} = scalar (keys %{$self->{clusters}});
}
1;
__END__
=head1 MODE
Check Mulesoft Anypoint clusters status.
Example:
perl centreon_plugins.pl --plugin=apps::mulesoft::restapi::plugin --mode=clusters
--environment-id='1234abc-56de-78fg-90hi-1234abcdefg' --organization-id='1234abcd-56ef-78fg-90hi-1234abcdefg'
--api-username='myapiuser' --api-password='myapipassword' --verbose
More information on'https://anypoint.mulesoft.com/exchange/portals/anypoint-platform/'.
=over 8
=item B<--filter-name>
Filter by cluster name (Regexp can be used).
Example: --filter-name='^cluster1$'
=item B<--warning-status>
Set warning threshold for status (Default: '').
Threshold can be matched on %{name}, %{id} or %{status} and Regexp can be used.
Typical syntax: --warning-status='%{status} ne "RUNNING"'
=item B<--critical-status>
Set warning threshold for status (Default: '').
Threshold can be matched on %{name}, %{id} or %{status} and Regexp can be used.
Typical syntax: --critical-status='%{status} ~= m/DISCONNECTED/'
=back
=cut

View File

@ -0,0 +1,109 @@
#
# Copyright 2020 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::mulesoft::restapi::mode::listapplications;
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;
$options{options}->add_options(arguments => {
'filter-name:s' => { name => 'filter_name' },
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
}
sub manage_selection {
my ($self, %options) = @_;
$self->{data} = $options{custom}->list_applications();
}
sub run {
my ($self, %options) = @_;
my $result = $options{custom}->list_applications();
foreach my $application (@{$result}) {
next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne ''
&& $application->{name} !~ /$self->{option_results}->{filter_name}/);
$self->{output}->output_add(
long_msg => sprintf(
"[id = %s][name = %s][status = %s]",
$application->{id},
$application->{name},
$application->{lastReportedStatus}
)
);
}
$self->{output}->output_add(severity => 'OK', short_msg => 'Mulesoft Anypoint Applications:');
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
$self->{output}->exit();
}
sub disco_format {
my ($self, %options) = @_;
$self->{output}->add_disco_format(elements => ['id', 'name', 'status']);
}
sub disco_show {
my ($self, %options) = @_;
$self->manage_selection(%options);
foreach my $application (@{$self->{data}}) {
$self->{output}->add_disco_entry(
id => $application->{id},
name => $application->{name},
status => $application->{lastReportedStatus},
);
}
}
1;
__END__
=head1 MODE
List Mulesoft Anypoint applications.
=over 8
=item B<--filter-name>
Filter application name (Can be a regexp).
=back
=cut

View File

@ -0,0 +1,103 @@
#
# Copyright 2020 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and server 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::mulesoft::restapi::mode::listservers;
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;
$options{options}->add_options(arguments => {
'filter-name:s' => { name => 'filter_name' },
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
}
sub run {
my ($self, %options) = @_;
my $result = $options{custom}->list_servers();
foreach my $server (@{$result}) {
next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne ''
&& $server->{name} !~ /$self->{option_results}->{filter_name}/);
$self->{output}->output_add(
long_msg => sprintf(
"[id = %s][name = %s][status = %s]",
$server->{id},
$server->{name},
$server->{status}
)
);
}
$self->{output}->output_add(severity => 'OK', short_msg => 'Mulesoft Anypoint Servers:');
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
$self->{output}->exit();
}
sub disco_format {
my ($self, %options) = @_;
$self->{output}->add_disco_format(elements => ['id', 'name', 'status']);
}
sub disco_show {
my ($self, %options) = @_;
my $result = $options{custom}->list_servers();
foreach my $server (@{$result}) {
$self->{output}->add_disco_entry(
id => $server->{id},
name => $server->{name},
status => $server->{status},
);
}
}
1;
__END__
=head1 MODE
List Mulesoft Anypoint Servers.
=over 8
=item B<--filter-name>
Filter server name (Can be a regexp).
=back
=cut

View File

@ -0,0 +1,174 @@
#
# Copyright 2020 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and server 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::mulesoft::restapi::mode::servers;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc);
sub custom_status_output {
my ($self, %options) = @_;
return sprintf('Id: %s, Status: %s', $self->{result_values}->{id}, $self->{result_values}->{status});
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0, cb_prefix_output => 'prefix_global_output' },
{ name => 'servers', type => 1, cb_prefix_output => 'prefix_server_output', message_multiple => 'All servers are ok' }
];
$self->{maps_counters}->{global} = [
{ label => 'total', nlabel => 'mulesoft.servers.total.count', set => {
key_values => [ { name => 'total' } ],
output_template => 'Total : %s',
perfdatas => [ { value => 'total_absolute', template => '%d', min => 0 } ]
}
},
{ label => 'running', nlabel => 'mulesoft.servers.status.running.count', set => {
key_values => [ { name => 'running' } ],
output_template => 'Running : %s',
perfdatas => [ { value => 'running_absolute', template => '%d', min => 0 } ]
}
},
{ label => 'disconnected', nlabel => 'mulesoft.servers.status.disconnected.count', set => {
key_values => [ { name => 'disconnected' } ],
output_template => 'Disconnected : %s',
perfdatas => [ { value => 'disconnected_absolute', template => '%d', min => 0 } ]
}
}
];
$self->{maps_counters}->{servers} = [
{ label => 'status', threshold => 0, set => {
key_values => [ { name => 'id' }, { name => 'status' }, { name => 'name'}, { name => 'display' } ],
closure_custom_calc => \&catalog_status_calc,
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold
}
}
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$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 => '' },
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$self->change_macros(macros => ['warning_status', 'critical_status']);
}
sub prefix_global_output {
my ($self, %options) = @_;
return "Total servers ";
}
sub prefix_server_output {
my ($self, %options) = @_;
return "Server '" . $options{instance_value}->{name} . "' ";
}
sub manage_selection {
my ($self, %options) = @_;
$self->{global} = { started => 0, stopped => 0, failed => 0 };
$self->{servers} = {};
my $result = $options{custom}->list_servers();
foreach my $server (@{$result}) {
next if ( defined($self->{option_results}->{filter_name})
&& $self->{option_results}->{filter_name} ne ''
&& $server->{name} !~ /$self->{option_results}->{filter_name}/ );
$self->{servers}->{$server} = {
display => $server,
id => $server->{id},
name => $server->{name},
status => $server->{status},
};
$self->{global}->{running}++ if $server->{status} =~ m/RUNNING/;
$self->{global}->{disconnected}++ if $server->{status} =~ m/DISCONNECTED/;
}
if (scalar(keys %{$self->{servers}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No server found.");
$self->{output}->option_exit();
}
$self->{global}->{total} = scalar (keys %{$self->{servers}});
}
1;
__END__
=head1 MODE
Check Mulesoft Anypoint Servers status.
Example:
perl centreon_plugins.pl --plugin=apps::mulesoft::restapi::plugin --mode=servers
--environment-id='1234abc-56de-78fg-90hi-1234abcdefg' --organization-id='1234abcd-56ef-78fg-90hi-1234abcdefg'
--api-username='myapiuser' --api-password='myapipassword' --verbose
More information on'https://anypoint.mulesoft.com/exchange/portals/anypoint-platform/'.
=over 8
=item B<--filter-name>
Filter by server name (Regexp can be used).
Example: --filter-name='^server1$'
=item B<--warning-status>
Set warning threshold for status (Default: '').
Threshold can be matched on %{name}, %{id} or %{status} and Regexp can be used.
Typical syntax: --warning-status='%{status} ne "RUNNING"'
=item B<--critical-status>
Set warning threshold for status (Default: '').
Threshold can be matched on %{name}, %{id} or %{status} and Regexp can be used.
Typical syntax: --critical-status='%{status} ~= m/DISCONNECTED/'
=back
=cut

View File

@ -0,0 +1,53 @@
#
# Copyright 2020 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::mulesoft::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} = '1.0';
%{$self->{modes}} = (
'applications' => 'apps::mulesoft::restapi::mode::applications',
'listapplications' => 'apps::mulesoft::restapi::mode::listapplications',
'servers' => 'apps::mulesoft::restapi::mode::servers',
'listservers' => 'apps::mulesoft::restapi::mode::listservers',
'clusters' => 'apps::mulesoft::restapi::mode::clusters'
);
$self->{custom_modes}{restapi} = 'apps::mulesoft::restapi::custom::api';
return $self;
}
1;
__END__
=head1 PLUGIN DESCRIPTION
Check Mulesoft components using API.
=cut

View File

@ -26,46 +26,44 @@ use Net::DNS;
my $handle;
my %map_search_field = (
MX => 'exchange',
SOA => 'mname',
NS => 'nsdname',
A => 'address',
PTR => 'name',
CNAME => 'cname',
TXT => 'txtdata',
);
sub search {
my ($self, %options) = @_;
my $map_search_field = {
MX => 'exchange',
SOA => 'mname',
NS => 'nsdname',
A => 'address',
PTR => 'name',
CNAME => 'cname',
TXT => 'txtdata'
};
my @results = ();
my $search_type = $self->{option_results}->{search_type};
if (defined($search_type) && !defined($map_search_field{$search_type})) {
if (defined($search_type) && !defined($map_search_field->{$search_type})) {
$self->{output}->add_option_msg(short_msg => "search-type '$search_type' is unknown or unsupported");
$self->{output}->option_exit();
}
$map_search_field->{PTR} = 'ptrdname' if (defined($self->{option_results}->{use_ptr_fqdn}));
my $error_quit = defined($options{error_quit}) ? $options{error_quit} : undef;
my $reply = $handle->search($self->{option_results}->{search}, $search_type);
if ($reply) {
foreach my $rr ($reply->answer) {
if (!defined($search_type)) {
push @results, $rr->address if ($rr->type eq 'A');
push @results, $rr->name if ($rr->type eq 'PTR');
push @results, $rr->txtdata if ($rr->type eq 'TXT');
next;
}
next if ($rr->type ne $search_type);
my $search_field = $map_search_field{$search_type};
push @results, $rr->$search_field;
my $type = defined($search_type) ? $search_type : $rr->type;
next if ($type ne $rr->type);
my $attr = $map_search_field->{$type};
push @results, $rr->$attr;
}
} else {
if (defined($error_quit)) {
$self->{output}->output_add(severity => $error_quit,
short_msg => sprintf("DNS Query Failed: %s", $handle->errorstring));
$self->{output}->output_add(
severity => $error_quit,
short_msg => sprintf('DNS query failed: %s', $handle->errorstring)
);
$self->{output}->display();
$self->{output}->exit();
}

View File

@ -34,18 +34,18 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$options{options}->add_options(arguments =>
{
"nameservers:s@" => { name => 'nameservers' },
"searchlist:s@" => { name => 'searchlist' },
"dns-options:s@" => { name => 'dns_options' },
"search:s" => { name => 'search' },
"search-type:s" => { name => 'search_type' },
"expected-answer:s" => { name => 'expected_answer' },
"warning:s" => { name => 'warning' },
"critical:s" => { name => 'critical' },
"memory" => { name => 'memory' },
});
$options{options}->add_options(arguments => {
'nameservers:s@' => { name => 'nameservers' },
'searchlist:s@' => { name => 'searchlist' },
'dns-options:s@' => { name => 'dns_options' },
'search:s' => { name => 'search' },
'search-type:s' => { name => 'search_type' },
'use-ptr-fqdn' => { name => 'use_ptr_fqdn' },
'expected-answer:s' => { name => 'expected_answer' },
'warning:s' => { name => 'warning' },
'critical:s' => { name => 'critical' },
'memory' => { name => 'memory' }
});
$self->{statefile_cache} = centreon::plugins::statefile->new(%options);
return $self;
@ -96,14 +96,20 @@ sub run {
my $timeelapsed = tv_interval ($timing0, [gettimeofday]);
my $result_str = join(', ', @results);
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) (answer: %s)", $timeelapsed, $result_str));
$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'));
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) (answer: %s)", $timeelapsed, $result_str)
);
$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')
);
if (defined($self->{option_results}->{expected_answer}) && $self->{option_results}->{expected_answer} ne '') {
my $match = 0;
@ -114,8 +120,11 @@ sub run {
}
if ($match == 0) {
$self->{output}->output_add(severity => 'CRITICAL',
short_msg => sprintf("No result values match expected answer (answer: %s)", $result_str));
$self->{output}->output_add(
severity => 'CRITICAL',
short_msg => sprintf("No result values match expected answer (answer: %s)", $result_str
)
);
}
}
@ -125,15 +134,17 @@ sub run {
my $old_result = $self->{statefile_cache}->get(name => "result");
if (defined($old_result)) {
if ($old_result ne $result_str) {
$self->{output}->output_add(severity => 'CRITICAL',
short_msg => sprintf("Result has changed [answer: %s] [old answer: %s]", $result_str, $old_result));
$self->{output}->output_add(
severity => 'CRITICAL',
short_msg => sprintf("Result has changed [answer: %s] [old answer: %s]", $result_str, $old_result)
);
}
} else {
$self->{output}->output_add(long_msg => 'cache file created.');
}
$self->{statefile_cache}->write(data => $datas);
}
$self->{output}->display();
$self->{output}->exit();
}
@ -169,6 +180,10 @@ Set the search value (required).
Set the search type. Can be: 'MX', 'SOA', 'NS', 'A', 'CNAME' or 'PTR'.
'A' or 'PTR' is used by default (depends if an IP or not).
=item B<--use-ptr-fqdn>
Search is done on conical names for PTR type.
=item B<--expected-answer>
What the server must answer (can be a regexp).

View File

@ -20,115 +20,130 @@
package apps::protocols::http::mode::response;
use base qw(centreon::plugins::mode);
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc);
use Time::HiRes qw(gettimeofday tv_interval);
use centreon::plugins::http;
sub custom_status_output {
my ($self, %options) = @_;
return $self->{result_values}->{http_code} . ' ' . $self->{result_values}->{message};
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0 }
];
$self->{maps_counters}->{global} = [
{ label => 'status', threshold => 0, display_ok => 0, set => {
key_values => [
{ name => 'http_code' }, { name => 'message' }
],
closure_custom_calc => \&catalog_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', nlabel => 'http.response.time.seconds', set => {
key_values => [ { name => 'time' } ],
output_template => 'Response time %.3fs',
perfdatas => [
{ label => 'time', value => 'time_absolute', template => '%.3f', min => 0, unit => 's' }
]
}
},
{ label => 'size', nlabel => 'http.response.size.count', 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' }
]
}
}
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$options{options}->add_options(arguments => {
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port', },
"method:s" => { name => 'method' },
"proto:s" => { name => 'proto' },
"urlpath:s" => { name => 'url_path' },
"credentials" => { name => 'credentials' },
"basic" => { name => 'basic' },
"ntlmv2" => { name => 'ntlmv2' },
"username:s" => { name => 'username' },
"password:s" => { name => 'password' },
"timeout:s" => { name => 'timeout' },
"no-follow" => { name => 'no_follow', },
"cert-file:s" => { name => 'cert_file' },
"key-file:s" => { name => 'key_file' },
"cacert-file:s" => { name => 'cacert_file' },
"cert-pwd:s" => { name => 'cert_pwd' },
"cert-pkcs12" => { name => 'cert_pkcs12' },
"header:s@" => { name => 'header' },
"get-param:s@" => { name => 'get_param' },
"post-param:s@" => { name => 'post_param' },
"cookies-file:s" => { name => 'cookies_file' },
"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' },
"warning:s" => { name => 'warning' },
"critical:s" => { name => 'critical' },
"warning-size:s" => { name => 'warning_size' },
"critical-size:s" => { name => 'critical_size' },
'hostname:s' => { name => 'hostname' },
'port:s' => { name => 'port', },
'method:s' => { name => 'method' },
'proto:s' => { name => 'proto' },
'urlpath:s' => { name => 'url_path' },
'credentials' => { name => 'credentials' },
'basic' => { name => 'basic' },
'ntlmv2' => { name => 'ntlmv2' },
'username:s' => { name => 'username' },
'password:s' => { name => 'password' },
'timeout:s' => { name => 'timeout' },
'no-follow' => { name => 'no_follow', },
'cert-file:s' => { name => 'cert_file' },
'key-file:s' => { name => 'key_file' },
'cacert-file:s' => { name => 'cacert_file' },
'cert-pwd:s' => { name => 'cert_pwd' },
'cert-pkcs12' => { name => 'cert_pkcs12' },
'header:s@' => { name => 'header' },
'get-param:s@' => { name => 'get_param' },
'post-param:s@' => { name => 'post_param' },
'cookies-file:s' => { name => 'cookies_file' },
'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' },
'warning:s' => { name => 'warning' },
'critical:s' => { name => 'critical' }
});
$self->{http} = centreon::plugins::http->new(%options);
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();
}
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();
# Compat
if (defined($options{option_results}->{warning})) {
$options{option_results}->{'warning-time'} = $options{option_results}->{warning};
$options{option_results}->{'warning-http-response-time-seconds'} = $options{option_results}->{warning};
}
if (defined($options{option_results}->{critical})) {
$options{option_results}->{'critical-time'} = $options{option_results}->{critical};
$options{option_results}->{'critical-http-response-time-seconds'} = $options{option_results}->{critical};
}
$self->SUPER::check_options(%options);
$self->change_macros(macros => ['warning_status', 'critical_status', 'unknown_status']);
$self->{http}->set_options(%{$self->{option_results}});
}
sub run {
sub manage_selection {
my ($self, %options) = @_;
$self->{global} = {};
my $timing0 = [gettimeofday];
my $webcontent = $self->{http}->request();
my $timeelapsed = tv_interval($timing0, [gettimeofday]);
my $webcontent = $self->{http}->request(
unknown_status => '', warning_status => '', critical_status => ''
);
$self->{global}->{time} = tv_interval($timing0, [gettimeofday]);
$self->{global}->{http_code} = $self->{http}->get_code();
$self->{global}->{message} = $self->{http}->get_message();
$self->{output}->output_add(long_msg => $webcontent);
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 %.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->{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->{global}->{size} = bytes::length($webcontent);
}
$self->{output}->display();
$self->{output}->exit();
}
1;
@ -241,11 +256,11 @@ Threshold warning for http response code
Threshold critical for http response code (Default: '%{http_code} < 200 or %{http_code} >= 300')
=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)

View File

@ -142,7 +142,7 @@ sub output_perf {
my $result = 'UNKNOWN';
$result = $errors_num{$options{result}} if ($options{result} =~ /[0-3]/);
$result = $options{result}if ($options{result} =~ /\w+/);
$result = $options{result} if ($options{result} =~ /[A-Z]+/);
my %result = (
code => $result,

View File

@ -127,7 +127,7 @@ sub manage_selection {
}
$self->{global} = {
rta => $total_time_elapsed * 1000 / $self->{option_packets},
rta => ($self->{option_packets} > $total_packet_lost) ? $total_time_elapsed * 1000 / ($self->{option_packets} - $total_packet_lost) : 0,
rtmax => $max_time_elapsed * 1000,
rtmin => $min_time_elapsed * 1000,
pl => int($total_packet_lost * 100 / $self->{option_packets}),

View File

@ -172,8 +172,8 @@ sub set_counters {
output_use => 'prct_cpu', threshold_use => 'prct_cpu',
perfdatas => [
{ label => 'cpu', value => 'prct_cpu', template => '%.2f',
unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' },
],
unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'memory', set => {
@ -181,7 +181,7 @@ sub set_counters {
closure_custom_calc => $self->can('custom_memory_calc'),
closure_custom_output => $self->can('custom_memory_output'),
closure_custom_perfdata => $self->can('custom_memory_perfdata'),
closure_custom_threshold_check => $self->can('custom_memory_threshold'),
closure_custom_threshold_check => $self->can('custom_memory_threshold')
}
},
{ label => 'read-iops', set => {
@ -190,8 +190,8 @@ sub set_counters {
output_template => 'Read IOPs : %.2f', output_error_template => "Read IOPs : %s",
perfdatas => [
{ label => 'read_iops', value => 'read_io_per_second', template => '%.2f',
unit => 'iops', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
],
unit => 'iops', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }
]
}
},
{ label => 'write-iops', set => {
@ -200,8 +200,8 @@ sub set_counters {
output_template => 'Write IOPs : %.2f', output_error_template => "Write IOPs : %s",
perfdatas => [
{ label => 'write_iops', value => 'write_io_per_second', template => '%.2f',
unit => 'iops', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
],
unit => 'iops', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }
]
}
},
{ label => 'swap', set => {
@ -209,9 +209,9 @@ sub set_counters {
closure_custom_calc => $self->can('custom_swap_calc'),
closure_custom_output => $self->can('custom_swap_output'),
closure_custom_perfdata => $self->can('custom_swap_perfdata'),
closure_custom_threshold_check => $self->can('custom_swap_threshold'),
closure_custom_threshold_check => $self->can('custom_swap_threshold')
}
},
}
];
$self->{maps_counters}->{vms_traffic} = [
@ -221,8 +221,8 @@ sub set_counters {
output_template => 'Traffic In : %s %s/s',
perfdatas => [
{ label => 'traffic_in', value => 'traffic_in_per_second', template => '%.2f',
min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display_absolute' },
],
min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display_absolute' }
]
}
},
{ label => 'traffic-out', set => {
@ -231,10 +231,10 @@ sub set_counters {
output_template => 'Traffic Out : %s %s/s',
perfdatas => [
{ label => 'traffic_out', value => 'traffic_out_per_second', template => '%.2f',
min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display_absolute' },
],
min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display_absolute' }
]
}
},
}
];
}
@ -249,7 +249,7 @@ sub new {
'filter-name:s' => { name => 'filter_name' },
'use-name' => { name => 'use_name' },
'warning-vm-status:s' => { name => 'warning_vm_status', default => '' },
'critical-vm-status:s' => { name => 'critical_vm_status', default => '' },
'critical-vm-status:s' => { name => 'critical_vm_status', default => '' }
});
$self->{statefile_cache_vms} = centreon::plugins::statefile->new(%options);
return $self;
@ -308,7 +308,7 @@ sub manage_selection {
memory_usage => $result->{$vm_id}->{Stats}->{mem},
memory_total => $result->{$vm_id}->{Stats}->{maxmem},
swap_usage => $result->{$vm_id}->{Stats}->{swap},
swap_total => $result->{$vm_id}->{Stats}->{maxswap},
swap_total => defined($result->{$vm_id}->{Stats}->{maxswap}) && $result->{$vm_id}->{Stats}->{maxswap} > 0 ? $result->{$vm_id}->{Stats}->{maxswap} : undef
};
$self->{vms_traffic}->{$name} = {
display => $name,

View File

@ -0,0 +1,171 @@
#
# Copyright 2020 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::salesforce::restapi::custom::api;
use strict;
use warnings;
use centreon::plugins::http;
use JSON;
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' },
'timeout:s' => { name => 'timeout' },
'api-versions:s' => { name => 'api_version' }
});
}
$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.status.salesforce.com';
$self->{timeout} = (defined($self->{option_results}->{timeout})) ? $self->{option_results}->{timeout} : 10;
$self->{api_version} = (defined($self->{option_results}->{api_version})) ? $self->{option_results}->{api_version} : 'v1';
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} = 443;
$self->{option_results}->{proto} = 'https';
}
sub settings {
my ($self, %options) = @_;
$self->build_options_for_httplib();
$self->{http}->add_header(key => 'Accept', value => 'application/json');
$self->{http}->add_header(key => 'Content-Type', value => 'application/json');
$self->{http}->set_options(%{$self->{option_results}});
}
sub request_api {
my ($self, %options) = @_;
$self->settings();
my $content = $self->{http}->request(
method => 'GET',
url_path => '/' . $self->{api_version} . $options{path},
critical_status => '',
warning_status => '',
unknown_status => ''
);
my $decoded;
eval {
$decoded = decode_json($content);
};
if ($@) {
$self->{output}->add_option_msg(short_msg => "Cannot decode json response");
$self->{output}->option_exit();
}
if ($self->{http}->get_code() != 200) {
$self->{output}->add_option_msg(short_msg => "Connection issue: " . $decoded->{message});
$self->{output}->option_exit();
}
return $decoded;
}
1;
__END__
=head1 NAME
SFDC API boilerplate
=head1 SYNOPSIS
Get informations from SFDC API
=head1 REST API OPTIONS
=over 8
=item B<--hostname>
Set hostname to query (default: 'api.status.salesforce.com')
=item B<--timeout>
Set HTTP timeout in seconds (Default: '10').
=item B<--api-path>
API base url path (Default: '/v1').
=back
=head1 DESCRIPTION
B<custom>.
=cut

View File

@ -0,0 +1,145 @@
#
# Copyright 2020 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::salesforce::restapi::mode::sfdcinstance;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc);
sub custom_status_output {
my ($self, %options) = @_;
return sprintf(
"status is '%s' (active:'%s') ",
$self->{result_values}->{status},
$self->{result_values}->{active}
);
}
sub prefix_salesforce_output {
my ($self, %options) = @_;
return "Salesforce '" . $options{instance_value}->{name} . "' instance ";
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'salesforce', type => 1, cb_prefix_output => 'prefix_salesforce_output', message_multiple => 'All salesforce instances are ok' }
];
$self->{maps_counters}->{salesforce} = [
{ label => 'status', threshold => 0, set => {
key_values => [ { name => 'status' }, { name => 'active' }, { name => 'name' } ],
closure_custom_calc => \&catalog_status_calc,
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold
}
},
{ label => 'incident', nlabel => 'salesforce.incident.current.count', set => {
key_values => [ { name => 'incident' } ],
output_template => '%s incidents currently',
perfdatas => [
{ label => 'incident', value => 'incident_absolute', template => '%s',
min => 0, label_extra_instance => 1 },
],
}
}
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
'instance:s@' => { name => 'instance' },
'alias' => { name => 'use_alias' },
'unknown-status:s' => { name => 'unknown_status', default => '' },
'warning-status:s' => { name => 'warning_status', default => '' },
'critical-status:s' => { name => 'critical_status', default => '%{status} !~ /OK/' }
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']);
}
sub manage_selection {
my ($self, %options) = @_;
my $instance_path = (defined($self->{option_results}->{use_alias})) ? '/instanceAliases/' : '/instances/';
foreach my $instance (@{$self->{option_results}->{instance}}) {
my $result = $options{custom}->request_api(path => $instance_path . $instance . '/status');
$self->{salesforce}->{$instance} = {
active => $result->{isActive},
incident => scalar(@{$result->{Incidents}}),
name => $instance,
status => $result->{status}
};
}
}
1;
__END__
=head1 MODE
Check instance status and incident count through Salesforce API
=over 8
=item B<--instance>
Set your instance identifier
=item B<--alias>
Add this option if your want to use your instance alias
=item B<--unknown-status>
Set unknown threshold for instance status (Default: '').
=item B<--warning-status>
Set warning threshold for instance status (Default: '').
=item B<--critical-status>
Set critical threshold for instance status (Default: '%{status} !~ /OK/').
=back
=cut

View File

@ -18,11 +18,11 @@
# limitations under the License.
#
package apps::hddtemp::remote::plugin;
package apps::salesforce::restapi::plugin;
use strict;
use warnings;
use base qw(centreon::plugins::script_simple);
use base qw(centreon::plugins::script_custom);
sub new {
my ($class, %options) = @_;
@ -30,11 +30,10 @@ sub new {
bless $self, $class;
$self->{version} = '0.1';
%{$self->{modes}} = (
'temperature' => 'apps::hddtemp::remote::mode::temperature',
'list-drives' => 'apps::hddtemp::remote::mode::listdrives',
%{$self->{modes}} = (
'sfdc-instance' => 'apps::salesforce::restapi::mode::sfdcinstance',
);
$self->{custom_modes}{api} = 'apps::salesforce::restapi::custom::api';
return $self;
}
@ -44,6 +43,6 @@ __END__
=head1 PLUGIN DESCRIPTION
Check HDDTEMP Status throuh TCP Socket
Check SFDC service through its status API
=cut

View File

@ -29,8 +29,7 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold)
sub custom_status_output {
my ($self, %options) = @_;
my $msg = 'status ' . $self->{result_values}->{status};
return $msg;
return 'status ' . $self->{result_values}->{status};
}
sub custom_status_calc {
@ -45,7 +44,7 @@ sub set_counters {
$self->{maps_counters_type} = [
{ name => 'global', type => 0, skipped_code => { -10 => 1 } },
{ name => 'host', type => 1, cb_prefix_output => 'prefix_host_output', message_multiple => 'All ESX Hosts are ok' },
{ name => 'host', type => 1, cb_prefix_output => 'prefix_host_output', message_multiple => 'All ESX Hosts are ok' }
];
$self->{maps_counters}->{global} = [
@ -54,8 +53,8 @@ sub set_counters {
output_template => '%s VM(s) poweredon',
perfdatas => [
{ label => 'poweredon', value => 'poweredon_absolute', template => '%s',
min => 0, max => 'total_absolute' },
],
min => 0, max => 'total_absolute' }
]
}
},
{ label => 'total-off', nlabel => 'host.vm.poweredoff.current.count', set => {
@ -63,8 +62,8 @@ sub set_counters {
output_template => '%s VM(s) poweredoff',
perfdatas => [
{ label => 'poweredoff', value => 'poweredoff_absolute', template => '%s',
min => 0, max => 'total_absolute' },
],
min => 0, max => 'total_absolute' }
]
}
},
{ label => 'total-suspended', nlabel => 'host.vm.suspended.current.count', set => {
@ -72,8 +71,8 @@ sub set_counters {
output_template => '%s VM(s) suspended',
perfdatas => [
{ label => 'suspended', value => 'suspended_absolute', template => '%s',
min => 0, max => 'total_absolute' },
],
min => 0, max => 'total_absolute' }
]
}
},
];
@ -84,7 +83,7 @@ sub set_counters {
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,
closure_custom_threshold_check => \&catalog_status_threshold
}
},
{ label => 'on', nlabel => 'host.vm.poweredon.current.count', set => {
@ -92,8 +91,8 @@ sub set_counters {
output_template => '%s VM(s) poweredon',
perfdatas => [
{ label => 'poweredon', value => 'poweredon_absolute', template => '%s',
min => 0, max => 'total_absolute', label_extra_instance => 1 },
],
min => 0, max => 'total_absolute', label_extra_instance => 1 }
]
}
},
{ label => 'off', nlabel => 'host.vm.poweredoff.current.count', set => {
@ -101,8 +100,8 @@ sub set_counters {
output_template => '%s VM(s) poweredoff',
perfdatas => [
{ label => 'poweredoff', value => 'poweredoff_absolute', template => '%s',
min => 0, max => 'total_absolute', label_extra_instance => 1 },
],
min => 0, max => 'total_absolute', label_extra_instance => 1 }
]
}
},
{ label => 'suspended', nlabel => 'host.vm.suspended.current.count', set => {
@ -110,10 +109,10 @@ sub set_counters {
output_template => '%s VM(s) suspended',
perfdatas => [
{ label => 'suspended', value => 'suspended_absolute', template => '%s',
min => 0, max => 'total_absolute', label_extra_instance => 1 },
],
min => 0, max => 'total_absolute', label_extra_instance => 1 }
]
}
},
}
];
}
@ -153,8 +152,10 @@ sub manage_selection {
$self->{global} = { poweredon => 0, poweredoff => 0, suspended => 0, total => 0 };
$self->{host} = {};
my $response = $options{custom}->execute(params => $self->{option_results},
command => 'countvmhost');
my $response = $options{custom}->execute(
params => $self->{option_results},
command => 'countvmhost'
);
foreach my $host_id (keys %{$response->{data}}) {
my $host_name = $response->{data}->{$host_id}->{name};
@ -170,7 +171,7 @@ sub manage_selection {
$self->{global}->{poweredoff} += $response->{data}->{$host_id}->{poweredoff} if (defined($response->{data}->{$host_id}->{poweredoff}));
$self->{global}->{suspended} += $response->{data}->{$host_id}->{suspended} if (defined($response->{data}->{$host_id}->{suspended}));
}
$self->{global}->{total} = $self->{global}->{poweredon} + $self->{global}->{poweredoff} + $self->{global}->{suspended};
}

View File

@ -63,7 +63,7 @@ sub set_counters {
}
},
];
$self->{maps_counters}->{global_cpu} = [
{ label => 'total-cpu', nlabel => 'host.cpu.utilization.percentage', set => {
key_values => [ { name => 'cpu_average' } ],

View File

@ -137,7 +137,7 @@ sub set_counters {
min => 0, max => 'total_space', label_extra_instance => 1 },
],
}
},
}
];
}
@ -153,14 +153,14 @@ sub new {
bless $self, $class;
$options{options}->add_options(arguments => {
'datastore-name:s' => { name => 'datastore_name' },
'filter' => { name => 'filter' },
'scope-datacenter:s' => { name => 'scope_datacenter' },
'units:s' => { name => 'units', default => '%' },
'free' => { name => 'free' },
'unknown-status:s' => { name => 'unknown_status', default => '%{accessible} !~ /^true|1$/i' },
'warning-status:s' => { name => 'warning_status', default => '' },
'critical-status:s' => { name => 'critical_status', default => '' },
'datastore-name:s' => { name => 'datastore_name' },
'filter' => { name => 'filter' },
'scope-datacenter:s' => { name => 'scope_datacenter' },
'units:s' => { name => 'units', default => '%' },
'free' => { name => 'free' },
'unknown-status:s' => { name => 'unknown_status', default => '%{accessible} !~ /^true|1$/i' },
'warning-status:s' => { name => 'warning_status', default => '' },
'critical-status:s' => { name => 'critical_status', default => '' }
});
return $self;
@ -172,8 +172,12 @@ sub check_options {
# Compatibility
$self->compat_threshold_counter(%options,
compat => {
th => [ ['usage', { free => 'usage-free', prct => 'usage-prct'} ], [ 'datastore.space.usage.bytes', { free => 'datastore.space.free.bytes', prct => 'datastore.space.usage.percentage' } ] ],
units => $options{option_results}->{units}, free => $options{option_results}->{free}
th => [
[ 'usage', { free => 'usage-free', prct => 'usage-prct'} ],
[ 'instance-datastore-space-usage-bytes', { free => 'instance-datastore-space-free-bytes', prct => 'instance-datastore-space-usage-percentage' } ]
],
units => $options{option_results}->{units},
free => $options{option_results}->{free}
}
);

View File

@ -47,7 +47,7 @@ sub custom_usage_perfdata {
my ($label, $nlabel) = ('used', $self->{nlabel});
my $value_perf = $self->{result_values}->{used};
if (defined($self->{instance_mode}->{option_results}->{free})) {
($label, $nlabel) = ('free', 'vm.memory.free.bytes');
($label, $nlabel) = ('free', 'vm.memory.' . $self->{result_values}->{label_ref} . '.free.bytes');
$value_perf = $self->{result_values}->{free};
}
@ -58,7 +58,7 @@ sub custom_usage_perfdata {
}
$self->{output}->perfdata_add(
label => $label, unit => 'B',
label => $self->{result_values}->{label_ref} . '_' . $label, unit => 'B',
instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef,
nlabel => $nlabel,
value => $value_perf,
@ -88,12 +88,13 @@ sub custom_usage_output {
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 %s Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)",
$self->{result_values}->{label_ref},
$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;
my $msg = sprintf(
'Memory %s Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)',
$self->{result_values}->{label_ref},
$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}
);
}
sub custom_usage_calc {
@ -107,7 +108,7 @@ sub custom_usage_calc {
$self->{error_msg} = 'size is 0';
return -20;
}
$self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_' . $self->{result_values}->{label_ref}};
$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};
@ -120,24 +121,21 @@ sub custom_overhead_output {
my ($self, %options) = @_;
my ($value, $unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{overhead_absolute});
my $msg = sprintf("Memory overhead: %s %s", $value, $unit);
return $msg;
return sprintf('Memory overhead: %s %s', $value, $unit);
}
sub custom_ballooning_output {
my ($self, %options) = @_;
my ($value, $unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{vmmemctl_absolute});
my $msg = sprintf("Memory ballooning: %s %s", $value, $unit);
return $msg;
return sprintf('Memory ballooning: %s %s', $value, $unit);
}
sub custom_shared_output {
my ($self, %options) = @_;
my ($value, $unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{shared_absolute});
my $msg = sprintf("Memory shared: %s %s", $value, $unit);
return $msg;
return sprintf('Memory shared: %s %s', $value, $unit);
}
sub set_counters {
@ -162,30 +160,30 @@ sub set_counters {
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,
closure_custom_threshold_check => \&catalog_status_threshold
}
},
}
];
$self->{maps_counters}->{global_consumed} = [
{ label => 'consumed', nlabel => 'vm.memory.usage.bytes', set => {
{ label => 'consumed', nlabel => 'vm.memory.consumed.usage.bytes', set => {
key_values => [ { name => 'consumed' }, { name => 'total' } ],
closure_custom_calc => $self->can('custom_usage_calc'), closure_custom_calc_extra_options => { label_ref => 'consumed' },
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'),
closure_custom_threshold_check => $self->can('custom_usage_threshold')
}
},
}
];
$self->{maps_counters}->{global_active} = [
{ label => 'active', nlabel => 'vm.memory.active.bytes', set => {
{ label => 'active', nlabel => 'vm.memory.active.usage.bytes', set => {
key_values => [ { name => 'active' }, { name => 'total' } ],
closure_custom_calc => $self->can('custom_usage_calc'), closure_custom_calc_extra_options => { label_ref => 'active' },
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'),
closure_custom_threshold_check => $self->can('custom_usage_threshold')
}
},
}
];
$self->{maps_counters}->{global_overhead} = [
{ label => 'overhead', nlabel => 'vm.memory.overhead.bytes', set => {
@ -193,10 +191,10 @@ sub set_counters {
closure_custom_output => $self->can('custom_overhead_output'),
perfdatas => [
{ label => 'overhead', value => 'overhead_absolute', template => '%s', unit => 'B',
min => 0, label_extra_instance => 1 },
],
min => 0, label_extra_instance => 1 }
]
}
},
}
];
$self->{maps_counters}->{global_vmmemctl} = [
{ label => 'ballooning', nlabel => 'vm.memory.ballooning.bytes', set => {
@ -204,10 +202,10 @@ sub set_counters {
closure_custom_output => $self->can('custom_ballooning_output'),
perfdatas => [
{ label => 'ballooning', value => 'vmmemctl_absolute', template => '%s', unit => 'B',
min => 0, label_extra_instance => 1 },
],
min => 0, label_extra_instance => 1 }
]
}
},
}
];
$self->{maps_counters}->{global_shared} = [
{ label => 'shared', nlabel => 'vm.memory.shared.bytes', set => {
@ -215,10 +213,10 @@ sub set_counters {
closure_custom_output => $self->can('custom_shared_output'),
perfdatas => [
{ label => 'shared', value => 'shared_absolute', template => '%s', unit => 'B',
min => 0, label_extra_instance => 1 },
],
min => 0, label_extra_instance => 1 }
]
}
},
}
];
}
@ -230,7 +228,7 @@ sub prefix_vm_output {
$msg .= ' [annotation: ' . $options{instance_value}->{config_annotation} . ']';
}
$msg .= ' : ';
return $msg;
}
@ -241,7 +239,7 @@ sub vm_long_output {
if (defined($options{instance_value}->{config_annotation})) {
$msg .= ' [annotation: ' . $options{instance_value}->{config_annotation} . ']';
}
return $msg;
}
@ -251,20 +249,20 @@ sub new {
bless $self, $class;
$options{options}->add_options(arguments => {
"vm-hostname:s" => { name => 'vm_hostname' },
"filter" => { name => 'filter' },
"scope-datacenter:s" => { name => 'scope_datacenter' },
"scope-cluster:s" => { name => 'scope_cluster' },
"scope-host:s" => { name => 'scope_host' },
"filter-description:s" => { name => 'filter_description' },
"filter-os:s" => { name => 'filter_os' },
"filter-uuid:s" => { name => 'filter_uuid' },
"display-description" => { name => 'display_description' },
"units:s" => { name => 'units', default => '%' },
"free" => { name => 'free' },
"unknown-status:s" => { name => 'unknown_status', default => '%{connection_state} !~ /^connected$/i or %{power_state} !~ /^poweredOn$/i' },
"warning-status:s" => { name => 'warning_status', default => '' },
"critical-status:s" => { name => 'critical_status', default => '' },
'vm-hostname:s' => { name => 'vm_hostname' },
'filter' => { name => 'filter' },
'scope-datacenter:s' => { name => 'scope_datacenter' },
'scope-cluster:s' => { name => 'scope_cluster' },
'scope-host:s' => { name => 'scope_host' },
'filter-description:s' => { name => 'filter_description' },
'filter-os:s' => { name => 'filter_os' },
'filter-uuid:s' => { name => 'filter_uuid' },
'display-description' => { name => 'display_description' },
'units:s' => { name => 'units', default => '%' },
'free' => { name => 'free' },
'unknown-status:s' => { name => 'unknown_status', default => '%{connection_state} !~ /^connected$/i or %{power_state} !~ /^poweredOn$/i' },
'warning-status:s' => { name => 'warning_status', default => '' },
'critical-status:s' => { name => 'critical_status', default => '' },
});
return $self;
@ -281,19 +279,21 @@ sub manage_selection {
my ($self, %options) = @_;
$self->{vm} = {};
my $response = $options{custom}->execute(params => $self->{option_results},
command => 'memvm');
my $response = $options{custom}->execute(
params => $self->{option_results},
command => 'memvm'
);
foreach my $vm_id (keys %{$response->{data}}) {
my $vm_name = $response->{data}->{$vm_id}->{name};
$self->{vm}->{$vm_name} = { display => $vm_name,
global => {
connection_state => $response->{data}->{$vm_id}->{connection_state},
power_state => $response->{data}->{$vm_id}->{power_state},
},
};
foreach (('consumed', 'active', 'overhead', 'vmmemctl', 'shared')) {
next if (!defined($response->{data}->{$vm_id}->{'mem.' . $_ . '.average'}));
$self->{vm}->{$vm_name}->{'global_' . $_} = {
@ -301,7 +301,7 @@ sub manage_selection {
total => $response->{data}->{$vm_id}->{memory_size}
};
}
if (defined($self->{option_results}->{display_description})) {
$self->{vm}->{$vm_name}->{config_annotation} = $options{custom}->strip_cr(value => $response->{data}->{$vm_id}->{'config.annotation'});
}

View File

@ -29,8 +29,7 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold)
sub custom_status_output {
my ($self, %options) = @_;
my $msg = 'status ' . $self->{result_values}->{status};
return $msg;
return 'status ' . $self->{result_values}->{status};
}
sub custom_status_calc {
@ -43,13 +42,13 @@ sub custom_status_calc {
sub custom_linkstatus_output {
my ($self, %options) = @_;
my $msg = 'status ' . $self->{result_values}->{link_status};
return $msg;
return 'status ' . $self->{result_values}->{link_status};
}
sub custom_linkstatus_calc {
my ($self, %options) = @_;
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
$self->{result_values}->{link_status} = $options{new_datas}->{$self->{instance} . '_status'};
return 0;
}
@ -58,9 +57,10 @@ sub custom_traffic_output {
my ($self, %options) = @_;
my ($value, $unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{traffic}, network => 1);
my $msg = sprintf("traffic %s : %s/s (%.2f %%)",
$self->{result_values}->{label_ref}, $value . $unit, $self->{result_values}->{traffic_prct});
return $msg;
return sprintf(
"traffic %s : %s/s (%.2f %%)",
$self->{result_values}->{label_ref}, $value . $unit, $self->{result_values}->{traffic_prct}
);
}
sub custom_traffic_calc {
@ -78,11 +78,12 @@ sub custom_traffic_calc {
sub custom_dropped_output {
my ($self, %options) = @_;
my $msg = sprintf("packets %s dropped : %.2f %% (%d/%d packets)",
$self->{result_values}->{label_ref},
$self->{result_values}->{dropped_prct},
$self->{result_values}->{dropped}, $self->{result_values}->{packets});
return $msg;
return sprintf(
'packets %s dropped : %.2f %% (%d/%d packets)',
$self->{result_values}->{label_ref},
$self->{result_values}->{dropped_prct},
$self->{result_values}->{dropped}, $self->{result_values}->{packets}
);
}
sub custom_dropped_calc {
@ -109,22 +110,22 @@ sub set_counters {
{ name => 'global', type => 0, skipped_code => { -10 => 1 } },
{ name => 'global_host', type => 0, skipped_code => { -10 => 1 } },
{ name => 'pnic', cb_prefix_output => 'prefix_pnic_output', message_multiple => 'All physical interfaces are ok', type => 1, skipped_code => { -10 => 1 } },
{ name => 'vswitch', cb_prefix_output => 'prefix_vswitch_output', message_multiple => 'All vswitchs are ok', type => 1, skipped_code => { -10 => 1 } },
{ name => 'vswitch', cb_prefix_output => 'prefix_vswitch_output', message_multiple => 'All vswitchs are ok', type => 1, skipped_code => { -10 => 1 } }
]
}
];
$self->{maps_counters}->{global} = [
{ label => 'status', threshold => 0, set => {
key_values => [ { name => '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,
closure_custom_threshold_check => \&catalog_status_threshold
}
},
}
];
$self->{maps_counters}->{global_host} = [
{ label => 'host-traffic-in', nlabel => 'host.traffic.in.bitsperseconds', set => {
key_values => [ { name => 'traffic_in' } ],
@ -132,8 +133,8 @@ sub set_counters {
output_change_bytes => 2,
perfdatas => [
{ label => 'host_traffic_in', value => 'traffic_in_absolute', template => '%s',
unit => 'b/s', min => 0, label_extra_instance => 1 },
],
unit => 'b/s', min => 0, label_extra_instance => 1 }
]
}
},
{ label => 'host-traffic-out', nlabel => 'host.traffic.out.bitsperseconds', set => {
@ -142,12 +143,12 @@ sub set_counters {
output_change_bytes => 2,
perfdatas => [
{ label => 'host_traffic_out', value => 'traffic_out_absolute', template => '%s',
unit => 'b/s', min => 0, label_extra_instance => 1 },
],
unit => 'b/s', min => 0, label_extra_instance => 1 }
]
}
},
}
];
$self->{maps_counters}->{vswitch} = [
{ label => 'vswitch-traffic-in', nlabel => 'host.vswitch.traffic.in.bitsperseconds', set => {
key_values => [ { name => 'traffic_in' } ],
@ -165,19 +166,19 @@ sub set_counters {
output_change_bytes => 2,
perfdatas => [
{ label => 'vswitch_traffic_out', value => 'traffic_out_absolute', template => '%s',
unit => 'b/s', min => 0, label_extra_instance => 1 },
],
unit => 'b/s', min => 0, label_extra_instance => 1 }
]
}
},
}
];
$self->{maps_counters}->{pnic} = [
{ label => 'link-status', threshold => 0, set => {
key_values => [ { name => 'status' } ],
key_values => [ { name => 'status' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_linkstatus_calc'),
closure_custom_output => $self->can('custom_linkstatus_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold,
closure_custom_threshold_check => \&catalog_status_threshold
}
},
{ label => 'link-traffic-in', nlabel => 'host.traffic.in.bitsperseconds', set => {
@ -187,8 +188,8 @@ sub set_counters {
threshold_use => 'traffic_prct',
perfdatas => [
{ label => 'traffic_in', value => 'traffic', template => '%s', unit => 'b/s',
min => 0, max => 'speed', threshold_total => 'speed', cast_int => 1, label_extra_instance => 1 },
],
min => 0, max => 'speed', threshold_total => 'speed', cast_int => 1, label_extra_instance => 1 }
]
}
},
{ label => 'link-traffic-out', nlabel => 'host.traffic.out.bitsperseconds', set => {
@ -198,8 +199,8 @@ sub set_counters {
threshold_use => 'traffic_prct',
perfdatas => [
{ label => 'traffic_out', value => 'traffic', template => '%s', unit => 'b/s',
min => 0, max => 'speed', threshold_total => 'speed', cast_int => 1, label_extra_instance => 1 },
],
min => 0, max => 'speed', threshold_total => 'speed', cast_int => 1, label_extra_instance => 1 }
]
}
},
{ label => 'link-dropped-in', nlabel => 'host.packets.in.dropped.percentage', set => {
@ -209,8 +210,8 @@ sub set_counters {
threshold_use => 'dropped_prct',
perfdatas => [
{ label => 'packets_dropped_in', value => 'dropped_prct', template => '%s', unit => '%',
min => 0, max => 100, label_extra_instance => 1 },
],
min => 0, max => 100, label_extra_instance => 1 }
]
}
},
{ label => 'link-dropped-out', nlabel => 'host.packets.out.dropped.percentage', set => {
@ -220,10 +221,10 @@ sub set_counters {
threshold_use => 'dropped_prct',
perfdatas => [
{ label => 'packets_dropped_out', value => 'dropped_prct', template => '%s', unit => '%',
min => 0, max => 100, label_extra_instance => 1 },
],
min => 0, max => 100, label_extra_instance => 1 }
]
}
},
}
];
}
@ -257,20 +258,20 @@ sub new {
bless $self, $class;
$options{options}->add_options(arguments => {
"esx-hostname:s" => { name => 'esx_hostname' },
"nic-name:s" => { name => 'nic_name' },
"filter" => { name => 'filter' },
"scope-datacenter:s" => { name => 'scope_datacenter' },
"scope-cluster:s" => { name => 'scope_cluster' },
"no-proxyswitch" => { name => 'no_proxyswitch' },
"unknown-status:s" => { name => 'unknown_status', default => '%{status} !~ /^connected$/i' },
"warning-status:s" => { name => 'warning_status', default => '' },
"critical-status:s" => { name => 'critical_status', default => '' },
"unknown-link-status:s" => { name => 'unknown_link_status', default => '' },
"warning-link-status:s" => { name => 'warning_link_status', default => '' },
"critical-link-status:s" => { name => 'critical_link_status', default => '%{link_status} !~ /up/' },
'esx-hostname:s' => { name => 'esx_hostname' },
'nic-name:s' => { name => 'nic_name' },
'filter' => { name => 'filter' },
'scope-datacenter:s' => { name => 'scope_datacenter' },
'scope-cluster:s' => { name => 'scope_cluster' },
'no-proxyswitch' => { name => 'no_proxyswitch' },
'unknown-status:s' => { name => 'unknown_status', default => '%{status} !~ /^connected$/i' },
'warning-status:s' => { name => 'warning_status', default => '' },
'critical-status:s' => { name => 'critical_status', default => '' },
'unknown-link-status:s' => { name => 'unknown_link_status', default => '' },
'warning-link-status:s' => { name => 'warning_link_status', default => '' },
'critical-link-status:s' => { name => 'critical_link_status', default => '%{link_status} !~ /up/' }
});
return $self;
}
@ -278,8 +279,10 @@ sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status',
'unknown_link_status', 'warning_link_status', 'critical_link_status']);
$self->change_macros(macros => [
'unknown_status', 'warning_status', 'critical_status',
'unknown_link_status', 'warning_link_status', 'critical_link_status'
]);
}
sub manage_selection {
@ -308,7 +311,7 @@ sub manage_selection {
$pnic_name !~ /$self->{option_results}->{nic_name}/);
$self->{host}->{$host_name}->{pnic}->{$pnic_name} = {
display => $pnic_name,
display => $pnic_name,
status => $response->{data}->{$host_id}->{pnic}->{$pnic_name}->{status} ,
traffic_in => $response->{data}->{$host_id}->{pnic}->{$pnic_name}->{'net.received.average'},
traffic_out => $response->{data}->{$host_id}->{pnic}->{$pnic_name}->{'net.transmitted.average'},
@ -392,30 +395,24 @@ Can used special variables like: %{status}
=item B<--unknown-link-status>
Set warning threshold for status (Default: '').
Can used special variables like: %{link_status}
Set warning threshold for status.
Can used special variables like: %{link_status}, %{display}
=item B<--warning-link-status>
Set warning threshold for status (Default: '').
Can used special variables like: %{link_status}
Set warning threshold for status.
Can used special variables like: %{link_status}, %{display}
=item B<--critical-link-status>
Set critical threshold for status (Default: '%{link_status} !~ /up/').
Can used special variables like: %{link_status}
Can used special variables like: %{link_status}, %{display}
=item B<--warning-*>
=item B<--warning-*> B<--critical-*>
Threshold warning.
Can be: 'host-traffic-in', 'host-traffic-out', 'vswitch-traffic-in', 'vswitch-traffic-out',
'link-traffic-in', 'link-traffic-out', 'link-dropped-in', 'link-dropped-out'.
=item B<--critical-*>
Threshold critical.
Can be: 'host-traffic-in', 'host-traffic-out', 'vswitch-traffic-in', 'vswitch-traffic-out',
'link-traffic-in', 'link-traffic-out', 'link-dropped-in', 'link-dropped-out'.
Thresholds.
Can be: 'host-traffic-in' (b/s), 'host-traffic-out' (b/s), 'vswitch-traffic-in' (b/s), 'vswitch-traffic-out' (b/s),
'link-traffic-in' (%), 'link-traffic-out' (%), 'link-dropped-in', 'link-dropped-out'.
=item B<--no-proxyswitch>

View File

@ -30,9 +30,9 @@ sub custom_status_output {
my ($self, %options) = @_;
my $msg = 'status is ' . $self->{result_values}->{overall_status};
if ($self->{result_values}->{vsan_status} ne '') {
$msg .= ' [vsan status: ' . $self->{result_values}->{vsan_status} . ']';
}
$msg .= ' [vsan status: ' . $self->{result_values}->{vsan_status} . ']' if ($self->{result_values}->{vsan_status} ne '');
$msg .= ' [ha enabled: ' . $self->{result_values}->{ha_enabled} . ']' if ($self->{result_values}->{ha_enabled} ne '');
$msg .= ' [drs enabled: ' . $self->{result_values}->{drs_enabled} . ']' if ($self->{result_values}->{drs_enabled} ne '');
return $msg;
}
@ -40,18 +40,24 @@ sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'cluster', type => 1, cb_prefix_output => 'prefix_cluster_output', message_multiple => 'All clusters are ok' },
{ name => 'cluster', type => 1, cb_prefix_output => 'prefix_cluster_output', message_multiple => 'All clusters are ok' }
];
$self->{maps_counters}->{cluster} = [
{ label => 'status', threshold => 0, set => {
key_values => [ { name => 'overall_status' }, { name => 'vsan_status' }, { name => 'display' } ],
key_values => [
{ name => 'overall_status' },
{ name => 'vsan_status' },
{ name => 'ha_enabled' },
{ name => 'drs_enabled' },
{ name => 'display' }
],
closure_custom_calc => \&catalog_status_calc,
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold,
closure_custom_threshold_check => \&catalog_status_threshold
}
},
}
];
}
@ -65,41 +71,43 @@ sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$options{options}->add_options(arguments => {
'cluster-name:s' => { name => 'cluster_name' },
'filter' => { name => 'filter' },
'scope-datacenter:s' => { name => 'scope_datacenter' },
'unknown-status:s' => { name => 'unknown_status', default => '%{overall_status} =~ /gray/i || %{vsan_status} =~ /gray/i' },
'warning-status:s' => { name => 'warning_status', default => '%{overall_status} =~ /yellow/i || %{vsan_status} =~ /yellow/i' },
'critical-status:s' => { name => 'critical_status', default => '%{overall_status} =~ /red/i || %{vsan_status} =~ /red/i' },
'critical-status:s' => { name => 'critical_status', default => '%{overall_status} =~ /red/i || %{vsan_status} =~ /red/i' }
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']);
}
sub manage_selection {
my ($self, %options) = @_;
$self->{cluster} = {};
my $response = $options{custom}->execute(
params => $self->{option_results},
command => 'statuscluster'
);
$self->{cluster} = {};
foreach my $cluster_id (keys %{$response->{data}}) {
my $cluster_name = $response->{data}->{$cluster_id}->{name};
$self->{cluster}->{$cluster_name} = {
display => $cluster_name,
overall_status => $response->{data}->{$cluster_id}->{overall_status},
vsan_status => defined($response->{data}->{$cluster_id}->{vsan_cluster_status}) ? $response->{data}->{$cluster_id}->{vsan_cluster_status} : '',
ha_enabled => defined($response->{data}->{$cluster_id}->{ha_enabled}) ? $response->{data}->{$cluster_id}->{ha_enabled} : '',
drs_enabled => defined($response->{data}->{$cluster_id}->{drs_enabled}) ? $response->{data}->{$cluster_id}->{drs_enabled} : ''
};
}
}
@ -130,17 +138,17 @@ Search in following datacenter(s) (can be a regexp).
=item B<--unknown-status>
Set warning threshold for status (Default: '%{overall_status} =~ /gray/i || %{vsan_status} =~ /gray/i').
Can used special variables like: %{overall_status}, %{vsan_status}
Can used special variables like: %{overall_status}, %{vsan_status}, %{drs_enabled}, %{ha_enabled}
=item B<--warning-status>
Set warning threshold for status (Default: '%{overall_status} =~ /yellow/i || %{vsan_status} =~ /yellow/i').
Can used special variables like: %{overall_status}, %{vsan_status}
Can used special variables like: %{overall_status}, %{vsan_status}, %{drs_enabled}, %{ha_enabled}
=item B<--critical-status>
Set critical threshold for status (Default: '%{overall_status} =~ /red/i || %{vsan_status} =~ /red/i').
Can used special variables like: %{overall_status}, %{vsan_status}
Can used special variables like: %{overall_status}, %{vsan_status}, %{drs_enabled}, %{ha_enabled}
=back

View File

@ -112,21 +112,14 @@ sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
'cluster-name:s' => { name => 'cluster_name' },
'filter' => { name => 'filter' },
'scope-datacenter:s' => { name => 'scope_datacenter' },
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']);
$options{options}->add_options(arguments => {
'cluster-name:s' => { name => 'cluster_name' },
'filter' => { name => 'filter' },
'scope-datacenter:s' => { name => 'scope_datacenter' }
});
return $self;
}
sub manage_selection {

View File

@ -136,9 +136,11 @@ sub settings {
$self->build_options_for_httplib();
$self->{http}->add_header(key => 'Content-Type', value => 'application/json;charset=UTF-8');
if (defined($self->{cookie}) && defined($self->{xsrf})) {
if (defined($self->{cookie})) {
$self->{http}->add_header(key => 'Cookie', value => '.AspNetCore.Cookies=' . $self->{cookie});
$self->{http}->add_header(key => 'X-XSRF-TOKEN', value => $self->{xsrf});
if (defined($self->{xsrf})) {
$self->{http}->add_header(key => 'X-XSRF-TOKEN', value => $self->{xsrf});
}
}
$self->{http}->set_options(%{$self->{option_results}});
}
@ -171,12 +173,9 @@ sub authenticate {
$self->{output}->add_option_msg(short_msg => "Error retrieving cookie");
$self->{output}->option_exit();
}
# 3CX 16.0.5.611 does not use XSRF-TOKEN anymore
if (defined ($header) && $header =~ /(?:^| )XSRF-TOKEN=([^;]+);.*/) {
$xsrf = $1;
} else {
$self->{output}->output_add(long_msg => $content, debug => 1);
$self->{output}->add_option_msg(short_msg => "Error retrieving xsrf-token");
$self->{output}->option_exit();
}
my $datas = { last_timestamp => time(), cookie => $cookie, xsrf => $xsrf, expires_on => time() + (3600 * 24) };

View File

@ -25,6 +25,7 @@ use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
use bigint;
sub set_counters {
my ($self, %options) = @_;
@ -32,7 +33,7 @@ sub set_counters {
$self->{maps_counters_type} = [
{ name => 'total', type => 0 },
{ name => 'interface_classmap', type => 1, cb_prefix_output => 'prefix_intcmap_output', message_multiple => 'All interface classmaps are ok' },
{ name => 'classmap', type => 1, cb_prefix_output => 'prefix_cmap_output', message_multiple => 'All classmaps are ok' },
{ name => 'classmap', type => 1, cb_prefix_output => 'prefix_cmap_output', message_multiple => 'All classmaps are ok' }
];
$self->{maps_counters}->{interface_classmap} = [
@ -42,7 +43,7 @@ sub set_counters {
closure_custom_calc => $self->can('custom_traffic_calc'),
closure_custom_output => $self->can('custom_traffic_output'),
closure_custom_perfdata => $self->can('custom_traffic_perfdata'),
closure_custom_threshold_check => $self->can('custom_traffic_threshold'),
closure_custom_threshold_check => $self->can('custom_traffic_threshold')
}
},
{ label => 'int-cmap-drop', set => {
@ -51,10 +52,10 @@ sub set_counters {
output_template => 'Drop : %s %s/s',
perfdatas => [
{ label => 'icmap_drop', value => 'drop_usage_per_second', template => '%d',
unit => 'b/s', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
],
unit => 'b/s', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }
]
}
},
}
];
$self->{maps_counters}->{classmap} = [
{ label => 'cmap-traffic', set => {
@ -63,8 +64,8 @@ sub set_counters {
output_template => 'Traffic : %s %s/s',
perfdatas => [
{ label => 'cmap_traffic', value => 'traffic_usage_per_second', template => '%d',
unit => 'b/s', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
],
unit => 'b/s', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }
]
}
},
{ label => 'cmap-drop', set => {
@ -73,11 +74,12 @@ sub set_counters {
output_template => 'Drop : %s %s/s',
perfdatas => [
{ label => 'cmap_drop', value => 'drop_usage_per_second', template => '%d',
unit => 'b/s', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
],
unit => 'b/s', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }
]
}
},
}
];
$self->{maps_counters}->{total} = [
{ label => 'total-traffic', set => {
key_values => [ { name => 'traffic_usage', diff => 1 } ],
@ -85,8 +87,8 @@ sub set_counters {
output_template => 'Total Traffic : %s %s/s',
perfdatas => [
{ label => 'total_traffic', value => 'traffic_usage_per_second', template => '%d',
unit => 'b/s', min => 0 },
],
unit => 'b/s', min => 0 }
]
}
},
{ label => 'total-drop', set => {
@ -95,16 +97,16 @@ sub set_counters {
output_template => 'Total Drop : %s %s/s',
perfdatas => [
{ label => 'total_drop', value => 'drop_usage_per_second', template => '%d',
unit => 'b/s', min => 0 },
],
unit => 'b/s', min => 0 }
]
}
},
}
];
}
sub custom_traffic_perfdata {
my ($self, %options) = @_;
my ($warning, $critical);
if ($self->{instance_mode}->{option_results}->{units_traffic} eq '%' &&
(defined($self->{result_values}->{total}) && $self->{result_values}->{total} =~ /[0-9]/)) {
@ -114,7 +116,7 @@ sub custom_traffic_perfdata {
$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 => 'icmap_traffic', unit => 'b/s',
instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef,
@ -127,7 +129,7 @@ sub custom_traffic_perfdata {
sub custom_traffic_threshold {
my ($self, %options) = @_;
my $exit = 'ok';
if ($self->{instance_mode}->{option_results}->{units_traffic} eq '%' &&
(defined($self->{result_values}->{total}) && $self->{result_values}->{total} =~ /[0-9]/)) {
@ -142,10 +144,11 @@ sub custom_traffic_output {
my ($self, %options) = @_;
my ($traffic_value, $traffic_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{traffic_per_seconds}, network => 1);
my $msg = sprintf("Traffic : %s/s (%s)",
$traffic_value . $traffic_unit,
defined($self->{result_values}->{traffic_prct}) ? sprintf("%.2f%%", $self->{result_values}->{traffic_prct}) : '-');
return $msg;
return sprintf(
'Traffic : %s/s (%s)',
$traffic_value . $traffic_unit,
defined($self->{result_values}->{traffic_prct}) ? sprintf("%.2f%%", $self->{result_values}->{traffic_prct}) : '-'
);
}
sub custom_traffic_calc {
@ -154,7 +157,7 @@ sub custom_traffic_calc {
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
$self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'};
$self->{result_values}->{traffic_usage} = $options{new_datas}->{$self->{instance} . '_traffic_usage'};
my $diff_traffic = ($options{new_datas}->{$self->{instance} . '_traffic_usage'} - $options{old_datas}->{$self->{instance} . '_traffic_usage'});
$self->{result_values}->{traffic_per_seconds} = $diff_traffic / $options{delta_time};
if ($options{new_datas}->{$self->{instance} . '_total'} =~ /[1-9]/) {
@ -182,10 +185,10 @@ sub new {
bless $self, $class;
$options{options}->add_options(arguments => {
"filter-source:s" => { name => 'filter_source' },
"oid-filter:s" => { name => 'oid_filter', default => 'ifname' },
"oid-display:s" => { name => 'oid_display', default => 'ifname' },
"units-traffic:s" => { name => 'units_traffic', default => '%' },
'filter-source:s' => { name => 'filter_source' },
'oid-filter:s' => { name => 'oid_filter', default => 'ifname' },
'oid-display:s' => { name => 'oid_display', default => 'ifname' },
'units-traffic:s' => { name => 'units_traffic', default => '%' }
});
return $self;
@ -205,7 +208,7 @@ sub check_options {
sub check_oids_label {
my ($self, %options) = @_;
foreach (('oid_filter', 'oid_display')) {
$self->{option_results}->{$_} = lc($self->{option_results}->{$_}) if (defined($self->{option_results}->{$_}));
if (!defined($self->{oids_label}->{$self->{option_results}->{$_}})) {
@ -218,23 +221,20 @@ sub check_oids_label {
}
my $mapping = {
cbQosCMPrePolicyByteOverflow => { oid => '.1.3.6.1.4.1.9.9.166.1.15.1.1.4' },
cbQosCMPrePolicyByte => { oid => '.1.3.6.1.4.1.9.9.166.1.15.1.1.5' },
cbQosCMPrePolicyByte64 => { oid => '.1.3.6.1.4.1.9.9.166.1.15.1.1.6' },
cbQosCMPostPolicyByteOverflow => { oid => '.1.3.6.1.4.1.9.9.166.1.15.1.1.8' },
cbQosCMPostPolicyByte => { oid => '.1.3.6.1.4.1.9.9.166.1.15.1.1.9' },
cbQosCMPostPolicyByte64 => { oid => '.1.3.6.1.4.1.9.9.166.1.15.1.1.10' },
cbQosCMDropByteOverflow => { oid => '.1.3.6.1.4.1.9.9.166.1.15.1.1.15' },
cbQosCMDropByte => { oid => '.1.3.6.1.4.1.9.9.166.1.15.1.1.16' },
cbQosCMDropByte64 => { oid => '.1.3.6.1.4.1.9.9.166.1.15.1.1.17' },
cbQosCMDropByte64 => { oid => '.1.3.6.1.4.1.9.9.166.1.15.1.1.17' }
};
my $mapping2 = {
cbQosTSCfgRate => { oid => '.1.3.6.1.4.1.9.9.166.1.13.1.1.1' }, # bps
cbQosTSCfgRate64 => { oid => '.1.3.6.1.4.1.9.9.166.1.13.1.1.11' }, # bps
cbQosTSCfgRate64 => { oid => '.1.3.6.1.4.1.9.9.166.1.13.1.1.11' } # bps
};
my $mapping3 = {
cbQosQueueingCfgBandwidth => { oid => '.1.3.6.1.4.1.9.9.166.1.9.1.1.1' },
cbQosQueueingCfgBandwidthUnits => { oid => '.1.3.6.1.4.1.9.9.166.1.9.1.1.2' },
cbQosQueueingCfgBandwidthUnits => { oid => '.1.3.6.1.4.1.9.9.166.1.9.1.1.2' }
};
my $oid_cbQosIfIndex = '.1.3.6.1.4.1.9.9.166.1.1.1.1.4';
@ -252,17 +252,17 @@ my $oid_cbQosQueueingCfgEntry = '.1.3.6.1.4.1.9.9.166.1.9.1.1';
sub build_qos_information {
my ($self, %options) = @_;
my $qos_data = { complete_name => $options{class_name} };
# Need to try and find the queueing (it's a child)
$qos_data->{queueing} = $options{link_queueing}->{$options{policy_index} . '.' . $options{object_index}}
if (defined($options{link_queueing}->{$options{policy_index} . '.' . $options{object_index}}));
$qos_data->{shaping} = $options{link_shaping}->{$options{policy_index} . '.' . $options{object_index}}
if (!defined($qos_data->{shaping}) && defined($options{link_shaping}->{$options{policy_index} . '.' . $options{object_index}}));
while (($options{object_index} = $self->{results}->{$oid_cbQosParentObjectsIndex}->{$oid_cbQosParentObjectsIndex . '.' . $options{policy_index} . '.' . $options{object_index}}) != 0) {
my $config_index = $self->{results}->{$oid_cbQosConfigIndex}->{$oid_cbQosConfigIndex . '.' . $options{policy_index} . '.' . $options{object_index}};
my $tmp_name = '';
# try to find policy_map or class_map
if (defined($self->{results}->{$oid_cbQosCMName}->{$oid_cbQosCMName . '.' . $config_index})) {
@ -270,23 +270,23 @@ sub build_qos_information {
} elsif (defined($self->{results}->{$oid_cbQosPolicyMapName}->{$oid_cbQosPolicyMapName . '.' . $config_index})) {
$tmp_name = $self->{results}->{$oid_cbQosPolicyMapName}->{$oid_cbQosPolicyMapName . '.' . $config_index};
}
$qos_data->{shaping} = $options{link_shaping}->{$options{policy_index} . '.' . $options{object_index}}
if (!defined($qos_data->{shaping}) && defined($options{link_shaping}->{$options{policy_index} . '.' . $options{object_index}}));
$qos_data->{complete_name} = $tmp_name . ':' . $qos_data->{complete_name};
}
return $qos_data;
}
sub manage_selection {
my ($self, %options) = @_;
$self->{interface_classmap} = {};
$self->{classmap} = {};
$self->{total} = { drop_usage => 0, total_usage => 0 };
my $request_oids = [
{ oid => $self->{oids_label}->{$self->{option_results}->{oid_filter}} },
{ oid => $oid_cbQosPolicyMapName },
@ -294,9 +294,9 @@ sub manage_selection {
{ oid => $oid_cbQosConfigIndex },
{ oid => $oid_cbQosCMName },
{ oid => $oid_cbQosQueueingCfgEntry, end => $mapping3->{cbQosQueueingCfgBandwidthUnits}->{oid} },
{ oid => $oid_cbQosCMStatsEntry, start => $mapping->{cbQosCMPrePolicyByteOverflow}->{oid}, end => $mapping->{cbQosCMDropByte64}->{oid} },
{ oid => $oid_cbQosCMStatsEntry, start => $mapping->{cbQosCMPostPolicyByteOverflow}->{oid}, end => $mapping->{cbQosCMDropByte64}->{oid} },
{ oid => $oid_cbQosParentObjectsIndex },
{ oid => $oid_cbQosTSCfgEntry, end => $mapping2->{cbQosTSCfgRate64}->{oid} },
{ oid => $oid_cbQosTSCfgEntry, end => $mapping2->{cbQosTSCfgRate64}->{oid} }
];
push @$request_oids, { oid => $self->{oids_label}->{$self->{option_results}->{oid_display}} }
if ($self->{option_results}->{oid_filter} ne $self->{option_results}->{oid_display});
@ -321,8 +321,8 @@ sub manage_selection {
}
foreach (keys %{$self->{results}->{$oid_cbQosCMStatsEntry}}) {
next if (!/$mapping->{cbQosCMPrePolicyByte}->{oid}\.(\d+)\.(\d+)/);
next if (!/$mapping->{cbQosCMPostPolicyByteOverflow}->{oid}\.(\d+)\.(\d+)/);
my ($policy_index, $qos_object_index) = ($1, $2);
my $class_name = $classmap_name{$policy_index . '.' . $qos_object_index};
@ -338,68 +338,87 @@ sub manage_selection {
next;
}
my $qos_data = $self->build_qos_information(class_name => $class_name, policy_index => $policy_index, object_index => $qos_object_index,
link_queueing => $link_queueing, link_shaping => $link_shaping);
my $qos_data = $self->build_qos_information(
class_name => $class_name,
policy_index => $policy_index,
object_index => $qos_object_index,
link_queueing => $link_queueing,
link_shaping => $link_shaping
);
my $interface_filter = $self->{results}->{$self->{oids_label}->{$self->{option_results}->{oid_filter}}}->{$self->{oids_label}->{$self->{option_results}->{oid_filter}} . '.' . $if_index};
my $name = $interface_filter . ':' . $qos_data->{complete_name};
if (defined($self->{option_results}->{filter_source}) && $self->{option_results}->{filter_source} ne '' &&
$name !~ /$self->{option_results}->{filter_source}/) {
$self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter source.", debug => 1);
next;
}
# Same hash key but only for disco context
if (defined($options{disco})) {
$self->{interface_classmap}->{$policy_index . '.' . $qos_object_index} = $name;
next;
}
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_cbQosCMStatsEntry}, instance => $policy_index . '.' . $qos_object_index);
my $traffic_usage = (defined($result->{cbQosCMPostPolicyByte64}) && $result->{cbQosCMPostPolicyByte64} =~ /[1-9]/) ?
$result->{cbQosCMPostPolicyByte64} : (($result->{cbQosCMPostPolicyByteOverflow} << 32) + $result->{cbQosCMPostPolicyByte});
my $drop_usage = (defined($result->{cbQosCMDropByte64}) && $result->{cbQosCMDropByte64} =~ /[1-9]/) ?
$result->{cbQosCMDropByte64} : (($result->{cbQosCMDropByteOverflow} << 32) + $result->{cbQosCMDropByte});
$result->{cbQosCMPostPolicyByte64} :
(
($result->{cbQosCMPostPolicyByteOverflow} == 4294967295) ?
undef :
($result->{cbQosCMPostPolicyByteOverflow} * 4294967295 + $result->{cbQosCMPostPolicyByte})
);
my $drop_usage =
(defined($result->{cbQosCMDropByte64}) && $result->{cbQosCMDropByte64} =~ /[1-9]/) ?
$result->{cbQosCMDropByte64} :
(
($result->{cbQosCMDropByteOverflow} == 4294967295) ?
undef :
($result->{cbQosCMDropByteOverflow} * 4294967295 + $result->{cbQosCMDropByte})
);
my $total = 'unknown';
if (defined($qos_data->{shaping})) {
my $result_shaping = $options{snmp}->map_instance(mapping => $mapping2, results => $self->{results}->{$oid_cbQosTSCfgEntry}, instance => $qos_data->{shaping});
$total = defined($result_shaping->{cbQosTSCfgRate64}) ? $result_shaping->{cbQosTSCfgRate64} : $result_shaping->{cbQosTSCfgRate};
}
$self->{interface_classmap}->{$policy_index . '.' . $qos_object_index} = {
display => $name,
traffic_usage => $traffic_usage * 8, drop_usage => $drop_usage * 8, total => $total
traffic_usage => defined($traffic_usage) ? $traffic_usage * 8 : undef,
drop_usage => defined($drop_usage) ? $drop_usage * 8 : undef,
total => $total
};
my @tabname = split /:/, $name;
if (defined($tabname[3])){
$class_name = $tabname[3].'-'.$class_name;
$class_name = $tabname[3] . '-' . $class_name;
}
$self->{classmap}->{$name} = { display => $class_name, drop_usage => 0, traffic_usage => 0} if (!defined($self->{classmap}->{$name}));
$self->{classmap}->{$name}->{traffic_usage} += $traffic_usage * 8;
$self->{classmap}->{$name}->{drop_usage} += $drop_usage * 8;
$self->{classmap}->{$name}->{traffic_usage} += defined($traffic_usage) ? $traffic_usage * 8 : 0;
$self->{classmap}->{$name}->{drop_usage} += defined($drop_usage) ? $drop_usage * 8 : 0;
if (!defined($tabname[3])){
$self->{total}->{traffic_usage} += $traffic_usage * 8;
$self->{total}->{drop_usage} += $drop_usage * 8;
$self->{total}->{traffic_usage} += defined($traffic_usage) ? $traffic_usage * 8 : 0;
$self->{total}->{drop_usage} += defined($drop_usage) ? $drop_usage * 8 : 0;
}
}
$self->{cache_name} = "cisco_qos_" . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' .
$self->{cache_name} = 'cisco_qos_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' .
(defined($self->{option_results}->{filter_source}) ? md5_hex($self->{option_results}->{filter_source}) : md5_hex('all')) . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
if (scalar(keys %{$self->{interface_classmap}}) <= 0 && !defined($options{disco})) {
$self->{output}->add_option_msg(short_msg => "Cannot found classmap.");
$self->{output}->add_option_msg(short_msg => 'Cannot found classmap.');
$self->{output}->option_exit();
}
}
sub disco_format {
my ($self, %options) = @_;
$self->{output}->add_disco_format(elements => ['name']);
}

View File

@ -0,0 +1,439 @@
#
# Copyright 2020 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 centreon::common::cisco::standard::snmp::mode::wan3g;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc);
use Digest::MD5 qw(md5_hex);
sub custom_connection_status_output {
my ($self, %options) = @_;
return sprintf(
'connection status: %s',
$self->{result_values}->{connection_status}
);
}
sub custom_sim_status_output {
my ($self, %options) = @_;
return sprintf(
'sim status: %s',
$self->{result_values}->{sim_status}
);
}
sub custom_modem_status_output {
my ($self, %options) = @_;
return sprintf(
'modem status: %s',
$self->{result_values}->{modem_status}
);
}
sub custom_radio_status_output {
my ($self, %options) = @_;
return sprintf(
'current band: %s [channel number: %s]',
$self->{result_values}->{current_band},
$self->{result_values}->{channel_number}
);
}
sub custom_network_status_output {
my ($self, %options) = @_;
return sprintf(
'service status: %s',
$self->{result_values}->{service_status}
);
}
sub modem_long_output {
my ($self, %options) = @_;
return "checking module '" . $options{instance_value}->{display} . "'";
}
sub prefix_modem_output {
my ($self, %options) = @_;
return "module '" . $options{instance_value}->{display} . "' ";
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'modem', type => 3, cb_prefix_output => 'prefix_modem_output', cb_long_output => 'modem_long_output',
indent_long_output => ' ', message_multiple => 'All cellular modems are ok',
group => [
{ name => 'global', type => 0, skipped_code => { -10 => 1 } },
{ name => 'radio', type => 0, skipped_code => { -10 => 1 } },
{ name => 'network', type => 0, skipped_code => { -10 => 1 } }
]
}
];
$self->{maps_counters}->{global} = [
{ label => 'modem-status', threshold => 0, set => {
key_values => [ { name => 'modem_status' }, { name => 'display' } ],
closure_custom_calc => \&catalog_status_calc,
closure_custom_output => $self->can('custom_modem_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold
}
},
{ label => 'connection-status', threshold => 0, set => {
key_values => [ { name => 'connection_status' }, { name => 'display' } ],
closure_custom_calc => \&catalog_status_calc,
closure_custom_output => $self->can('custom_connection_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold
}
},
{ label => 'sim-status', threshold => 0, set => {
key_values => [ { name => 'sim_status' }, { name => 'display' } ],
closure_custom_calc => \&catalog_status_calc,
closure_custom_output => $self->can('custom_sim_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold
}
},
{ label => 'temperature', nlabel => 'modem.temperature.celsius', display_ok => 0, set => {
key_values => [ { name => 'temperature' }, { name => 'display' } ],
output_template => 'memory used: %s%s',
output_change_bytes => 1,
perfdatas => [
{ value => 'temperature_absolute', template => '%s', min => 0,
unit => 'C', label_extra_instance => 1, instance_use => 'display_absolute' }
]
}
}
];
$self->{maps_counters}->{radio} = [
{ label => 'radio-status', threshold => 0, set => {
key_values => [ { name => 'current_band' }, { name => 'channel_number' }, { name => 'display' } ],
closure_custom_calc => \&catalog_status_calc,
closure_custom_output => $self->can('custom_radio_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold
}
},
{ label => 'radio-rssi', nlabel => 'modem.radio.rssi.dbm', set => {
key_values => [ { name => 'rssi' }, { name => 'display' } ],
output_template => 'received signal strength: %s dBm',
output_change_bytes => 1,
perfdatas => [
{ value => 'rssi_absolute', template => '%s', min => 0,
unit => 'dBm', label_extra_instance => 1, instance_use => 'display_absolute' }
]
}
}
];
$self->{maps_counters}->{network} = [
{ label => 'network-status', threshold => 0, set => {
key_values => [ { name => 'service_status' }, { name => 'display' } ],
closure_custom_calc => \&catalog_status_calc,
closure_custom_output => $self->can('custom_network_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold
}
},
{ label => 'traffic-in', nlabel => 'modem.traffic.in.bitspersecond', set => {
key_values => [ { name => 'traffic_in', diff => 1 }, { name => 'display' } ],
output_template => 'traffic in: %s%s/s',
per_second => 1, output_change_bytes => 2,
perfdatas => [
{ value => 'traffic_in_per_second', template => '%s',
min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'traffic-out', nlabel => 'modem.traffic.out.bitspersecond', set => {
key_values => [ { name => 'traffic_out', diff => 1 }, { name => 'display' } ],
output_template => 'traffic out: %s%s/s',
per_second => 1, output_change_bytes => 2,
perfdatas => [
{ value => 'traffic_out_per_second', template => '%s',
min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' }
]
}
}
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
'filter-name:s' => { name => 'filter_name' },
'unknown-modem-status:s' => { name => 'unknown_modem_status', default => '%{modem_status} =~ /unknown/i' },
'warning-modem-status:s' => { name => 'warning_modem_status', default => '%{modem_status} =~ /lowPowerMode/i' },
'critical-modem-status:s' => { name => 'critical_modem_status', default => '%{modem_status} =~ /offLine/i' },
'unknown-connection-status:s' => { name => 'unknown_connection_status', default => '%{connection_status} =~ /unknown/i' },
'warning-connection-status:s' => { name => 'warning_connection_status', default => '' },
'critical-connection-status:s' => { name => 'critical_connection_status', default => '%{connection_status} =~ /inactive|idle|disconnected|error/i' },
'unknown-sim-status:s' => { name => 'unknown_sim_status', default => '%{sim_status} =~ /unknown/i' },
'warning-sim-status:s' => { name => 'warning_sim_status', default => '' },
'critical-sim-status:s' => { name => 'critical_sim_status', default => '%{sim_status} !~ /ok|unknown/i' },
'unknown-radio-status:s' => { name => 'unknown_radio_status', default => '%{current_band} =~ /unknown/i' },
'warning-radio-status:s' => { name => 'warning_radio_status', default => '' },
'critical-radio-status:s' => { name => 'critical_radio_status', default => '%{current_band} =~ /invalid|none/i' },
'unknown-network-status:s' => { name => 'unknown_network_status', default => '%{service_status} =~ /unknown/i' },
'warning-network-status:s' => { name => 'warning_network_status', default => '' },
'critical-network-status:s' => { name => 'critical_network_status', default => '%{service_status} =~ /emergencyOnly|noService/i' }
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$self->change_macros(
macros => [
'unknown_modem_status', 'warning_modem_status', 'critical_modem_status',
'unknown_connection_status', 'warning_connection_status', 'critical_connection_status',
'unknown_sim_status', 'warning_sim_status', 'critical_sim_status',
'unknown_radio_status', 'warning_radio_status', 'critical_radio_status',
'unknown_network_status', 'warning_network_status', 'critical_network_status',
]
);
}
my $map_current_band = {
1 => 'unknown', 2 => 'invalid', 3 => 'none',
4 => 'gsm850', 5 => 'gsm900', 6 => 'gsm1800',
7 => 'gsm1900', 8 => 'wcdma800', 9 => 'wcdma850',
10 => 'wcdma1900', 11 => 'wcdma2100', 12 => 'lteBand'
};
my $map_modem_status = {
1 => 'unknown', 2 => 'offLine', 3 => 'onLine', 4 => 'lowPowerMode'
};
my $map_connection_status = {
1 => 'unknown', 2 => 'error', 3 => 'connecting',
4 => 'dormant', 5 => 'connected', 6 => 'disconnected',
7 => 'idle', 8 => 'active', 9 => 'inactive'
};
my $map_sim_status = {
1 => 'unknown', 2 => 'ok', 3 => 'notInserted',
4 => 'removed', 5 => 'initFailure', 6 => 'generalFailure',
7 => 'locked', 8 => 'chv1Blocked', 9 => 'chv2Blocked',
10 => 'chv1Rejected', 11 => 'chv2Rejected',
12 => 'mepLocked', 13 => 'networkRejected'
};
my $map_service_status = {
1 => 'unknown', 2 => 'noService',
3 => 'normal', 4 => 'emergencyOnly'
};
my $mapping = {
rssi => { oid => '.1.3.6.1.4.1.9.9.661.1.3.4.1.1.1' }, # c3gCurrentGsmRssi
current_band => { oid => '.1.3.6.1.4.1.9.9.661.1.3.4.1.1.3', map => $map_current_band }, # c3gGsmCurrentBand
channel_number => { oid => '.1.3.6.1.4.1.9.9.661.1.3.4.1.1.4' }, # c3gGsmChannelNumber
modem_status => { oid => '.1.3.6.1.4.1.9.9.661.1.3.1.1.6', map => $map_modem_status }, # c3gModemStatus
temperature => { oid => '.1.3.6.1.4.1.9.9.661.1.1.1.12' }, # c3gModemTemperature
connection_status => { oid => '.1.3.6.1.4.1.9.9.661.1.1.1.8', map => $map_connection_status }, # c3gConnectionStatus
sim_status => { oid => '.1.3.6.1.4.1.9.9.661.1.3.5.1.1.2', map => $map_sim_status }, # c3gGsmSimStatus
service_status => { oid => '.1.3.6.1.4.1.9.9.661.1.3.2.1.2', map => $map_service_status }, # c3gGsmCurrentServiceStatus
traffic_out => { oid => '.1.3.6.1.4.1.9.9.661.1.3.2.1.19' }, # c3gGsmTotalByteTransmitted
traffic_in => { oid => '.1.3.6.1.4.1.9.9.661.1.3.2.1.20' }, # c3gGsmTotalByteReceived
};
sub manage_selection {
my ($self, %options) = @_;
my $oid_entPhysicalName = '.1.3.6.1.2.1.47.1.1.1.1.7';
my $snmp_result = $options{snmp}->get_table(
oid => $mapping->{connection_status}->{oid},
nothing_quit => 1
);
my $instances = [];
foreach (keys %$snmp_result) {
/\.(\d+)$/;
push @$instances, $1;
}
$options{snmp}->load(
oids => [ $oid_entPhysicalName ],
instances => $instances,
instance_regexp => '^(.*)$'
);
$snmp_result = $options{snmp}->get_leef();
$self->{modem} = {};
foreach (keys %$snmp_result) {
/\.(\d+)$/;
my $instance = $1;
my $name = $snmp_result->{$_};
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 module '" . $name . "'.", debug => 1);
next;
}
$self->{modem}->{$instance} = {
display => $name,
global => { display => $name },
radio => { display => $name },
network => { display => $name }
};
}
return if (scalar(keys %{$self->{modem}}) <= 0);
$options{snmp}->load(
oids => [ map($_->{oid}, values(%$mapping)) ],
instances => [ keys %{$self->{modem}} ],
instance_regexp => '^(.*)$'
);
$snmp_result = $options{snmp}->get_leef();
foreach (keys %{$self->{modem}}) {
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $_);
$self->{modem}->{$_}->{global}->{modem_status} = $result->{modem_status};
$self->{modem}->{$_}->{global}->{connection_status} = $result->{connection_status};
$self->{modem}->{$_}->{global}->{sim_status} = $result->{sim_status};
$self->{modem}->{$_}->{global}->{temperature} = $result->{temperature};
$self->{modem}->{$_}->{radio}->{current_band} = $result->{current_band};
$self->{modem}->{$_}->{radio}->{channel_number} = $result->{channel_number};
$self->{modem}->{$_}->{radio}->{rssi} = $result->{rssi};
$self->{modem}->{$_}->{network}->{traffic_in} = $result->{traffic_in};
$self->{modem}->{$_}->{network}->{traffic_out} = $result->{traffic_out};
$self->{modem}->{$_}->{network}->{service_status} = $result->{service_status};
}
$self->{cache_name} = 'cisco_standard_' . $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')) . '_' .
(defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all'));
}
1;
__END__
=head1 MODE
Check cellular 3G and 4G LTE WAN.
=over 8
=item B<--filter-name>
Filter by name (can be a regexp).
=item B<--unknown-modem-status>
Set unknown threshold for status (Default: '%{modem_status} =~ /unknown/i').
Can used special variables like: %{modem_status}, %{display}
=item B<--warning-modem-status>
Set warning threshold for status (Default: '%{modem_status} =~ /lowPowerMode/i').
Can used special variables like: %{modem_status}, %{display}
=item B<--critical-modem-status>
Set critical threshold for status (Default: '%{modem_status} =~ /offLine/i').
Can used special variables like: %{modem_status}, %{display}
=item B<--unknown-connection-status>
Set unknown threshold for status (Default: '%{connection_status} =~ /unknown/i').
Can used special variables like: %{connection_status}, %{display}
=item B<--warning-connection-status>
Set warning threshold for status.
Can used special variables like: %{connection_status}, %{display}
=item B<--critical-connection-status>
Set critical threshold for status (Default: '%{connection_status} =~ /inactive|idle|disconnected|error/i').
Can used special variables like: %{connection_status}, %{display}
=item B<--unknown-sim-status>
Set unknown threshold for status (Default: '%{sim_status} =~ /unknown/i').
Can used special variables like: %{sim_status}, %{display}
=item B<--warning-sim-status>
Set warning threshold for status.
Can used special variables like: %{sim_status}, %{display}
=item B<--critical-sim-status>
Set critical threshold for status (Default: '%{sim_status} !~ /ok|unknown/i').
Can used special variables like: %{sim_status}, %{display}
=item B<--unknown-radio-status>
Set unknown threshold for status (Default: '%{current_band} =~ /unknown/i').
Can used special variables like: %{current_band}, %{channel_number}, %{display}
=item B<--warning-radio-status>
Set warning threshold for status.
Can used special variables like: %{current_band}, %{channel_number}, %{display}
=item B<--critical-radio-status>
Set critical threshold for status (Default: '%{current_band} =~ /invalid|none/i').
Can used special variables like: %{current_band}, %{channel_number}, %{display}
=item B<--unknown-network-status>
Set unknown threshold for status (Default: '%{service_status} =~ /unknown/i').
Can used special variables like: %{service_status}, %{display}
=item B<--warning-network-status>
Set warning threshold for status.
Can used special variables like: %{service_status}, %{display}
=item B<--critical-network-status>
Set critical threshold for status (Default: '%{service_status} =~ /emergencyOnly|noService/i').
Can used special variables like: %{service_status}, %{display}
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'temperature', 'traffic-in', 'traffic-out'.
=back
=cut

View File

@ -147,8 +147,9 @@ sub manage_selection {
$cpu += $snmp_result->{$oid_fgProcessorUsage}->{$_};
}
my $num_core = scalar(keys %{$self->{cpu_core}});
$self->{cpu_avg} = {
average => ($i > 0) ? $cpu / $i : $snmp_result->{$oid_fgSysCpuUsage}->{$oid_fgSysCpuUsage . '.0'}
average => $num_core > 0 ? $cpu / $num_core : $snmp_result->{$oid_fgSysCpuUsage}->{$oid_fgSysCpuUsage . '.0'}
};
if (defined($self->{option_results}->{cluster})) {

View File

@ -0,0 +1,197 @@
#
# Copyright 2020 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 centreon::common::fortinet::fortigate::snmp::mode::interfaces;
use base qw(snmp_standard::mode::interfaces);
use strict;
use warnings;
sub set_oids_label {
my ($self, %options) = @_;
$self->SUPER::set_oids_label(%options);
$self->{oids_label}->{vdom} = { oid => '.1.3.6.1.4.1.12356.101.7.2.1.1.1', cache => 'reload_cache_vdom_index' };
}
sub reload_cache_vdom_index {
my ($self, %options) = @_;
my $oid_fgVdEntName = '.1.3.6.1.4.1.12356.101.3.2.1.1.2';
my $snmp_result = $self->{snmp}->get_table(oid => $oid_fgVdEntName);
my $store_index = defined($options{store_index}) && $options{store_index} == 1 ? 1 : 0;
foreach (keys %{$options{result}->{ $self->{oids_label}->{$options{name}}->{oid} }}) {
/^$self->{oids_label}->{$options{name}}->{oid}\.(.*)$/;
push @{$options{datas}->{all_ids}}, $1 if ($store_index == 1);
$options{datas}->{$options{name} . "_" . $1} = $snmp_result->{ $oid_fgVdEntName . '.' . $options{result}->{ $self->{oids_label}->{$options{name}}->{oid} }->{$_} };
}
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
return $self;
}
1;
__END__
=head1 MODE
Check interfaces.
=over 8
=item B<--add-global>
Check global port statistics (By default if no --add-* option is set).
=item B<--add-status>
Check interface status.
=item B<--add-duplex-status>
Check duplex status (with --warning-status and --critical-status).
=item B<--add-traffic>
Check interface traffic.
=item B<--add-errors>
Check interface errors.
=item B<--add-cast>
Check interface cast.
=item B<--add-speed>
Check interface speed.
=item B<--add-volume>
Check interface data volume between two checks (not supposed to be graphed, useful for BI reporting).
=item B<--warning-status>
Set warning threshold for status.
Can used special variables like: %{admstatus}, %{opstatus}, %{duplexstatus}, %{display}
=item B<--critical-status>
Set critical threshold for status (Default: '%{admstatus} eq "up" and %{opstatus} ne "up"').
Can used special variables like: %{admstatus}, %{opstatus}, %{duplexstatus}, %{display}
=item B<--warning-*>
Threshold warning.
Can be: 'total-port', 'total-admin-up', 'total-admin-down', 'total-oper-up', 'total-oper-down',
'in-traffic', 'out-traffic', 'in-error', 'in-discard', 'out-error', 'out-discard',
'in-ucast' (%), 'in-bcast' (%), 'in-mcast' (%), 'out-ucast' (%), 'out-bcast' (%), 'out-mcast' (%),
'speed' (b/s).
=item B<--critical-*>
Threshold critical.
Can be: 'total-port', 'total-admin-up', 'total-admin-down', 'total-oper-up', 'total-oper-down',
'in-traffic', 'out-traffic', 'in-error', 'in-discard', 'out-error', 'out-discard',
'in-ucast' (%), 'in-bcast' (%), 'in-mcast' (%), 'out-ucast' (%), 'out-bcast' (%), 'out-mcast' (%),
'speed' (b/s).
=item B<--units-traffic>
Units of thresholds for the traffic (Default: '%') ('%', 'b/s').
=item B<--units-errors>
Units of thresholds for errors/discards (Default: '%') ('%', 'absolute').
=item B<--nagvis-perfdata>
Display traffic perfdata to be compatible with nagvis widget.
=item B<--interface>
Set the interface (number expected) ex: 1,2,... (empty means 'check all interface').
=item B<--name>
Allows to use interface name with option --interface instead of interface oid index (Can be a regexp)
=item B<--speed>
Set interface speed for incoming/outgoing traffic (in Mb).
=item B<--speed-in>
Set interface speed for incoming traffic (in Mb).
=item B<--speed-out>
Set interface speed for outgoing traffic (in Mb).
=item B<--no-skipped-counters>
Don't skip counters when no change.
=item B<--force-counters32>
Force to use 32 bits counters (even in snmp v2c and v3). Should be used when 64 bits counters are buggy.
=item B<--reload-cache-time>
Time in minutes before reloading cache file (default: 180).
=item B<--oid-filter>
Choose OID used to filter interface (default: ifName) (values: ifDesc, ifAlias, ifName, IpAddr, Vdom).
=item B<--oid-display>
Choose OID used to display interface (default: ifName) (values: ifDesc, ifAlias, ifName, IpAddr, Vdom).
=item B<--oid-extra-display>
Add an OID to display.
=item B<--display-transform-src>
Regexp src to transform display value.
=item B<--display-transform-dst>
Regexp dst to transform display value.
=item B<--show-cache>
Display cache interface datas.
=back
=cut

View File

@ -103,6 +103,7 @@ sub set_counters {
{ name => 'vdom_memory', type => 0, skipped_code => { -10 => 1 } },
{ name => 'vdom_session', type => 0, skipped_code => { -10 => 1 } },
{ name => 'vdom_traffic', type => 0, skipped_code => { -10 => 1 } },
{ name => 'vdom_policy', type => 0, skipped_code => { -10 => 1 } },
{ name => 'vdom_status', type => 0, skipped_code => { -10 => 1 } }
]
}
@ -114,7 +115,7 @@ sub set_counters {
closure_custom_output => $self->can('custom_license_output'),
perfdatas => [
{ value => 'used_absolute', template => '%d', min => 0, max => 'total_absolute' }
],
]
}
},
{ label => 'license-free', nlabel => 'virtualdomains.license.free.count', display_ok => 0, set => {
@ -122,7 +123,7 @@ sub set_counters {
closure_custom_output => $self->can('custom_license_output'),
perfdatas => [
{ value => 'free_absolute', template => '%d', min => 0, max => 'total_absolute' }
],
]
}
},
{ label => 'license-usage-prct', nlabel => 'virtualdomains.license.usage.percentage', display_ok => 0, set => {
@ -130,7 +131,7 @@ sub set_counters {
closure_custom_output => $self->can('custom_license_output'),
perfdatas => [
{ value => 'prct_used_absolute', template => '%.2f', min => 0, max => 100, unit => '%' }
],
]
}
}
];
@ -142,7 +143,7 @@ sub set_counters {
perfdatas => [
{ value => 'cpu_absolute', template => '%.2f', unit => '%', min => 0, max => 100,
label_extra_instance => 1, instance_use => 'display_absolute' }
],
]
}
}
];
@ -159,6 +160,18 @@ sub set_counters {
}
];
$self->{maps_counters}->{vdom_policy} = [
{ label => 'policies-active', nlabel => 'virtualdomain.policies.active.count', set => {
key_values => [ { name => 'active_policies' }, { name => 'display' } ],
output_template => 'active policies: %d',
perfdatas => [
{ value => 'active_policies_absolute', template => '%d',
min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
]
}
}
];
$self->{maps_counters}->{vdom_session} = [
{ label => 'sessions-active', nlabel => 'virtualdomain.sessions.active.count', set => {
key_values => [ { name => 'active_sessions' }, { name => 'display' } ],
@ -166,7 +179,7 @@ sub set_counters {
perfdatas => [
{ value => 'active_sessions_absolute', template => '%d',
min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
],
]
}
},
{ label => 'session-rate', nlabel => 'virtualdomain.sessions.rate.persecond', set => {
@ -175,9 +188,9 @@ sub set_counters {
perfdatas => [
{ value => 'session_rate_absolute', template => '%d',
min => 0, unit => '/s', label_extra_instance => 1, instance_use => 'display_absolute' }
],
]
}
},
}
];
$self->{maps_counters}->{vdom_status} = [
@ -202,7 +215,7 @@ sub set_counters {
perfdatas => [
{ value => 'traffic_per_second', template => '%s',
min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' },
],
]
}
},
{ label => 'traffic-out', nlabel => 'virtualdomain.traffic.out.bitspersecond', set => {
@ -215,9 +228,9 @@ sub set_counters {
perfdatas => [
{ value => 'traffic_per_second', template => '%s',
min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' },
],
]
}
},
}
];
}
@ -227,12 +240,15 @@ sub new {
bless $self, $class;
$options{options}->add_options(arguments => {
'filter-vdomain:s' => { name => 'filter_vdomain' },
'add-traffic' => { name => 'add_traffic' },
'warning-status:s' => { name => 'warning_status', default => '' },
'critical-status:s' => { name => 'critical_status', default => '' }
'filter-vdomain:s' => { name => 'filter_vdomain' },
'add-traffic' => { name => 'add_traffic' },
'add-policy' => { name => 'add_policy' },
'policy-cache-time:s' => { name => 'policy_cache_time', default => 60 },
'warning-status:s' => { name => 'warning_status', default => '' },
'critical-status:s' => { name => 'critical_status', default => '' }
});
$self->{cache_policy} = centreon::plugins::statefile->new(%options);
return $self;
}
@ -241,6 +257,7 @@ sub check_options {
$self->SUPER::check_options(%options);
$self->change_macros(macros => ['warning_status', 'critical_status']);
$self->{cache_policy}->check_options(%options) if (defined($self->{option_results}->{add_policy}));
}
my $map_opmode = { 1 => 'nat', 2 => 'transparent' };
@ -248,7 +265,7 @@ my $map_ha = { 1 => 'master', 2 => 'backup', 3 => 'standalone' };
my $mapping = {
fgVdNumber => { oid => '.1.3.6.1.4.1.12356.101.3.1.1' },
fgVdMaxVdoms => { oid => '.1.3.6.1.4.1.12356.101.3.1.2' },
fgVdMaxVdoms => { oid => '.1.3.6.1.4.1.12356.101.3.1.2' }
};
my $mapping_vdom = {
fgVdEntOpMode => { oid => '.1.3.6.1.4.1.12356.101.3.2.1.1.3', map => $map_opmode },
@ -301,6 +318,27 @@ sub add_traffic {
}
}
sub add_policy {
my ($self, %options) = @_;
my $oid_fgFwPolID = '.1.3.6.1.4.1.12356.101.5.1.2.1.1.1';
my $has_cache_file = $self->{cache_policy}->read(statefile => 'fortinet_fortigate_policy_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port());
my $timestamp_cache = $self->{cache_policy}->get(name => 'last_timestamp');
my $snmp_result = $self->{cache_policy}->get(name => 'snmp_result');
if ($has_cache_file == 0 || !defined($timestamp_cache) || !defined($snmp_result) ||
((time() - $timestamp_cache) > (($self->{option_results}->{policy_cache_time}) * 60))) {
$snmp_result = $options{snmp}->get_table(oid => $oid_fgFwPolID);
$self->{cache_policy}->write(data => { last_timestamp => time(), snmp_result => $snmp_result });
}
foreach (keys %$snmp_result) {
/^$oid_fgFwPolID\.(\d+)/;
$self->{vdom}->{$1}->{vdom_policy}->{active_policies}++
if (defined($self->{vdom}->{$1}));
}
}
sub manage_selection {
my ($self, %options) = @_;
@ -338,8 +376,10 @@ sub manage_selection {
vdom_cpu => { display => $name },
vdom_memory => { display => $name },
vdom_session => { display => $name },
vdom_status => { display => $name },
vdom_status => { display => $name }
};
$self->{vdom}->{$instance}->{vdom_policy} = { display => $name, active_policies => 0 }
if (defined($self->{option_results}->{add_policy}));
}
return if (scalar(keys %{$self->{vdom}}) <= 0);
@ -362,6 +402,8 @@ sub manage_selection {
$self->add_traffic(snmp => $options{snmp})
if (defined($self->{option_results}->{add_traffic}));
$self->add_policy(snmp => $options{snmp})
if (defined($self->{option_results}->{add_policy}));
$self->{cache_name} = 'fortinet_fortigate_' . $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')) . '_' .
@ -386,6 +428,14 @@ Filter by virtual domain name (can be a regexp).
Add traffic usage by virtual domain.
=item B<--add-policy>
Add number of policies by virtual domain.
=item B<--policy-cache-time>
Time in minutes before reloading cache file (default: 60).
=item B<--warning-status>
Set warning threshold for status (Default: '').
@ -401,7 +451,7 @@ Can used special variables like: %{op_mode}, %{ha_state}
Thresholds.
Can be: 'cpu-utilization', 'sessions-active', 'session-rate',
'memory-usage-prct', 'license-usage', 'license-free',
'license-usage-prct', 'traffic-in', 'traffic-out'.
'license-usage-prct', 'traffic-in', 'traffic-out', 'policies-active'.
=back

View File

@ -0,0 +1,85 @@
#
# Copyright 2020 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 centreon::common::foundry::snmp::mode::components::board;
use strict;
use warnings;
my $mapping_board_status = {
0 => 'moduleEmpty', 2 => 'moduleGoingDown', 3 => 'moduleRejected',
4 => 'moduleBad', 8 => 'moduleConfigured', 9 => 'moduleComingUp',
10 => 'moduleRunning'
};
my $mapping = {
snAgentBrdMainBrdDescription => { oid => '.1.3.6.1.4.1.1991.1.1.2.2.1.1.2' },
snAgentBrdModuleStatus => { oid => '.1.3.6.1.4.1.1991.1.1.2.2.1.1.12', map => $mapping_board_status }
};
sub load {
my ($self) = @_;
push @{$self->{request}},
{ oid => $mapping->{snAgentBrdMainBrdDescription}->{oid} },
{ oid => $mapping->{snAgentBrdModuleStatus}->{oid} };
}
sub check {
my ($self) = @_;
$self->{output}->output_add(long_msg => 'checking boards');
$self->{components}->{board} = { name => 'boards', total => 0, skip => 0 };
return if ($self->check_filter(section => 'board'));
my $result = {
%{$self->{results}->{ $mapping->{snAgentBrdMainBrdDescription}->{oid} }},
%{$self->{results}->{ $mapping->{snAgentBrdModuleStatus}->{oid} }}
};
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %$result)) {
next if ($oid !~ /^$mapping->{snAgentBrdModuleStatus}->{oid}\.(.*)$/);
my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $result, instance => $instance);
next if ($self->check_filter(section => 'board', instance => $instance));
$self->{components}->{board}->{total}++;
$self->{output}->output_add(
long_msg => sprintf(
"board '%s' status is '%s' [instance: %s].",
$result->{snAgentBrdMainBrdDescription},
$result->{snAgentBrdModuleStatus},
$instance
)
);
my $exit = $self->get_severity(section => 'board', value => $result->{snAgentBrdModuleStatus});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(
severity => $exit,
short_msg => sprintf(
"board '%s' status is '%s'",
$result->{snAgentBrdMainBrdDescription},
$result->{snAgentBrdModuleStatus}
)
);
}
}
}
1;

View File

@ -0,0 +1,77 @@
#
# Copyright 2020 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 centreon::common::foundry::snmp::mode::components::fan;
use strict;
use warnings;
use centreon::common::foundry::snmp::mode::components::resources qw($map_status);
my $mapping = {
snChasFan2Description => { oid => '.1.3.6.1.4.1.1991.1.1.1.3.2.1.3' },
snChasFan2OperStatus => { oid => '.1.3.6.1.4.1.1991.1.1.1.3.2.1.4', map => $map_status }
};
my $oid_snChasFan2Entry = '.1.3.6.1.4.1.1991.1.1.1.3.2.1';
sub load {
my ($self) = @_;
push @{$self->{request}}, {
oid => $oid_snChasFan2Entry,
start => $mapping->{snChasFan2Description}->{oid}
};
}
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_snChasFan2Entry}})) {
next if ($oid !~ /^$mapping->{snChasFan2OperStatus}->{oid}\.(.*)$/);
my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_snChasFan2Entry}, instance => $instance);
next if ($self->check_filter(section => 'fan', instance => $instance));
$self->{components}->{fan}->{total}++;
$self->{output}->output_add(
long_msg => sprintf(
"fan '%s' status is '%s' [instance = %s]",
$result->{snChasFan2Description}, $result->{snChasFan2OperStatus}, $instance
)
);
my $exit = $self->get_severity(label => 'default', section => 'fan', value => $result->{snChasFan2OperStatus});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(
severity => $exit,
short_msg => sprintf(
"fan '%s' status is '%s'",
$result->{snChasFan2Description}, $result->{snChasFan2OperStatus}
)
);
}
}
}
1;

View File

@ -0,0 +1,79 @@
#
# Copyright 2020 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 centreon::common::foundry::snmp::mode::components::psu;
use strict;
use warnings;
use centreon::common::foundry::snmp::mode::components::resources qw($map_status);
my $mapping = {
snChasPwrSupply2Description => { oid => '.1.3.6.1.4.1.1991.1.1.1.2.2.1.3' },
snChasPwrSupply2OperStatus => { oid => '.1.3.6.1.4.1.1991.1.1.1.2.2.1.4', map => $map_status }
};
my $oid_snChasPwrSupply2Entry = '.1.3.6.1.4.1.1991.1.1.1.2.2.1';
sub load {
my ($self) = @_;
push @{$self->{request}}, {
oid => $oid_snChasPwrSupply2Entry,
start => $mapping->{snChasPwrSupply2Description}->{oid}
};
}
sub check {
my ($self) = @_;
$self->{output}->output_add(long_msg => 'checking power supplies');
$self->{components}->{psu} = { name => 'psu', total => 0, skip => 0 };
return if ($self->check_filter(section => 'psu'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_snChasPwrSupply2Entry}})) {
next if ($oid !~ /^$mapping->{snChasPwrSupply2OperStatus}->{oid}\.(.*)$/);
my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_snChasPwrSupply2Entry}, instance => $instance);
next if ($self->check_filter(section => 'psu', instance => $instance));
$self->{components}->{psu}->{total}++;
$self->{output}->output_add(
long_msg => sprintf(
"power supply '%s' status is '%s' [instance: %s].",
$result->{snChasPwrSupply2Description},
$result->{snChasPwrSupply2OperStatus},
$instance
)
);
my $exit = $self->get_severity(label => 'default', section => 'psu', value => $result->{snChasPwrSupply2OperStatus});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(
severity => $exit,
short_msg => sprintf(
"power supply '%s' status is '%s'",
$result->{snChasPwrSupply2Description},
$result->{snChasPwrSupply2OperStatus}
)
);
}
}
}
1;

View File

@ -0,0 +1,36 @@
#
# Copyright 2020 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 centreon::common::foundry::snmp::mode::components::resources;
use strict;
use warnings;
use Exporter;
our $map_status;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw($map_status);
$map_status = {
1 => 'other', 2 => 'normal', 3 => 'failure'
};
1;

View File

@ -0,0 +1,105 @@
#
# Copyright 2020 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 centreon::common::foundry::snmp::mode::components::temperature;
use strict;
use warnings;
my $mapping = {
snChasActualTemperature => { oid => '.1.3.6.1.4.1.1991.1.1.1.1.18' },
snChasWarningTemperature => { oid => '.1.3.6.1.4.1.1991.1.1.1.1.19' },
snChasShutdownTemperature => { oid => '.1.3.6.1.4.1.1991.1.1.1.1.20' }
};
my $oid_snChasGen = '.1.3.6.1.4.1.1991.1.1.1.1';
sub load {
my ($self) = @_;
push @{$self->{request}}, {
oid => $oid_snChasGen,
start => $mapping->{snChasActualTemperature}->{oid},
end => $mapping->{snChasShutdownTemperature}->{oid}
};
}
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'));
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_snChasGen}, instance => '0');
my ($name, $instance) = ('chassi', 1);
next if ($self->check_filter(section => 'temperature', instance => $instance));
$self->{components}->{temperature}->{total}++;
$result->{snChasActualTemperature} *= 0.5;
$result->{snChasWarningTemperature} *= 0.5;
$result->{snChasShutdownTemperature} *= 0.5;
$self->{output}->output_add(
long_msg => sprintf(
"temperature '%s' is %s celsius [instance = %s]",
$name, $result->{snChasActualTemperature}, $instance
)
);
my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result->{snChasActualTemperature});
if ($checked == 0) {
my $warn_th = defined($result->{snChasWarningTemperature}) ? $result->{snChasWarningTemperature} : '';
my $crit_th = defined($result->{snChasShutdownTemperature}) ? $result->{snChasShutdownTemperature} : '';
$self->{perfdata}->threshold_validate(label => 'warning-temperature-instance-' . $instance, value => $warn_th);
$self->{perfdata}->threshold_validate(label => 'critical-temperature-instance-' . $instance, value => $crit_th);
$exit = $self->{perfdata}->threshold_check(
value => $result->{snChasActualTemperature},
threshold => [
{ label => 'critical-temperature-instance-' . $instance, exit_litteral => 'critical' },
{ label => 'warning-temperature-instance-' . $instance, exit_litteral => 'warning' }
]
);
$warn = $self->{perfdata}->get_perfdata_for_output(label => 'warning-temperature-instance-' . $instance);
$crit = $self->{perfdata}->get_perfdata_for_output(label => 'critical-temperature-instance-' . $instance)
}
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(
severity => $exit,
short_msg => sprintf(
"temperature '%s' is %s celsius",
$name,
$result->{snChasActualTemperature}
)
);
}
$self->{output}->perfdata_add(
nlabel => 'hardware.temperature.celsius',
unit => 'C',
instances => $name,
value => $result->{snChasActualTemperature},
warning => $warn,
critical => $crit
);
}
1;

View File

@ -0,0 +1,120 @@
#
# Copyright 2020 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 centreon::common::foundry::snmp::mode::cpu;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'cpu', type => 1, cb_prefix_output => 'prefix_cpu_output', message_multiple => 'All CPUs are ok' }
];
$self->{maps_counters}->{cpu} = [
{ label => 'utilization-5s', nlabel => 'cpu.utilization.5s.percentage', set => {
key_values => [ { name => 'cpu_5s' }, { name => 'display' } ],
output_template => '%.2f %% (5s)',
perfdatas => [
{ value => 'cpu_5s_absolute', template => '%.2f',
unit => '%', min => 0, max => 100, label_extra_instance => 1 }
]
}
},
{ label => 'utilization-1m', nlabel => 'cpu.utilization.1m.percentage', set => {
key_values => [ { name => 'cpu_1m' }, { name => 'display' } ],
output_template => '%.2f %% (1m)',
perfdatas => [
{ value => 'cpu_1m_absolute', template => '%.2f',
unit => '%', min => 0, max => 100, label_extra_instance => 1 }
]
}
},
{ label => 'utilization-5m', nlabel => 'cpu.utilization.5m.percentage', set => {
key_values => [ { name => 'cpu_5m' }, { name => 'display' } ],
output_template => '%.2f %% (5m)',
perfdatas => [
{ value => 'cpu_5m_absolute', template => '%.2f',
unit => '%', min => 0, max => 100, label_extra_instance => 1 }
]
}
}
];
}
sub prefix_cpu_output {
my ($self, %options) = @_;
return "CPU '" . $options{instance_value}->{display} . "' usage: ";
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
});
return $self;
}
sub manage_selection {
my ($self, %options) = @_;
my $oid_snAgentCpuUtilPercent = '.1.3.6.1.4.1.1991.1.1.2.11.1.1.5';
my $snmp_result = $options{snmp}->get_table(oid => $oid_snAgentCpuUtilPercent, nothing_quit => 1);
$self->{cpu} = {};
foreach my $oid (keys %$snmp_result) {
next if ($oid !~ /^$oid_snAgentCpuUtilPercent\.(.*?)\.(.*?)\.60/);
my $instance = "slot$1:cpu$2";
$self->{cpu}->{$instance} = {
display => $instance,
cpu_5s => $snmp_result->{ $oid_snAgentCpuUtilPercent . '.' . $1 . '.' . $2 . '.5' },
cpu_1m => $snmp_result->{ $oid_snAgentCpuUtilPercent . '.' . $1 . '.' . $2 . '.60' },
cpu_5m => $snmp_result->{ $oid_snAgentCpuUtilPercent . '.' . $1 . '.' . $2 . '.300' }
};
}
}
1;
__END__
=head1 MODE
Check CPU usage.
=over 8
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'utilization-5s', 'utilization-1m', 'utilization-5m'.
=back
=cut

View File

@ -0,0 +1,119 @@
#
# Copyright 2020 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 centreon::common::foundry::snmp::mode::hardware;
use base qw(centreon::plugins::templates::hardware);
use strict;
use warnings;
sub set_system {
my ($self, %options) = @_;
$self->{regexp_threshold_overload_check_section_option} = '^(?:board|fan|psu|temperature)$';
$self->{regexp_threshold_numeric_check_section_option} = '^(?:temperature)$';
$self->{cb_hook2} = 'snmp_execute';
$self->{thresholds} = {
default => [
['other', 'UNKNOWN'],
['normal', 'OK'],
['failure', 'CRITICAL']
],
board => [
['moduleEmpty', 'OK'],
['moduleGoingDown', 'WARNING'],
['moduleRejected', 'CRITICAL'],
['moduleBad', 'CRITICAL'],
['moduleConfigured', 'OK'],
['moduleComingUp', 'OK'],
['moduleRunning', 'OK']
]
};
$self->{components_path} = 'centreon::common::foundry::snmp::mode::components';
$self->{components_module} = ['board', 'fan', 'psu', 'temperature'];
}
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;
$options{options}->add_options(arguments => {
});
return $self;
}
1;
__END__
=head1 MODE
Check hardware.
=over 8
=item B<--component>
Which component to check (Default: '.*').
Can be: 'board', 'fan', 'temperature', 'psu'.
=item B<--filter>
Exclude some parts (comma seperated list) (Example: --filter=fan --filter=psu)
Can also exclude specific instance: --filter=fan,1.1
=item B<--no-component>
Return an error if no compenents are checked.
If total (with skipped) is 0. (Default: 'critical' returns).
=item B<--threshold-overload>
Set to overload default threshold values (syntax: section,[instance,]status,regexp)
It used before default thresholds (order stays).
Example: --threshold-overload='psu,CRITICAL,fail'
=item B<--warning>
Set warning threshold for 'temperature' (syntax: type,regexp,threshold)
Example: --warning='temperature,.*,30'
=item B<--critical>
Set critical threshold for 'temperature' (syntax: type,regexp,threshold)
Example: --critical='temperature,.*,50'
=back
=cut

View File

@ -0,0 +1,133 @@
#
# Copyright 2020 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 centreon::common::foundry::snmp::mode::memory;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
sub custom_usage_output {
my ($self, %options) = @_;
return sprintf(
'Ram total: %s %s used: %s %s (%.2f%%) free: %s %s (%.2f%%)',
$self->{perfdata}->change_bytes(value => $self->{result_values}->{total_absolute}),
$self->{perfdata}->change_bytes(value => $self->{result_values}->{used_absolute}),
$self->{result_values}->{prct_used_absolute},
$self->{perfdata}->change_bytes(value => $self->{result_values}->{free_absolute}),
$self->{result_values}->{prct_free_absolute}
);
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'memory', type => 0 }
];
$self->{maps_counters}->{memory} = [
{ label => 'usage', nlabel => 'memory.usage.bytes', set => {
key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ],
closure_custom_output => $self->can('custom_usage_output'),
perfdatas => [
{ value => 'used_absolute', template => '%d', min => 0, max => 'total_absolute',
unit => 'B', cast_int => 1 }
]
}
},
{ label => 'usage-free', display_ok => 0, nlabel => 'memory.free.bytes', set => {
key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ],
closure_custom_output => $self->can('custom_usage_output'),
perfdatas => [
{ value => 'free_absolute', template => '%d', min => 0, max => 'total_absolute',
unit => 'B', cast_int => 1 }
]
}
},
{ label => 'usage-prct', display_ok => 0, nlabel => 'memory.usage.percentage', set => {
key_values => [ { name => 'prct_used' } ],
output_template => 'Ram used: %.2f %%',
perfdatas => [
{ value => 'prct_used_absolute', template => '%.2f', min => 0, max => 100, unit => '%' }
]
}
}
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
});
return $self;
}
my $mapping = {
total => { oid => '.1.3.6.1.4.1.20301.2.5.1.2.12.9.1.1.3' }, # totalMemoryStatsRev
free => { oid => '.1.3.6.1.4.1.20301.2.5.1.2.12.9.1.1.4' } # memoryFreeStatsRev
};
my $oid_memoryStatsEntry = '.1.3.6.1.4.1.20301.2.5.1.2.12.9.1.1';
sub manage_selection {
my ($self, %options) = @_;
my $oid_snAgGblDynMemUtil = '.1.3.6.1.4.1.1991.1.1.2.1.53.0'; # %
my $oid_snAgGblDynMemTotal = '.1.3.6.1.4.1.1991.1.1.2.1.54.0'; # Bytes
my $snmp_result = $options{snmp}->get_leef(
oids => [$oid_snAgGblDynMemUtil, $oid_snAgGblDynMemTotal],
nothing_quit => 1
);
my $used = $snmp_result->{$oid_snAgGblDynMemUtil} * $snmp_result->{$oid_snAgGblDynMemTotal} / 100;
$self->{memory} = {
prct_used => $snmp_result->{$oid_snAgGblDynMemUtil},
prct_free => 100 - $snmp_result->{$oid_snAgGblDynMemUtil},
total => $snmp_result->{$oid_snAgGblDynMemTotal},
used => $used,
free => $snmp_result->{$oid_snAgGblDynMemTotal} - $used
};
}
1;
__END__
=head1 MODE
Check memory usage.
=over 8
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'usage' (B), 'usage-free' (B), 'usage-prct' (%).
=back
=cut

View File

@ -0,0 +1,67 @@
#
# Copyright 2020 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 centreon::common::ibm::nos::snmp::mode::components::faultled;
use strict;
use warnings;
my %map_faultled_states = ( 1 => 'on', 2 => 'off' );
sub load {}
sub check_faultled {
my ($self, %options) = @_;
$self->{components}->{faultled}->{total}++;
$self->{output}->output_add(long_msg =>
sprintf(
"Fault LED state is %s",
$options{value}
)
);
my $exit = $self->get_severity(section => 'faultled', value => $options{value});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(
severity => $exit,
short_msg => sprintf(
"Fault LED state is %s",
$options{value}
)
);
}
}
sub check {
my ($self) = @_;
$self->{output}->output_add(long_msg => 'checking fault LED');
$self->{components}->{faultled} = { name => 'faultled', total => 0, skip => 0 };
return if ($self->check_filter(section => 'faultled'));
my $oid_mmspFaultLED = '.1.3.6.1.4.1.26543.2.5.1.3.10.12.0';
my $results = $self->{snmp}->get_leef(oids => [$oid_mmspFaultLED]);
return if (!defined($results->{$oid_mmspFaultLED}));
check_faultled($self, value => $map_faultled_states{$results->{$oid_mmspFaultLED}});
}
1;

View File

@ -0,0 +1,102 @@
#
# Copyright 2020 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 centreon::common::ibm::nos::snmp::mode::components::temperature;
use strict;
use warnings;
sub load {}
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'));
my $oid_hwTemperatureWarn = '.1.3.6.1.4.1.26543.2.5.1.3.1.22.0';
my $oid_hwTemperatureShut = '.1.3.6.1.4.1.26543.2.5.1.3.1.23.0';
my $results = $self->{snmp}->get_leef(oids => [$oid_hwTemperatureWarn, $oid_hwTemperatureShut]);
return if (!defined($results->{$oid_hwTemperatureWarn}));
my $instance = 'system';
# .1.3.6.1.4.1.20301.2.5.1.3.1.41.1.1.20.1 = STRING: "44 C (Warn at 66 C / Recover at 61 C)"
# .1.3.6.1.4.1.20301.2.5.1.3.1.41.1.1.21.1 = STRING: "44 C (Shutdown at 72 C / Recover at 67 C)"
$results->{$oid_hwTemperatureWarn} =~ /^([.0-9]+)\s*C\s*\(Warn(?:ing)?\s*at\s*([.0-9]+)\s*C/i;
my ($temperature, $warning_mib) = ($1, $2);
$results->{$oid_hwTemperatureShut} =~ /^([.0-9]+)\s*C\s*\(Shutdown\s*at\s*([.0-9]+)\s*C/i;
$temperature = $1 if ($1 > $temperature);
my $critical_mib = ($warning_mib + $2) / 2;
if ($warning_mib == $critical_mib) { #seen on some chassis !
$warning_mib -= 10;
$critical_mib -= 5;
}
$self->{components}->{temperature}->{total}++;
$self->{output}->output_add(long_msg =>
sprintf(
"temperature '%s' is %.1f C [instance: %s]",
$instance,
$temperature,
$instance
)
);
my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $temperature);
if ($checked == 0) {
$self->{perfdata}->threshold_validate(label => 'warning-temperature-instance-' . $instance, value => $warning_mib);
$self->{perfdata}->threshold_validate(label => 'critical-temperature-instance-' . $instance, value => $critical_mib);
$warn = $self->{perfdata}->get_perfdata_for_output(label => 'warning-temperature-instance-' . $instance);
$crit = $self->{perfdata}->get_perfdata_for_output(label => 'critical-temperature-instance-' . $instance);
$exit = $self->{perfdata}->threshold_check(
value => $temperature,
threshold => [
{ label => 'critical-temperature-instance-' . $instance, exit_litteral => 'critical' },
{ label => 'warning-temperature-instance-' . $instance, exit_litteral => 'warning' }
]
);
}
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(
severity => $exit,
short_msg => sprintf(
"Temperature '%s' is %.1f C",
$instance,
$temperature
)
);
}
$self->{output}->perfdata_add(
unit => 'C',
nlabel => 'hardware.temperature.celsius',
instances => 'system',
value => $temperature,
warning => $warn,
critical => $crit
);
}
1;

View File

@ -0,0 +1,101 @@
#
# Copyright 2020 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 centreon::common::ibm::nos::snmp::mode::cpu;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'cpu', type => 0, cb_prefix_output => 'prefix_message_output', skipped_code => { -10 => 1 } }
];
$self->{maps_counters}->{cpu} = [
{ label => 'average-1m', nlabel => 'cpu.utilization.1m.percentage', set => {
key_values => [ { name => 'average_1m' } ],
output_template => '%.2f %% (1m)',
perfdatas => [
{ value => 'average_1m_absolute', template => '%.2f',
min => 0, max => 100, unit => '%' }
]
}
},
{ label => 'average-5m', nlabel => 'cpu.utilization.5m.percentage', set => {
key_values => [ { name => 'average_5m' } ],
output_template => '%.2f %% (5m)',
perfdatas => [
{ value => 'average_5m_absolute', template => '%.2f',
min => 0, max => 100, unit => '%' }
]
}
}
];
}
sub prefix_message_output {
my ($self, %options) = @_;
return "CPU average usage: ";
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
return $self;
}
sub manage_selection {
my ($self, %options) = @_;
my $oid_mpCpuStatsUtil1Minute = '.1.3.6.1.4.1.26543.2.5.1.2.2.3.0';
my $oid_mpCpuStatsUtil5Minutes = '.1.3.6.1.4.1.26543.2.5.1.2.2.6.0';
my $result = $options{snmp}->get_leef(oids => [$oid_mpCpuStatsUtil1Minute, $oid_mpCpuStatsUtil5Minutes], nothing_quit => 1);
$self->{cpu} = {
average_1m => $result->{$oid_mpCpuStatsUtil1Minute},
average_5m => $result->{$oid_mpCpuStatsUtil5Minutes}
}
}
1;
__END__
=head1 MODE
Check CPU usage (over the last minute).
=over 8
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'average-1m' (%), 'average-5m' (%).
=back
=cut

View File

@ -0,0 +1,104 @@
#
# Copyright 2020 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 centreon::common::ibm::nos::snmp::mode::disk;
use base qw(snmp_standard::mode::storage);
use strict;
use warnings;
sub default_storage_type {
my ($self, %options) = @_;
return '^(?!(hrStorageRam)$)';
}
sub prefix_storage_output {
my ($self, %options) = @_;
return "Disk '" . $options{instance_value}->{display} . "' ";
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
return $self;
}
1;
__END__
=head1 MODE
Check disks.
=over 8
=item B<--warning-usage>
Threshold warning.
=item B<--critical-usage>
Threshold critical.
=item B<--units>
Units of thresholds (Default: '%') ('%', 'B').
=item B<--free>
Thresholds are on free space left.
=item B<--storage>
Set the storage (number expected) ex: 1, 2,... (empty means 'check all storage').
=item B<--name>
Allows to use storage name with option --storage instead of storage oid index.
=item B<--regexp>
Allows to use regexp to filter storage (with option --name).
=item B<--regexp-isensitive>
Allows to use regexp non case-sensitive (with --regexp).
=item B<--reload-cache-time>
Time in minutes before reloading cache file (default: 180).
=item B<--show-cache>
Display cache storage datas.
=item B<--filter-storage-type>
Filter storage types with a regexp (Default: '^(?!(hrStorageRam)$)').
=back
=cut

View File

@ -0,0 +1,101 @@
#
# Copyright 2020 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 centreon::common::ibm::nos::snmp::mode::environment;
use base qw(centreon::plugins::templates::hardware);
use strict;
use warnings;
sub set_system {
my ($self, %options) = @_;
$self->{regexp_threshold_overload_check_section_option} = '^(faultled)$';
$self->{regexp_threshold_numeric_check_section_option} = '^(?:temperature)$';
$self->{cb_hook2} = 'snmp_execute';
$self->{thresholds} = {
'faultled' => [
['on', 'CRITICAL'],
['off', 'OK']
]
};
$self->{components_path} = 'centreon::common::ibm::nos::snmp::mode::components';
$self->{components_module} = ['faultled', 'temperature'];
}
sub snmp_execute {
my ($self, %options) = @_;
$self->{snmp} = $options{snmp};
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
});
return $self;
}
1;
__END__
=head1 MODE
Check hardware.
=over 8
=item B<--component>
Which component to check (Default: '.*').
Can be: 'faultled', 'temperature'.
=item B<--no-component>
Return an error if no compenents are checked.
If total (with skipped) is 0. (Default: 'critical' returns).
=item B<--threshold-overload>
Set to overload default threshold values (syntax: section,status,regexp)
It used before default thresholds (order stays).
Example: --threshold-overload='faulted,WARNING,on'
=item B<--warning>
Set warning threshold for temperatures (syntax: type,regexp,threshold)
Example: --warning='temperature,.*,30'
=item B<--critical>
Set critical threshold for temperatures (syntax: type,regexp,threshold)
Example: --critical='temperature,.*,40'
=back
=cut

View File

@ -0,0 +1,123 @@
#
# Copyright 2020 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 centreon::common::ibm::nos::snmp::mode::memory;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
sub custom_usage_output {
my ($self, %options) = @_;
return sprintf(
'Ram Total: %s %s Used: %s %s (%.2f%%) Free: %s %s (%.2f%%)',
$self->{perfdata}->change_bytes(value => $self->{result_values}->{total_absolute}),
$self->{perfdata}->change_bytes(value => $self->{result_values}->{used_absolute}),
$self->{result_values}->{prct_used_absolute},
$self->{perfdata}->change_bytes(value => $self->{result_values}->{free_absolute}),
$self->{result_values}->{prct_free_absolute}
);
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'memory', type => 0, skipped_code => { -10 => 1 } }
];
$self->{maps_counters}->{memory} = [
{ label => 'usage', nlabel => 'memory.usage.bytes', set => {
key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ],
closure_custom_output => $self->can('custom_usage_output'),
perfdatas => [
{ value => 'used_absolute', template => '%d', min => 0, max => 'total_absolute',
unit => 'B', cast_int => 1 }
]
}
},
{ label => 'usage-free', display_ok => 0, nlabel => 'memory.free.bytes', set => {
key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ],
closure_custom_output => $self->can('custom_usage_output'),
perfdatas => [
{ value => 'free_absolute', template => '%d', min => 0, max => 'total_absolute',
unit => 'B', cast_int => 1 }
]
}
},
{ label => 'usage-prct', display_ok => 0, nlabel => 'memory.usage.percentage', set => {
key_values => [ { name => 'prct_used' } ],
output_template => 'Ram Used : %.2f %%',
perfdatas => [
{ value => 'prct_used_absolute', template => '%.2f', min => 0, max => 100,
unit => '%' }
]
}
}
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
return $self;
}
sub manage_selection {
my ($self, %options) = @_;
my $oid_totalMemoryStats = '.1.3.6.1.4.1.26543.2.5.1.2.12.1.0'; # in bytes
my $oid_memoryFreeStats = '.1.3.6.1.4.1.26543.2.5.1.2.12.2.0'; # in bytes
my $result = $options{snmp}->get_leef(oids => [$oid_totalMemoryStats, $oid_memoryFreeStats], nothing_quit => 1);
my $free = $result->{$oid_memoryFreeStats};
my $total = $result->{$oid_totalMemoryStats};
my $prct_used = ($total - $free) * 100 / $total;
$self->{memory} = {
total => $total,
used => $total - $free,
free => $free,
prct_used => $prct_used,
prct_free => 100 - $prct_used
}
}
1;
__END__
=head1 MODE
Check memory usage.
=over 8
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'usage' (B), 'usage-free' (B), 'usage-prct' (%).
=back
=cut

View File

@ -1,74 +0,0 @@
#
# Copyright 2020 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 centreon::common::radlan::mode::components::fan;
use strict;
use warnings;
my %map_states = (
1 => 'normal',
2 => 'warning',
3 => 'critical',
4 => 'shutdown',
5 => 'notPresent',
6 => 'notFunctioning',
);
my $mapping = {
rlEnvMonFanStatusDescr => { oid => '.1.3.6.1.4.1.89.83.1.1.1.2' },
rlEnvMonFanState => { oid => '.1.3.6.1.4.1.89.83.1.1.1.3', map => \%map_states },
};
my $oid_rlEnvMonFanStatusEntry = '.1.3.6.1.4.1.89.83.1.1.1';
sub load {
my ($self) = @_;
push @{$self->{request}}, { oid => $oid_rlEnvMonFanStatusEntry };
}
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_rlEnvMonFanStatusEntry}})) {
next if ($oid !~ /^$mapping->{rlEnvMonFanState}->{oid}\.(.*)$/);
my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_rlEnvMonFanStatusEntry}, instance => $instance);
next if ($self->check_filter(section => 'fan', instance => $instance, name => $result->{rlEnvMonFanStatusDescr}));
next if ($result->{rlEnvMonFanState} eq 'notPresent' &&
$self->absent_problem(section => 'fan', instance => $instance, name => $result->{rlEnvMonFanStatusDescr}));
$self->{components}->{fan}->{total}++;
$self->{output}->output_add(long_msg => sprintf("fan '%s' state is %s [instance: %s]",
$result->{rlEnvMonFanStatusDescr}, $result->{rlEnvMonFanState}, $instance));
my $exit = $self->get_severity(section => 'fan', value => $result->{rlEnvMonFanState});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Fan '%s' state is %s.", $result->{rlEnvMonFanStatusDescr}, $result->{rlEnvMonFanState}));
}
}
}
1;

View File

@ -1,74 +0,0 @@
#
# Copyright 2020 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 centreon::common::radlan::mode::components::psu;
use strict;
use warnings;
my %map_states = (
1 => 'normal',
2 => 'warning',
3 => 'critical',
4 => 'shutdown',
5 => 'notPresent',
6 => 'notFunctioning',
);
my $mapping = {
rlEnvMonSupplyStatusDescr => { oid => '.1.3.6.1.4.1.89.83.1.2.1' },
rlEnvMonSupplyState => { oid => '.1.3.6.1.4.1.89.83.1.2.1.3', map => \%map_states },
};
my $oid_rlEnvMonSupplyStatusEntry = '.1.3.6.1.4.1.89.83.1.2.1.2';
sub load {
my ($self) = @_;
push @{$self->{request}}, { oid => $oid_rlEnvMonSupplyStatusEntry };
}
sub check {
my ($self) = @_;
$self->{output}->output_add(long_msg => 'checking power supplies');
$self->{components}->{psu} = { name => 'psus', total => 0, skip => 0 };
return if ($self->check_filter(section => 'psu'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_rlEnvMonSupplyStatusEntry}})) {
next if ($oid !~ /^$mapping->{rlEnvMonSupplyState}->{oid}\.(.*)$/);
my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_rlEnvMonSupplyStatusEntry}, instance => $instance);
next if ($self->check_filter(section => 'psu', instance => $instance, name => $result->{rlEnvMonSupplyStatusDescr}));
next if ($result->{rlEnvMonSupplyState} eq 'notPresent' &&
$self->absent_problem(section => 'psu', instance => $instance, name => $result->{rlEnvMonSupplyStatusDescr}));
$self->{components}->{psu}->{total}++;
$self->{output}->output_add(long_msg => sprintf("power supply '%s' state is %s [instance: %s]",
$result->{rlEnvMonSupplyStatusDescr}, $result->{rlEnvMonSupplyState}, $instance));
my $exit = $self->get_severity(section => 'psu', value => $result->{rlEnvMonSupplyState});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Power supply '%s' state is %s.", $result->{rlEnvMonSupplyStatusDescr}, $result->{rlEnvMonSupplyState}));
}
}
}
1;

View File

@ -1,148 +0,0 @@
#
# Copyright 2020 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 centreon::common::radlan::mode::cpu;
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;
$options{options}->add_options(arguments =>
{
"warning:s" => { name => 'warning', default => '' },
"critical:s" => { name => 'critical', default => '' },
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
($self->{warn1s}, $self->{warn1m}, $self->{warn5m}) = split /,/, $self->{option_results}->{warning};
($self->{crit1s}, $self->{crit1m}, $self->{crit5m}) = split /,/, $self->{option_results}->{critical};
if (($self->{perfdata}->threshold_validate(label => 'warn1s', value => $self->{warn1s})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong warning (1sec) threshold '" . $self->{warn1s} . "'.");
$self->{output}->option_exit();
}
if (($self->{perfdata}->threshold_validate(label => 'warn1m', value => $self->{warn1m})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong warning (1min) threshold '" . $self->{warn1m} . "'.");
$self->{output}->option_exit();
}
if (($self->{perfdata}->threshold_validate(label => 'warn5m', value => $self->{warn5m})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong warning (5min) threshold '" . $self->{warn5m} . "'.");
$self->{output}->option_exit();
}
if (($self->{perfdata}->threshold_validate(label => 'crit1s', value => $self->{crit1s})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong critical (1sec) threshold '" . $self->{crit1s} . "'.");
$self->{output}->option_exit();
}
if (($self->{perfdata}->threshold_validate(label => 'crit1m', value => $self->{crit1m})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong critical (1min) threshold '" . $self->{crit1m} . "'.");
$self->{output}->option_exit();
}
if (($self->{perfdata}->threshold_validate(label => 'crit5m', value => $self->{crit5})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong critical (5min) threshold '" . $self->{crit5m} . "'.");
$self->{output}->option_exit();
}
}
sub run {
my ($self, %options) = @_;
$self->{snmp} = $options{snmp};
my $oid_rlCpuUtilEnable = '.1.3.6.1.4.1.89.1.6.0';
my $oid_rlCpuUtilDuringLastSecond = '.1.3.6.1.4.1.89.1.7.0';
my $oid_rlCpuUtilDuringLastMinute = '.1.3.6.1.4.1.89.1.8.0';
my $oid_rlCpuUtilDuringLast5Minutes = '.1.3.6.1.4.1.89.1.9.0';
$self->{result} = $self->{snmp}->get_leef(oids => [ $oid_rlCpuUtilEnable, $oid_rlCpuUtilDuringLastSecond, $oid_rlCpuUtilDuringLastMinute, $oid_rlCpuUtilDuringLast5Minutes ],
nothing_quit => 1);
if (defined($self->{result}->{$oid_rlCpuUtilEnable}) && $self->{result}->{$oid_rlCpuUtilEnable} == 1) {
my $cpu1sec = $self->{result}->{$oid_rlCpuUtilDuringLastSecond};
my $cpu1min = $self->{result}->{$oid_rlCpuUtilDuringLastMinute};
my $cpu5min = $self->{result}->{$oid_rlCpuUtilDuringLast5Minutes};
my $exit1 = $self->{perfdata}->threshold_check(value => $cpu1sec,
threshold => [ { label => 'crit1s', exit_litteral => 'critical' }, { label => 'warn1s', exit_litteral => 'warning' } ]);
my $exit2 = $self->{perfdata}->threshold_check(value => $cpu1min,
threshold => [ { label => 'crit1m', exit_litteral => 'critical' }, { label => 'warn1m', exit_litteral => 'warning' } ]);
my $exit3 = $self->{perfdata}->threshold_check(value => $cpu5min,
threshold => [ { label => 'crit5m', exit_litteral => 'critical' }, { label => 'warn5m', exit_litteral => 'warning' } ]);
my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2, $exit3 ]);
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("CPU Usage: %.2f%% (1sec), %.2f%% (1min), %.2f%% (5min)",
$cpu1sec, $cpu1min, $cpu5min));
$self->{output}->perfdata_add(label => "cpu_1s", unit => '%',
value => $cpu1sec,
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn1s'),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit1s'),
min => 0, max => 100);
$self->{output}->perfdata_add(label => "cpu_1m", unit => '%',
value => $cpu1min,
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn1m'),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit1m'),
min => 0, max => 100);
$self->{output}->perfdata_add(label => "cpu_5m", unit => '%',
value => $cpu5min,
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn5m'),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit5m'),
min => 0, max => 100);
} else {
$self->{output}->output_add(severity => 'UNKNOWN',
short_msg => sprintf("CPU measurement is not enabled."));
}
$self->{output}->display();
$self->{output}->exit();
}
1;
__END__
=head1 MODE
Check cpu usage (RADLAN-rndMng).
=over 8
=item B<--warning>
Threshold warning in percent (1s,1min,5min).
=item B<--critical>
Threshold critical in percent (1s,1min,5min).
=back
=cut

View File

@ -0,0 +1,111 @@
#
# Copyright 2020 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 centreon::common::radlan::snmp::mode::components::fan;
use strict;
use warnings;
use centreon::common::radlan::snmp::mode::components::resources qw(
$rl_envmon_state
$oid_rlPhdUnitEnvParamMonitorAutoRecoveryEnable
$oid_rlPhdUnitEnvParamEntry
);
my $mapping_stack = {
new => {
rlPhdUnitEnvParamFan1Status => { oid => '.1.3.6.1.4.1.89.53.15.1.4', map => $rl_envmon_state },
rlPhdUnitEnvParamFan2Status => { oid => '.1.3.6.1.4.1.89.53.15.1.5', map => $rl_envmon_state },
rlPhdUnitEnvParamFan3Status => { oid => '.1.3.6.1.4.1.89.53.15.1.6', map => $rl_envmon_state },
rlPhdUnitEnvParamFan4Status => { oid => '.1.3.6.1.4.1.89.53.15.1.7', map => $rl_envmon_state },
rlPhdUnitEnvParamFan5Status => { oid => '.1.3.6.1.4.1.89.53.15.1.8', map => $rl_envmon_state },
rlPhdUnitEnvParamFan6Status => { oid => '.1.3.6.1.4.1.89.53.15.1.9', map => $rl_envmon_state }
},
old => {
rlPhdUnitEnvParamFan1Status => { oid => '.1.3.6.1.4.1.89.53.15.1.4', map => $rl_envmon_state },
rlPhdUnitEnvParamFan2Status => { oid => '.1.3.6.1.4.1.89.53.15.1.5', map => $rl_envmon_state },
rlPhdUnitEnvParamFan3Status => { oid => '.1.3.6.1.4.1.89.53.15.1.6', map => $rl_envmon_state },
rlPhdUnitEnvParamFan4Status => { oid => '.1.3.6.1.4.1.89.53.15.1.7', map => $rl_envmon_state },
rlPhdUnitEnvParamFan5Status => { oid => '.1.3.6.1.4.1.89.53.15.1.8', map => $rl_envmon_state }
}
};
sub load {
my ($self) = @_;
}
sub check_fan_stack {
my ($self) = @_;
my $num_fans = 5;
$num_fans = 6 if ($self->{radlan_new} == 1);
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_rlPhdUnitEnvParamEntry}})) {
next if ($oid !~ /^$mapping_stack->{new}->{rlPhdUnitEnvParamFan1Status}->{oid}\.(.*)$/);
my $instance = $1;
my $result = $self->{snmp}->map_instance(
mapping => $self->{radlan_new} == 1 ? $mapping_stack->{new} : $mapping_stack->{old},
results => $self->{results}->{$oid_rlPhdUnitEnvParamEntry},
instance => $instance
);
for (my $i = 1; $i <= $num_fans; $i++) {
my $instance2 = 'stack.' . $instance . '.fan.' . $i;
my $name = 'rlPhdUnitEnvParamFan' . $i . 'Status';
next if ($self->check_filter(section => 'fan', instance => $instance2));
next if ($result->{$name} =~ /notPresent/i &&
$self->absent_problem(section => 'fan', instance => $instance2));
$self->{components}->{fan}->{total}++;
$self->{output}->output_add(
long_msg => sprintf(
"fan '%s' status is '%s' [instance: %s]",
$instance2,
$result->{$name},
$instance2
)
);
my $exit = $self->get_severity(label => 'default', section => 'fan', value => $result->{$name});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(
severity => $exit,
short_msg => sprintf(
"Fan '%s' status is '%s'",
$instance2,
$result->{$name}
)
);
}
}
}
}
sub check {
my ($self) = @_;
$self->{output}->output_add(long_msg => "Checking fans");
$self->{components}->{fan} = { name => 'fan', total => 0, skip => 0 };
return if ($self->check_filter(section => 'fan'));
check_fan_stack($self);
}
1;

View File

@ -0,0 +1,140 @@
#
# Copyright 2020 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 centreon::common::radlan::snmp::mode::components::psu;
use strict;
use warnings;
use centreon::common::radlan::snmp::mode::components::resources qw(
$rl_envmon_state
$oid_rlPhdUnitEnvParamEntry
);
my $mapping_stack = {
rlPhdUnitEnvParamMainPSStatus => { oid => '.1.3.6.1.4.1.89.53.15.1.2', map => $rl_envmon_state },
rlPhdUnitEnvParamRedundantPSStatus => { oid => '.1.3.6.1.4.1.89.53.15.1.3', map => $rl_envmon_state }
};
my $mapping = {
rlEnvMonSupplyStatusDescr => { oid => '.1.3.6.1.4.1.89.83.1.2.1.2' },
rlEnvMonSupplyState => { oid => '.1.3.6.1.4.1.89.83.1.2.1.3', map => $rl_envmon_state }
};
my $oid_rlEnvMonSupplyStatusEntry = '.1.3.6.1.4.1.89.83.1.2.1';
sub load {
my ($self) = @_;
push @{$self->{request}}, {
oid => $oid_rlEnvMonSupplyStatusEntry,
$mapping->{rlEnvMonSupplyStatusDescr}->{oid},
$mapping->{rlEnvMonSupplyState}->{oid}
};
}
sub check_psu_stack {
my ($self) = @_;
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_rlPhdUnitEnvParamEntry}})) {
next if ($oid !~ /^$mapping_stack->{rlPhdUnitEnvParamMainPSStatus}->{oid}\.(.*)$/);
my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping_stack, results => $self->{results}->{$oid_rlPhdUnitEnvParamEntry}, instance => $instance);
foreach (['rlPhdUnitEnvParamMainPSStatus', 'main.psu'], ['rlPhdUnitEnvParamRedundantPSStatus', 'redundant.psu']) {
my $instance2 = 'stack.' . $instance . '.' . $_->[1];
next if ($self->check_filter(section => 'psu', instance => $instance2));
next if ($result->{$_->[0]} =~ /notPresent/i &&
$self->absent_problem(section => 'psu', instance => $instance2));
$self->{components}->{psu}->{total}++;
$self->{output}->output_add(
long_msg => sprintf(
"power supply '%s' status is '%s' [instance: %s]",
$instance2,
$result->{$_->[0]},
$instance2
)
);
my $exit = $self->get_severity(label => 'default', section => 'psu', value => $result->{$_->[0]});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(
severity => $exit,
short_msg => sprintf(
"Power supply '%s' status is '%s'",
$instance2,
$result->{$_->[0]}
)
);
}
}
}
}
sub check_psu {
my ($self) = @_;
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_rlEnvMonSupplyStatusEntry}})) {
next if ($oid !~ /^$mapping->{rlEnvMonSupplyState}->{oid}\.(.*)$/);
my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_rlEnvMonSupplyStatusEntry}, instance => $instance);
next if ($self->check_filter(section => 'psu', instance => $instance));
if ($result->{rlEnvMonSupplyState} =~ /notPresent/i) {
$self->absent_problem(section => 'psu', instance => $instance);
next;
}
$self->{components}->{psu}->{total}++;
$self->{output}->output_add(
long_msg => sprintf(
"power supply '%s' status is '%s' [instance: %s]",
$result->{rlEnvMonSupplyStatusDescr},
$result->{rlEnvMonSupplyState},
$instance
)
);
my $exit = $self->get_severity(label => 'default', section => 'psu', value => $result->{rlEnvMonSupplyState});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(
severity => $exit,
short_msg => sprintf(
"Power supply '%s' status is '%s'",
$result->{rlEnvMonSupplyStatusDescr},
$result->{rlEnvMonSupplyState}
)
);
}
}
}
sub check {
my ($self) = @_;
$self->{output}->output_add(long_msg => "Checking power supplies");
$self->{components}->{psu} = { name => 'psu', total => 0, skip => 0 };
return if ($self->check_filter(section => 'psu'));
check_psu($self);
check_psu_stack($self);
}
1;

View File

@ -0,0 +1,53 @@
#
# Copyright 2020 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 centreon::common::radlan::snmp::mode::components::resources;
use strict;
use warnings;
use Exporter;
our $rl_envmon_state;
our $oid_rlPhdUnitEnvParamMonitorAutoRecoveryEnable;
our $oid_rlPhdUnitEnvParamEntry;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw(
$rl_envmon_state
$oid_rlPhdUnitEnvParamMonitorAutoRecoveryEnable
$oid_rlPhdUnitEnvParamEntry
);
$rl_envmon_state = {
1 => 'normal',
2 => 'warning',
3 => 'critical',
4 => 'shutdown',
5 => 'notPresent',
6 => 'notFunctioning',
7 => 'notAvailable',
8 => 'backingUp',
9 => 'readingFailed'
};
$oid_rlPhdUnitEnvParamMonitorAutoRecoveryEnable = '.1.3.6.1.4.1.89.53.15.1.15';
$oid_rlPhdUnitEnvParamEntry = '.1.3.6.1.4.1.89.53.15.1';
1;

View File

@ -0,0 +1,124 @@
#
# Copyright 2020 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 centreon::common::radlan::snmp::mode::components::temperature;
use strict;
use warnings;
use centreon::common::radlan::snmp::mode::components::resources qw($oid_rlPhdUnitEnvParamEntry);
my $map_entity_sensor = { 1 => 'ok', 2 => 'unavailable', 3 => 'nonoperational' };
my $mapping = {
new => {
rlPhdUnitEnvParamTempSensorValue => { oid => '.1.3.6.1.4.1.89.53.15.1.10' },
rlPhdUnitEnvParamTempSensorStatus => { oid => '.1.3.6.1.4.1.89.53.15.1.11', map => $map_entity_sensor },
rlPhdUnitEnvParamTempSensorWarningThresholdValue => { oid => '.1.3.6.1.4.1.89.53.15.1.12' },
rlPhdUnitEnvParamTempSensorCriticalThresholdValue => { oid => '.1.3.6.1.4.1.89.53.15.1.13' }
},
old => {
rlPhdUnitEnvParamTempSensorValue => { oid => '.1.3.6.1.4.1.89.53.15.1.9' },
rlPhdUnitEnvParamTempSensorStatus => { oid => '.1.3.6.1.4.1.89.53.15.1.10', map => $map_entity_sensor },
}
};
sub load {}
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_rlPhdUnitEnvParamEntry}})) {
next if ($oid !~ /^$mapping->{new}->{rlPhdUnitEnvParamTempSensorValue}->{oid}\.(.*)$/);
my $instance = $1;
my $result = $self->{snmp}->map_instance(
mapping => $self->{radlan_new} == 1 ? $mapping->{new} : $mapping->{old},
results => $self->{results}->{$oid_rlPhdUnitEnvParamEntry},
instance => $instance
);
next if ($self->check_filter(section => 'temperature', instance => $instance));
$self->{components}->{temperature}->{total}++;
$self->{output}->output_add(
long_msg => sprintf(
"temperature '%s' status is '%s' [instance = %s, value: %s degree centigrade]",
$instance,
$result->{rlPhdUnitEnvParamTempSensorStatus},
$instance,
$result->{rlPhdUnitEnvParamTempSensorValue}
)
);
my $exit = $self->get_severity(section => 'temperature', value => $result->{rlPhdUnitEnvParamTempSensorStatus});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(
severity => $exit,
short_msg => sprintf(
"Temperature '%s' status is '%s'",
$instance,
$result->{rlPhdUnitEnvParamTempSensorStatus}
)
);
}
my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result->{rlPhdUnitEnvParamTempSensorValue});
if ($checked == 0 && defined($result->{rlPhdUnitEnvParamTempSensorWarningThresholdValue})) {
my $warn_th = ':' . $result->{rlPhdUnitEnvParamTempSensorWarningThresholdValue};
my $crit_th = ':' . $result->{rlPhdUnitEnvParamTempSensorCriticalThresholdValue};
$self->{perfdata}->threshold_validate(label => 'warning-temperature-instance-' . $instance, value => $warn_th);
$self->{perfdata}->threshold_validate(label => 'critical-temperature-instance-' . $instance, value => $crit_th);
$exit2 = $self->{perfdata}->threshold_check(
value => $result->{rlPhdUnitEnvParamTempSensorValue},
threshold => [
{ label => 'critical-temperature-instance-' . $instance, exit_litteral => 'critical' },
{ label => 'warning-temperature-instance-' . $instance, exit_litteral => 'warning' }
]
);
$warn = $self->{perfdata}->get_perfdata_for_output(label => 'warning-temperature-instance-' . $instance);
$crit = $self->{perfdata}->get_perfdata_for_output(label => 'critical-temperature-instance-' . $instance);
}
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(
severity => $exit2,
short_msg => sprintf(
"Temperature '%s' is %s degree centigrade",
$instance,
$result->{rlPhdUnitEnvParamTempSensorValue}
)
);
}
$self->{output}->perfdata_add(
label => 'temp', unit => 'C',
nlabel => 'hardware.temperature.celsius',
instances => $instance,
value => $result->{rlPhdUnitEnvParamTempSensorValue},
warning => $warn,
critical => $crit
);
}
}
1;

View File

@ -0,0 +1,120 @@
#
# Copyright 2020 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 centreon::common::radlan::snmp::mode::cpu;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'cpu', type => 0, cb_prefix_output => 'prefix_message_output', skipped_code => { -10 => 1 } }
];
$self->{maps_counters}->{cpu} = [
{ label => 'average-1s', nlabel => 'cpu.utilization.1s.percentage', set => {
key_values => [ { name => 'average_1s' } ],
output_template => '%.2f %% (1s)',
perfdatas => [
{ value => 'average_1s_absolute', template => '%.2f',
min => 0, max => 100, unit => '%' }
]
}
},
{ label => 'average-1m', nlabel => 'cpu.utilization.1m.percentage', set => {
key_values => [ { name => 'average_1m' } ],
output_template => '%.2f %% (1m)',
perfdatas => [
{ value => 'average_1m_absolute', template => '%.2f',
min => 0, max => 100, unit => '%' }
]
}
},
{ label => 'average-5m', nlabel => 'cpu.utilization.5m.percentage', set => {
key_values => [ { name => 'average_5m' } ],
output_template => '%.2f %% (5m)',
perfdatas => [
{ value => 'average_5m_absolute', template => '%.2f',
min => 0, max => 100, unit => '%' }
]
}
}
];
}
sub prefix_message_output {
my ($self, %options) = @_;
return "CPU average usage: ";
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
});
return $self;
}
sub manage_selection {
my ($self, %options) = @_;
my $oid_rlCpuUtilDuringLastSecond = '.1.3.6.1.4.1.89.1.7.0';
my $oid_rlCpuUtilDuringLastMinute = '.1.3.6.1.4.1.89.1.8.0';
my $oid_rlCpuUtilDuringLast5Minutes = '.1.3.6.1.4.1.89.1.9.0';
my $result = $options{snmp}->get_leef(
oids => [$oid_rlCpuUtilDuringLastSecond, $oid_rlCpuUtilDuringLastMinute, $oid_rlCpuUtilDuringLast5Minutes],
nothing_quit => 1
);
$self->{cpu} = {
average_1s => $result->{$oid_rlCpuUtilDuringLastSecond},
average_1m => $result->{$oid_rlCpuUtilDuringLastMinute},
average_5m => $result->{$oid_rlCpuUtilDuringLast5Minutes}
}
}
1;
__END__
=head1 MODE
Check cpu usage.
=over 8
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'average-1s' (%), 'average-1m' (%), 'average-5m' (%).
=back
=cut

View File

@ -0,0 +1,140 @@
#
# Copyright 2020 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 centreon::common::radlan::snmp::mode::environment;
use base qw(centreon::plugins::templates::hardware);
use strict;
use warnings;
use centreon::common::radlan::snmp::mode::components::resources qw(
$oid_rlPhdUnitEnvParamEntry
$oid_rlPhdUnitEnvParamMonitorAutoRecoveryEnable
);
sub set_system {
my ($self, %options) = @_;
$self->{regexp_threshold_overload_check_section_option} = '^(?:fan|psu|temperature)$';
$self->{regexp_threshold_numeric_check_section_option} = '^temperature$';
$self->{cb_hook2} = 'snmp_execute';
$self->{thresholds} = {
default => [
['normal', 'OK'],
['notPresent', 'OK'],
['warning', 'WARNING'],
['critical', 'CRITICAL'],
['shutdown', 'CRITICAL'],
['notFunctioning', 'CRITICAL'],
],
temperature => [
['ok', 'OK'],
['unavailable', 'OK'],
['nonoperational', 'CRITICAL'],
]
};
$self->{components_path} = 'centreon::common::radlan::snmp::mode::components';
$self->{components_module} = ['psu', 'fan', 'temperature'];
}
sub snmp_execute {
my ($self, %options) = @_;
$self->{snmp} = $options{snmp};
push @{$self->{request}}, {
oid => $oid_rlPhdUnitEnvParamEntry,
start => '.1.3.6.1.4.1.89.53.15.1.2', # rlPhdUnitEnvParamMainPSStatus
end => $oid_rlPhdUnitEnvParamMonitorAutoRecoveryEnable
};
$self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request});
$self->{radlan_new} = 0;
foreach (keys %{$self->{results}->{$oid_rlPhdUnitEnvParamEntry}}) {
if (/^$oid_rlPhdUnitEnvParamMonitorAutoRecoveryEnable\./) {
$self->{radlan_new} = 1;
last;
}
}
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
});
return $self;
}
1;
__END__
=head1 MODE
Check environment.
=over 8
=item B<--component>
Which component to check (Default: '.*').
Can be: 'fan', 'psu', 'temperature'.
=item B<--filter>
Exclude some parts (comma seperated list) (Example: --filter=psu)
Can also exclude specific instance: --filter=psu,0
=item B<--absent-problem>
Return an error if an entity is not 'present' (default is skipping) (comma seperated list)
Can be specific or global: --absent-problem=fan#2#
=item B<--no-component>
Return an error if no compenents are checked.
If total (with skipped) is 0. (Default: 'critical' returns).
=item B<--threshold-overload>
Set to overload default threshold values (syntax: section,[instance,]status,regexp)
It used before default thresholds (order stays).
Example: --threshold-overload='fan,CRITICAL,^(?!(normal)$)'
=item B<--warning>
Set warning threshold (syntax: type,regexp,threshold)
Example: --warning='temperature,.*,30'
=item B<--critical>
Set critical threshold (syntax: type,regexp,threshold)
Example: --critical='temperature,.*,40'
=back
=cut

View File

@ -138,7 +138,7 @@ sub execute {
$self->{output}->option_exit();
}
if ($exit_code != 0) {
if ($exit_code != 0 && (!defined($options{no_quit}) || $options{no_quit} != 1)) {
$self->{output}->add_option_msg(short_msg => sprintf('command execution error [exit code: %s]', $exit_code));
$self->{output}->option_exit();
}

View File

@ -65,6 +65,7 @@ sub execute {
my ($self, %options) = @_;
push @{$self->{ssh_option}}, '-T' if (defined($options{ssh_pipe}) && $options{ssh_pipe} == 1);
$options{command} .= $options{cmd_exit} if (defined($options{cmd_exit}) && $options{cmd_exit} ne '');
my ($content, $exit_code) = centreon::plugins::misc::execute(
output => $self->{output},
@ -80,7 +81,8 @@ sub execute {
ssh_path => $self->{ssh_path},
ssh_option => $self->{ssh_option},
timeout => $options{timeout}
}
},
no_quit => $options{no_quit}
);
if (defined($options{ssh_pipe}) && $options{ssh_pipe} == 1) {

View File

@ -33,7 +33,7 @@ sub new {
$options{options}->add_options(arguments => {
'sshcli-command:s' => { name => 'sshcli_command', default => 'ssh' },
'sshcli-path:s' => { name => 'sshcli_path' },
'sslcli-option:s@' => { name => 'sshcli_option' }
'sshcli-option:s@' => { name => 'sshcli_option' }
});
$options{options}->add_help(package => __PACKAGE__, sections => 'BACKEND SSHCLI OPTIONS', once => 1);
}
@ -57,7 +57,7 @@ sub check_options {
$self->{output}->option_exit();
}
push @{$self->{ssh_option}}, '-o="BatchMode yes"';
push @{$self->{ssh_option}}, '-o=BatchMode yes';
push @{$self->{ssh_option}}, '-l=' . $self->{ssh_username} if (defined($self->{ssh_username}) && $self->{ssh_username} ne '');
push @{$self->{ssh_option}}, '-p=' . $self->{ssh_port} if (defined($self->{ssh_port}) && $self->{ssh_port} ne '');
push @{$self->{ssh_option}}, '-i=' . $self->{ssh_priv_key} if (defined($self->{ssh_priv_key}) && $self->{ssh_priv_key} ne '');
@ -67,6 +67,7 @@ sub execute {
my ($self, %options) = @_;
push @{$self->{ssh_option}}, '-T' if (defined($options{ssh_pipe}) && $options{ssh_pipe} == 1);
$options{command} .= $options{cmd_exit} if (defined($options{cmd_exit}) && $options{cmd_exit} ne '');
my ($content, $exit_code) = centreon::plugins::misc::execute(
output => $self->{output},
@ -82,7 +83,8 @@ sub execute {
ssh_path => $self->{ssh_path},
ssh_option => $self->{ssh_option},
timeout => $options{timeout}
}
},
no_quit => $options{no_quit}
);
if (defined($options{ssh_pipe}) && $options{ssh_pipe} == 1) {

View File

@ -82,6 +82,12 @@ sub add_header {
$self->{add_headers}->{$options{key}} = $options{value};
}
sub remove_header {
my ($self, %options) = @_;
delete $self->{add_headers}->{$options{key}} if (defined($self->{add_headers}->{$options{key}}));
}
sub check_options {
my ($self, %options) = @_;

View File

@ -294,7 +294,7 @@ List available custom modes.
=item B<--multiple>
Multiple custom mode objects (some mode needs it).
Multiple custom mode objects (required by some specific modes)
=item B<--pass-manager>

View File

@ -291,7 +291,7 @@ List available sql modes.
=item B<--multiple>
Multiple database connections (some mode needs it).
Multiple database connections (required by some specific modes).
=item B<--pass-manager>

View File

@ -772,6 +772,7 @@ sub check_options {
}
if ($options{option_results}->{snmp_version} eq '3') {
delete $self->{snmp_params}->{Community};
$self->{snmp_params}->{Context} = $options{option_results}->{snmp_context_name} if (defined($options{option_results}->{snmp_context_name}));
$self->{snmp_params}->{ContextEngineId} = $options{option_results}->{snmp_context_engine_id} if (defined($options{option_results}->{snmp_context_engine_id}));

View File

@ -309,7 +309,7 @@ sub run_instances {
$self->{lproblems} = 0;
$self->{multiple} = 1;
if (scalar(keys %{$self->{$options{config}->{name}}}) == 1) {
if (scalar(keys %{$self->{$options{config}->{name}}}) <= 1) {
$self->{multiple} = 0;
}
@ -401,7 +401,7 @@ sub run_group {
my $multiple = 1;
return if (scalar(keys %{$self->{$options{config}->{name}}}) <= 0);
if (scalar(keys %{$self->{$options{config}->{name}}}) == 1) {
if (scalar(keys %{$self->{$options{config}->{name}}}) <= 1) {
$multiple = 0;
}
@ -441,8 +441,10 @@ sub run_group {
$prefix_output = '' if (!defined($prefix_output));
if ($multiple == 0 && (!defined($group->{display}) || $group->{display} != 0)) {
$self->{output}->output_add(severity => $self->{most_critical_instance},
short_msg => sprintf("${prefix_output}" . $format_output, $self->{lproblems}));
$self->{output}->output_add(
severity => $self->{most_critical_instance},
short_msg => sprintf("${prefix_output}" . $format_output, $self->{lproblems})
);
}
}
}
@ -450,8 +452,10 @@ sub run_group {
if ($multiple == 1) {
my $exit = $self->{output}->get_most_critical(status => [ @{$global_exit} ]);
if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf($format_output, $total_problems));
$self->{output}->output_add(
severity => $exit,
short_msg => sprintf($format_output, $total_problems)
);
}
}
@ -476,12 +480,12 @@ sub run_multiple_instances {
my $multiple_parent = defined($options{multiple_parent}) && $options{multiple_parent} == 1 ? $options{multiple_parent} : 0;
my $indent_long_output = defined($options{indent_long_output}) ? $options{indent_long_output} : '';
my $no_message_multiple = 1;
my $multiple = 1;
if (scalar(keys %{$self->{$options{config}->{name}}}) == 1) {
if (scalar(keys %{$self->{$options{config}->{name}}}) <= 1) {
$multiple = 0;
}
my $message_separator = defined($options{config}->{message_separator}) ?
$options{config}->{message_separator} : ', ';
my $sort_method = 'cmp';
@ -506,8 +510,10 @@ sub run_multiple_instances {
$no_message_multiple = 0;
$obj->set(instance => $instance);
my ($value_check) = $obj->execute(new_datas => $self->{new_datas},
values => $self->{$options{config}->{name}}->{$id});
my ($value_check) = $obj->execute(
new_datas => $self->{new_datas},
values => $self->{$options{config}->{name}}->{$id}
);
next if (defined($options{config}->{skipped_code}) && defined($options{config}->{skipped_code}->{$value_check}));
if ($value_check != 0) {
$long_msg .= $long_msg_append . $obj->output_error();
@ -549,17 +555,19 @@ sub run_multiple_instances {
}
if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) {
$self->run_multiple_prefix_output(severity => $exit,
short_msg => $prefix_output . $short_msg . $suffix_output);
$self->run_multiple_prefix_output(
severity => $exit,
short_msg => $prefix_output . $short_msg . $suffix_output
);
}
if ($multiple == 0 && $multiple_parent == 0) {
$self->run_multiple_prefix_output(severity => 'ok', short_msg => $prefix_output . $long_msg . $suffix_output);
}
}
if ($no_message_multiple == 0 && $multiple == 1 && $multiple_parent == 0) {
$self->{output}->output_add(short_msg => $options{config}->{message_multiple});
$self->run_multiple_prefix_output(severity => 'ok', short_msg => $options{config}->{message_multiple});
}
}
@ -572,7 +580,7 @@ sub run_multiple_prefix_output {
$self->{prefix_multiple_output_done}->{lc($options{severity})} = 1;
$separator{separator} = '';
}
$self->{output}->output_add(severity => $options{severity}, short_msg => "$options{short_msg}", %separator);
}
@ -580,13 +588,15 @@ sub run_multiple {
my ($self, %options) = @_;
my $multiple = 1;
if (scalar(keys %{$self->{$options{config}->{name}}}) == 1) {
if (scalar(keys %{$self->{$options{config}->{name}}}) <= 1) {
$multiple = 0;
}
if ($multiple == 1) {
$self->{output}->output_add(severity => 'OK',
short_msg => $options{config}->{message_multiple});
$self->{output}->output_add(
severity => 'OK',
short_msg => $options{config}->{message_multiple}
);
}
foreach my $instance (sort keys %{$self->{$options{config}->{name}}}) {
@ -620,6 +630,13 @@ sub run_multiple {
}
}
sub read_statefile_key {
my ($self, %options) = @_;
$self->{statefile_value}->read(statefile => $self->{cache_name});
return $self->{statefile_value}->get(name => $options{key});
}
sub run {
my ($self, %options) = @_;

View File

@ -1,3 +1,34 @@
2020-XX-XX Quentin Garnier <qgarnier@centreon.com>
* Plugin added: Ruckus SmartZone SNMP
* Plugin added: Ruckus ZoneDirector SNMP
* Plugin added: Ruckus ICX SNMP
* Plugin added: Dell Xseries SNMP
* Plugin added: Adva FSP150 SNMP
* Plugin added: Lenovo Iomega SNMP
* Plugin added: Netapp Santricity Rest API
* Plugin added: Bluemind
* Plugin added: Mulesoft Rest API
* Plugin added: Salesforce Rest API
* Break: [netapp/snmp] move directory
* Break: [netapp/restapi] move directory
2020-04-10 Quentin Garnier <qgarnier@centreon.com>
* Plugin added: Dell OS10 SNMP
* Plugin added: Sirportly notification
* Plugin added: Mobotix Camera SNMP
* Plugin added: Ibm MQ MQI
* Plugin added: Supermicro BMC SNMP
* Plugin added: Eltek Enexus SNMP
* Plugin added: Cisco Meraki Rest API
* Plugin added: Aws EFS
* Core: add backend ssh system (plink, ssh and libssh)
* Mode added: [azure] 'alert'
* Mode added: [checkpoint/snmp] 'vsx'
* Mode added: [synology/snmp] 'ha'
* Mode added: [cisco/standard/snmp] 'wan3g'
* Break: [fortigate/snmp] 'cpu', 'memory', 'vdom' (merge)
* Break: [supermicro/snmp] move directory
2020-02-04 Quentin Garnier <qgarnier@centreon.com>
* Plugin added: Allied Telesis SNMP
* Plugin added: UPS HP SNMP

View File

@ -160,7 +160,7 @@ sub execute {
$self->{output}->option_exit();
}
return $raw_results;
return $raw_results;
}
sub cloudwatch_get_metrics_set_cmd {
@ -176,7 +176,7 @@ sub cloudwatch_get_metrics_set_cmd {
}
$cmd_options .= " --endpoint-url $self->{endpoint_url}" if (defined($self->{endpoint_url}) && $self->{endpoint_url} ne '');
return $cmd_options;
return $cmd_options;
}
sub cloudwatch_get_metrics {
@ -229,7 +229,7 @@ sub discovery_set_cmd {
my $cmd_options = $options{service} . " " . $options{command} . " --region $options{region} --output json";
$cmd_options .= " --endpoint-url $self->{endpoint_url}" if (defined($self->{endpoint_url}) && $self->{endpoint_url} ne '');
return $cmd_options;
return $cmd_options;
}
sub discovery {
@ -249,7 +249,7 @@ sub cloudwatch_get_alarms_set_cmd {
my $cmd_options = "cloudwatch describe-alarms --region $options{region} --output json";
$cmd_options .= " --endpoint-url $self->{endpoint_url}" if (defined($self->{endpoint_url}) && $self->{endpoint_url} ne '');
return $cmd_options;
return $cmd_options;
}
sub cloudwatch_get_alarms {
@ -282,7 +282,7 @@ sub cloudwatch_list_metrics_set_cmd {
$cmd_options .= " --metric-name $options{metric}" if (defined($options{metric}));
$cmd_options .= " --endpoint-url $self->{endpoint_url}" if (defined($self->{endpoint_url}) && $self->{endpoint_url} ne '');
return $cmd_options;
return $cmd_options;
}
sub cloudwatch_list_metrics {
@ -302,7 +302,7 @@ sub cloudwatchlogs_describe_log_groups_set_cmd {
my $cmd_options = "logs describe-log-groups --region $self->{option_results}->{region} --output json";
$cmd_options .= " --endpoint-url $self->{endpoint_url}" if (defined($self->{endpoint_url}) && $self->{endpoint_url} ne '');
return $cmd_options;
return $cmd_options;
}
sub cloudwatchlogs_describe_log_groups {
@ -329,7 +329,7 @@ sub cloudwatchlogs_filter_log_events_set_cmd {
}
$cmd_options .= " --endpoint-url $self->{endpoint_url}" if (defined($self->{endpoint_url}) && $self->{endpoint_url} ne '');
return $cmd_options;
return $cmd_options;
}
sub cloudwatchlogs_filter_log_events {
@ -349,7 +349,7 @@ sub ec2_get_instances_status_set_cmd {
my $cmd_options = "ec2 describe-instance-status --include-all-instances --no-dry-run --region $options{region} --output json";
$cmd_options .= " --endpoint-url $self->{endpoint_url}" if (defined($self->{endpoint_url}) && $self->{endpoint_url} ne '');
return $cmd_options;
return $cmd_options;
}
sub ec2_get_instances_status {
@ -361,7 +361,7 @@ sub ec2_get_instances_status {
my $instance_results = {};
foreach (@{$raw_results->{InstanceStatuses}}) {
$instance_results->{$_->{InstanceId}} = {
state => $_->{InstanceState}->{Name},
state => $_->{InstanceState}->{Name},
status => => $_->{InstanceStatus}->{Status}
};
}
@ -369,6 +369,65 @@ sub ec2_get_instances_status {
return $instance_results;
}
sub ec2spot_get_active_instances_set_cmd {
my ($self, %options) = @_;
return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '');
my $cmd_options = "ec2 describe-spot-fleet-instances --no-dry-run --region $options{region} --output json";
$cmd_options .= " --endpoint-url $self->{endpoint_url}" if (defined($self->{endpoint_url}) && $self->{endpoint_url} ne '');
$cmd_options .= " --spot-fleet-request-id " . $options{spot_fleet_request_id};
return $cmd_options;
}
sub ec2spot_get_active_instances_status {
my ($self, %options) = @_;
my $cmd_options = $self->ec2spot_get_active_instances_set_cmd(%options);
my $raw_results = $self->execute(cmd_options => $cmd_options);
my $instance_results = {};
foreach (@{$raw_results->{ActiveInstances}}) {
$instance_results->{$_->{InstanceId}} = {
health => $_->{InstanceHealth},
type => $_->{InstanceType},
request_id => $_->{SpotInstanceRequestId}
};
}
return $instance_results;
}
sub ec2spot_list_fleet_requests_set_cmd {
my ($self, %options) = @_;
return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '');
my $cmd_options = "ec2 describe-spot-fleet-requests --no-dry-run --region $options{region} --output json";
$cmd_options .= " --endpoint-url $self->{endpoint_url}" if (defined($self->{endpoint_url}) && $self->{endpoint_url} ne '');
return $cmd_options;
}
sub ec2spot_list_fleet_requests {
my ($self, %options) = @_;
my $cmd_options = $self->ec2spot_list_fleet_requests_set_cmd(%options);
my $raw_results = $self->execute(cmd_options => $cmd_options);
my $resource_results = [];
foreach my $fleet_request (@{$raw_results->{SpotFleetRequestConfigs}}) {
push @{$resource_results}, {
SpotFleetRequestState => $fleet_request->{SpotFleetRequestState},
SpotFleetRequestId => $fleet_request->{SpotFleetRequestId},
ActivityStatus => $fleet_request->{ActivityStatus}
};
}
return $resource_results;
}
sub ec2_list_resources_set_cmd {
my ($self, %options) = @_;
@ -377,7 +436,7 @@ sub ec2_list_resources_set_cmd {
my $cmd_options = "ec2 describe-instances --no-dry-run --region $options{region} --output json";
$cmd_options .= " --endpoint-url $self->{endpoint_url}" if (defined($self->{endpoint_url}) && $self->{endpoint_url} ne '');
return $cmd_options;
return $cmd_options;
}
sub ec2_list_resources {
@ -394,7 +453,7 @@ sub ec2_list_resources {
my %already = map { $_->{Name} => $_ } @{$resource_results};
if ($tag->{Key} eq "aws:autoscaling:groupName") {
next if (defined($already{$tag->{Value}}));
push @{$resource_results}, {
push @{$resource_results}, {
Name => $tag->{Value},
Type => 'asg',
};
@ -402,7 +461,7 @@ sub ec2_list_resources {
push @instance_tags, $tag->{Value};
}
}
push @{$resource_results}, {
push @{$resource_results}, {
Name => $instance->{InstanceId},
Type => 'instance',
AvailabilityZone => $instance->{Placement}->{AvailabilityZone},
@ -411,7 +470,6 @@ sub ec2_list_resources {
Tags => join(",", @instance_tags),
KeyName => $instance->{KeyName},
};
}
}
@ -426,7 +484,7 @@ sub asg_get_resources_set_cmd {
my $cmd_options = "autoscaling describe-auto-scaling-groups --region $options{region} --output json";
$cmd_options .= " --endpoint-url $self->{endpoint_url}" if (defined($self->{endpoint_url}) && $self->{endpoint_url} ne '');
return $cmd_options;
return $cmd_options;
}
sub asg_get_resources {
@ -446,7 +504,7 @@ sub rds_get_instances_status_set_cmd {
my $cmd_options = "rds describe-db-instances --region $options{region} --output json";
$cmd_options .= " --endpoint-url $self->{endpoint_url}" if (defined($self->{endpoint_url}) && $self->{endpoint_url} ne '');
return $cmd_options;
return $cmd_options;
}
sub rds_get_instances_status {
@ -471,7 +529,7 @@ sub rds_list_instances_set_cmd {
my $cmd_options = "rds describe-db-instances --region $options{region} --output json";
$cmd_options .= " --endpoint-url $self->{endpoint_url}" if (defined($self->{endpoint_url}) && $self->{endpoint_url} ne '');
return $cmd_options;
return $cmd_options;
}
sub rds_list_instances {
@ -502,7 +560,7 @@ sub rds_list_clusters_set_cmd {
my $cmd_options = "rds describe-db-clusters --region $options{region} --output json";
$cmd_options .= " --endpoint-url $self->{endpoint_url}" if (defined($self->{endpoint_url}) && $self->{endpoint_url} ne '');
return $cmd_options;
return $cmd_options;
}
sub rds_list_clusters {
@ -524,6 +582,40 @@ sub rds_list_clusters {
return $cluster_results;
}
sub vpn_list_connections_set_cmd {
my ($self, %options) = @_;
return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '');
my $cmd_options = "ec2 describe-vpn-connections --region $options{region} --output json";
$cmd_options .= " --endpoint-url $self->{endpoint_url}" if (defined($self->{endpoint_url}) && $self->{endpoint_url} ne '');
return $cmd_options;
}
sub vpn_list_connections {
my ($self, %options) = @_;
my $cmd_options = $self->vpn_list_connections_set_cmd(%options);
my $raw_results = $self->execute(cmd_options => $cmd_options);
my $connections_results = [];
foreach my $connection (@{$raw_results->{VpnConnections}}) {
my @name_tags;
foreach my $tag (@{$connection->{Tags}}) {
if ($tag->{Key} eq "Name" && defined($tag->{Value})) {
push @name_tags, $tag->{Value};
}
}
push @{$connections_results}, {
id => $connection->{VpnConnectionId},
name => join(",", @name_tags),
state => $connection->{State}
}
};
return $connections_results;
}
1;
__END__

View File

@ -39,9 +39,9 @@ sub new {
$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 => {
$options{options}->add_options(arguments => {
'aws-secret-key:s' => { name => 'aws_secret_key' },
'aws-access-key:s' => { name => 'aws_access_key' },
'region:s' => { name => 'region' },
@ -56,7 +56,7 @@ sub new {
$self->{output} = $options{output};
$self->{mode} = $options{mode};
return $self;
}
@ -122,14 +122,14 @@ sub check_options {
sub cloudwatch_get_metrics {
my ($self, %options) = @_;
my $metric_results = {};
eval {
my $lwp_caller = new Paws::Net::LWPCaller();
my $cw = Paws->service('CloudWatch', caller => $lwp_caller, region => $options{region});
my $start_time = DateTime->now->subtract(seconds => $options{timeframe})->iso8601;
my $end_time = DateTime->now->iso8601;
foreach my $metric_name (@{$options{metrics}}) {
my $metric_result = $cw->GetMetricStatistics(
MetricName => $metric_name,
@ -142,7 +142,7 @@ sub cloudwatch_get_metrics {
#Unit => $unit,
Dimensions => $options{dimensions},
);
$metric_results->{$metric_result->{Label}} = { points => 0 };
foreach my $point (@{$metric_result->{Datapoints}}) {
if (defined($point->{Average})) {
@ -161,10 +161,10 @@ sub cloudwatch_get_metrics {
$metric_results->{$metric_result->{Label}}->{sum} = 0 if (!defined($metric_results->{$metric_result->{Label}}->{sum}));
$metric_results->{$metric_result->{Label}}->{sum} += $point->{Sum};
}
$metric_results->{$metric_result->{Label}}->{points}++;
}
if (defined($metric_results->{$metric_result->{Label}}->{average})) {
$metric_results->{$metric_result->{Label}}->{average} /= $metric_results->{$metric_result->{Label}}->{points};
}
@ -174,7 +174,7 @@ sub cloudwatch_get_metrics {
$self->{output}->add_option_msg(short_msg => "error: $@");
$self->{output}->option_exit();
}
return $metric_results;
}
@ -205,7 +205,7 @@ sub cloudwatch_get_alarms {
sub cloudwatch_list_metrics {
my ($self, %options) = @_;
my $metric_results = [];
eval {
my $lwp_caller = new Paws::Net::LWPCaller();
@ -219,13 +219,13 @@ sub cloudwatch_list_metrics {
foreach my $dimension (@{$_->{Dimensions}}) {
push @$dimensions, { Name => $dimension->{Name}, Value => $dimension->{Value} };
}
push @{$metric_results}, {
push @{$metric_results}, {
Namespace => $_->{Namespace},
MetricName => $_->{MetricName},
Dimensions => $dimensions,
};
}
last if (!defined($list_metrics->{NextToken}));
$cw_options{NextToken} = $list_metrics->{NextToken};
}
@ -234,7 +234,7 @@ sub cloudwatch_list_metrics {
$self->{output}->add_option_msg(short_msg => "error: $@");
$self->{output}->option_exit();
}
return $metric_results;
}
@ -250,7 +250,7 @@ sub cloudwatchlogs_describe_log_groups {
foreach (@{$list_log_groups->{logGroups}}) {
push @$log_groups_results, $_;
}
last if (!defined($list_log_groups->{NextToken}));
$cw_options{NextToken} = $list_log_groups->{NextToken};
}
@ -277,7 +277,7 @@ sub cloudwatchlogs_filter_log_events {
foreach (@{$list_log_groups->{logGroups}}) {
push @$log_groups_results, $_;
}
last if (!defined($list_log_groups->{NextToken}));
$cw_options{NextToken} = $list_log_groups->{NextToken};
}
@ -292,35 +292,84 @@ sub cloudwatchlogs_filter_log_events {
sub ec2_get_instances_status {
my ($self, %options) = @_;
my $instance_results = {};
eval {
my $lwp_caller = new Paws::Net::LWPCaller();
my $ec2 = Paws->service('EC2', caller => $lwp_caller, region => $options{region});
my $instances = $ec2->DescribeInstanceStatus(DryRun => 0, IncludeAllInstances => 1);
foreach (@{$instances->{InstanceStatuses}}) {
$instance_results->{$_->{InstanceId}} = { state => $_->{InstanceState}->{Name},
status => => $_->{InstanceStatus}->{Status} };
status => $_->{InstanceStatus}->{Status} };
}
};
if ($@) {
$self->{output}->add_option_msg(short_msg => "error: $@");
$self->{output}->option_exit();
}
return $instance_results;
}
sub ec2spot_get_active_instances {
my ($self, %options) = @_;
my $instance_results = {};
eval {
my $lwp_caller = new Paws::Net::LWPCaller();
my $ec2 = Paws->service('EC2', caller => $lwp_caller, region => $options{region});
my $instances = $ec2->DescribeSpotFleetInstances('SpotFleetRequestId' => $options{spot_fleet_request_id}, DryRun => 0, IncludeAllInstances => 1);
foreach (@{$instances->{ActiveInstances}}) {
$instance_results->{$_->{InstanceId}} = {
health => $_->{InstanceHealth},
type => $_->{InstanceType},
request_id => $_->{SpotInstanceRequestId} };
}
};
if ($@) {
$self->{output}->add_option_msg(short_msg => "error: $@");
$self->{output}->option_exit();
}
return $instance_results;
}
sub ec2spot_list_fleet_requests {
my ($self, %options) = @_;
my $resource_results = [];
eval {
my $lwp_caller = new Paws::Net::LWPCaller();
my $ec2spot = Paws->service('EC2', caller => $lwp_caller, region => $options{region});
my $spot_fleet_requests = $ec2spot->DescribeSpotFleetRequests(DryRun => 0);
foreach (@{$spot_fleet_requests->{SpotFleetRequestConfigs}}) {
push @{$resource_results}, {
SpotFleetRequestState => $_->{SpotFleetRequestState},
SpotFleetRequestId => $_->{SpotFleetRequestId},
ActivityStatus => $_->{ActivityStatus}
};
}
};
if ($@) {
$self->{output}->add_option_msg(short_msg => "error: $@");
$self->{output}->option_exit();
}
return $resource_results;
}
sub ec2_list_resources {
my ($self, %options) = @_;
my $resource_results = [];
eval {
my $lwp_caller = new Paws::Net::LWPCaller();
my $ec2 = Paws->service('EC2', caller => $lwp_caller, region => $options{region});
my $list_instances = $ec2->DescribeInstances(DryRun => 0);
foreach my $reservation (@{$list_instances->{Reservations}}) {
foreach my $instance (@{$reservation->{Instances}}) {
my @instance_tags;
@ -344,7 +393,7 @@ sub ec2_list_resources {
State => $instance->{State}->{Name},
Tags => join(",", @instance_tags),
};
}
}
};
@ -352,7 +401,7 @@ sub ec2_list_resources {
$self->{output}->add_option_msg(short_msg => "error: $@");
$self->{output}->option_exit();
}
return $resource_results;
}
@ -375,7 +424,7 @@ sub asg_get_resources {
sub rds_get_instances_status {
my ($self, %options) = @_;
my $instance_results = {};
eval {
my $lwp_caller = new Paws::Net::LWPCaller();
@ -389,19 +438,19 @@ sub rds_get_instances_status {
$self->{output}->add_option_msg(short_msg => "error: $@");
$self->{output}->option_exit();
}
return $instance_results;
}
sub rds_list_instances {
my ($self, %options) = @_;
my $instance_results = [];
eval {
my $lwp_caller = new Paws::Net::LWPCaller();
my $rds = Paws->service('RDS', caller => $lwp_caller, region => $options{region});
my $list_instances = $rds->DescribeDBInstances();
foreach my $instance (@{$list_instances->{DBInstances}}) {
push @{$instance_results}, {
Name => $instance->{DBInstanceIdentifier},
@ -416,19 +465,19 @@ sub rds_list_instances {
$self->{output}->add_option_msg(short_msg => "error: $@");
$self->{output}->option_exit();
}
return $instance_results;
}
sub rds_list_clusters {
my ($self, %options) = @_;
my $cluster_results = [];
eval {
my $lwp_caller = new Paws::Net::LWPCaller();
my $rds = Paws->service('RDS', caller => $lwp_caller, region => $options{region});
my $list_clusters = $rds->DescribeDBClusters();
foreach my $cluster (@{$list_clusters->{DBClusters}}) {
push @{$cluster_results}, {
Name => $cluster->{DBClusterIdentifier},
@ -442,10 +491,39 @@ sub rds_list_clusters {
$self->{output}->add_option_msg(short_msg => "error: $@");
$self->{output}->option_exit();
}
return $cluster_results;
}
sub vpn_list_connections {
my ($self, %options) = @_;
my $connections_results = [];
eval {
my $lwp_caller = new Paws::Net::LWPCaller();
my $vpn = Paws->service('EC2', caller => $lwp_caller, region => $options{region});
my $list_vpn = $vpn->DescribeVpnConnections();
foreach my $connection (@{$list_vpn->{VpnConnections}}) {
my @name_tags;
foreach my $tag (@{$connection->{Tags}}) {
if ($tag->{Key} eq "Name" && defined($tag->{Value})) {
push @name_tags, $tag->{Value};
}
}
push @{$connections_results}, {
id => $connection->{VpnConnectionId},
name => join(",", @name_tags),
state => $connection->{State}
}
};
};
if ($@) {
$self->{output}->add_option_msg(short_msg => "error: $@");
$self->{output}->option_exit();
}
return $connections_results;
}
1;
__END__
@ -484,7 +562,8 @@ Set timeframe in seconds.
=item B<--statistic>
Set cloudwatch statistics (Can be: 'minimum', 'maximum', 'average', 'sum').
Set cloudwatch statistics
(Can be: 'minimum', 'maximum', 'average', 'sum').
=item B<--zeroed>

View File

@ -32,7 +32,8 @@ sub new {
bless $self, $class;
$options{options}->add_options(arguments => {
"prettify" => { name => 'prettify' },
"prettify" => { name => 'prettify' },
"filter-type:s" => { name => 'filter_type' },
});
return $self;
@ -86,8 +87,10 @@ sub run {
}
push @{$ec2{tags}}, { key => $tag->{Key}, value => $tag->{Value} };
}
push @disco_data, \%ec2;
push @disco_data, \%asg if (defined($asg{name}) && $asg{name} ne '');
push @disco_data, \%ec2 unless (defined($self->{option_results}->{filter_type})
&& $ec2{type} !~ /$self->{option_results}->{filter_type}/);
push @disco_data, \%asg unless ((defined($self->{option_results}->{filter_type})
&& $asg{type} !~ /$self->{option_results}->{filter_type}/) || !defined($asg{name}) || $asg{name} eq '');
}
}
@ -123,6 +126,10 @@ EC2/ASG discovery.
=over 8
=item B<--filter-type>
Filter type.
=item B<--prettify>
Prettify JSON output.

View File

@ -0,0 +1,117 @@
#
# Copyright 2020 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 cloud::aws::ec2::mode::discoveryspotfleetrequests;
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;
$options{options}->add_options(arguments => {
"prettify" => { name => 'prettify' },
"filter-state:s" => { name => 'filter_state' },
});
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 %asgs;
my $spot_fleet_requests = $options{custom}->discovery(
region => $self->{option_results}->{region},
service => 'ec2',
command => 'describe-spot-fleet-requests'
);
foreach my $fleet_request (@{$spot_fleet_requests->{SpotFleetRequestConfigs}}) {
my %sfr;
$sfr{state} = $fleet_request->{SpotFleetRequestState};
$sfr{id} = $fleet_request->{SpotFleetRequestId};
$sfr{activity_status} = $fleet_request->{ActivityStatus};
push @disco_data, \%sfr unless (defined($self->{option_results}->{filter_state})
&& $sfr{state} !~ /$self->{option_results}->{filter_state}/);
}
$disco_stats->{end_time} = time();
$disco_stats->{duration} = $disco_stats->{end_time} - $disco_stats->{start_time};
$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
EC2 Spot Fleet Requests discovery.
=over 8
=item B<--filter-state>
Filter on Spot Fleet Request state.
=item B<--prettify>
Prettify JSON output.
=back
=cut

View File

@ -0,0 +1,96 @@
#
# Copyright 2020 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 cloud::aws::ec2::mode::listspotfleetrequests;
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;
$options{options}->add_options(arguments => {});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
}
sub manage_selection {
my ($self, %options) = @_;
$self->{spot_fleet_requests} = $options{custom}->ec2spot_list_fleet_requests(region => $self->{option_results}->{region});
}
sub run {
my ($self, %options) = @_;
$self->manage_selection(%options);
foreach (@{$self->{spot_fleet_requests}}) {
$self->{output}->output_add(
long_msg => sprintf("[id = %s][state = %s][status = %s]",
$_->{SpotFleetRequestId}, $_->{SpotFleetRequestState}, $_->{ActivityStatus}));
}
$self->{output}->output_add(severity => 'OK',
short_msg => 'List spot fleet requests:');
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
$self->{output}->exit();
}
sub disco_format {
my ($self, %options) = @_;
$self->{output}->add_disco_format(elements => ['id', 'state', 'status']);
}
sub disco_show {
my ($self, %options) = @_;
$self->manage_selection(%options);
foreach (@{$self->{spot_fleet_requests}}) {
$self->{output}->add_disco_entry(
id => $_->{SpotFleetRequestId},
state => $_->{SpotFleetRequestState},
status => $_->{ActivityStatus}
);
}
}
1;
__END__
=head1 MODE
List EC2 Spot Fleet Requests
=over 8
=back
=cut

View File

@ -0,0 +1,122 @@
#
# Copyright 2020 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 cloud::aws::ec2::mode::spotactiveinstances;
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 },
];
$self->{maps_counters}->{global} = [
{ label => 'active', nlabel => 'ec2.spot.instances.active.count', set => {
key_values => [ { name => 'active' } ],
output_template => 'Active instances : %s',
perfdatas => [
{ label => 'active', value => 'active_absolute', template => '%s',
min => 0 },
],
}
},
{ label => 'healthy', nlabel => 'ec2.spot.instances.healthy.count', set => {
key_values => [ { name => 'healthy' } ],
output_template => 'Healthy instances : %s',
perfdatas => [
{ label => 'healthy', value => 'healthy_absolute', template => '%s',
min => 0 },
],
}
},
{ label => 'unhealthy', nlabel => 'ec2.spot.instances.unhealthy.count', set => {
key_values => [ { name => 'unhealthy' } ],
output_template => 'Unhealty instances : %s',
perfdatas => [
{ label => 'unhealthy', value => 'unhealthy_absolute', template => '%s',
min => 0 },
],
}
},
]
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
'region:s' => { name => 'region' },
'spot-fleet-request-id:s' => { name => 'spot_fleet_request_id' }
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
if (!defined($self->{option_results}->{region}) || $self->{option_results}->{region} eq '') {
$self->{output}->add_option_msg(short_msg => "Need to specify --region option.");
$self->{output}->option_exit();
}
if (!defined($self->{option_results}->{spot_fleet_request_id}) || $self->{option_results}->{spot_fleet_request_id} eq '') {
$self->{output}->add_option_msg(short_msg => "Need to specify --spot-fleet-request-id option.");
$self->{output}->option_exit();
}
}
sub manage_selection {
my ($self, %options) = @_;
$self->{global} = { active => 0, healthy => 0, unhealthy => 0 };
$self->{instances} = $options{custom}->ec2spot_get_active_instances_status(region => $self->{option_results}->{region}, spot_fleet_request_id => $self->{option_results}->{spot_fleet_request_id});
foreach my $instance_id (keys %{$self->{instances}}) {
$self->{global}->{active}++;
$self->{global}->{lc($self->{instances}->{$instance_id}->{health})}++;
}
}
1;
__END__
=head1 MODE
Check EC2 Spot active instance for a specific fleet
=over 8
=item B<--warning-*> B<--critical-*>
Warning and Critical thresholds. You can use 'active', 'healthy', 'unhealthy'
=back
=cut

Some files were not shown because too many files have changed in this diff Show More