Debian Codegraph @

src/hardware/pdu/emerson/snmp/mode/globalstatus.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::emerson::snmp::mode::globalstatus;
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);
28
29 sub custom_status_output {
30 my ($self, %options) = @_;
31 my $msg = "status is '" . $self->{result_values}->{status} . "'";
32
33 return $msg;
34 }
35
36 sub custom_status_calc {
37 my ($self, %options) = @_;
38
39 $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'};
40 $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
41 return 0;
42 }
43
44 sub set_counters {
45 my ($self, %options) = @_;
46
47 $self->{maps_counters_type} = [
48 { name => 'pdu', type => 1, cb_prefix_output => 'prefix_pdu_output', message_multiple => 'All PDU status are ok' }
49 ];
50
51 $self->{maps_counters}->{pdu} = [
52 { label => 'status', threshold => 0, set => {
53 key_values => [ { name => 'status' }, { name => 'display' } ],
54 closure_custom_calc => $self->can('custom_status_calc'),
55 closure_custom_output => $self->can('custom_status_output'),
56 closure_custom_perfdata => sub { return 0; },
57 closure_custom_threshold_check => \&catalog_status_threshold,
58 }
59 },
60 ];
61 }
62
63 sub new {
64 my ($class, %options) = @_;
65 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
66 bless $self, $class;
67
68 $options{options}->add_options(arguments => {
69 'filter-name:s' => { name => 'filter_name' },
70 'warning-status:s' => { name => 'warning_status', default => '%{status} =~ /normalWithWarning/i' },
71 'critical-status:s' => { name => 'critical_status', default => '%{status} =~ /normalWithAlarm|abnormalOperation/i' },
72 });
73
74 return $self;
75 }
76
77 sub check_options {
78 my ($self, %options) = @_;
79 $self->SUPER::check_options(%options);
80
81 $self->change_macros(macros => ['warning_status', 'critical_status']);
82 }
83
84 sub prefix_pdu_output {
85 my ($self, %options) = @_;
86
87 return "PDU '" . $options{instance_value}->{display} . "' ";
88 }
89
90 my %bitmap_status = (
91 1 => 'normalOperation',
92 2 => 'startUp',
93 8 => 'normalWithWarning',
94 16 => 'normalWithAlarm',
95 32 => 'abnormalOperation',
96 );
97 my $mapping = {
98 lgpPduEntryUsrLabel => { oid => '.1.3.6.1.4.1.476.1.42.3.8.20.1.10' },
99 lgpPduEntrySysStatus => { oid => '.1.3.6.1.4.1.476.1.42.3.8.20.1.25' },
100 };
101 my $oid_lgpPduEntry = '.1.3.6.1.4.1.476.1.42.3.8.20.1';
102
103 sub manage_selection {
104 my ($self, %options) = @_;
105
106 $self->{pdu} = {};
107 $self->{results} = $options{snmp}->get_table(
108 oid => $oid_lgpPduEntry,
109 start => $mapping->{lgpPduEntryUsrLabel}->{oid},
110 end => $mapping->{lgpPduEntrySysStatus}->{oid},
111 nothing_quit => 1
112 );
113
114 foreach my $oid (keys %{$self->{results}}) {
115 next if ($oid !~ /^$mapping->{lgpPduEntrySysStatus}->{oid}\.(.*)$/);
116 my $instance = $1;
117
118 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $self->{results}, instance => $instance);
119 my $name = defined($result->{lgpPduEntryUsrLabel}) && $result->{lgpPduEntryUsrLabel} ne '' ?
120 $result->{lgpPduEntryUsrLabel} : $instance;
121 my $status = 'unknown';
122 foreach (keys %bitmap_status) {
123 if ((int($result->{lgpPduEntrySysStatus}) & $_)) {
124 $status = $bitmap_status{$_};
125 last;
126 }
127 }
128 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
129 $name !~ /$self->{option_results}->{filter_name}/) {
130 $self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter.", debug => 1);
131 next;
132 }
133
134 $self->{pdu}->{$instance} = { display => $name,
135 status => $status };
136 }
137
138 if (scalar(keys %{$self->{pdu}}) <= 0) {
139 $self->{output}->add_option_msg(short_msg => "Cannot find pdu.");
140 $self->{output}->option_exit();
141 }
142 }
143
144 1;
145
146 __END__
147
148 =head1 MODE
149
150 Check global status.
151
152 =over 8
153
154 =item B<--filter-name>
155
156 Filter PDU name (can be a regexp).
157
158 =item B<--warning-status>
159
160 Define the conditions to match for the status to be WARNING (default: '%{status} =~ /normalWithWarning/i').
161 You can use the following variables: %{status}, %{display}.
162
163 =item B<--critical-status>
164
165 Define the conditions to match for the status to be CRITICAL (default: '%{status} =~ /normalWithAlarm|abnormalOperation/i').
166 You can use the following variables: %{status}, %{display}
167
168 =back
169
170 =cut