Debian Codegraph @

src/network/symbol/wing/snmp/mode/systems.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 network::symbol::wing::snmp::mode::systems;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27
28 sub custom_memory_usage_output {
29 my ($self, %options) = @_;
30
31 my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total});
32 my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
33 my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
34 return sprintf(
35 "memory usage total: %s used: %s (%.2f%%) free: %s (%.2f%%)",
36 $total_size_value . " " . $total_size_unit,
37 $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
38 $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}
39 );
40 }
41
42 sub device_long_output {
43 my ($self, %options) = @_;
44
45 return "checking device '" . $options{instance_value}->{name} . "'";
46 }
47
48 sub prefix_device_output {
49 my ($self, %options) = @_;
50
51 return "Device '" . $options{instance_value}->{name} . "' ";
52 }
53
54 sub prefix_cpu_output {
55 my ($self, %options) = @_;
56
57 return 'cpu average usage: ';
58 }
59
60 sub set_counters {
61 my ($self, %options) = @_;
62
63 $self->{maps_counters_type} = [
64 { name => 'global', type => 0, skipped_code => { -10 => 1 } },
65 { name => 'devices', type => 3, cb_prefix_output => 'prefix_device_output', cb_long_output => 'device_long_output', indent_long_output => ' ', message_multiple => 'All devices are ok',
66 group => [
67 { name => 'cpu', type => 0, cb_prefix_output => 'prefix_cpu_output', skipped_code => { -10 => 1 } },
68 { name => 'memory', type => 0, skipped_code => { -10 => 1 } },
69 ]
70 }
71 ];
72
73 $self->{maps_counters}->{global} = [
74 { label => 'devices-total', nlabel => 'devices.total.count', display_ok => 0, set => {
75 key_values => [ { name => 'devices'} ],
76 output_template => 'total devices: %s',
77 perfdatas => [
78 { template => '%s', min => 0 },
79 ]
80 }
81 }
82 ];
83
84 $self->{maps_counters}->{cpu} = [
85 { label => 'cpu-utilization-1m', nlabel => 'cpu.utilization.1m.percentage', set => {
86 key_values => [ { name => 'cpu_load1' } ],
87 output_template => '%.2f %% (1m)',
88 perfdatas => [
89 { template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1 }
90 ]
91 }
92 },
93 { label => 'cpu-utilization-5m', nlabel => 'cpu.utilization.5m.percentage', set => {
94 key_values => [ { name => 'cpu_load5' } ],
95 output_template => '%.2f %% (5m)',
96 perfdatas => [
97 { template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1 }
98 ]
99 }
100 },
101 { label => 'cpu-utilization-15m', nlabel => 'cpu.utilization.15m.percentage', set => {
102 key_values => [ { name => 'cpu_load15' } ],
103 output_template => '%.2f %% (15m)',
104 perfdatas => [
105 { template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1 }
106 ]
107 }
108 }
109 ];
110
111 $self->{maps_counters}->{memory} = [
112 { label => 'memory-usage', nlabel => 'device.memory.usage.bytes', set => {
113 key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ],
114 closure_custom_output => $self->can('custom_memory_usage_output'),
115 perfdatas => [
116 { template => '%d', min => 0, max => 'total', unit => 'B', cast_int => 1, label_extra_instance => 1 }
117 ]
118 }
119 },
120 { label => 'memory-usage-free', display_ok => 0, nlabel => 'device.memory.free.bytes', set => {
121 key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ],
122 closure_custom_output => $self->can('custom_memory_usage_output'),
123 perfdatas => [
124 { template => '%d', min => 0, max => 'total', unit => 'B', cast_int => 1, label_extra_instance => 1 }
125 ]
126 }
127 },
128 { label => 'memory-usage-prct', display_ok => 0, nlabel => 'device.memory.usage.percentage', set => {
129 key_values => [ { name => 'prct_used' }, { name => 'free' }, { name => 'used' }, { name => 'prct_free' }, { name => 'total' } ],
130 closure_custom_output => $self->can('custom_memory_usage_output'),
131 perfdatas => [
132 { template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1 }
133 ]
134 }
135 }
136 ];
137 }
138
139 sub new {
140 my ($class, %options) = @_;
141 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
142 bless $self, $class;
143
144 $options{options}->add_options(arguments => {
145 'filter-name:s' => { name => 'filter_name' }
146 });
147
148 return $self;
149 }
150
151 my $mapping = {
152 mem_free => { oid => '.1.3.6.1.4.1.388.50.1.4.2.2.1.1.1' }, # wingStatsDevSysInfoFreeMem
153 mem_total => { oid => '.1.3.6.1.4.1.388.50.1.4.2.2.1.1.2' }, # wingStatsDevSysInfoTotalMem
154 cpu_load1 => { oid => '.1.3.6.1.4.1.388.50.1.4.2.2.1.1.8' }, # wingStatsDevSysInfoLoadLimitS0
155 cpu_load5 => { oid => '.1.3.6.1.4.1.388.50.1.4.2.2.1.1.9' }, # wingStatsDevSysInfoLoadLimitS1
156 cpu_load15 => { oid => '.1.3.6.1.4.1.388.50.1.4.2.2.1.1.10' } # wingStatsDevSysInfoLoadLimitS2
157 };
158
159 sub manage_selection {
160 my ($self, %options) = @_;
161
162 my $oid_hostname = '.1.3.6.1.4.1.388.50.1.4.2.1.1.3'; # wingStatsDevHostname
163 my $snmp_result = $options{snmp}->get_table(
164 oid => $oid_hostname,
165 nothing_quit => 1
166 );
167
168 $self->{devices} = {};
169 foreach (keys %$snmp_result) {
170 /^$oid_hostname\.(.*)$/;
171 my $instance = $1;
172
173 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
174 $snmp_result->{$_} !~ /$self->{option_results}->{filter_name}/) {
175 $self->{output}->output_add(long_msg => "skipping device '" . $snmp_result->{$_} . "'.", debug => 1);
176 next;
177 }
178
179 $self->{devices}->{ $snmp_result->{$_} } = {
180 name => $snmp_result->{$_},
181 instance => $instance
182 };
183 }
184
185 $self->{global} = { devices => scalar(keys %{$self->{devices}}) };
186
187 return if (scalar(keys %{$self->{devices}}) <= 0);
188
189 $options{snmp}->load(
190 oids => [ map($_->{oid}, values(%$mapping)) ],
191 instances => [ map($_->{instance}, values(%{$self->{devices}})) ],
192 instance_regexp => '^(.*)$'
193 );
194 $snmp_result = $options{snmp}->get_leef();
195 foreach (keys %{$self->{devices}}) {
196 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $self->{devices}->{$_}->{instance});
197
198 $self->{devices}->{$_}->{cpu} = {
199 cpu_load1 => $result->{cpu_load1} / 10,
200 cpu_load5 => $result->{cpu_load5} / 10,
201 cpu_load15 => $result->{cpu_load15} / 10
202 };
203 $result->{mem_free} *= 1024;
204 $result->{mem_total} *= 1024;
205 $self->{devices}->{$_}->{memory} = {
206 free => $result->{mem_free},
207 total => $result->{mem_total},
208 used => $result->{mem_total} - $result->{mem_free}
209 };
210 $self->{devices}->{$_}->{memory}->{prct_free} = $result->{mem_free} * 100 / $result->{mem_total};
211 $self->{devices}->{$_}->{memory}->{prct_used} = 100 - $self->{devices}->{$_}->{memory}->{prct_free};
212 }
213 }
214
215 1;
216
217 __END__
218
219 =head1 MODE
220
221 Check systems.
222
223 =over 8
224
225 =item B<--filter-name>
226
227 Filter devices by device hostname (can be a regexp).
228
229 =item B<--warning-*> B<--critical-*>
230
231 Thresholds.
232 Can be: 'devices-total',
233 'memory-usage-prct', 'memory-usage', 'memory-usage-free',
234 'cpu-utilization-1m', 'cpu-utilization-5m', 'cpu-utilization-15m'.
235
236 =back
237
238 =cut