| 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::socomec::netvision::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("Output source status is '%s'", $self->{result_values}->{status}); |
| 33 |
} |
| 34 |
|
| 35 |
sub prefix_oline_output { |
| 36 |
my ($self, %options) = @_; |
| 37 |
|
| 38 |
return "Output line '" . $options{instance_value}->{display} . "' "; |
| 39 |
} |
| 40 |
|
| 41 |
sub set_counters { |
| 42 |
my ($self, %options) = @_; |
| 43 |
|
| 44 |
$self->{maps_counters_type} = [ |
| 45 |
{ name => 'global', type => 0, skipped_code => { -10 => 1 } }, |
| 46 |
{ name => 'oline', type => 1, cb_prefix_output => 'prefix_oline_output', message_multiple => 'All output lines are ok', skipped_code => { -10 => 1 } } |
| 47 |
]; |
| 48 |
|
| 49 |
$self->{maps_counters}->{global} = [ |
| 50 |
{ |
| 51 |
label => 'source-status', |
| 52 |
type => 2, |
| 53 |
unknown_default => '%{status} =~ /unknown/i', |
| 54 |
set => { |
| 55 |
key_values => [ { name => 'status' } ], |
| 56 |
closure_custom_output => $self->can('custom_status_output'), |
| 57 |
closure_custom_perfdata => sub { return 0; }, |
| 58 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 59 |
} |
| 60 |
} |
| 61 |
]; |
| 62 |
|
| 63 |
$self->{maps_counters}->{oline} = [ |
| 64 |
{ label => 'load', nlabel => 'line.output.load.percentage', set => { |
| 65 |
key_values => [ { name => 'percent_load' } ], |
| 66 |
output_template => 'load: %.2f %%', |
| 67 |
perfdatas => [ |
| 68 |
{ template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1 } |
| 69 |
] |
| 70 |
} |
| 71 |
}, |
| 72 |
{ label => 'current', nlabel => 'line.output.current.ampere', set => { |
| 73 |
key_values => [ { name => 'current' } ], |
| 74 |
output_template => 'current: %.2f A', |
| 75 |
perfdatas => [ |
| 76 |
{ template => '%.2f', min => 0, unit => 'A', label_extra_instance => 1 } |
| 77 |
] |
| 78 |
} |
| 79 |
}, |
| 80 |
{ label => 'voltage', nlabel => 'line.output.voltage.volt', set => { |
| 81 |
key_values => [ { name => 'voltage' } ], |
| 82 |
output_template => 'voltage: %.2f V', |
| 83 |
perfdatas => [ |
| 84 |
{ template => '%.2f', unit => 'V', label_extra_instance => 1 } |
| 85 |
] |
| 86 |
} |
| 87 |
} |
| 88 |
]; |
| 89 |
} |
| 90 |
|
| 91 |
sub new { |
| 92 |
my ($class, %options) = @_; |
| 93 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 94 |
bless $self, $class; |
| 95 |
|
| 96 |
$options{options}->add_options(arguments => { |
| 97 |
'ignore-zero-counters' => { name => 'ignore_zero_counters' } |
| 98 |
}); |
| 99 |
|
| 100 |
return $self; |
| 101 |
} |
| 102 |
|
| 103 |
my $map_status = { |
| 104 |
1 => 'unknown', 2 => 'onMaintenBypass', 3 => 'onInverter', |
| 105 |
4 => 'normalMode', 5 => 'ecoMode', 6 => 'onBypass', |
| 106 |
7 => 'standby', 8 => 'upsOff' |
| 107 |
}; |
| 108 |
|
| 109 |
my $mapping = { |
| 110 |
netvision5 => { |
| 111 |
voltage => { oid => '.1.3.6.1.4.1.4555.1.1.1.1.4.4.1.2' }, # upsOutputVoltage (Volt) |
| 112 |
current => { oid => '.1.3.6.1.4.1.4555.1.1.1.1.4.4.1.3' }, # upsOutputCurrent (dA) |
| 113 |
percent_load => { oid => '.1.3.6.1.4.1.4555.1.1.1.1.4.4.1.4' } # upsOutputPercentLoad |
| 114 |
}, |
| 115 |
netvision6 => { |
| 116 |
voltage => { oid => '.1.3.6.1.4.1.4555.1.1.7.1.4.4.1.2' }, # upsOutputVoltage (Volt) |
| 117 |
current => { oid => '.1.3.6.1.4.1.4555.1.1.7.1.4.4.1.3' }, # upsOutputCurrent (dA) |
| 118 |
percent_load => { oid => '.1.3.6.1.4.1.4555.1.1.7.1.4.4.1.4' } # upsOutputPercentLoad |
| 119 |
} |
| 120 |
}; |
| 121 |
my $mapping2 = { |
| 122 |
netvision5 => { |
| 123 |
status => { oid => '.1.3.6.1.4.1.4555.1.1.1.1.4.1', map => $map_status } # upsOutputSource |
| 124 |
}, |
| 125 |
netvision6 => { |
| 126 |
status => { oid => '.1.3.6.1.4.1.4555.1.1.7.1.4.1', map => $map_status } # upsOutputSource |
| 127 |
} |
| 128 |
}; |
| 129 |
my $tables = { |
| 130 |
netvision5 => { |
| 131 |
upsOutput => '.1.3.6.1.4.1.4555.1.1.1.1.4', |
| 132 |
upsOutputEntry => '.1.3.6.1.4.1.4555.1.1.1.1.4.4.1' |
| 133 |
}, |
| 134 |
netvision6 => { |
| 135 |
upsOutput => '.1.3.6.1.4.1.4555.1.1.7.1.4', |
| 136 |
upsOutputEntry => '.1.3.6.1.4.1.4555.1.1.7.1.4.4.1' |
| 137 |
} |
| 138 |
}; |
| 139 |
|
| 140 |
sub manage_selection { |
| 141 |
my ($self, %options) = @_; |
| 142 |
|
| 143 |
my $label = 'netvision6'; |
| 144 |
my $snmp_result = $options{snmp}->get_table( |
| 145 |
oid => $tables->{$label}->{upsOutput}, |
| 146 |
end => $mapping->{$label}->{percent_load}->{oid} |
| 147 |
); |
| 148 |
if (scalar(keys %$snmp_result) <= 0) { |
| 149 |
$label = 'netvision5'; |
| 150 |
$snmp_result = $options{snmp}->get_table( |
| 151 |
oid => $tables->{$label}->{upsOutput}, |
| 152 |
end => $mapping->{$label}->{percent_load}->{oid}, |
| 153 |
nothing_quit => 1 |
| 154 |
); |
| 155 |
} |
| 156 |
|
| 157 |
$self->{oline} = {}; |
| 158 |
foreach my $oid (keys %$snmp_result) { |
| 159 |
next if ($oid !~ /^$tables->{$label}->{upsOutputEntry}\.\d+\.(.*)$/); |
| 160 |
my $instance = $1; |
| 161 |
next if (defined($self->{oline}->{$instance})); |
| 162 |
|
| 163 |
my $result = $options{snmp}->map_instance(mapping => $mapping->{$label}, results => $snmp_result, instance => $instance); |
| 164 |
foreach (keys %$result) { |
| 165 |
delete $result->{$_} if ( |
| 166 |
(defined($self->{option_results}->{ignore_zero_counters}) && $result->{$_} == 0) || |
| 167 |
($result->{$_} == -1 || $result->{$_} == 65535) |
| 168 |
); |
| 169 |
} |
| 170 |
$result->{current} *= 0.1 if (defined($result->{current})); |
| 171 |
$result->{voltage} *= 0.1 if (defined($result->{voltage})); |
| 172 |
if (scalar(keys %$result) > 0) { |
| 173 |
$self->{oline}->{$instance} = { display => $instance, %$result }; |
| 174 |
} |
| 175 |
} |
| 176 |
|
| 177 |
$self->{global} = $options{snmp}->map_instance(mapping => $mapping2->{$label}, results => $snmp_result, instance => 0); |
| 178 |
} |
| 179 |
|
| 180 |
1; |
| 181 |
|
| 182 |
__END__ |
| 183 |
|
| 184 |
=head1 MODE |
| 185 |
|
| 186 |
Check output lines. |
| 187 |
|
| 188 |
=over 8 |
| 189 |
|
| 190 |
=item B<--ignore-zero-counters> |
| 191 |
|
| 192 |
Ignore counters equals to 0. |
| 193 |
|
| 194 |
=item B<--unknown-source-status> |
| 195 |
|
| 196 |
Define the conditions to match for the status to be UNKNOWN (default: '%{status} =~ /unknown/i'). |
| 197 |
You can use the following variables: %{status} |
| 198 |
|
| 199 |
=item B<--warning-source-status> |
| 200 |
|
| 201 |
Define the conditions to match for the status to be WARNING. |
| 202 |
You can use the following variables: %{status} |
| 203 |
|
| 204 |
=item B<--critical-source-status> |
| 205 |
|
| 206 |
Define the conditions to match for the status to be CRITICAL. |
| 207 |
You can use the following variables: %{status} |
| 208 |
|
| 209 |
=item B<--warning-*> B<--critical-*> |
| 210 |
|
| 211 |
Thresholds. |
| 212 |
Can be: 'load', 'voltage', 'current'. |
| 213 |
|
| 214 |
=back |
| 215 |
|
| 216 |
=cut |