Debian Codegraph @

src/hardware/pdu/eaton/snmp/mode/group.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 hardware::pdu::eaton::snmp::mode::group;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27
28 sub set_counters {
29 my ($self, %options) = @_;
30
31 $self->{maps_counters_type} = [
32 { name => 'group', type => 1, cb_prefix_output => 'prefix_group_output', message_multiple => 'All groups are ok', skipped_code => { -10 => 1 } }
33 ];
34
35 $self->{maps_counters}->{group} = [
36 { label => 'current', nlabel => 'group.current.ampere', set => {
37 key_values => [ { name => 'groupCurrent', no_value => 0 }, { name => 'display' } ],
38 output_template => 'Current : %.2f A',
39 perfdatas => [
40 { value => 'groupCurrent', template => '%.2f',
41 min => 0, unit => 'A', label_extra_instance => 1, instance_use => 'display' }
42 ]
43 }
44 },
45 { label => 'voltage', nlabel => 'group.voltage.volt', set => {
46 key_values => [ { name => 'groupVoltage', no_value => 0 }, { name => 'display' } ],
47 output_template => 'Voltage : %.2f V',
48 perfdatas => [
49 { value => 'groupVoltage', template => '%.2f',
50 unit => 'V', label_extra_instance => 1, instance_use => 'display' }
51 ]
52 }
53 },
54 { label => 'power', nlabel => 'group.power.watt', set => {
55 key_values => [ { name => 'groupWatts', no_value => 0 }, { name => 'display' } ],
56 output_template => 'Power : %.2f W',
57 perfdatas => [
58 { value => 'groupWatts', template => '%.2f',
59 unit => 'W', label_extra_instance => 1, instance_use => 'display' }
60 ]
61 }
62 }
63 ];
64 }
65
66 sub new {
67 my ($class, %options) = @_;
68 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
69 bless $self, $class;
70
71 $options{options}->add_options(arguments => {
72 'filter-name:s' => { name => 'filter_name' }
73 });
74
75 return $self;
76 }
77
78 sub prefix_group_output {
79 my ($self, %options) = @_;
80
81 return "Group '" . $options{instance_value}->{display} . "' ";
82 }
83
84 my $mapping = {
85 groupName => { oid => '.1.3.6.1.4.1.534.6.6.7.5.1.1.3' },
86 groupVoltage => { oid => '.1.3.6.1.4.1.534.6.6.7.5.3.1.3' }, # in mVolt
87 groupCurrent => { oid => '.1.3.6.1.4.1.534.6.6.7.5.4.1.3' }, # in mA
88 groupWatts => { oid => '.1.3.6.1.4.1.534.6.6.7.5.5.1.3' }, # in Watt
89 };
90
91 sub manage_selection {
92 my ($self, %options) = @_;
93
94 my $snmp_result = $options{snmp}->get_multiple_table(
95 oids => [
96 { oid => $mapping->{groupName}->{oid} },
97 { oid => $mapping->{groupVoltage}->{oid} },
98 { oid => $mapping->{groupCurrent}->{oid} },
99 { oid => $mapping->{groupWatts}->{oid} },
100 ],
101 return_type => 1, nothing_quit => 1
102 );
103
104 $self->{group} = {};
105 foreach my $oid (keys %{$snmp_result}) {
106 $oid =~ /\.(\d+)\.(\d+)$/;
107 my ($strapping_index, $group_index) = ($1, $2);
108 next if (defined($self->{group}->{$strapping_index . '.' . $group_index}));
109
110 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $strapping_index . '.' . $group_index);
111 $result->{groupVoltage} *= 0.001 if (defined($result->{groupVoltage}));
112 $result->{groupCurrent} *= 0.001 if (defined($result->{groupCurrent}));
113 my $display = $strapping_index . '.' . $group_index;
114 if (defined($result->{groupName}) && $result->{groupName} ne '') {
115 $display = $result->{groupName} . ' strapping ' . $strapping_index;
116 }
117
118 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
119 $display !~ /$self->{option_results}->{filter_name}/) {
120 $self->{output}->output_add(long_msg => "skipping '" . $display . "': no matching filter.", debug => 1);
121 next;
122 }
123
124 $self->{group}->{$strapping_index . '.' . $group_index} = { display => $display, %$result };
125 }
126
127 if (scalar(keys %{$self->{group}}) <= 0) {
128 $self->{output}->add_option_msg(short_msg => "No group found.");
129 $self->{output}->option_exit();
130 }
131 }
132
133 1;
134
135 __END__
136
137 =head1 MODE
138
139 Check group metrics (voltage, current and power).
140
141 =over 8
142
143 =item B<--filter-name>
144
145 Filter group name (can be a regexp).
146
147 =item B<--warning-*>
148
149 Warning threshold.
150 Can be: 'voltage', 'current', 'power'.
151
152 =item B<--critical-*>
153
154 Critical threshold.
155 Can be: 'voltage', 'current', 'power'.
156
157 =back
158
159 =cut