Debian Codegraph @

src/apps/antivirus/mcafee/webgateway/snmp/mode/versions.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::mcafee::webgateway::snmp::mode::versions;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27 use centreon::plugins::statefile;
28 use Digest::MD5 qw(md5_hex);
29
30 sub custom_version_calc {
31 my ($self, %options) = @_;
32
33 $self->{result_values}->{output} = $options{extra_options}->{output_ref};
34 $self->{result_values}->{version} = $options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{label_ref}};
35 $self->{result_values}->{timestamp} = $options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{label_ref} . '_timestamp'};
36 $self->{result_values}->{since} = time() - $self->{result_values}->{timestamp};
37
38 return 0;
39 }
40
41 sub custom_version_threshold {
42 my ($self, %options) = @_;
43
44 return $self->{perfdata}->threshold_check(
45 value => $self->{result_values}->{since},
46 threshold => [
47 { label => 'critical-' . $self->{label}, exit_litteral => 'critical' },
48 { label => 'warning-' . $self->{label}, exit_litteral => 'warning' }
49 ]
50 );
51 }
52
53 sub custom_version_output {
54 my ($self, %options) = @_;
55
56 return sprintf(
57 "%s: %s [Last update: %s]",
58 $self->{result_values}->{output},
59 $self->{result_values}->{version},
60 centreon::plugins::misc::change_seconds(value => $self->{result_values}->{since})
61 );
62 }
63
64 sub set_counters {
65 my ($self, %options) = @_;
66
67 $self->{maps_counters_type} = [
68 { name => 'global', type => 0, skipped_code => { -10 => 1 } }
69 ];
70
71 $self->{maps_counters}->{global} = [
72 { label => 'dat-version', set => {
73 key_values => [ { name => 'pMFEDATVersion' }, { name => 'pMFEDATVersion_timestamp' } ],
74 closure_custom_calc => $self->can('custom_version_calc'),
75 closure_custom_calc_extra_options => { label_ref => 'pMFEDATVersion', output_ref => 'DAT Version' },
76 closure_custom_output => $self->can('custom_version_output'),
77 closure_custom_perfdata => sub { return 0; },
78 closure_custom_threshold_check => $self->can('custom_version_threshold')
79 }
80 },
81 { label => 'tsdb-version', set => {
82 key_values => [ { name => 'pTSDBVersion' }, { name => 'pTSDBVersion_timestamp' } ],
83 closure_custom_calc => $self->can('custom_version_calc'),
84 closure_custom_calc_extra_options => { label_ref => 'pTSDBVersion', output_ref => 'TrustedSource Database Version' },
85 closure_custom_output => $self->can('custom_version_output'),
86 closure_custom_perfdata => sub { return 0; },
87 closure_custom_threshold_check => $self->can('custom_version_threshold')
88 }
89 },
90 { label => 'proactive-version', set => {
91 key_values => [ { name => 'pAMProactiveVersion' }, { name => 'pAMProactiveVersion_timestamp' } ],
92 closure_custom_calc => $self->can('custom_version_calc'),
93 closure_custom_calc_extra_options => { label_ref => 'pAMProactiveVersion', output_ref => 'ProActive Database Version' },
94 closure_custom_output => $self->can('custom_version_output'),
95 closure_custom_perfdata => sub { return 0; },
96 closure_custom_threshold_check => $self->can('custom_version_threshold')
97 }
98 }
99 ];
100 }
101
102 sub new {
103 my ($class, %options) = @_;
104 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
105 bless $self, $class;
106
107 $options{options}->add_options(arguments => {
108 });
109
110 $self->{cache} = centreon::plugins::statefile->new(%options);
111 return $self;
112 }
113
114 sub check_options {
115 my ($self, %options) = @_;
116 $self->SUPER::check_options(%options);
117
118 $self->{cache}->check_options(%options);
119 }
120
121 my $oid_pMFEDATVersion = '.1.3.6.1.4.1.1230.2.7.1.20.4.0';
122 my $oid_pAMProactiveVersion = '.1.3.6.1.4.1.1230.2.7.1.20.5.0';
123 my $oid_pTSDBVersion = '.1.3.6.1.4.1.1230.2.7.1.20.6.0';
124
125 sub manage_selection {
126 my ($self, %options) = @_;
127
128 $self->{cache}->read(statefile => 'mcafee_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' .
129 (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')));
130
131 my $results = $options{snmp}->get_leef(
132 oids => [ $oid_pMFEDATVersion, $oid_pAMProactiveVersion, $oid_pTSDBVersion ],
133 nothing_quit => 1
134 );
135
136 $self->{new_datas} = {
137 pMFEDATVersion => $results->{$oid_pMFEDATVersion},
138 pAMProactiveVersion => $results->{$oid_pAMProactiveVersion},
139 pTSDBVersion => $results->{$oid_pTSDBVersion}
140 };
141
142 foreach my $version (('pMFEDATVersion', 'pAMProactiveVersion', 'pTSDBVersion')) {
143 next if (!defined($self->{new_datas}->{$version}) || $self->{new_datas}->{$version} eq '');
144 $self->{new_datas}->{$version . '_timestamp'} = ($self->{new_datas}->{$version} > $self->{cache}->{datas}->{$version}) ? time() : $self->{cache}->{datas}->{$version . '_timestamp'};
145 $self->{new_datas}->{$version . '_timestamp'} = time() if (!defined($self->{new_datas}->{$version . '_timestamp'}));
146 }
147
148 $self->{global} = { %{$self->{new_datas}} };
149
150 $self->{cache}->write(data => $self->{new_datas});
151 }
152
153 1;
154
155 __END__
156
157 =head1 MODE
158
159 Check signature databases versions
160 (last update is only guessed by version's changement,
161 it does not appear clearly in the MIB).
162
163 =over 8
164
165 =item B<--filter-counters>
166
167 Only display some counters (regexp can be used).
168 (example: --filter-counters='dat')
169
170 =item B<--warning-*>
171
172 Warning threshold on last update.
173 Can be: 'dat-version', 'tsdb-version', 'proactive-version'.
174
175 =item B<--critical-*>
176
177 Critical threshold on last update.
178 Can be: 'dat-version', 'tsdb-version', 'proactive-version'.
179
180 =back
181
182 =cut