Debian Codegraph @

src/network/ucopia/wlc/snmp/mode/system.pm

raw
1 #
2 # Copyright 2018 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 network::ucopia::wlc::snmp::mode::system;
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 catalog_status_calc);
28
29 sub custom_service_status_output {
30 my ($self, %options) = @_;
31
32 my $msg = sprintf("status is %s",
33 $self->{result_values}->{status},
34 );
35 return $msg;
36 }
37
38 sub custom_ha_status_output {
39 my ($self, %options) = @_;
40
41 my $msg = sprintf("high-availablity status is %s",
42 $self->{result_values}->{ha_status},
43 );
44 return $msg;
45 }
46
47 sub custom_users_output {
48 my ($self, %options) = @_;
49
50 my $msg = sprintf("%d connected users (Available licence: %s)",
51 $self->{result_values}->{connected_users},
52 $self->{result_values}->{max_users} ne '' ? $self->{result_values}->{max_users} : '-'
53 );
54 return $msg;
55 }
56
57 sub set_counters {
58 my ($self, %options) = @_;
59
60 $self->{maps_counters_type} = [
61 { name => 'global', type => 0, message_separator => ' - ', skipped_code => { -10 => 1 } },
62 { name => 'service', type => 1, cb_prefix_output => 'prefix_service_output', message_multiple => 'All services are ok', skipped_code => { -10 => 1 } }
63 ];
64
65 $self->{maps_counters}->{global} = [
66 { label => 'users-connected', nlabel => 'system.users.connected.count', set => {
67 key_values => [ { name => 'connected_users' }, { name => 'max_users' } ],
68 closure_custom_output => $self->can('custom_users_output'),
69 perfdatas => [
70 { value => 'connected_users', template => '%s', min => 0, max => 'max_users' },
71 ],
72 }
73 },
74 { label => 'users-connected-prct', nlabel => 'system.users.connected.percentage', display_ok => 0, set => {
75 key_values => [ { name => 'connected_users_prct' } ],
76 output_template => 'users connected: %.2f %%',
77 perfdatas => [
78 { value => 'connected_users_prct', template => '%.2f', unit => '%', min => 0, max => 100 },
79 ],
80 }
81 },
82 { label => 'ha-status', threshold => 0, set => {
83 key_values => [ { name => 'ha_status' } ],
84 closure_custom_calc => \&catalog_status_calc,
85 closure_custom_output => $self->can('custom_ha_status_output'),
86 closure_custom_perfdata => sub { return 0; },
87 closure_custom_threshold_check => \&catalog_status_threshold,
88 }
89 },
90 { label => 'disk-temperature', nlabel => 'system.disk.temperature.celsius', display_ok => 0, set => {
91 key_values => [ { name => 'disk_temperature', no_value => 0 } ],
92 output_template => 'disk temperature: %s C',
93 perfdatas => [
94 { value => 'disk_temperature', template => '%s', unit => 'C' },
95 ],
96 }
97 },
98 { label => 'cpu-temperature', nlabel => 'system.cpu.temperature.celsius', display_ok => 0, set => {
99 key_values => [ { name => 'cpu_temperature', no_value => 0 } ],
100 output_template => 'cpu temperature: %s C',
101 perfdatas => [
102 { value => 'cpu_temperature', template => '%s', unit => 'C' },
103 ],
104 }
105 },
106 ];
107
108 $self->{maps_counters}->{service} = [
109 { label => 'service-status', threshold => 0, set => {
110 key_values => [ { name => 'status' }, { name => 'display' } ],
111 closure_custom_calc => \&catalog_status_calc,
112 closure_custom_output => $self->can('custom_service_status_output'),
113 closure_custom_perfdata => sub { return 0; },
114 closure_custom_threshold_check => \&catalog_status_threshold,
115 }
116 },
117 ];
118 }
119
120 sub prefix_service_output {
121 my ($self, %options) = @_;
122
123 return "Service '" . $options{instance_value}->{display} . "' ";
124 }
125
126 sub new {
127 my ($class, %options) = @_;
128 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
129 bless $self, $class;
130
131 $options{options}->add_options(arguments => {
132 'warning-service-status:s' => { name => 'warning_service_status', default => '' },
133 'critical-service-status:s' => { name => 'critical_service_status', default => '%{status} eq "stopped"' },
134 'warning-ha-status:s' => { name => 'warning_ha_status', default => '' },
135 'critical-ha-status:s' => { name => 'critical_ha_status', default => '%{ha_status} eq "fault"' },
136 });
137
138 return $self;
139 }
140
141 sub check_options {
142 my ($self, %options) = @_;
143 $self->SUPER::check_options(%options);
144
145 $self->change_macros(macros => [
146 'warning_service_status', 'critical_service_status',
147 'warning_ha_status', 'critical_ha_status',
148 ]);
149 }
150
151 my $map_sc_status = { 1 => 'running', 2 => 'stopped', 3 => 'disabled' };
152 my $map_ha_status = { 0 => 'standalone', 1 => 'master', 2 => 'active', 3 => 'passive', 4 => 'fault' };
153
154 my $mapping = {
155 totalConnectedUsers => { oid => '.1.3.6.1.4.1.31218.3.1' },
156 cpuTemperature => { oid => '.1.3.6.1.4.1.31218.3.3' },
157 diskTemperature => { oid => '.1.3.6.1.4.1.31218.3.4' },
158 licenseUsers => { oid => '.1.3.6.1.4.1.31218.3.5' },
159 highAvailabilityStatus => { oid => '.1.3.6.1.4.1.31218.3.7', map => $map_ha_status },
160 };
161
162 my $mapping2 = {
163 webServer => { oid => '.1.3.6.1.4.1.31218.4.1', map => $map_sc_status },
164 sqlServer => { oid => '.1.3.6.1.4.1.31218.4.2', map => $map_sc_status },
165 urlSniffer => { oid => '.1.3.6.1.4.1.31218.4.3', map => $map_sc_status },
166 portal => { oid => '.1.3.6.1.4.1.31218.4.4', map => $map_sc_status },
167 webProxy => { oid => '.1.3.6.1.4.1.31218.4.5', map => $map_sc_status },
168 autodisconnect => { oid => '.1.3.6.1.4.1.31218.4.6', map => $map_sc_status },
169 printingServer => { oid => '.1.3.6.1.4.1.31218.4.7', map => $map_sc_status },
170 dhcpServer => { oid => '.1.3.6.1.4.1.31218.4.8', map => $map_sc_status },
171 dnsServer => { oid => '.1.3.6.1.4.1.31218.4.9', map => $map_sc_status },
172 staticIpManager => { oid => '.1.3.6.1.4.1.31218.4.10', map => $map_sc_status },
173 highAvailability => { oid => '.1.3.6.1.4.1.31218.4.11', map => $map_sc_status },
174 ldapDirectory => { oid => '.1.3.6.1.4.1.31218.4.12', map => $map_sc_status },
175 ldapReplicationManager => { oid => '.1.3.6.1.4.1.31218.4.13', map => $map_sc_status },
176 timeServer => { oid => '.1.3.6.1.4.1.31218.4.14', map => $map_sc_status },
177 radiusServer => { oid => '.1.3.6.1.4.1.31218.4.15', map => $map_sc_status },
178 samba => { oid => '.1.3.6.1.4.1.31218.4.16', map => $map_sc_status },
179 ssh => { oid => '.1.3.6.1.4.1.31218.4.17', map => $map_sc_status },
180 syslog => { oid => '.1.3.6.1.4.1.31218.4.18', map => $map_sc_status },
181 usersLog => { oid => '.1.3.6.1.4.1.31218.4.19', map => $map_sc_status },
182 pmsClient => { oid => '.1.3.6.1.4.1.31218.4.20', map => $map_sc_status },
183 };
184
185 sub manage_selection {
186 my ($self, %options) = @_;
187
188 my $snmp_result = $options{snmp}->get_leef(
189 oids => [ map($_->{oid} . '.0', values(%$mapping)), map($_->{oid} . '.0', values(%$mapping2)) ], nothing_quit => 1
190 );
191
192 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => '0');
193 $self->{global} = {
194 ha_status => $result->{highAvailabilityStatus},
195 disk_temperature => $result->{diskTemperature},
196 cpu_temperature => $result->{cpuTemperature},
197 connected_users => $result->{totalConnectedUsers},
198 max_users => defined($result->{licenseUsers}) ? $result->{licenseUsers} : '',
199 connected_users_prct => defined($result->{licenseUsers}) && $result->{licenseUsers} != 0 ? $result->{totalConnectedUsers} * 100 / $result->{licenseUsers} : undef
200 };
201
202 $result = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result, instance => '0');
203 $self->{service} = {};
204 foreach (keys %$result) {
205 $self->{service}->{$_} = { display => $_, status => $result->{$_} };
206 }
207 }
208
209 1;
210
211 __END__
212
213 =head1 MODE
214
215 Check system.
216
217 =over 8
218
219 =item B<--filter-counters>
220
221 Only display some counters (regexp can be used).
222 Example: --filter-counters='service-status'
223
224 =item B<--warning-service-status>
225
226 Define the conditions to match for the status to be WARNING (default: '').
227 You can use the following variables: %{status}, %{display}
228
229 =item B<--critical-service-status>
230
231 Define the conditions to match for the status to be CRITICAL (default: '%{status} eq "stopped"').
232 You can use the following variables: %{status}, %{display}
233
234 =item B<--warning-ha-status>
235
236 Define the conditions to match for the status to be WARNING (default: '').
237 You can use the following variables: %{ha_status}
238
239 =item B<--critical-ha-status>
240
241 Define the conditions to match for the status to be CRITICAL (default: '%{ha_status} eq "fault"').
242 You can use the following variables: %{ha_status}
243
244 =item B<--warning-*> B<--critical-*>
245
246 Thresholds.
247 Can be: 'users-connected', 'users-connected-prct',
248 'disk-temperature', 'cpu-temperature'.
249
250 =back
251
252 =cut