Debian Codegraph @

src/network/citrix/netscaler/snmp/mode/certificatesexpire.pm

raw
1 #
2 # Copyright 2024 Centreon (http://www.centreon.com/)
3 #
4 # Centreon is a full-fledged industry-strength solution that meets
5 # the needs in IT infrastructure and application monitoring for
6 # service performance.
7 #
8 # Licensed under the Apache License, Version 2.0 (the "License");
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
11 #
12 # http://www.apache.org/licenses/LICENSE-2.0
13 #
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
19 #
20
21 package network::citrix::netscaler::snmp::mode::certificatesexpire;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27
28 sub set_counters {
29 my ($self, %options) = @_;
30
31 $self->{maps_counters_type} = [
32 { name => 'certificates', type => 1, cb_prefix_output => 'prefix_certificates_output', message_multiple => 'All certificates are ok' }
33 ];
34
35 $self->{maps_counters}->{certificates} = [
36 { label => 'days', set => {
37 key_values => [ { name => 'days' }, { name => 'display' } ],
38 output_template => '%d days remaining before expiration',
39 closure_custom_perfdata => sub { return 0; },
40 }
41 },
42 ];
43 }
44
45 sub prefix_certificates_output {
46 my ($self, %options) = @_;
47
48 return "Certificate '" . $options{instance_value}->{display} . "' ";
49 }
50
51 sub new {
52 my ($class, %options) = @_;
53 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
54 bless $self, $class;
55
56 $options{options}->add_options(arguments =>
57 {
58 "filter-name:s" => { name => 'filter_name' },
59 });
60
61 return $self;
62 }
63
64 my $mapping = {
65 sslCertKeyName => { oid => '.1.3.6.1.4.1.5951.4.1.1.56.1.1.1' },
66 sslDaysToExpire => { oid => '.1.3.6.1.4.1.5951.4.1.1.56.1.1.5' },
67 };
68
69 sub manage_selection {
70 my ($self, %options) = @_;
71
72 $self->{certificates} = {};
73 my $snmp_result = $options{snmp}->get_multiple_table(oids => [ { oid => $mapping->{sslCertKeyName}->{oid} }, { oid => $mapping->{sslDaysToExpire}->{oid} } ],
74 return_type => 1, nothing_quit => 1);
75
76 foreach my $oid (keys %{$snmp_result}) {
77 next if ($oid !~ /^$mapping->{sslCertKeyName}->{oid}\.(.*)$/);
78 my $instance = $1;
79 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
80
81 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
82 $result->{sslCertKeyName} !~ /$self->{option_results}->{filter_name}/) {
83 $self->{output}->output_add(long_msg => "skipping '" . $result->{sslCertKeyName} . "': no matching filter.", debug => 1);
84 next;
85 }
86
87 $self->{certificates}->{$instance} = {
88 display => $result->{sslCertKeyName},
89 days => $result->{sslDaysToExpire},
90 };
91 }
92
93 if (scalar(keys %{$self->{certificates}}) <= 0) {
94 $self->{output}->add_option_msg(short_msg => "No certificate found.");
95 $self->{output}->option_exit();
96 }
97 }
98
99 1;
100
101 __END__
102
103 =head1 MODE
104
105 Check number of days remaining before the expiration of certificates (NS-MIB-smiv2).
106
107 =over 8
108
109 =item B<--filter-name>
110
111 Filter by name (can be a regexp).
112
113 =item B<--warning-days>
114
115 Warning threshold in days.
116
117 =item B<--critical-days>
118
119 Critical threshold in days.
120
121 =back
122
123 =cut
124