| 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::fortinet::fortigate::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} = '^sensors$'; |
| 32 |
|
| 33 |
$self->{cb_hook1} = 'get_system_information'; |
| 34 |
$self->{cb_hook2} = 'snmp_execute'; |
| 35 |
|
| 36 |
$self->{thresholds} = { |
| 37 |
sensors => [ |
| 38 |
['on', 'CRITICAL'], |
| 39 |
['off', 'OK'] |
| 40 |
] |
| 41 |
}; |
| 42 |
|
| 43 |
$self->{components_path} = 'centreon::common::fortinet::fortigate::snmp::mode::components'; |
| 44 |
$self->{components_module} = ['sensors']; |
| 45 |
} |
| 46 |
|
| 47 |
sub new { |
| 48 |
my ($class, %options) = @_; |
| 49 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, |
| 50 |
no_absent => 1, no_load_components => 1, force_new_perfdata => 1); |
| 51 |
bless $self, $class; |
| 52 |
|
| 53 |
$options{options}->add_options(arguments => {}); |
| 54 |
|
| 55 |
return $self; |
| 56 |
} |
| 57 |
|
| 58 |
sub get_system_information { |
| 59 |
my ($self, %options) = @_; |
| 60 |
|
| 61 |
my $oid_sysDescr = '.1.3.6.1.2.1.1.1.0'; |
| 62 |
my $oid_fgSysVersion = '.1.3.6.1.4.1.12356.101.4.1.1.0'; |
| 63 |
|
| 64 |
my $result = $options{snmp}->get_leef(oids => [$oid_sysDescr, $oid_fgSysVersion]);#, nothing_quit => 1); |
| 65 |
$self->{output}->output_add( |
| 66 |
long_msg => sprintf( |
| 67 |
'[System: %s] [Firmware: %s]', |
| 68 |
$result->{$oid_sysDescr}, |
| 69 |
defined($result->{$oid_fgSysVersion}) ? $result->{$oid_fgSysVersion} : 'unknown' |
| 70 |
) |
| 71 |
); |
| 72 |
} |
| 73 |
|
| 74 |
sub snmp_execute { |
| 75 |
my ($self, %options) = @_; |
| 76 |
|
| 77 |
$self->{snmp} = $options{snmp}; |
| 78 |
$self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}); |
| 79 |
} |
| 80 |
|
| 81 |
1; |
| 82 |
|
| 83 |
=head1 MODE |
| 84 |
|
| 85 |
Check hardware. |
| 86 |
It's deprecated. Work only for 'FortiGate-5000 Series Chassis'. |
| 87 |
|
| 88 |
=over 8 |
| 89 |
|
| 90 |
=item B<--component> |
| 91 |
|
| 92 |
Which component to check (default: '.*'). |
| 93 |
Can be: 'sensors'. |
| 94 |
|
| 95 |
=item B<--add-name-instance> |
| 96 |
|
| 97 |
Add literal description for instance value (used in filter, and threshold options). |
| 98 |
|
| 99 |
=item B<--filter> |
| 100 |
|
| 101 |
Exclude some parts (comma separated list) |
| 102 |
You can also exclude items from specific instances: --filter=sensors,1 |
| 103 |
|
| 104 |
=item B<--no-component> |
| 105 |
|
| 106 |
Define the expected status if no components are found (default: critical). |
| 107 |
|
| 108 |
|
| 109 |
=item B<--threshold-overload> |
| 110 |
|
| 111 |
Use this option to override the status returned by the plugin when the status label matches a regular expression (syntax: section,[instance,]status,regexp). |
| 112 |
Example: --threshold-overload='sensors,WARNING,off' |
| 113 |
|
| 114 |
=item B<--warning> |
| 115 |
|
| 116 |
Set warning threshold for 'sensors' (syntax: type,regexp,threshold) |
| 117 |
Example: --warning='sensors,.*,30' |
| 118 |
|
| 119 |
=item B<--critical> |
| 120 |
|
| 121 |
Set critical threshold for 'sensors' (syntax: type,regexp,threshold) |
| 122 |
Example: --critical='sensors,.*,50' |
| 123 |
|
| 124 |
|
| 125 |
=back |
| 126 |
|
| 127 |
=cut |
| 128 |
|
| 129 |
package centreon::common::fortinet::fortigate::snmp::mode::components::sensors; |
| 130 |
|
| 131 |
use strict; |
| 132 |
use warnings; |
| 133 |
|
| 134 |
my %alarm_map = ( |
| 135 |
0 => 'off', |
| 136 |
1 => 'on', |
| 137 |
); |
| 138 |
my $mapping = { |
| 139 |
fgHwSensorEntName => { oid => '.1.3.6.1.4.1.12356.101.4.3.2.1.2' }, |
| 140 |
fgHwSensorEntValue => { oid => '.1.3.6.1.4.1.12356.101.4.3.2.1.3' }, |
| 141 |
fgHwSensorEntAlarmStatus => { oid => '.1.3.6.1.4.1.12356.101.4.3.2.1.4', map => \%alarm_map } |
| 142 |
}; |
| 143 |
my $oid_fgHwSensorEntry = '.1.3.6.1.4.1.12356.101.4.3.2.1'; |
| 144 |
|
| 145 |
sub load { |
| 146 |
my ($self) = @_; |
| 147 |
|
| 148 |
push @{$self->{request}}, { oid => $oid_fgHwSensorEntry }; |
| 149 |
} |
| 150 |
|
| 151 |
sub check { |
| 152 |
my ($self) = @_; |
| 153 |
|
| 154 |
$self->{output}->output_add(long_msg => "Checking sensors"); |
| 155 |
$self->{components}->{sensors} = {name => 'sensors', total => 0, skip => 0}; |
| 156 |
return if ($self->check_filter(section => 'sensors')); |
| 157 |
|
| 158 |
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_fgHwSensorEntry}})) { |
| 159 |
next if ($oid !~ /^$mapping->{fgHwSensorEntAlarmStatus}->{oid}\.(.*)$/); |
| 160 |
my $instance = $1; |
| 161 |
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_fgHwSensorEntry}, instance => $instance); |
| 162 |
my $name = centreon::plugins::misc::trim($result->{fgHwSensorEntName}); |
| 163 |
|
| 164 |
next if ($self->check_filter(section => 'sensors', instance => $instance, name => $name)); |
| 165 |
|
| 166 |
$self->{components}->{sensors}->{total}++; |
| 167 |
|
| 168 |
$self->{output}->output_add( |
| 169 |
long_msg => sprintf( |
| 170 |
"sensor '%s' alarm status is '%s' [instance = %s] [value = %s]", |
| 171 |
$name, $result->{fgHwSensorEntAlarmStatus}, $instance, |
| 172 |
defined($result->{fgHwSensorEntValue}) ? $result->{fgHwSensorEntValue} : '-' |
| 173 |
) |
| 174 |
); |
| 175 |
|
| 176 |
my $exit = $self->get_severity(section => 'sensors', name => $name, value => $result->{fgHwSensorEntAlarmStatus}); |
| 177 |
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { |
| 178 |
$self->{output}->output_add( |
| 179 |
severity => $exit, |
| 180 |
short_msg => sprintf("Sensor '%s' alarm status is '%s'", $name, $result->{fgHwSensorEntAlarmStatus}) |
| 181 |
); |
| 182 |
} |
| 183 |
|
| 184 |
next if (!defined($result->{fgHwSensorEntValue})); |
| 185 |
# can be: ON |
| 186 |
next if ($result->{fgHwSensorEntValue} !~ /^[0-9.]+$/); |
| 187 |
|
| 188 |
my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'sensors', instance => $instance, name => $name, value => $result->{fgHwSensorEntValue}); |
| 189 |
|
| 190 |
if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) { |
| 191 |
$self->{output}->output_add( |
| 192 |
severity => $exit2, |
| 193 |
short_msg => sprintf("Sensor '%s' measure is %s", $name, $result->{fgHwSensorEntValue}) |
| 194 |
); |
| 195 |
} |
| 196 |
$self->{output}->perfdata_add( |
| 197 |
nlabel => 'hardware.sensors.measure', |
| 198 |
instances => $name, |
| 199 |
value => $result->{fgHwSensorEntValue}, |
| 200 |
warning => $warn, |
| 201 |
critical => $crit |
| 202 |
); |
| 203 |
} |
| 204 |
} |
| 205 |
|
| 206 |
1; |