| 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::fortinet::fortiweb::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 |
sub custom_ha_status_output { |
| 30 |
my ($self, %options) = @_; |
| 31 |
|
| 32 |
return sprintf('high-availability mode: %s', $self->{result_values}->{ha_mode}); |
| 33 |
} |
| 34 |
|
| 35 |
sub system_long_output { |
| 36 |
my ($self, %options) = @_; |
| 37 |
|
| 38 |
return 'checking system'; |
| 39 |
} |
| 40 |
|
| 41 |
sub set_counters { |
| 42 |
my ($self, %options) = @_; |
| 43 |
|
| 44 |
$self->{maps_counters_type} = [ |
| 45 |
{ name => 'system', type => 3, cb_long_output => 'system_long_output', indent_long_output => ' ', |
| 46 |
group => [ |
| 47 |
{ name => 'ha', type => 0, display_short => 0, skipped_code => { -10 => 1 } }, |
| 48 |
{ name => 'cpu', type => 0, display_short => 0, skipped_code => { -10 => 1 } }, |
| 49 |
{ name => 'memory', type => 0, display_short => 0, skipped_code => { -10 => 1 } }, |
| 50 |
{ name => 'disk', type => 0, display_short => 0, skipped_code => { -10 => 1 } } |
| 51 |
] |
| 52 |
} |
| 53 |
]; |
| 54 |
|
| 55 |
$self->{maps_counters}->{ha} = [ |
| 56 |
{ label => 'ha-status', type => 2, set => { |
| 57 |
key_values => [ { name => 'ha_mode' }, ], |
| 58 |
closure_custom_output => $self->can('custom_ha_status_output'), |
| 59 |
closure_custom_perfdata => sub { return 0; }, |
| 60 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 61 |
} |
| 62 |
} |
| 63 |
]; |
| 64 |
|
| 65 |
$self->{maps_counters}->{cpu} = [ |
| 66 |
{ label => 'cpu-load', nlabel => 'cpu.utilization.percentage', set => { |
| 67 |
key_values => [ { name => 'cpu_load' } ], |
| 68 |
output_template => 'cpu load: %.2f %%', |
| 69 |
perfdatas => [ |
| 70 |
{ template => '%.2f', min => 0, max => 100, unit => '%' } |
| 71 |
] |
| 72 |
} |
| 73 |
} |
| 74 |
]; |
| 75 |
|
| 76 |
$self->{maps_counters}->{memory} = [ |
| 77 |
{ label => 'memory-usage', nlabel => 'memory.usage.percentage', set => { |
| 78 |
key_values => [ { name => 'memory_used' } ], |
| 79 |
output_template => 'memory used: %.2f %%', |
| 80 |
perfdatas => [ |
| 81 |
{ template => '%.2f', min => 0, max => 100, unit => '%' } |
| 82 |
] |
| 83 |
} |
| 84 |
} |
| 85 |
]; |
| 86 |
|
| 87 |
$self->{maps_counters}->{disk} = [ |
| 88 |
{ label => 'disk-usage', nlabel => 'disk.log.space.usage.percentage', set => { |
| 89 |
key_values => [ { name => 'disk_used' } ], |
| 90 |
output_template => 'disk log space used: %.2f %%', |
| 91 |
perfdatas => [ |
| 92 |
{ template => '%.2f', min => 0, max => 100, unit => '%' } |
| 93 |
] |
| 94 |
} |
| 95 |
} |
| 96 |
]; |
| 97 |
} |
| 98 |
|
| 99 |
sub new { |
| 100 |
my ($class, %options) = @_; |
| 101 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 102 |
bless $self, $class; |
| 103 |
|
| 104 |
$options{options}->add_options(arguments => { |
| 105 |
}); |
| 106 |
|
| 107 |
return $self; |
| 108 |
} |
| 109 |
|
| 110 |
sub manage_selection { |
| 111 |
my ($self, %options) = @_; |
| 112 |
|
| 113 |
my $mapping_ha_mode = { |
| 114 |
1 => 'standalone', 2 => 'master', 3 => 'slave' |
| 115 |
}; |
| 116 |
my $mapping = { |
| 117 |
ha_mode => { oid => '.1.3.6.1.4.1.12356.107.2.1.3', map => $mapping_ha_mode }, # fwSysHaMode |
| 118 |
cpu_load => { oid => '.1.3.6.1.4.1.12356.107.2.1.5' }, # fwSysCpuUsage |
| 119 |
memory_used => { oid => '.1.3.6.1.4.1.12356.107.2.1.7' }, # fwSysMemUsage |
| 120 |
disk_used => { oid => '.1.3.6.1.4.1.12356.107.2.1.9' } # fwSysDiskUsage |
| 121 |
}; |
| 122 |
|
| 123 |
my $snmp_result = $options{snmp}->get_leef( |
| 124 |
oids => [ map($_->{oid} . '.0', values(%$mapping)) ], |
| 125 |
nothing_quit => 1 |
| 126 |
); |
| 127 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => 0); |
| 128 |
|
| 129 |
$self->{output}->output_add(short_msg => 'system usage is ok'); |
| 130 |
|
| 131 |
$self->{system} = { |
| 132 |
global => { |
| 133 |
ha => { ha_mode => $result->{ha_mode} }, |
| 134 |
cpu => { cpu_load => $result->{cpu_load} }, |
| 135 |
memory => { memory_used => $result->{memory_used} }, |
| 136 |
disk => { disk_used => $result->{disk_used} } |
| 137 |
} |
| 138 |
}; |
| 139 |
} |
| 140 |
|
| 141 |
1; |
| 142 |
|
| 143 |
__END__ |
| 144 |
|
| 145 |
=head1 MODE |
| 146 |
|
| 147 |
Check system usage. |
| 148 |
|
| 149 |
=over 8 |
| 150 |
|
| 151 |
=item B<--filter-counters> |
| 152 |
|
| 153 |
Only display some counters (regexp can be used). |
| 154 |
Example: --filter-counters='memory-usage' |
| 155 |
|
| 156 |
=item B<--warning-ha-status> |
| 157 |
|
| 158 |
Define the conditions to match for the status to be WARNING. |
| 159 |
You can use the following variables: %{ha_mode} |
| 160 |
|
| 161 |
=item B<--critical-ha-status> |
| 162 |
|
| 163 |
Define the conditions to match for the status to be CRITICAL. |
| 164 |
You can use the following variables: %{ha_mode} |
| 165 |
|
| 166 |
=item B<--warning-*> B<--critical-*> |
| 167 |
|
| 168 |
Thresholds. |
| 169 |
Can be: 'disk-usage' (%), 'memory-usage' (%), 'cpu-load' (%). |
| 170 |
|
| 171 |
=back |
| 172 |
|
| 173 |
=cut |