Debian Codegraph @

src/apps/antivirus/kaspersky/snmp/mode/fullscan.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::fullscan;
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("Full scan 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} . '_fullscanStatus'};
39 return 0;
40 }
41
42 sub set_counters {
43 my ($self, %options) = @_;
44
45 $self->{maps_counters_type} = [
46 { name => 'global', type => 0, message_separator => ' - ' },
47 ];
48
49 $self->{maps_counters}->{global} = [
50 {
51 label => 'status',
52 type => 2,
53 warning_default => '%{status} =~ /Warning/i',
54 critical_default => '%{status} =~ /Critical/i',
55 set => {
56 key_values => [ { name => 'fullscanStatus' } ],
57 closure_custom_calc => $self->can('custom_status_calc'),
58 closure_custom_output => $self->can('custom_status_output'),
59 closure_custom_perfdata => sub { return 0; },
60 closure_custom_threshold_check => \&catalog_status_threshold_ng
61 }
62 },
63 { label => 'not-scanned', nlabel => 'hosts.unscanned.count', set => {
64 key_values => [ { name => 'hostsNotScannedLately' } ],
65 output_template => '%d hosts(s) has not been scanned lately',
66 perfdatas => [
67 { label => 'not_scanned', template => '%d', min => 0 }
68 ]
69 }
70 }
71 ];
72 }
73
74 sub new {
75 my ($class, %options) = @_;
76 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
77 bless $self, $class;
78
79 $options{options}->add_options(arguments => {
80 });
81
82 return $self;
83 }
84
85 my %map_status = (
86 0 => 'OK',
87 1 => 'Info',
88 2 => 'Warning',
89 3 => 'Critical'
90 );
91
92 my $oid_fullscanStatus = '.1.3.6.1.4.1.23668.1093.1.4.1';
93 my $oid_hostsNotScannedLately = '.1.3.6.1.4.1.23668.1093.1.4.3';
94
95 sub manage_selection {
96 my ($self, %options) = @_;
97
98 my $snmp_result = $options{snmp}->get_leef(
99 oids => [ $oid_fullscanStatus, $oid_hostsNotScannedLately ],
100 nothing_quit => 1
101 );
102
103 $self->{global} = {
104 fullscanStatus => $map_status{$snmp_result->{$oid_fullscanStatus}},
105 hostsNotScannedLately => $snmp_result->{$oid_hostsNotScannedLately}
106 };
107 }
108
109 1;
110
111 __END__
112
113 =head1 MODE
114
115 Check full scan status.
116
117 =over 8
118
119 =item B<--warning-status>
120
121 Define the conditions to match for the status to be WARNING. (default: '%{status} =~ /Warning/i').
122 Can use special variables like: %{status}
123
124 =item B<--critical-status>
125
126 Define the conditions to match for the status to be CRITICAL. (default: '%{status} =~ /Critical/i').
127 Can use special variables like: %{status}
128
129 =item B<--warning-*>
130
131 Warning threshold.
132 Can be: 'not-scanned'.
133
134 =item B<--critical-*>
135
136 Critical threshold.
137 Can be: 'not-scanned'.
138
139 =back
140
141 =cut