Debian Codegraph @

src/network/cyberoam/snmp/mode/license.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::cyberoam::snmp::mode::license;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27 use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
28 use centreon::plugins::misc;
29 use POSIX;
30 use Time::Local;
31 use DateTime::Format::Strptime;
32
33 my $unitdiv = { s => 1, w => 604800, d => 86400, h => 3600, m => 60 };
34 my $unitdiv_long = { s => 'seconds', w => 'weeks', d => 'days', h => 'hours', m => 'minutes' };
35
36 sub custom_expires_perfdata {
37 my ($self, %options) = @_;
38
39 $self->{output}->perfdata_add(
40 nlabel => $self->{nlabel} . '.' . $unitdiv_long->{ $self->{instance_mode}->{option_results}->{unit} },
41 unit => $self->{instance_mode}->{option_results}->{unit},
42 instances => $self->{result_values}->{name},
43 value => floor($self->{result_values}->{expires_seconds} / $unitdiv->{ $self->{instance_mode}->{option_results}->{unit} }),
44 warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}),
45 critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}),
46 min => 0
47 );
48 }
49
50 sub custom_expires_threshold {
51 my ($self, %options) = @_;
52
53 return $self->{perfdata}->threshold_check(
54 value =>
55 floor($self->{result_values}->{expires_seconds} / $unitdiv->{ $self->{instance_mode}->{option_results}->{unit} }),
56 threshold =>
57 [
58 { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' },
59 { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' },
60 { label => 'unknown-' . $self->{thlabel}, exit_litteral => 'unknown' }
61 ]
62 );
63 }
64
65 sub custom_status_output {
66 my ($self, %options) = @_;
67
68 return 'status: ' . $self->{result_values}->{status} . ', expires in ' . $self->{result_values}->{expires_human};
69 }
70
71 sub prefix_license_output {
72 my ($self, %options) = @_;
73
74 return sprintf(
75 "License '%s' ",
76 $options{instance_value}->{name}
77 );
78 }
79
80 sub set_counters {
81 my ($self, %options) = @_;
82
83 $self->{maps_counters_type} = [
84 {
85 name => 'licenses',
86 type => 1,
87 cb_prefix_output => 'prefix_license_output',
88 message_multiple => 'All licenses are ok',
89 skipped_code => { -10 => 1 }
90 }
91 ];
92
93 $self->{maps_counters}->{licenses} = [
94 {
95 label => 'status',
96 type => 2,
97 critical_default => '%{status} =~ /expired/i',
98 set => {
99 key_values => [ { name => 'name' }, { name => 'status' }, { name => 'expires_human' } ],
100 closure_custom_output => $self->can('custom_status_output'),
101 closure_custom_perfdata => sub {return 0;},
102 closure_custom_threshold_check => \&catalog_status_threshold_ng
103 }
104 },
105 {
106 label => 'expires',
107 type => 1,
108 nlabel => 'license.expires',
109 set => {
110 key_values => [ { name => 'expires_seconds' }, { name => 'expires_human' }, { name => 'name' } ],
111 output_template => 'expires in %s',
112 output_use => 'expires_human',
113 closure_custom_perfdata => $self->can('custom_expires_perfdata'),
114 closure_custom_threshold_check => $self->can('custom_expires_threshold')
115 }
116 }
117 ];
118 }
119
120 sub new {
121 my ($class, %options) = @_;
122 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
123 bless $self, $class;
124
125 $options{options}->add_options(arguments => {
126 'filter-name:s' => { name => 'filter_name' },
127 'unit:s' => { name => 'unit', default => 's' }
128 });
129
130 return $self;
131 }
132
133 my %map_lic_status = (
134 0 => 'none',
135 1 => 'evaluating',
136 2 => 'notsubscribed',
137 3 => 'subscribed',
138 4 => 'expired',
139 5 => 'deactivated'
140 );
141
142 sub check_options {
143 my ($self, %options) = @_;
144 $self->SUPER::check_options(%options);
145
146 if ($self->{option_results}->{unit} eq '' || !defined($unitdiv->{$self->{option_results}->{unit}})) {
147 $self->{option_results}->{unit} = 's';
148 }
149 }
150
151 sub add_license {
152 my ($self, %options) = @_;
153
154 return if (!defined($options{status}));
155 return if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
156 $options{name} !~ /$self->{option_results}->{filter_name}/);
157
158 $self->{licenses}->{ $options{name} } = {
159 name => $options{name},
160 status => $options{status},
161 expires => $options{expires}
162 };
163
164 if (defined($options{expires}) && $options{expires} ne "fail" && $options{status} =~ /subscribed|expired|evaluating/i) {
165 my $strp = DateTime::Format::Strptime->new(
166 pattern => '%b %d %Y',
167 locale => 'en_US',
168 );
169
170 my $dt = $strp->parse_datetime($options{expires});
171
172 $self->{licenses}->{ $options{name} }->{expires_seconds} = $dt->epoch - time();
173 $self->{licenses}->{ $options{name} }->{expires_seconds} = 0 if ($self->{licenses}->{ $options{name} }->{expires_seconds} < 0);
174 $self->{licenses}->{ $options{name} }->{expires_human} = centreon::plugins::misc::change_seconds(
175 value => $self->{licenses}->{ $options{name} }->{expires_seconds}
176 );
177 } else {
178 $self->{licenses}->{ $options{name} }->{expires_human} = "n.d.";
179 }
180 }
181
182 sub manage_selection {
183 my ($self, %options) = @_;
184
185 my $oid_base_fw_lic_status = '.1.3.6.1.4.1.2604.5.1.5.1.1.0';# sfosBaseFWLicRegStatus
186 my $oid_base_fw_lic_expiry_date = '.1.3.6.1.4.1.2604.5.1.5.1.2.0';# sfosBaseFWLicExpiryDate
187 my $oid_net_protection_lic_status = '.1.3.6.1.4.1.2604.5.1.5.2.1.0';# sfosNetProtectionLicRegStatus
188 my $oid_net_protection_lic_expiry_date = '.1.3.6.1.4.1.2604.5.1.5.2.2.0';# sfosNetProtectionLicExpiryDate
189 my $oid_web_protection_lic_status = '.1.3.6.1.4.1.2604.5.1.5.3.1.0';# sfosWebProtectionLicRegStatus
190 my $oid_web_protection_lic_expiry_date = '.1.3.6.1.4.1.2604.5.1.5.3.2.0';# sfosWebProtectionLicExpiryDate
191 my $oid_mail_protection_lic_status = '.1.3.6.1.4.1.2604.5.1.5.4.1.0';# sfosMailProtectionLicRegStatus
192 my $oid_mail_protection_lic_expiry_date = '.1.3.6.1.4.1.2604.5.1.5.4.2.0';# sfosMailProtectionLicExpiryDate
193 my $oid_web_server_protection_lic_status = '.1.3.6.1.4.1.2604.5.1.5.5.1';# sfosWebServerProtectionLicRegStatus
194 my $oid_web_server_protection_lic_expiry_date = '.1.3.6.1.4.1.2604.5.1.5.5.2';# sfosWebServerProtectionLicExpiryDate
195 my $oid_sand_storm_lic_status = '.1.3.6.1.4.1.2604.5.1.5.6.1';# sfosSandstromLicRegStatus
196 my $oid_sand_storm_protection_lic_expiry_date = '.1.3.6.1.4.1.2604.5.1.5.6.2';# sfosSandstromLicExpiryDate
197 my $oid_enhanced_support_lic_status = '.1.3.6.1.4.1.2604.5.1.5.7.1';# sfosEnhancedSupportLicRegStatus
198 my $oid_enhanced_support_lic_expiry_date = '.1.3.6.1.4.1.2604.5.1.5.7.2';# sfosEnhancedSupportLicExpiryDate
199 my $oid_enhanced_plus_lic_status = '.1.3.6.1.4.1.2604.5.1.5.8.1';# sfosEnhancedPlusLicRegStatus
200 my $oid_enhanced_plus_lic_expiry_date = '.1.3.6.1.4.1.2604.5.1.5.8.2';# sfosEnhancedPlusLicExpiryDate
201 my $oid_central_orchestra_lic_status = '.1.3.6.1.4.1.2604.5.1.5.9.1';# sfosCentralOrchestrationLicRegStatus
202 my $oid_central_orchestra_lic_expiry_date = '.1.3.6.1.4.1.2604.5.1.5.9.2';# sfosCentralOrchestrationLicExpiryDate
203
204 my $result = $options{snmp}->get_leef(
205 oids => [
206 $oid_base_fw_lic_status,
207 $oid_base_fw_lic_expiry_date,
208 $oid_net_protection_lic_status,
209 $oid_net_protection_lic_expiry_date,
210 $oid_web_protection_lic_status,
211 $oid_web_protection_lic_expiry_date,
212 $oid_mail_protection_lic_status,
213 $oid_mail_protection_lic_expiry_date,
214 # $oid_web_server_protection_lic_status,
215 # $oid_web_server_protection_lic_expiry_date,
216 # $oid_sand_storm_lic_status,
217 # $oid_sand_storm_protection_lic_expiry_date,
218 # $oid_enhanced_support_lic_status,
219 # $oid_enhanced_support_lic_expiry_date,
220 # $oid_enhanced_plus_lic_status,
221 # $oid_mail_protection_lic_status,
222 # $oid_enhanced_plus_lic_expiry_date,
223 # $oid_central_orchestra_lic_status,
224 # $oid_central_orchestra_lic_expiry_date
225 ],
226 nothing_quit => 1
227 );
228
229 $self->{licenses} = {};
230 $self->add_license(
231 name => 'base_fw',
232 status => $map_lic_status{$result->{$oid_base_fw_lic_status}},
233 expires => $result->{$oid_base_fw_lic_expiry_date}
234 );
235 $self->add_license(
236 name => 'net_protection',
237 status => $map_lic_status{$result->{$oid_net_protection_lic_status}},
238 expires => $result->{$oid_net_protection_lic_expiry_date}
239 );
240 $self->add_license(
241 name => 'web_protection',
242 status => $map_lic_status{$result->{$oid_web_protection_lic_status}},
243 expires => $result->{$oid_web_protection_lic_expiry_date}
244 );
245 $self->add_license(
246 name => 'mail_protection',
247 status => $map_lic_status{$result->{$oid_mail_protection_lic_status}},
248 expires => $result->{$oid_mail_protection_lic_expiry_date}
249 );
250 }
251
252 1;
253
254 __END__
255
256 =head1 MODE
257
258 Check license (SFOS-FIREWALL-MIB).
259
260 =over 8
261
262 =item B<--filter-name>
263
264 Filter licenses by name (can be a regexp).
265
266 =item B<--warning-status>
267
268 Define the conditions to match for the status to be WARNING.
269 You can use the following variables: %{name}, %{status}.
270
271 =item B<--critical-status>
272
273 Define the conditions to match for the status to be CRITICAL (default: '%{status} =~ /expired/i').
274 You can use the following variables: %{name}, %{status}.
275
276 =item B<--unit>
277
278 Select the time unit for the expiration thresholds. May be 's' for seconds, 'm' for minutes, 'h' for hours, 'd' for days, 'w' for weeks. Default is seconds.
279
280 =item B<--warning-expires>
281
282 Threshold.
283 Example: C<--unit=w --warning-expires=2:> will result in a WARNING state when one of the licenses expires in less than
284 two weeks.
285
286 =item B<--critical-expires>
287
288 Threshold.
289 Example: C<--unit=w --critical-expires=2:> will result in a CRITICAL state when one of the licenses expires in less than
290 two weeks.
291
292 =back
293
294 =cut