Debian Codegraph @

src/apps/antivirus/kaspersky/snmp/mode/logicalnetwork.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::logicalnetwork;
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("Logical network 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} . '_logicalNetworkStatus'};
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 => 'logicalNetworkStatus' } ],
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 => 'new-hosts', nlabel => 'hosts.new.count', set => {
64 key_values => [ { name => 'hostsFound' } ],
65 output_template => '%d new host(s) found',
66 perfdatas => [
67 { label => 'new_hosts', template => '%d', min => 0 }
68 ]
69 }
70 },
71 { label => 'groups', nlabel => 'groups.total.count', set => {
72 key_values => [ { name => 'groupsCount' } ],
73 output_template => '%d group(s) on the server',
74 perfdatas => [
75 { label => 'groups', template => '%d', min => 0 }
76 ]
77 }
78 },
79 { label => 'not-connected-long-time', nlabel => 'hosts.notconnected.count', set => {
80 key_values => [ { name => 'hostsNotConnectedLongTime' } ],
81 output_template => '%d host(s) has not connected for a long time',
82 perfdatas => [
83 { label => 'not_connected_long_time', template => '%d', min => 0 }
84 ]
85 }
86 },
87 { label => 'not-controlled', nlabel => 'hosts.uncontrolled.count', set => {
88 key_values => [ { name => 'hostsControlLost' } ],
89 output_template => '%d host(s) are not controlled',
90 perfdatas => [
91 { label => 'not_controlled', template => '%d', min => 0 }
92 ]
93 }
94 }
95 ];
96 }
97
98 sub new {
99 my ($class, %options) = @_;
100 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
101 bless $self, $class;
102
103 $options{options}->add_options(arguments => {
104 });
105
106 return $self;
107 }
108
109 my %map_status = (
110 0 => 'OK',
111 1 => 'Info',
112 2 => 'Warning',
113 3 => 'Critical'
114 );
115
116 my $oid_logicalNetworkStatus = '.1.3.6.1.4.1.23668.1093.1.5.1';
117 my $oid_hostsFound = '.1.3.6.1.4.1.23668.1093.1.5.3';
118 my $oid_groupsCount = '.1.3.6.1.4.1.23668.1093.1.5.4';
119 my $oid_hostsNotConnectedLongTime = '.1.3.6.1.4.1.23668.1093.1.5.5';
120 my $oid_hostsControlLost = '.1.3.6.1.4.1.23668.1093.1.5.6';
121
122 sub manage_selection {
123 my ($self, %options) = @_;
124
125 my $snmp_result = $options{snmp}->get_leef(
126 oids => [
127 $oid_logicalNetworkStatus, $oid_hostsFound,
128 $oid_groupsCount, $oid_hostsNotConnectedLongTime,
129 $oid_hostsControlLost
130 ],
131 nothing_quit => 1
132 );
133
134 $self->{global} = {
135 logicalNetworkStatus => $map_status{$snmp_result->{$oid_logicalNetworkStatus}},
136 hostsFound => $snmp_result->{$oid_hostsFound},
137 groupsCount => $snmp_result->{$oid_groupsCount},
138 hostsNotConnectedLongTime => $snmp_result->{$oid_hostsNotConnectedLongTime},
139 hostsControlLost => $snmp_result->{$oid_hostsControlLost}
140 };
141 }
142
143 1;
144
145 __END__
146
147 =head1 MODE
148
149 Check logical network status.
150
151 =over 8
152
153 =item B<--warning-status>
154
155 Define the conditions to match for the status to be WARNING. (default: '%{status} =~ /Warning/i').
156 Can use special variables like: %{status}
157
158 =item B<--critical-status>
159
160 Define the conditions to match for the status to be CRITICAL. (default: '%{status} =~ /Critical/i').
161 Can use special variables like: %{status}
162
163 =item B<--warning-*>
164
165 Warning threshold.
166 Can be: 'new-hosts', 'groups', 'not-connected-long-time',
167 'not-controlled'.
168
169 =item B<--critical-*>
170
171 Critical threshold.
172 Can be: 'new-hosts', 'groups', 'not-connected-long-time',
173 'not-controlled'.
174
175 =back
176
177 =cut