| 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 centreon::common::cps::ups::snmp::mode::outputlines; |
| 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_status_output { |
| 30 |
my ($self, %options) = @_; |
| 31 |
|
| 32 |
return sprintf("status is '%s'", $self->{result_values}->{status}); |
| 33 |
} |
| 34 |
|
| 35 |
sub set_counters { |
| 36 |
my ($self, %options) = @_; |
| 37 |
|
| 38 |
$self->{maps_counters_type} = [ |
| 39 |
{ name => 'olines', type => 0, cb_prefix_output => 'prefix_olines_output', skipped_code => { -10 => 1 } }, |
| 40 |
]; |
| 41 |
|
| 42 |
$self->{maps_counters}->{olines} = [ |
| 43 |
{ label => 'status', threshold => 0, set => { |
| 44 |
key_values => [ { name => 'status' } ], |
| 45 |
closure_custom_calc => \&catalog_status_calc, |
| 46 |
closure_custom_output => $self->can('custom_status_output'), |
| 47 |
closure_custom_perfdata => sub { return 0; }, |
| 48 |
closure_custom_threshold_check => \&catalog_status_threshold, |
| 49 |
} |
| 50 |
}, |
| 51 |
{ label => 'load', nlabel => 'lines.output.load.percentage', set => { |
| 52 |
key_values => [ { name => 'load' } ], |
| 53 |
output_template => 'Load : %.2f %%', |
| 54 |
perfdatas => [ |
| 55 |
{ value => 'load', template => '%.2f', min => 0, max => 100, unit => '%' }, |
| 56 |
], |
| 57 |
} |
| 58 |
}, |
| 59 |
{ label => 'current', nlabel => 'lines.output.current.ampere', set => { |
| 60 |
key_values => [ { name => 'current' } ], |
| 61 |
output_template => 'Current : %.2f A', |
| 62 |
perfdatas => [ |
| 63 |
{ value => 'current', template => '%.2f', min => 0, unit => 'A' }, |
| 64 |
], |
| 65 |
} |
| 66 |
}, |
| 67 |
{ label => 'voltage', nlabel => 'lines.output.voltage.volt', set => { |
| 68 |
key_values => [ { name => 'voltage' } ], |
| 69 |
output_template => 'Voltage : %.2f V', |
| 70 |
perfdatas => [ |
| 71 |
{ value => 'voltage', template => '%.2f', unit => 'V' }, |
| 72 |
], |
| 73 |
} |
| 74 |
}, |
| 75 |
{ label => 'power', nlabel => 'lines.output.power.watt', set => { |
| 76 |
key_values => [ { name => 'power' } ], |
| 77 |
output_template => 'Power : %.2f W', |
| 78 |
perfdatas => [ |
| 79 |
{ value => 'power', template => '%.2f', min => 0, unit => 'W' }, |
| 80 |
], |
| 81 |
} |
| 82 |
}, |
| 83 |
{ label => 'frequence', nlabel => 'lines.output.frequence.hertz', set => { |
| 84 |
key_values => [ { name => 'frequence' } ], |
| 85 |
output_template => 'Frequence : %.2f Hz', |
| 86 |
perfdatas => [ |
| 87 |
{ value => 'frequence', template => '%.2f', min => 0, unit => 'Hz' }, |
| 88 |
], |
| 89 |
} |
| 90 |
}, |
| 91 |
]; |
| 92 |
} |
| 93 |
|
| 94 |
sub prefix_olines_output { |
| 95 |
my ($self, %options) = @_; |
| 96 |
|
| 97 |
return 'Output '; |
| 98 |
} |
| 99 |
|
| 100 |
sub new { |
| 101 |
my ($class, %options) = @_; |
| 102 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 103 |
bless $self, $class; |
| 104 |
|
| 105 |
$options{options}->add_options(arguments => { |
| 106 |
'unknown-status:s' => { name => 'unknown_status', default => '%{status} =~ /unknown/i' }, |
| 107 |
'warning-status:s' => { name => 'warning_status', default => '%{status} =~ /rebooting|onBattery|onBypass/i' }, |
| 108 |
'critical-status:s' => { name => 'critical_status', default => '' }, |
| 109 |
}); |
| 110 |
|
| 111 |
return $self; |
| 112 |
} |
| 113 |
|
| 114 |
sub check_options { |
| 115 |
my ($self, %options) = @_; |
| 116 |
$self->SUPER::check_options(%options); |
| 117 |
|
| 118 |
$self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']); |
| 119 |
} |
| 120 |
|
| 121 |
my $map_status = { |
| 122 |
1 => 'unknown', 2 => 'onLine', |
| 123 |
3 => 'onBattery', 4 => 'onBoost', |
| 124 |
5 => 'onSleep', 6 => 'off', |
| 125 |
7 => 'rebooting', 8 => 'onECO', |
| 126 |
9 => 'onBypass', 10 => 'onBuck', |
| 127 |
11 => 'onOverload', |
| 128 |
}; |
| 129 |
|
| 130 |
my $mapping = { |
| 131 |
upsBaseOutputStatus => { oid => '.1.3.6.1.4.1.3808.1.1.1.4.1.1', map => $map_status }, |
| 132 |
upsAdvanceOutputVoltage => { oid => '.1.3.6.1.4.1.3808.1.1.1.4.2.1' }, # in dV |
| 133 |
upsAdvanceOutputFrequency => { oid => '.1.3.6.1.4.1.3808.1.1.1.4.2.2' }, # in dHz |
| 134 |
upsAdvanceOutputLoad => { oid => '.1.3.6.1.4.1.3808.1.1.1.4.2.3' }, # in % |
| 135 |
upsAdvanceOutputCurrent => { oid => '.1.3.6.1.4.1.3808.1.1.1.4.2.4' }, # in dA |
| 136 |
upsAdvanceOutputPower => { oid => '.1.3.6.1.4.1.3808.1.1.1.4.2.5' }, # in W |
| 137 |
}; |
| 138 |
|
| 139 |
sub manage_selection { |
| 140 |
my ($self, %options) = @_; |
| 141 |
|
| 142 |
my $oid_upsOutput = '.1.3.6.1.4.1.3808.1.1.1.4'; |
| 143 |
my $snmp_result = $options{snmp}->get_table(oid => $oid_upsOutput, nothing_quit => 1); |
| 144 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => '0'); |
| 145 |
|
| 146 |
$self->{olines} = { |
| 147 |
frequence => (defined($result->{upsAdvanceOutputFrequency}) && $result->{upsAdvanceOutputFrequency} =~ /\d/) ? $result->{upsAdvanceOutputFrequency} * 0.1 : undef, |
| 148 |
voltage => (defined($result->{upsAdvanceOutputVoltage}) && $result->{upsAdvanceOutputVoltage} =~ /\d/) ? $result->{upsAdvanceOutputVoltage} * 0.1 : undef, |
| 149 |
current => (defined($result->{upsAdvanceOutputCurrent}) && $result->{upsAdvanceOutputCurrent} =~ /\d/) ? $result->{upsAdvanceOutputCurrent} * 0.1 : undef, |
| 150 |
load => (defined($result->{upsAdvanceOutputLoad}) && $result->{upsAdvanceOutputLoad} =~ /\d/) ? $result->{upsAdvanceOutputLoad} : undef, |
| 151 |
power => (defined($result->{upsAdvanceOutputPower}) && $result->{upsAdvanceOutputPower} =~ /\d/) ? $result->{upsAdvanceOutputPower} : undef, |
| 152 |
status => $result->{upsBaseOutputStatus}, |
| 153 |
}; |
| 154 |
} |
| 155 |
|
| 156 |
1; |
| 157 |
|
| 158 |
__END__ |
| 159 |
|
| 160 |
=head1 MODE |
| 161 |
|
| 162 |
Check output lines metrics. |
| 163 |
|
| 164 |
=over 8 |
| 165 |
|
| 166 |
=item B<--unknown-status> |
| 167 |
|
| 168 |
Define the conditions to match for the status to be UNKNOWN (default: '%{status} =~ /unknown/i'). |
| 169 |
You can use the following variables: %{status} |
| 170 |
|
| 171 |
=item B<--warning-status> |
| 172 |
|
| 173 |
Define the conditions to match for the status to be WARNING (default: '%{status} =~ /rebooting|onBattery|onBypass/i'). |
| 174 |
You can use the following variables: %{status} |
| 175 |
|
| 176 |
=item B<--critical-status> |
| 177 |
|
| 178 |
Define the conditions to match for the status to be CRITICAL (default: ''). |
| 179 |
You can use the following variables: %{status} |
| 180 |
|
| 181 |
=item B<--warning-*> B<--critical-*> |
| 182 |
|
| 183 |
Thresholds. |
| 184 |
Can be: 'load', 'voltage', 'current', 'power', 'frequence'. |
| 185 |
|
| 186 |
=back |
| 187 |
|
| 188 |
=cut |