Debian Codegraph @

src/apps/antivirus/kaspersky/snmp/mode/deployment.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 apps::antivirus::kaspersky::snmp::mode::deployment;
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
29 sub custom_status_output {
30 my ($self, %options) = @_;
31
32 return sprintf("Deployment status is '%s'", $self->{result_values}->{status});
33 }
34
35 sub custom_status_calc {
36 my ($self, %options) = @_;
37
38 $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_deploymentStatus'};
39 return 0;
40 }
41
42 sub custom_progress_perfdata {
43 my ($self, %options) = @_;
44
45 $self->{output}->perfdata_add(
46 label => 'progress',
47 nlabel => $self->{nlabel},
48 value => $self->{result_values}->{installed},
49 min => 0, max => $self->{result_values}->{total}
50 );
51 }
52
53 sub custom_progress_threshold {
54 my ($self, %options) = @_;
55
56 my ($exit, $threshold_value);
57 $threshold_value = defined($self->{instance_mode}->{option_results}->{percent}) ? $self->{result_values}->{prct_installed} : $self->{result_values}->{installed} ;
58 $exit = $self->{perfdata}->threshold_check(
59 value => $threshold_value,
60 threshold => [
61 { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' },
62 { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' }
63 ]
64 );
65 return $exit;
66 }
67
68 sub custom_progress_output {
69 my ($self, %options) = @_;
70
71 return sprintf(
72 "Deployment progress: %d/%d (%.2f%%)",
73 $self->{result_values}->{installed},
74 $self->{result_values}->{total},
75 $self->{result_values}->{prct_installed}
76 );
77 }
78
79 sub custom_progress_calc {
80 my ($self, %options) = @_;
81
82 $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_hostsInGroups'};
83 $self->{result_values}->{installed} = $options{new_datas}->{$self->{instance} . '_hostsWithAntivirus'};
84 $self->{result_values}->{prct_installed} = ($self->{result_values}->{total} != 0) ? $self->{result_values}->{installed} * 100 / $self->{result_values}->{total} : 0;
85
86 return 0;
87 }
88
89 sub custom_expiring_perfdata {
90 my ($self, %options) = @_;
91
92 $self->{output}->perfdata_add(
93 label => 'expiring',
94 nlabel => $self->{nlabel},
95 value => $self->{result_values}->{expiring},
96 warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}),
97 critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}),
98 min => 0
99 );
100 }
101
102 sub custom_expiring_threshold {
103 my ($self, %options) = @_;
104
105 my $exit = $self->{perfdata}->threshold_check(
106 value => $self->{result_values}->{expiring},
107 threshold => [
108 { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' },
109 { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' }
110 ]
111 );
112 return $exit;
113 }
114
115 sub custom_expiring_output {
116 my ($self, %options) = @_;
117
118 my $msg = sprintf("%d host(s) with expiring licence", $self->{result_values}->{expiring});
119 $msg .= sprintf(" [serial: %s] [days: %d]", $self->{result_values}->{serial}, $self->{result_values}->{days}) if ($self->{result_values}->{serial} ne '');
120 return $msg;
121 }
122
123 sub custom_expiring_calc {
124 my ($self, %options) = @_;
125
126 $self->{result_values}->{serial} = $options{new_datas}->{$self->{instance} . '_licenceExpiringSerial'};
127 $self->{result_values}->{days} = $options{new_datas}->{$self->{instance} . '_licenceExpiringDays'};
128 $self->{result_values}->{expiring} = $options{new_datas}->{$self->{instance} . '_hostsLicenceExpiring'};
129
130 return 0;
131 }
132
133 sub custom_expired_perfdata {
134 my ($self, %options) = @_;
135
136 $self->{output}->perfdata_add(
137 label => 'expired',
138 nlabel => $self->{nlabel},
139 value => $self->{result_values}->{expired},
140 warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}),
141 critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}),
142 min => 0
143 );
144 }
145
146 sub custom_expired_threshold {
147 my ($self, %options) = @_;
148
149 my $exit = $self->{perfdata}->threshold_check(
150 value => $self->{result_values}->{expired},
151 threshold => [
152 { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' },
153 { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' }
154 ]
155 );
156 return $exit;
157 }
158
159 sub custom_expired_output {
160 my ($self, %options) = @_;
161
162 my $msg = sprintf("%d host(s) with expired licence", $self->{result_values}->{expired});
163 $msg .= sprintf(" [serial: %s]", $self->{result_values}->{serial}) if ($self->{result_values}->{serial} ne '');
164 return $msg;
165 }
166
167 sub custom_expired_calc {
168 my ($self, %options) = @_;
169
170 $self->{result_values}->{serial} = $options{new_datas}->{$self->{instance} . '_licenceExpiredSerial'};
171 $self->{result_values}->{expired} = $options{new_datas}->{$self->{instance} . '_hostsLicenceExpired'};
172
173 return 0;
174 }
175
176 sub set_counters {
177 my ($self, %options) = @_;
178
179 $self->{maps_counters_type} = [
180 { name => 'global', type => 0, message_separator => ' - ' },
181 ];
182
183 $self->{maps_counters}->{global} = [
184 {
185 label => 'status',
186 type => 2,
187 warning_default => '%{status} =~ /Warning/i',
188 critical_default => '%{status} =~ /Critical/i',
189 set => {
190 key_values => [ { name => 'deploymentStatus' } ],
191 closure_custom_calc => $self->can('custom_status_calc'),
192 closure_custom_output => $self->can('custom_status_output'),
193 closure_custom_perfdata => sub { return 0; },
194 closure_custom_threshold_check => \&catalog_status_threshold_ng,
195 }
196 },
197 { label => 'progress', nlabel => 'hosts.antivirus.installed.count', set => {
198 key_values => [ { name => 'hostsInGroups' }, { name => 'hostsWithAntivirus' } ],
199 closure_custom_calc => $self->can('custom_progress_calc'),
200 closure_custom_output => $self->can('custom_progress_output'),
201 closure_custom_threshold_check => $self->can('custom_progress_threshold'),
202 closure_custom_perfdata => $self->can('custom_progress_perfdata'),
203 }
204 },
205 { label => 'failed', nlabel => 'hosts.antivirus.install.failed.count', set => {
206 key_values => [ { name => 'hostsRemoteInstallFailed' } ],
207 output_template => '%d failed remote installation(s)',
208 perfdatas => [
209 { label => 'failed', template => '%d', min => 0 },
210 ]
211 }
212 },
213 { label => 'expiring', nlabel => 'hosts.expiring.licence.count', set => {
214 key_values => [ { name => 'licenceExpiringSerial' }, { name => 'licenceExpiringDays' }, { name => 'hostsLicenceExpiring' } ],
215 closure_custom_calc => $self->can('custom_expiring_calc'),
216 closure_custom_output => $self->can('custom_expiring_output'),
217 closure_custom_threshold_check => $self->can('custom_expiring_threshold'),
218 closure_custom_perfdata => $self->can('custom_expiring_perfdata'),
219 }
220 },
221 { label => 'expired', nlabel => 'hosts.expired.licence.count', set => {
222 key_values => [ { name => 'licenceExpiredSerial' }, { name => 'hostsLicenceExpired' } ],
223 closure_custom_calc => $self->can('custom_expired_calc'),
224 closure_custom_output => $self->can('custom_expired_output'),
225 closure_custom_threshold_check => $self->can('custom_expired_threshold'),
226 closure_custom_perfdata => $self->can('custom_expired_perfdata'),
227 }
228 }
229 ];
230 }
231
232 sub new {
233 my ($class, %options) = @_;
234 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
235 bless $self, $class;
236
237 $options{options}->add_options(arguments => {
238 'percent' => { name => 'percent' }
239 });
240
241 return $self;
242 }
243
244 my %map_status = (
245 0 => 'OK',
246 1 => 'Info',
247 2 => 'Warning',
248 3 => 'Critical'
249 );
250
251 my $oid_deploymentStatus = '.1.3.6.1.4.1.23668.1093.1.1.1';
252 my $oid_hostsInGroups = '.1.3.6.1.4.1.23668.1093.1.1.3';
253 my $oid_hostsWithAntivirus = '.1.3.6.1.4.1.23668.1093.1.1.4';
254 my $oid_hostsRemoteInstallFailed = '.1.3.6.1.4.1.23668.1093.1.1.5';
255 my $oid_licenceExpiringSerial = '.1.3.6.1.4.1.23668.1093.1.1.6';
256 my $oid_licenceExpiredSerial = '.1.3.6.1.4.1.23668.1093.1.1.7';
257 my $oid_licenceExpiringDays = '.1.3.6.1.4.1.23668.1093.1.1.8';
258 my $oid_hostsLicenceExpiring = '.1.3.6.1.4.1.23668.1093.1.1.9';
259 my $oid_hostsLicenceExpired = '.1.3.6.1.4.1.23668.1093.1.1.10';
260
261 sub manage_selection {
262 my ($self, %options) = @_;
263
264 my $snmp_result = $options{snmp}->get_leef(
265 oids => [
266 $oid_deploymentStatus, $oid_hostsInGroups,
267 $oid_hostsWithAntivirus, $oid_hostsRemoteInstallFailed,
268 $oid_licenceExpiringSerial, $oid_licenceExpiredSerial,
269 $oid_licenceExpiringDays, $oid_hostsLicenceExpiring,
270 $oid_hostsLicenceExpired
271 ],
272 nothing_quit => 1
273 );
274
275 $self->{global} = {
276 deploymentStatus => $map_status{$snmp_result->{$oid_deploymentStatus}},
277 hostsInGroups => $snmp_result->{$oid_hostsInGroups},
278 hostsWithAntivirus => $snmp_result->{$oid_hostsWithAntivirus},
279 hostsRemoteInstallFailed => $snmp_result->{$oid_hostsRemoteInstallFailed},
280 licenceExpiringSerial => $snmp_result->{$oid_licenceExpiringSerial},
281 licenceExpiredSerial => $snmp_result->{$oid_licenceExpiredSerial},
282 licenceExpiringDays => $snmp_result->{$oid_licenceExpiringDays},
283 hostsLicenceExpiring => $snmp_result->{$oid_hostsLicenceExpiring},
284 hostsLicenceExpired => $snmp_result->{$oid_hostsLicenceExpired},
285 };
286 }
287
288 1;
289
290 __END__
291
292 =head1 MODE
293
294 Check antivirus software deployment status.
295
296 =over 8
297
298 =item B<--warning-status>
299
300 Define the conditions to match for the status to be WARNING. (default: '%{status} =~ /Warning/i').
301 Can use special variables like: %{status}
302
303 =item B<--critical-status>
304
305 Define the conditions to match for the status to be CRITICAL. (default: '%{status} =~ /Critical/i').
306 Can use special variables like: %{status}
307
308 =item B<--warning-*>
309
310 Warning threshold.
311 Can be: 'progress' (counter or %), 'failed', 'expiring', 'expired'.
312
313 =item B<--critical-*>
314
315 Critical threshold.
316 Can be: 'progress' (counter or %), 'failed', 'expiring', 'expired'.
317
318 =item B<--percent>
319
320 Set this option if you want to use percent on progress thresholds.
321
322 =back
323
324 =cut