| 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::ees::snmp::mode::system; |
| 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 |
my $map_system_status = { |
| 30 |
1 => 'unknown', |
| 31 |
2 => 'normal', |
| 32 |
3 => 'warning', |
| 33 |
4 => 'minor', |
| 34 |
5 => 'major', |
| 35 |
6 => 'critical', |
| 36 |
7 => 'unmanaged', |
| 37 |
8 => 'restricted', |
| 38 |
9 => 'testing', |
| 39 |
10 => 'disabled' |
| 40 |
}; |
| 41 |
|
| 42 |
my $map_communication_status = { |
| 43 |
1 => 'unknown', |
| 44 |
2 => 'normal', |
| 45 |
3 => 'interrupt' |
| 46 |
}; |
| 47 |
|
| 48 |
sub status_custom_output { |
| 49 |
my ($self, %options) = @_; |
| 50 |
|
| 51 |
return sprintf( |
| 52 |
"system status: '%s' - communication status: '%s'", |
| 53 |
$self->{result_values}->{system_status}, |
| 54 |
$self->{result_values}->{communication_status} |
| 55 |
); |
| 56 |
} |
| 57 |
|
| 58 |
sub set_counters { |
| 59 |
my ($self, %options) = @_; |
| 60 |
|
| 61 |
$self->{maps_counters_type} = [ |
| 62 |
{ name => 'system', type => 0 } |
| 63 |
]; |
| 64 |
|
| 65 |
$self->{maps_counters}->{system} = [ |
| 66 |
{ |
| 67 |
label => 'status', |
| 68 |
unknown_default => '%{system_status} =~ /unknown|unmanaged|restricted|testing|disabled/i || %{communication_status} =~ /unknown/i', |
| 69 |
warning_default => '%{system_status} =~ /warning|minor/i', |
| 70 |
critical_default => '%{system_status} =~ /major|critical/i || %{communication_status} =~ /interrupt/i', |
| 71 |
type => 2, |
| 72 |
set => { |
| 73 |
key_values => [ |
| 74 |
{ name => 'system_status' }, |
| 75 |
{ name => 'communication_status' } |
| 76 |
], |
| 77 |
closure_custom_threshold_check => \&catalog_status_threshold_ng, |
| 78 |
closure_custom_perfdata => sub {return 0;}, |
| 79 |
closure_custom_output => $self->can('status_custom_output') |
| 80 |
} |
| 81 |
}, |
| 82 |
{ |
| 83 |
label => 'voltage', nlabel => 'system.voltage.volt', |
| 84 |
set => { |
| 85 |
key_values => [ { name => 'voltage' } ], |
| 86 |
output_template => 'voltage: %.2fV', |
| 87 |
perfdatas => [ { template => '%.2f', unit => 'V' } ] |
| 88 |
} |
| 89 |
}, |
| 90 |
{ |
| 91 |
label => 'current', nlabel => 'system.current.ampere', |
| 92 |
set => { |
| 93 |
key_values => [ { name => 'current' } ], |
| 94 |
output_template => 'current: %.2fA', |
| 95 |
perfdatas => [ { template => '%.2f', unit => 'A' } ] |
| 96 |
} |
| 97 |
}, |
| 98 |
{ |
| 99 |
label => 'used-capacity', nlabel => 'system.used.capacity.percentage', |
| 100 |
set => { |
| 101 |
key_values => [ { name => 'used_capacity' } ], |
| 102 |
output_template => 'used capacity: %.2f%%', |
| 103 |
perfdatas => [ { template => '%.2f', min => 0, max => 100, unit => '%' } ] |
| 104 |
} |
| 105 |
} |
| 106 |
]; |
| 107 |
} |
| 108 |
|
| 109 |
sub new { |
| 110 |
my ($class, %options) = @_; |
| 111 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 112 |
bless $self, $class; |
| 113 |
|
| 114 |
return $self; |
| 115 |
} |
| 116 |
|
| 117 |
sub manage_selection { |
| 118 |
my ($self, %options) = @_; |
| 119 |
|
| 120 |
my $oid_systemStatus = '.1.3.6.1.4.1.6302.2.1.2.1.0'; |
| 121 |
my $oid_systemVoltage = '.1.3.6.1.4.1.6302.2.1.2.2.0'; |
| 122 |
my $oid_systemCurrent = '.1.3.6.1.4.1.6302.2.1.2.3.0'; |
| 123 |
my $oid_systemUsedCapacity = '.1.3.6.1.4.1.6302.2.1.2.4.0'; |
| 124 |
my $oid_psStatusCommunication = '.1.3.6.1.4.1.6302.2.1.2.8.0'; |
| 125 |
|
| 126 |
my $snmp_result = $options{snmp}->get_leef( |
| 127 |
oids => [ |
| 128 |
$oid_systemStatus, |
| 129 |
$oid_systemVoltage, |
| 130 |
$oid_systemCurrent, |
| 131 |
$oid_systemUsedCapacity, |
| 132 |
$oid_psStatusCommunication |
| 133 |
], |
| 134 |
nothing_quit => 1 |
| 135 |
); |
| 136 |
|
| 137 |
$self->{system} = { |
| 138 |
system_status => $map_system_status->{$snmp_result->{$oid_systemStatus}}, |
| 139 |
communication_status => $map_communication_status->{$snmp_result->{$oid_psStatusCommunication}}, |
| 140 |
voltage => $snmp_result->{$oid_systemVoltage} / 1000, |
| 141 |
current => $snmp_result->{$oid_systemCurrent} / 1000, |
| 142 |
used_capacity => $snmp_result->{$oid_systemUsedCapacity} |
| 143 |
}; |
| 144 |
} |
| 145 |
|
| 146 |
1; |
| 147 |
|
| 148 |
__END__ |
| 149 |
|
| 150 |
=head1 MODE |
| 151 |
|
| 152 |
Check system. |
| 153 |
|
| 154 |
=over 8 |
| 155 |
|
| 156 |
=item B<--unknown-status> |
| 157 |
|
| 158 |
Define the conditions to match for the status to be UNKNOWN (default: '%{system_status} =~ /unknown|unmanaged|restricted|testing|disabled/i || %{communication_status} =~ /unknown/i'). |
| 159 |
You can use the following variables: %{system_status}, %{communication_status} |
| 160 |
|
| 161 |
=item B<--warning-status> |
| 162 |
|
| 163 |
Define the conditions to match for the status to be WARNING (default: '%{system_status} =~ /warning|minor/i'). |
| 164 |
You can use the following variables: %{system_status}, %{communication_status} |
| 165 |
|
| 166 |
=item B<--critical-status> |
| 167 |
|
| 168 |
Define the conditions to match for the status to be CRITICAL (default: '%{system_status} =~ /major|critical/i || %{communication_status} =~ /interrupt/i'). |
| 169 |
You can use the following variables: %{system_status}, %{communication_status} |
| 170 |
|
| 171 |
=item B<--warning-*> B<--critical-*> |
| 172 |
|
| 173 |
Thresholds: voltage (V), current (A), used-capacity (%) |
| 174 |
|
| 175 |
=back |
| 176 |
|
| 177 |
=cut |