| 1 |
# |
| 2 |
# Copyright 2022 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::fortinet::fortimail::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} = 'network::fortinet::fortimail::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, no_absent => 1, no_load_components => 1, force_new_perfdata => 1); |
| 50 |
bless $self, $class; |
| 51 |
|
| 52 |
$options{options}->add_options(arguments => {}); |
| 53 |
|
| 54 |
return $self; |
| 55 |
} |
| 56 |
|
| 57 |
sub get_system_information { |
| 58 |
my ($self, %options) = @_; |
| 59 |
|
| 60 |
my $oid_fmlSysModel = '.1.3.6.1.4.1.12356.105.1.1.0'; |
| 61 |
my $oid_fmlSerial = '.1.3.6.1.4.1.12356.105.1.2.0'; |
| 62 |
my $oid_fmlSysVersion = '.1.3.6.1.4.1.12356.105.1.3.0'; |
| 63 |
my $oid_fmlAVVersion = '.1.3.6.1.4.1.12356.105.1.4.0'; |
| 64 |
|
| 65 |
my $result = $options{snmp}->get_leef( |
| 66 |
oids => [ $oid_fmlSysModel, $oid_fmlSerial, $oid_fmlSysVersion, $oid_fmlAVVersion ] |
| 67 |
); |
| 68 |
|
| 69 |
$self->{output}->output_add( |
| 70 |
long_msg => sprintf( |
| 71 |
'[System: %s] [Serial: %s] [Firmware: %s] [Antivirus Version: %s]', |
| 72 |
$result->{$oid_fmlSysModel}, |
| 73 |
$result->{$oid_fmlSerial}, |
| 74 |
defined($result->{$oid_fmlSysVersion}) ? $result->{$oid_fmlSysVersion} : 'unknown', |
| 75 |
defined($result->{$oid_fmlAVVersion}) ? $result->{$oid_fmlAVVersion} : 'unknown' |
| 76 |
) |
| 77 |
); |
| 78 |
} |
| 79 |
|
| 80 |
sub snmp_execute { |
| 81 |
my ($self, %options) = @_; |
| 82 |
|
| 83 |
$self->{snmp} = $options{snmp}; |
| 84 |
$self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}); |
| 85 |
} |
| 86 |
|
| 87 |
1; |
| 88 |
|
| 89 |
=head1 MODE |
| 90 |
|
| 91 |
Check hardware. |
| 92 |
|
| 93 |
=over 8 |
| 94 |
|
| 95 |
=item B<--component> |
| 96 |
|
| 97 |
Which component to check (default: '.*'). |
| 98 |
Can be: 'sensors'. |
| 99 |
|
| 100 |
=item B<--add-name-instance> |
| 101 |
|
| 102 |
Add literal description for instance value (used in filter, and threshold options). |
| 103 |
|
| 104 |
=item B<--filter> |
| 105 |
|
| 106 |
Exclude some parts (comma separated list) |
| 107 |
Can also exclude specific instance: --filter=sensors,1 |
| 108 |
|
| 109 |
=item B<--no-component> |
| 110 |
|
| 111 |
Return an error if no compenents are checked. |
| 112 |
If total (with skipped) is 0. (default: 'critical' returns). |
| 113 |
|
| 114 |
=item B<--threshold-overload> |
| 115 |
|
| 116 |
Set to overload default threshold values (syntax: section,[instance,]status,regexp) |
| 117 |
It used before default thresholds (order stays). |
| 118 |
Example: --threshold-overload='sensors,WARNING,off' |
| 119 |
|
| 120 |
=item B<--warning> |
| 121 |
|
| 122 |
Set warning threshold for 'sensors' (syntax: type,regexp,threshold) |
| 123 |
Example: --warning='sensors,.*,30' |
| 124 |
|
| 125 |
=item B<--critical> |
| 126 |
|
| 127 |
Set critical threshold for 'sensors' (syntax: type,regexp,threshold) |
| 128 |
Example: --critical='sensors,.*,50' |
| 129 |
|
| 130 |
|
| 131 |
=back |
| 132 |
|
| 133 |
=cut |
| 134 |
|
| 135 |
|
| 136 |
package network::fortinet::fortimail::snmp::mode::components::sensors; |
| 137 |
|
| 138 |
use strict; |
| 139 |
use warnings; |
| 140 |
|
| 141 |
my %alarm_map = ( |
| 142 |
0 => 'off', |
| 143 |
1 => 'on', |
| 144 |
); |
| 145 |
my $mapping = { |
| 146 |
fgHwSensorEntName => { oid => '.1.3.6.1.4.1.12356.105.1.110.2.1.2' }, |
| 147 |
fgHwSensorEntValue => { oid => '.1.3.6.1.4.1.12356.105.1.110.2.1.3' }, |
| 148 |
fgHwSensorEntAlarmStatus => { oid => '.1.3.6.1.4.1.12356.105.1.110.2.1.4', map => \%alarm_map }, |
| 149 |
}; |
| 150 |
my $oid_fgHwSensorEntry = '.1.3.6.1.4.1.12356.105.1.110.2.1'; |
| 151 |
|
| 152 |
sub load { |
| 153 |
my ($self) = @_; |
| 154 |
|
| 155 |
push @{$self->{request}}, { oid => $oid_fgHwSensorEntry }; |
| 156 |
} |
| 157 |
|
| 158 |
sub check { |
| 159 |
my ($self) = @_; |
| 160 |
|
| 161 |
$self->{output}->output_add(long_msg => "Checking sensors"); |
| 162 |
$self->{components}->{sensors} = { name => 'sensors', total => 0, skip => 0 }; |
| 163 |
return if ($self->check_filter(section => 'sensors')); |
| 164 |
|
| 165 |
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_fgHwSensorEntry}})) { |
| 166 |
next if ($oid !~ /^$mapping->{fgHwSensorEntAlarmStatus}->{oid}\.(.*)$/); |
| 167 |
my $instance = $1; |
| 168 |
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_fgHwSensorEntry}, instance => $instance); |
| 169 |
my $name = centreon::plugins::misc::trim($result->{fgHwSensorEntName}); |
| 170 |
|
| 171 |
next if ($self->check_filter(section => 'sensors', instance => $instance, name => $name)); |
| 172 |
|
| 173 |
$self->{components}->{sensors}->{total}++; |
| 174 |
|
| 175 |
$self->{output}->output_add( |
| 176 |
long_msg => sprintf( |
| 177 |
"sensor '%s' alarm status is '%s' [instance: %s] [value: %s]", |
| 178 |
$name, $result->{fgHwSensorEntAlarmStatus}, $instance, |
| 179 |
defined($result->{fgHwSensorEntValue}) ? $result->{fgHwSensorEntValue} : '-' |
| 180 |
) |
| 181 |
); |
| 182 |
|
| 183 |
my $exit = $self->get_severity(section => 'sensors', name => $name, value => $result->{fgHwSensorEntAlarmStatus}); |
| 184 |
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { |
| 185 |
$self->{output}->output_add( |
| 186 |
severity => $exit, |
| 187 |
short_msg => sprintf("Sensor '%s' alarm status is '%s'", $name, $result->{fgHwSensorEntAlarmStatus}) |
| 188 |
); |
| 189 |
} |
| 190 |
|
| 191 |
next if (!defined($result->{fgHwSensorEntValue})); |
| 192 |
|
| 193 |
my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'sensors', instance => $instance, name => $name, value => $result->{fgHwSensorEntValue}); |
| 194 |
|
| 195 |
if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) { |
| 196 |
$self->{output}->output_add( |
| 197 |
severity => $exit2, |
| 198 |
short_msg => sprintf("Sensor '%s' measure is %s", $name, $result->{fgHwSensorEntValue}) |
| 199 |
); |
| 200 |
} |
| 201 |
$self->{output}->perfdata_add( |
| 202 |
nlabel => 'hardware.sensors.measure', |
| 203 |
instances => $name, |
| 204 |
value => $result->{fgHwSensorEntValue}, |
| 205 |
warning => $warn, |
| 206 |
critical => $crit |
| 207 |
); |
| 208 |
} |
| 209 |
} |
| 210 |
|
| 211 |
1; |