| 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 network::nokia::timos::snmp::mode::hardware; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::hardware); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
|
| 28 |
sub set_system { |
| 29 |
my ($self, %options) = @_; |
| 30 |
|
| 31 |
$self->{regexp_threshold_numeric_check_section_option} = '^temperature$'; |
| 32 |
|
| 33 |
$self->{cb_hook2} = 'snmp_execute'; |
| 34 |
|
| 35 |
$self->{thresholds} = { |
| 36 |
default => [ |
| 37 |
['unknown', 'UNKNOWN'], |
| 38 |
['inService', 'OK'], |
| 39 |
['outOfService', 'OK'], |
| 40 |
['diagnosing', 'OK'], |
| 41 |
['failed', 'CRITICAL'], |
| 42 |
['booting', 'OK'], |
| 43 |
['empty', 'OK'], |
| 44 |
['unprovisioned', 'OK'], |
| 45 |
['provisioned', 'OK'], |
| 46 |
['upgrade', 'OK'], |
| 47 |
['downgrade', 'OK'], |
| 48 |
['resetPending', 'OK'], |
| 49 |
['softReset', 'OK'], |
| 50 |
['preExtension', 'OK'] |
| 51 |
] |
| 52 |
}; |
| 53 |
|
| 54 |
$self->{components_path} = 'network::nokia::timos::snmp::mode::components'; |
| 55 |
$self->{components_module} = ['entity']; |
| 56 |
} |
| 57 |
|
| 58 |
sub snmp_execute { |
| 59 |
my ($self, %options) = @_; |
| 60 |
|
| 61 |
$self->{snmp} = $options{snmp}; |
| 62 |
$self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}, return_type => 1); |
| 63 |
} |
| 64 |
|
| 65 |
sub new { |
| 66 |
my ($class, %options) = @_; |
| 67 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_load_components => 1); |
| 68 |
bless $self, $class; |
| 69 |
|
| 70 |
$options{options}->add_options(arguments => {}); |
| 71 |
|
| 72 |
return $self; |
| 73 |
} |
| 74 |
|
| 75 |
1; |
| 76 |
|
| 77 |
=head1 MODE |
| 78 |
|
| 79 |
Check Hardware. |
| 80 |
|
| 81 |
=over 8 |
| 82 |
|
| 83 |
=item B<--component> |
| 84 |
|
| 85 |
Which component to check (default: '.*'). |
| 86 |
Can be: 'entity'. |
| 87 |
|
| 88 |
=item B<--filter> |
| 89 |
|
| 90 |
Exclude some parts (comma separated list) |
| 91 |
You can also exclude items from specific instances: --filter=entity,fan.1 |
| 92 |
|
| 93 |
=item B<--no-component> |
| 94 |
|
| 95 |
Define the expected status if no components are found (default: critical). |
| 96 |
|
| 97 |
=item B<--threshold-overload> |
| 98 |
|
| 99 |
Use this option to override the status returned by the plugin when the status label matches a regular expression (syntax: section,[instance,]status,regexp). |
| 100 |
Example: --threshold-overload='entity,fan..*,CRITICAL,booting' |
| 101 |
|
| 102 |
=item B<--warning> |
| 103 |
|
| 104 |
Set warning threshold (syntax: type,regexp,threshold) |
| 105 |
Example: --warning='temperature,.*,20' |
| 106 |
|
| 107 |
=item B<--critical> |
| 108 |
|
| 109 |
Set critical threshold (syntax: type,regexp,threshold) |
| 110 |
Example: --critical='temperature,.*,30' |
| 111 |
|
| 112 |
=back |
| 113 |
|
| 114 |
=cut |
| 115 |
|
| 116 |
package network::nokia::timos::snmp::mode::components::entity; |
| 117 |
|
| 118 |
use strict; |
| 119 |
use warnings; |
| 120 |
|
| 121 |
my %map_class = ( |
| 122 |
1 => 'other', 2 => 'unknown', 3 => 'physChassis', |
| 123 |
4 => 'container', 5 => 'powerSupply', 6 => 'fan', |
| 124 |
7 => 'sensor', 8 => 'ioModule', 9 => 'cpmModule', |
| 125 |
10 => 'fabricModule', 11 => 'mdaModule', |
| 126 |
12 => 'flashDiskModule', 13 => 'port', 14 => 'mcm', |
| 127 |
15 => 'ccm', 16 => 'oesCard', 17 => 'oesControlCard', |
| 128 |
18 => 'oesUserPanel', 19 => 'alarmInputModule', |
| 129 |
); |
| 130 |
my %map_truth = (1 => 'true', 2 => 'false'); |
| 131 |
my %map_oper_state = ( |
| 132 |
1 => 'unknown', 2 => 'inService', 3 => 'outOfService', |
| 133 |
4 => 'diagnosing', 5 => 'failed', 6 => 'booting', |
| 134 |
7 => 'empty', 8 => 'provisioned', 9 => 'unprovisioned', |
| 135 |
10 => 'upgrade', 11 => 'downgrade', 12 => 'inServiceUpgrade', |
| 136 |
13 => 'inServiceDowngrade', 14 => 'resetPending', |
| 137 |
15 => 'softReset', 16 => 'preExtension', |
| 138 |
); |
| 139 |
|
| 140 |
my $mapping = { |
| 141 |
tmnxHwClass => { oid => '.1.3.6.1.4.1.6527.3.1.2.2.1.8.1.7', map => \%map_class }, |
| 142 |
tmnxHwName => { oid => '.1.3.6.1.4.1.6527.3.1.2.2.1.8.1.8' }, |
| 143 |
tmnxHwOperState => { oid => '.1.3.6.1.4.1.6527.3.1.2.2.1.8.1.16', map => \%map_oper_state }, |
| 144 |
tmnxHwTempSensor => { oid => '.1.3.6.1.4.1.6527.3.1.2.2.1.8.1.17', map => \%map_truth }, |
| 145 |
tmnxHwTemperature => { oid => '.1.3.6.1.4.1.6527.3.1.2.2.1.8.1.18' }, |
| 146 |
tmnxHwTempThreshold => { oid => '.1.3.6.1.4.1.6527.3.1.2.2.1.8.1.19' }, |
| 147 |
}; |
| 148 |
|
| 149 |
sub load { |
| 150 |
my ($self) = @_; |
| 151 |
|
| 152 |
push @{$self->{request}}, { oid => $mapping->{tmnxHwClass}->{oid} }, { oid => $mapping->{tmnxHwName}->{oid} }, |
| 153 |
{ oid => $mapping->{tmnxHwTempSensor}->{oid} }, { oid => $mapping->{tmnxHwOperState}->{oid} }, |
| 154 |
{ oid => $mapping->{tmnxHwTemperature}->{oid} }, { oid => $mapping->{tmnxHwTempThreshold}->{oid} }; |
| 155 |
} |
| 156 |
|
| 157 |
sub check { |
| 158 |
my ($self) = @_; |
| 159 |
|
| 160 |
$self->{output}->output_add(long_msg => "Checking entities"); |
| 161 |
$self->{components}->{entity} = {name => 'entity', total => 0, skip => 0}; |
| 162 |
return if ($self->check_filter(section => 'entity')); |
| 163 |
|
| 164 |
my ($exit, $warn, $crit, $checked); |
| 165 |
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}})) { |
| 166 |
next if ($oid !~ /^$mapping->{tmnxHwName}->{oid}\.(.*)$/); |
| 167 |
my $instance = $1; |
| 168 |
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}, instance => $instance); |
| 169 |
|
| 170 |
next if ($self->check_filter(section => 'entity', instance => $result->{tmnxHwClass} . '.' . $instance)); |
| 171 |
|
| 172 |
$self->{components}->{entity}->{total}++; |
| 173 |
$self->{output}->output_add( |
| 174 |
long_msg => sprintf( |
| 175 |
"%s '%s' status is '%s' [instance = %s, temperature = %s]", |
| 176 |
$result->{tmnxHwClass}, $result->{tmnxHwName}, |
| 177 |
$result->{tmnxHwOperState}, $result->{tmnxHwClass} . '.' . $instance, |
| 178 |
$result->{tmnxHwTempSensor} eq 'true' ? $result->{tmnxHwTemperature} : '-' |
| 179 |
) |
| 180 |
); |
| 181 |
$exit = $self->get_severity(label => 'default', section => 'entity', instance => $result->{tmnxHwClass} . '.' . $instance, value => $result->{tmnxHwOperState}); |
| 182 |
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { |
| 183 |
$self->{output}->output_add( |
| 184 |
severity => $exit, |
| 185 |
short_msg => sprintf("%s '%s' status is '%s'", $result->{tmnxHwClass}, $result->{tmnxHwName}, $result->{tmnxHwOperState})); |
| 186 |
} |
| 187 |
|
| 188 |
next if ($result->{tmnxHwTempSensor} eq 'false'); |
| 189 |
($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $result->{tmnxHwClass} . '.' . $instance, value => $result->{tmnxHwTemperature}); |
| 190 |
if ($checked == 0 && $result->{tmnxHwTempThreshold} != -1 ) { |
| 191 |
$self->{perfdata}->threshold_validate(label => 'critical-temperature-instance-' . $result->{tmnxHwClass} . '.' . $instance, value => $result->{tmnxHwTempThreshold}); |
| 192 |
|
| 193 |
$exit = $self->{perfdata}->threshold_check(value => $result->{tmnxHwTemperature}, threshold => [ { label => 'critical-temperature-instance-' . $instance, exit_litteral => 'critical' }]); |
| 194 |
$warn = undef; |
| 195 |
$crit = $self->{perfdata}->get_perfdata_for_output(label => 'critical-temperature-instance-' . $result->{tmnxHwClass} . '.' . $instance); |
| 196 |
} |
| 197 |
|
| 198 |
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { |
| 199 |
$self->{output}->output_add( |
| 200 |
severity => $exit, |
| 201 |
short_msg => sprintf( |
| 202 |
"%s '%s' temperature is '%s' C", $result->{tmnxHwClass}, |
| 203 |
$result->{tmnxHwName}, $result->{tmnxHwTemperature} |
| 204 |
) |
| 205 |
); |
| 206 |
} |
| 207 |
|
| 208 |
$self->{output}->perfdata_add( |
| 209 |
label => 'temperature', unit => 'C', |
| 210 |
nlabel => 'hardware.entity.temperature.celsius', |
| 211 |
instances => $result->{tmnxHwName}, |
| 212 |
value => $result->{tmnxHwTemperature}, |
| 213 |
warning => $warn, |
| 214 |
critical => $crit |
| 215 |
); |
| 216 |
} |
| 217 |
} |
| 218 |
|
| 219 |
1; |