| 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::xppc::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_ng); |
| 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 prefix_global_output { |
| 36 |
my ($self, %options) = @_; |
| 37 |
|
| 38 |
return 'Output lines '; |
| 39 |
} |
| 40 |
|
| 41 |
sub set_counters { |
| 42 |
my ($self, %options) = @_; |
| 43 |
|
| 44 |
$self->{maps_counters_type} = [ |
| 45 |
{ name => 'global', type => 0, cb_prefix_output => 'prefix_global_output', skipped_code => { -10 => 1 } } |
| 46 |
]; |
| 47 |
|
| 48 |
$self->{maps_counters}->{global} = [ |
| 49 |
{ |
| 50 |
label => 'status', |
| 51 |
type => 2, |
| 52 |
unknown_default => '%{status} =~ /unknown/i', |
| 53 |
warning_default => '%{status} =~ /rebooting|onBypass/i', |
| 54 |
critical_default => '%{status} =~ /onBattery/i', |
| 55 |
set => { |
| 56 |
key_values => [ { name => 'status' } ], |
| 57 |
closure_custom_output => $self->can('custom_status_output'), |
| 58 |
closure_custom_perfdata => sub { return 0; }, |
| 59 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 60 |
} |
| 61 |
}, |
| 62 |
{ label => 'load', nlabel => 'lines.output.load.percentage', set => { |
| 63 |
key_values => [ { name => 'upsSmartOutputLoad', no_value => -1 } ], |
| 64 |
output_template => 'load: %.2f %%', |
| 65 |
perfdatas => [ |
| 66 |
{ template => '%.2f', min => 0, max => 100 } |
| 67 |
] |
| 68 |
} |
| 69 |
}, |
| 70 |
{ label => 'frequence', nlabel => 'lines.output.frequence.hertz', set => { |
| 71 |
key_values => [ { name => 'upsSmartOutputFrequency', no_value => 0 } ], |
| 72 |
output_template => 'frequence: %.2f Hz', |
| 73 |
perfdatas => [ |
| 74 |
{ template => '%.2f', unit => 'Hz' } |
| 75 |
] |
| 76 |
} |
| 77 |
}, |
| 78 |
{ label => 'voltage', nlabel => 'lines.output.voltage.volt', set => { |
| 79 |
key_values => [ { name => 'upsSmartOutputVoltage', no_value => 0 } ], |
| 80 |
output_template => 'voltage: %s V', |
| 81 |
perfdatas => [ |
| 82 |
{ template => '%s', unit => 'V' } |
| 83 |
] |
| 84 |
} |
| 85 |
} |
| 86 |
]; |
| 87 |
} |
| 88 |
|
| 89 |
sub new { |
| 90 |
my ($class, %options) = @_; |
| 91 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 92 |
bless $self, $class; |
| 93 |
|
| 94 |
$options{options}->add_options(arguments => { |
| 95 |
}); |
| 96 |
|
| 97 |
return $self; |
| 98 |
} |
| 99 |
|
| 100 |
my $map_status = { |
| 101 |
1 => 'unknown', 2 => 'onLine', |
| 102 |
3 => 'onBattery', 4 => 'onBoost', |
| 103 |
5 => 'sleeping', 6 => 'onBypass', |
| 104 |
7 => 'rebooting', 8 => 'standBy', |
| 105 |
9 => 'onBuck' |
| 106 |
}; |
| 107 |
|
| 108 |
my $mapping = { |
| 109 |
upsBaseOutputStatus => { oid => '.1.3.6.1.4.1.935.1.1.1.4.1.1', map => $map_status }, |
| 110 |
upsSmartOutputVoltage => { oid => '.1.3.6.1.4.1.935.1.1.1.4.2.1' }, # in dV |
| 111 |
upsSmartOutputFrequency => { oid => '.1.3.6.1.4.1.935.1.1.1.4.2.2' }, # in tenth of Hz |
| 112 |
upsSmartOutputLoad => { oid => '.1.3.6.1.4.1.935.1.1.1.4.2.3' } # in % |
| 113 |
}; |
| 114 |
|
| 115 |
sub manage_selection { |
| 116 |
my ($self, %options) = @_; |
| 117 |
|
| 118 |
my $snmp_result = $options{snmp}->get_leef( |
| 119 |
oids => [ map($_->{oid} . '.0', values(%$mapping)) ], |
| 120 |
nothing_quit => 1 |
| 121 |
); |
| 122 |
|
| 123 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => '0'); |
| 124 |
$result->{upsSmartOutputFrequency} = defined($result->{upsSmartOutputFrequency}) ? $result->{upsSmartOutputFrequency} * 0.1 : 0; |
| 125 |
$result->{upsSmartOutputVoltage} = defined($result->{upsSmartOutputVoltage}) ? $result->{upsSmartOutputVoltage} * 0.1 : 0; |
| 126 |
$result->{status} = $result->{upsBaseOutputStatus}; |
| 127 |
|
| 128 |
$self->{global} = $result; |
| 129 |
} |
| 130 |
1; |
| 131 |
|
| 132 |
__END__ |
| 133 |
|
| 134 |
=head1 MODE |
| 135 |
|
| 136 |
Check output lines metrics. |
| 137 |
|
| 138 |
=over 8 |
| 139 |
|
| 140 |
=item B<--unknown-status> |
| 141 |
|
| 142 |
Define the conditions to match for the status to be UNKNOWN (default: '%{status} =~ /unknown/i'). |
| 143 |
You can use the following variables: %{status}. |
| 144 |
|
| 145 |
=item B<--warning-status> |
| 146 |
|
| 147 |
Define the conditions to match for the status to be WARNING (default: '%{status} =~ /rebooting|onBypass/i'). |
| 148 |
You can use the following variables: %{status}. |
| 149 |
|
| 150 |
=item B<--critical-status> |
| 151 |
|
| 152 |
Define the conditions to match for the status to be CRITICAL (default: '%{status} =~ /onBattery/i'). |
| 153 |
You can use the following variables: %{status}. |
| 154 |
|
| 155 |
=item B<--warning-*> B<--critical-*> |
| 156 |
|
| 157 |
Thresholds. |
| 158 |
Can be: 'load', 'voltage', 'current', 'power'. |
| 159 |
|
| 160 |
=back |
| 161 |
|
| 162 |
=cut |