Debian Codegraph @

src/apps/antivirus/mcafee/webgateway/snmp/mode/detections.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::detections;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27 use Digest::MD5 qw(md5_hex);
28
29 sub set_counters {
30 my ($self, %options) = @_;
31
32 $self->{maps_counters_type} = [
33 { name => 'global', type => 0 },
34 { name => 'categories', type => 1, cb_prefix_output => 'prefix_categories_output',
35 message_multiple => 'All categories are ok' }
36 ];
37
38 $self->{maps_counters}->{global} = [
39 { label => 'malware-detected', nlabel => 'malwares.detected.persecond', set => {
40 key_values => [ { name => 'stMalwareDetected', per_second => 1 } ],
41 output_template => 'Malware detected (per sec): %d',
42 perfdatas => [
43 { label => 'malware_detected', template => '%d', min => 0, unit => 'detections/s' }
44 ]
45 }
46 }
47 ];
48 $self->{maps_counters}->{categories} = [
49 { label => 'category', nlabel => 'category.malwares.detected.persecond', set => {
50 key_values => [ { name => 'stCategoryCount', per_second => 1 }, { name => 'stCategoryName' } ],
51 output_template => 'detections (per sec): %d',
52 perfdatas => [
53 { label => 'category', template => '%d',
54 min => 0, unit => 'detections/s', label_extra_instance => 1,
55 instance_use => 'stCategoryName' }
56 ]
57 }
58 }
59 ];
60 }
61
62 sub prefix_categories_output {
63 my ($self, %options) = @_;
64
65 return "Category '" . $options{instance_value}->{stCategoryName} . "' ";
66 }
67
68 sub new {
69 my ($class, %options) = @_;
70 my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
71 bless $self, $class;
72
73 $options{options}->add_options(arguments => {
74 'filter-name:s' => { name => 'filter_name' }
75 });
76
77 return $self;
78 }
79
80 my $oid_stMalwareDetected = '.1.3.6.1.4.1.1230.2.7.2.1.2.0';
81
82 my $mapping = {
83 stCategoryName => { oid => '.1.3.6.1.4.1.1230.2.7.2.1.10.1.1' },
84 stCategoryCount => { oid => '.1.3.6.1.4.1.1230.2.7.2.1.10.1.2' },
85 };
86 my $oid_stCategoriesEntry = '.1.3.6.1.4.1.1230.2.7.2.1.10.1';
87
88 sub manage_selection {
89 my ($self, %options) = @_;
90
91 $self->{cache_name} = 'mcafee_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' .
92 (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')) . '_' .
93 (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
94
95 my $results = $options{snmp}->get_leef(oids => [ $oid_stMalwareDetected ], nothing_quit => 1);
96 my $results2 = $options{snmp}->get_table(oid => $oid_stCategoriesEntry, nothing_quit => 1);
97
98 $self->{global} = {
99 stMalwareDetected => $results->{$oid_stMalwareDetected},
100 };
101
102 $self->{categories} = {};
103 foreach my $oid (keys %{$results2}) {
104 next if ($oid !~ /^$mapping->{stCategoryName}->{oid}\.(\d+)/);
105 my $instance = $1;
106 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $results2, instance => $instance);
107
108 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
109 $result->{stCategoryName} !~ /$self->{option_results}->{filter_name}/) {
110 $self->{output}->output_add(long_msg => "skipping '" . $result->{stCategoryName} . "': no matching filter name.", debug => 1);
111 next;
112 }
113
114 $self->{categories}->{ $result->{stCategoryName} } = {
115 stCategoryName => $result->{stCategoryName},
116 stCategoryCount => $result->{stCategoryCount}
117 }
118 }
119
120 if (scalar(keys %{$self->{categories}}) <= 0) {
121 $self->{output}->add_option_msg(short_msg => "No categories found.");
122 $self->{output}->option_exit();
123 }
124 }
125
126 1;
127
128 __END__
129
130 =head1 MODE
131
132 Check detections statistics.
133
134 =over 8
135
136 =item B<--filter-name>
137
138 Filter category name (can be a regexp).
139
140 =item B<--filter-counters>
141
142 Only display some counters (regexp can be used).
143 (example: --filter-counters='^(?!(category)$)')
144
145 =item B<--warning-*>
146
147 Warning threshold.
148 Can be: 'malware-detected', 'category'
149
150 =item B<--critical-*>
151
152 Critical threshold.
153 Can be: 'malware-detected', 'category'
154
155 =back
156
157 =cut