Debian Codegraph @

src/apps/antivirus/kaspersky/snmp/mode/events.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::events;
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("Events 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} . '_eventsStatus'};
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 => 'eventsStatus' } ],
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 => 'events', nlabel => 'events.critical.count', set => {
64 key_values => [ { name => 'criticalEventsCount' } ],
65 output_template => '%d critical event(s)',
66 perfdatas => [
67 { label => 'events', 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_eventsStatus = '.1.3.6.1.4.1.23668.1093.1.6.1';
93 my $oid_criticalEventsCount = '.1.3.6.1.4.1.23668.1093.1.6.3';
94
95 sub manage_selection {
96 my ($self, %options) = @_;
97
98 my $snmp_result = $options{snmp}->get_leef(
99 oids => [
100 $oid_eventsStatus, $oid_criticalEventsCount
101 ],
102 nothing_quit => 1
103 );
104
105 $self->{global} = {
106 eventsStatus => $map_status{$snmp_result->{$oid_eventsStatus}},
107 criticalEventsCount => $snmp_result->{$oid_criticalEventsCount}
108 };
109 }
110
111 1;
112
113 __END__
114
115 =head1 MODE
116
117 Check events status.
118
119 =over 8
120
121 =item B<--warning-status>
122
123 Define the conditions to match for the status to be WARNING. (default: '%{status} =~ /Warning/i').
124 Can use special variables like: %{status}
125
126 =item B<--critical-status>
127
128 Define the conditions to match for the status to be CRITICAL. (default: '%{status} =~ /Critical/i').
129 Can use special variables like: %{status}
130
131 =item B<--warning-*>
132
133 Warning threshold.
134 Can be: 'events'.
135
136 =item B<--critical-*>
137
138 Critical threshold.
139 Can be: 'events'.
140
141 =back
142
143 =cut