| 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::ats::eaton::snmp::mode::inputlines; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
|
| 28 |
sub set_counters { |
| 29 |
my ($self, %options) = @_; |
| 30 |
|
| 31 |
$self->{maps_counters_type} = [ |
| 32 |
{ name => 'line', type => 1, cb_prefix_output => 'prefix_line_output', message_multiple => 'All input lines are ok', skipped_code => { -10 => 1 } } |
| 33 |
]; |
| 34 |
|
| 35 |
$self->{maps_counters}->{line} = [ |
| 36 |
{ label => 'voltage', nlabel => 'line.input.voltage.volt', set => { |
| 37 |
key_values => [ { name => 'voltage' }, { name => 'display' } ], |
| 38 |
output_template => 'Voltage : %.2f V', |
| 39 |
perfdatas => [ |
| 40 |
{ value => 'voltage', template => '%s', |
| 41 |
unit => 'V', label_extra_instance => 1, instance_use => 'display' }, |
| 42 |
], |
| 43 |
} |
| 44 |
}, |
| 45 |
{ label => 'frequence', nlabel => 'line.input.frequence.hertz', set => { |
| 46 |
key_values => [ { name => 'frequency', no_value => -1 } ], |
| 47 |
output_template => 'Frequence : %.2f Hz', |
| 48 |
perfdatas => [ |
| 49 |
{ value => 'frequency', template => '%.2f', |
| 50 |
unit => 'Hz', label_extra_instance => 1 }, |
| 51 |
], |
| 52 |
} |
| 53 |
}, |
| 54 |
]; |
| 55 |
} |
| 56 |
|
| 57 |
sub prefix_line_output { |
| 58 |
my ($self, %options) = @_; |
| 59 |
|
| 60 |
return "Input Line '" . $options{instance_value}->{display} . "' "; |
| 61 |
} |
| 62 |
|
| 63 |
sub new { |
| 64 |
my ($class, %options) = @_; |
| 65 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 66 |
bless $self, $class; |
| 67 |
|
| 68 |
$options{options}->add_options(arguments => { |
| 69 |
}); |
| 70 |
|
| 71 |
return $self; |
| 72 |
} |
| 73 |
|
| 74 |
my $map_input_name = { |
| 75 |
1 => 'source-1', |
| 76 |
2 => 'source-2', |
| 77 |
}; |
| 78 |
|
| 79 |
sub check_ats { |
| 80 |
my ($self, %options) = @_; |
| 81 |
|
| 82 |
return if (scalar(keys %{$self->{line}}) > 0); |
| 83 |
|
| 84 |
my $mapping = { |
| 85 |
atsInputIndex => { oid => '.1.3.6.1.4.1.534.10.1.3.1.1.1', map => $map_input_name }, |
| 86 |
atsInputVoltage => { oid => '.1.3.6.1.4.1.534.10.1.3.1.1.2' }, |
| 87 |
atsInputFrequency => { oid => '.1.3.6.1.4.1.534.10.1.3.1.1.3' }, |
| 88 |
}; |
| 89 |
|
| 90 |
my $oid_atsInputEntry = '.1.3.6.1.4.1.534.10.1.3.1.1'; |
| 91 |
my $snmp_result = $options{snmp}->get_table(oid => $oid_atsInputEntry, nothing_quit => 1); |
| 92 |
|
| 93 |
foreach my $oid (keys %{$snmp_result}) { |
| 94 |
next if ($oid !~ /^$mapping->{atsInputIndex}->{oid}\.(.*)$/); |
| 95 |
my $instance = $1; |
| 96 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); |
| 97 |
|
| 98 |
$self->{line}->{$result->{atsInputIndex}} = { |
| 99 |
display => $result->{atsInputIndex}, |
| 100 |
voltage => $result->{atsInputVoltage} * 0.1, |
| 101 |
frequency => $result->{atsInputFrequency} * 0.1, |
| 102 |
}; |
| 103 |
} |
| 104 |
} |
| 105 |
|
| 106 |
sub check_ats2 { |
| 107 |
my ($self, %options) = @_; |
| 108 |
|
| 109 |
my $mapping = { |
| 110 |
ats2InputIndex => { oid => '.1.3.6.1.4.1.534.10.2.2.2.1.1', map => $map_input_name }, |
| 111 |
ats2InputVoltage => { oid => '.1.3.6.1.4.1.534.10.2.2.2.1.2' }, |
| 112 |
ats2InputFrequency => { oid => '.1.3.6.1.4.1.534.10.2.2.2.1.3' }, |
| 113 |
}; |
| 114 |
|
| 115 |
my $oid_ats2InputEntry = '.1.3.6.1.4.1.534.10.2.2.2.1'; |
| 116 |
my $snmp_result = $options{snmp}->get_table(oid => $oid_ats2InputEntry); |
| 117 |
|
| 118 |
foreach my $oid (keys %{$snmp_result}) { |
| 119 |
next if ($oid !~ /^$mapping->{ats2InputIndex}->{oid}\.(.*)$/); |
| 120 |
my $instance = $1; |
| 121 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); |
| 122 |
|
| 123 |
$self->{line}->{$result->{ats2InputIndex}} = { |
| 124 |
display => $result->{ats2InputIndex}, |
| 125 |
voltage => $result->{ats2InputVoltage} * 0.1, |
| 126 |
frequency => $result->{ats2InputFrequency} * 0.1, |
| 127 |
}; |
| 128 |
} |
| 129 |
} |
| 130 |
|
| 131 |
sub manage_selection { |
| 132 |
my ($self, %options) = @_; |
| 133 |
|
| 134 |
$self->{line} = {}; |
| 135 |
|
| 136 |
$self->check_ats2(%options); |
| 137 |
$self->check_ats(%options); |
| 138 |
|
| 139 |
if (scalar(keys %{$self->{line}}) <= 0) { |
| 140 |
$self->{output}->add_option_msg(short_msg => "No line found."); |
| 141 |
$self->{output}->option_exit(); |
| 142 |
} |
| 143 |
} |
| 144 |
|
| 145 |
1; |
| 146 |
|
| 147 |
__END__ |
| 148 |
|
| 149 |
=head1 MODE |
| 150 |
|
| 151 |
Check input lines. |
| 152 |
|
| 153 |
=over 8 |
| 154 |
|
| 155 |
=item B<--filter-counters> |
| 156 |
|
| 157 |
Only display some counters (regexp can be used). |
| 158 |
Example: --filter-counters='^voltage$' |
| 159 |
|
| 160 |
=item B<--warning-*> B<--critical-*> |
| 161 |
|
| 162 |
Warning threshold. |
| 163 |
Can be: 'voltage', 'frequence'. |
| 164 |
|
| 165 |
=back |
| 166 |
|
| 167 |
=cut |