add certificates cces
This commit is contained in:
parent
fab4806e8e
commit
638012a1c3
|
@ -193,6 +193,19 @@ sub authenticate {
|
||||||
sub request_api {
|
sub request_api {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
my $plop = do {
|
||||||
|
local $/ = undef;
|
||||||
|
if (!open my $fh, "<", '/tmp/plop4.txt') {
|
||||||
|
$self->{output}->add_option_msg(short_msg => "Could not open file");
|
||||||
|
$self->{output}->option_exit();
|
||||||
|
}
|
||||||
|
<$fh>;
|
||||||
|
};
|
||||||
|
eval {
|
||||||
|
$plop = XMLin($plop, ForceArray => $options{ForceArray}, KeyAttr => []);
|
||||||
|
};
|
||||||
|
return $plop;
|
||||||
|
|
||||||
$self->settings();
|
$self->settings();
|
||||||
if (!defined($self->{session_cookie})) {
|
if (!defined($self->{session_cookie})) {
|
||||||
$self->authenticate(statefile => $self->{cache});
|
$self->authenticate(statefile => $self->{cache});
|
||||||
|
|
|
@ -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 network::cisco::cces::restapi::mode::certificates;
|
||||||
|
|
||||||
|
use base qw(centreon::plugins::templates::counter);
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
use centreon::plugins::misc;
|
||||||
|
|
||||||
|
sub custom_validity_output {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
return sprintf(
|
||||||
|
'expires in %s',
|
||||||
|
$self->{result_values}->{generation_time_absolute}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
sub set_counters {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
$self->{maps_counters_type} = [
|
||||||
|
{ name => 'certificates', type => 1, cb_prefix_output => 'prefix_certificate_output', message_multiple => 'All certificates are ok', skipped_code => { -10 => 1 } },
|
||||||
|
];
|
||||||
|
|
||||||
|
$self->{maps_counters}->{certificates} = [
|
||||||
|
{ label => 'certificate-expires', nlabel => 'system.certificate.expires.seconds', set => {
|
||||||
|
key_values => [ { name => 'validity_time' }, { name => 'generation_time' } ],
|
||||||
|
closure_custom_output => $self->can('custom_validity_output'),
|
||||||
|
perfdatas => [
|
||||||
|
{ value => 'validity_time_absolute', template => '%d', min => 0, unit => 's' },
|
||||||
|
],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
sub prefix_certificate_output {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
return "Certificate '" . $options{instance_value}->{display} . "' ";
|
||||||
|
}
|
||||||
|
|
||||||
|
sub new {
|
||||||
|
my ($class, %options) = @_;
|
||||||
|
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
|
||||||
|
bless $self, $class;
|
||||||
|
|
||||||
|
$self->{version} = '1.0';
|
||||||
|
$options{options}->add_options(arguments => {
|
||||||
|
});
|
||||||
|
|
||||||
|
centreon::plugins::misc::mymodule_load(
|
||||||
|
output => $self->{output},
|
||||||
|
module => 'Date::Parse',
|
||||||
|
error_msg => "Cannot load module 'Date::Parse'."
|
||||||
|
);
|
||||||
|
return $self;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub manage_selection {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
my $result = $options{custom}->request_api(
|
||||||
|
method => 'POST',
|
||||||
|
url_path => '/putxml',
|
||||||
|
query_form_post => '<Command><Security><Certificates><Services><Show/></Services></Certificates></Security></Command>',
|
||||||
|
ForceArray => ['Details']
|
||||||
|
);
|
||||||
|
|
||||||
|
$self->{certificates} = {};
|
||||||
|
if (defined($result->{ServicesShowResult}->{Details})) {
|
||||||
|
foreach (@{$result->{ServicesShowResult}->{Details}}) {
|
||||||
|
my $end_date = Date::Parse::str2time($_->{notAfter});
|
||||||
|
if (!defined($end_date)) {
|
||||||
|
$self->{output}->output_add(
|
||||||
|
severity => 'UNKNOWN',
|
||||||
|
short_msg => "can't parse date '" . $_->{notAfter} . "'"
|
||||||
|
);
|
||||||
|
next;
|
||||||
|
}
|
||||||
|
|
||||||
|
$self->{certificates}->{$_->{item}} = {
|
||||||
|
display => $_->{SubjectName},
|
||||||
|
validity_time => $end_date - time(),
|
||||||
|
generation_time => centreon::plugins::misc::change_seconds(value => $end_date - time()),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (scalar(keys %{$self->{certificates}}) <= 0) {
|
||||||
|
$self->{output}->add_option_msg(short_msg => 'No certificate found.');
|
||||||
|
$self->{output}->option_exit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
||||||
|
|
||||||
|
__END__
|
||||||
|
|
||||||
|
=head1 MODE
|
||||||
|
|
||||||
|
Check certificates validity.
|
||||||
|
|
||||||
|
=over 8
|
||||||
|
|
||||||
|
=item B<--warning-*> B<--critical-*>
|
||||||
|
|
||||||
|
Thresholds.
|
||||||
|
Can be: 'peripherals-connected'.
|
||||||
|
|
||||||
|
=back
|
||||||
|
|
||||||
|
=cut
|
|
@ -80,7 +80,7 @@ sub manage_selection {
|
||||||
if (defined($self->{option_results}->{filter_since}) && $self->{option_results}->{filter_since} =~ /\d+/) {
|
if (defined($self->{option_results}->{filter_since}) && $self->{option_results}->{filter_since} =~ /\d+/) {
|
||||||
my $last_seen = Date::Parse::str2time($_->{LastSeen});
|
my $last_seen = Date::Parse::str2time($_->{LastSeen});
|
||||||
if (!defined($last_seen)) {
|
if (!defined($last_seen)) {
|
||||||
$self->{manager}->{output}->output_add(
|
$self->{output}->output_add(
|
||||||
severity => 'UNKNOWN',
|
severity => 'UNKNOWN',
|
||||||
short_msg => "can't parse date '" . $_->{LastSeen} . "'"
|
short_msg => "can't parse date '" . $_->{LastSeen} . "'"
|
||||||
);
|
);
|
||||||
|
|
|
@ -35,6 +35,7 @@ sub new {
|
||||||
'components' => 'network::cisco::cces::restapi::mode::components',
|
'components' => 'network::cisco::cces::restapi::mode::components',
|
||||||
'calls-summary' => 'network::cisco::cces::restapi::mode::callssummary',
|
'calls-summary' => 'network::cisco::cces::restapi::mode::callssummary',
|
||||||
'calls-rt' => 'network::cisco::cces::restapi::mode::callsrt',
|
'calls-rt' => 'network::cisco::cces::restapi::mode::callsrt',
|
||||||
|
'certificates' => 'network::cisco::cces::restapi::mode::certificates',
|
||||||
'diagnostics' => 'network::cisco::cces::restapi::mode::diagnostics',
|
'diagnostics' => 'network::cisco::cces::restapi::mode::diagnostics',
|
||||||
'peripherals' => 'network::cisco::cces::restapi::mode::peripherals',
|
'peripherals' => 'network::cisco::cces::restapi::mode::peripherals',
|
||||||
'sessions' => 'network::cisco::cces::restapi::mode::sessions'
|
'sessions' => 'network::cisco::cces::restapi::mode::sessions'
|
||||||
|
|
Loading…
Reference in New Issue