| 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::ups::mge::snmp::mode::inputlines; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
|
| 28 |
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); |
| 29 |
|
| 30 |
sub custom_status_output { |
| 31 |
my ($self, %options) = @_; |
| 32 |
|
| 33 |
my $msg = "Input Line(s) bad status is '" . $self->{result_values}->{badstatus} . "' [failcause = " . $self->{result_values}->{failcause} . "]"; |
| 34 |
return $msg; |
| 35 |
} |
| 36 |
|
| 37 |
sub custom_status_calc { |
| 38 |
my ($self, %options) = @_; |
| 39 |
|
| 40 |
$self->{result_values}->{badstatus} = $options{new_datas}->{$self->{instance} . '_badstatus'}; |
| 41 |
$self->{result_values}->{failcause} = $options{new_datas}->{$self->{instance} . '_failcause'}; |
| 42 |
return 0; |
| 43 |
} |
| 44 |
|
| 45 |
sub set_counters { |
| 46 |
my ($self, %options) = @_; |
| 47 |
|
| 48 |
$self->{maps_counters_type} = [ |
| 49 |
{ name => 'global', type => 0, skipped_code => { -10 => 1 } }, |
| 50 |
{ name => 'iline', type => 1, cb_prefix_output => 'prefix_iline_output', message_multiple => 'All input lines are ok', skipped_code => { -10 => 1 } }, |
| 51 |
]; |
| 52 |
|
| 53 |
$self->{maps_counters}->{global} = [ |
| 54 |
{ label => 'status', set => { |
| 55 |
key_values => [ { name => 'badstatus' }, { name => 'failcause' } ], |
| 56 |
closure_custom_calc => $self->can('custom_status_calc'), |
| 57 |
closure_custom_output => $self->can('custom_status_output'), |
| 58 |
closure_custom_perfdata => sub { return 0; }, |
| 59 |
closure_custom_threshold_check => \&catalog_status_threshold, |
| 60 |
} |
| 61 |
}, |
| 62 |
]; |
| 63 |
|
| 64 |
$self->{maps_counters}->{iline} = [ |
| 65 |
{ label => 'current', set => { |
| 66 |
key_values => [ { name => 'mginputCurrent', no_value => 0 } ], |
| 67 |
output_template => 'Current : %.2f A', |
| 68 |
perfdatas => [ |
| 69 |
{ label => 'current', value => 'mginputCurrent', template => '%.2f', |
| 70 |
min => 0, unit => 'A', label_extra_instance => 1 }, |
| 71 |
], |
| 72 |
} |
| 73 |
}, |
| 74 |
{ label => 'voltage', set => { |
| 75 |
key_values => [ { name => 'mginputVoltage', no_value => 0 } ], |
| 76 |
output_template => 'Voltage : %.2f V', |
| 77 |
perfdatas => [ |
| 78 |
{ label => 'voltage', value => 'mginputVoltage', template => '%.2f', |
| 79 |
unit => 'V', label_extra_instance => 1 }, |
| 80 |
], |
| 81 |
} |
| 82 |
}, |
| 83 |
{ label => 'frequence', set => { |
| 84 |
key_values => [ { name => 'mginputFrequency', no_value => 0 } ], |
| 85 |
output_template => 'Frequence : %.2f Hz', |
| 86 |
perfdatas => [ |
| 87 |
{ label => 'frequence', value => 'mginputFrequency', template => '%.2f', |
| 88 |
unit => 'Hz', label_extra_instance => 1 }, |
| 89 |
], |
| 90 |
} |
| 91 |
}, |
| 92 |
]; |
| 93 |
} |
| 94 |
|
| 95 |
sub new { |
| 96 |
my ($class, %options) = @_; |
| 97 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options); |
| 98 |
bless $self, $class; |
| 99 |
|
| 100 |
$options{options}->add_options(arguments => { |
| 101 |
"warning-status:s" => { name => 'warning_status' }, |
| 102 |
"critical-status:s" => { name => 'critical_status', default => '%{badstatus} =~ /yes/' }, |
| 103 |
}); |
| 104 |
|
| 105 |
return $self; |
| 106 |
} |
| 107 |
|
| 108 |
sub check_options { |
| 109 |
my ($self, %options) = @_; |
| 110 |
$self->SUPER::check_options(%options); |
| 111 |
|
| 112 |
$self->change_macros(macros => ['warning_status', 'critical_status']); |
| 113 |
} |
| 114 |
|
| 115 |
sub prefix_iline_output { |
| 116 |
my ($self, %options) = @_; |
| 117 |
|
| 118 |
return "Input Line '" . $options{instance_value}->{display} . "' "; |
| 119 |
} |
| 120 |
|
| 121 |
my %map_input_failcause = ( |
| 122 |
1 => 'no', |
| 123 |
2 => 'outoftolvolt', |
| 124 |
3 => 'outoftolfreq', |
| 125 |
4 => 'utilityoff', |
| 126 |
); |
| 127 |
my %map_bad_status = ( |
| 128 |
1 => 'yes', |
| 129 |
2 => 'no', |
| 130 |
); |
| 131 |
|
| 132 |
my $mapping = { |
| 133 |
mginputVoltage => { oid => '.1.3.6.1.4.1.705.1.6.2.1.2' }, # in dV |
| 134 |
mginputFrequency => { oid => '.1.3.6.1.4.1.705.1.6.2.1.3' }, # in dHz |
| 135 |
mginputCurrent => { oid => '.1.3.6.1.4.1.705.1.6.2.1.6' }, # in dA |
| 136 |
}; |
| 137 |
my $oid_upsmgInput = '.1.3.6.1.4.1.705.1.6'; |
| 138 |
my $oid_upsmgInputPhaseEntry = '.1.3.6.1.4.1.705.1.6.2.1'; |
| 139 |
my $oid_upsmgInputPhaseNum = '.1.3.6.1.4.1.705.1.6.1.0'; |
| 140 |
my $oid_upsmgInputBadStatus = '.1.3.6.1.4.1.705.1.6.3.0'; |
| 141 |
my $oid_upsmgInputLineFailCause = '.1.3.6.1.4.1.705.1.6.4.0'; |
| 142 |
|
| 143 |
sub manage_selection { |
| 144 |
my ($self, %options) = @_; |
| 145 |
|
| 146 |
$self->{iline} = {}; |
| 147 |
my $snmp_result = $options{snmp}->get_table( |
| 148 |
oid => $oid_upsmgInput, |
| 149 |
nothing_quit => 1 |
| 150 |
); |
| 151 |
|
| 152 |
if (!defined($snmp_result->{$oid_upsmgInputPhaseNum}) || |
| 153 |
$snmp_result->{$oid_upsmgInputPhaseNum} == 0) { |
| 154 |
$self->{output}->add_option_msg(short_msg => "No input lines found."); |
| 155 |
$self->{output}->option_exit(); |
| 156 |
} |
| 157 |
|
| 158 |
foreach my $oid (keys %{$snmp_result}) { |
| 159 |
next if ($oid !~ /^$oid_upsmgInputPhaseEntry\.\d+\.(.*)$/); |
| 160 |
my $instance = $1; |
| 161 |
next if (defined($self->{iline}->{$instance})); |
| 162 |
|
| 163 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); |
| 164 |
$result->{mginputVoltage} *= 0.1 if (defined($result->{mginputVoltage})); |
| 165 |
$result->{mginputFrequency} *= 0.1 if (defined($result->{mginputFrequency})); |
| 166 |
$result->{mginputCurrent} *= 0.1 if (defined($result->{mginputCurrent})); |
| 167 |
next if ((!defined($result->{mginputVoltage}) || $result->{mginputVoltage} == 0) && |
| 168 |
(!defined($result->{mginputFrequency}) || $result->{mginputFrequency} == 0) && |
| 169 |
(!defined($result->{mginputCurrent}) || $result->{mginputCurrent} == 0)); |
| 170 |
$self->{iline}->{$instance} = { display => $instance, %$result }; |
| 171 |
} |
| 172 |
|
| 173 |
$self->{global} = { |
| 174 |
badstatus => $map_bad_status{$snmp_result->{$oid_upsmgInputBadStatus}}, |
| 175 |
failcause => $map_input_failcause{$snmp_result->{$oid_upsmgInputLineFailCause}}, |
| 176 |
}; |
| 177 |
} |
| 178 |
|
| 179 |
1; |
| 180 |
|
| 181 |
__END__ |
| 182 |
|
| 183 |
=head1 MODE |
| 184 |
|
| 185 |
Check Input lines metrics (frequence, voltage, current). |
| 186 |
|
| 187 |
=over 8 |
| 188 |
|
| 189 |
=item B<--warning-*> |
| 190 |
|
| 191 |
Warning threshold. |
| 192 |
Can be: 'frequence', 'voltage', 'current'. |
| 193 |
|
| 194 |
=item B<--critical-*> |
| 195 |
|
| 196 |
Critical threshold. |
| 197 |
Can be: 'frequence', 'voltage', 'current'. |
| 198 |
|
| 199 |
=item B<--warning-status> |
| 200 |
|
| 201 |
Define the conditions to match for the status to be WARNING (default: ''). |
| 202 |
You can use the following variables: %{badstatus}, %{failcause} |
| 203 |
|
| 204 |
=item B<--critical-status> |
| 205 |
|
| 206 |
Define the conditions to match for the status to be CRITICAL (default: '%{badstatus} =~ /yes/'). |
| 207 |
You can use the following variables: %{badstatus}, %{failcause} |
| 208 |
|
| 209 |
=back |
| 210 |
|
| 211 |
=cut |