| 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::memory; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
|
| 28 |
sub custom_usage_output { |
| 29 |
my ($self, %options) = @_; |
| 30 |
|
| 31 |
return sprintf("memory total: %s %s used: %s %s (%.2f%%) free: %s %s (%.2f%%)", |
| 32 |
$self->{perfdata}->change_bytes(value => $self->{result_values}->{total}), |
| 33 |
$self->{perfdata}->change_bytes(value => $self->{result_values}->{used}), |
| 34 |
$self->{result_values}->{prct_used}, |
| 35 |
$self->{perfdata}->change_bytes(value => $self->{result_values}->{free}), |
| 36 |
$self->{result_values}->{prct_free} |
| 37 |
); |
| 38 |
} |
| 39 |
|
| 40 |
sub prefix_cluster_output { |
| 41 |
my ($self, %options) = @_; |
| 42 |
|
| 43 |
return "Cluster '" . $options{instance_value}->{display} . "' "; |
| 44 |
} |
| 45 |
|
| 46 |
sub set_counters { |
| 47 |
my ($self, %options) = @_; |
| 48 |
|
| 49 |
$self->{maps_counters_type} = [ |
| 50 |
{ name => 'memory', type => 0 }, |
| 51 |
{ name => 'cluster', type => 1, cb_prefix_output => 'prefix_cluster_output' } |
| 52 |
]; |
| 53 |
|
| 54 |
$self->{maps_counters}->{memory} = [ |
| 55 |
{ label => 'usage', nlabel => 'memory.usage.bytes', set => { |
| 56 |
key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ], |
| 57 |
closure_custom_output => $self->can('custom_usage_output'), |
| 58 |
perfdatas => [ |
| 59 |
{ value => 'used', template => '%d', min => 0, max => 'total', |
| 60 |
unit => 'B', cast_int => 1 }, |
| 61 |
] |
| 62 |
} |
| 63 |
}, |
| 64 |
{ label => 'usage-free', display_ok => 0, nlabel => 'memory.free.bytes', set => { |
| 65 |
key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ], |
| 66 |
closure_custom_output => $self->can('custom_usage_output'), |
| 67 |
perfdatas => [ |
| 68 |
{ value => 'free', template => '%d', min => 0, max => 'total', |
| 69 |
unit => 'B', cast_int => 1 }, |
| 70 |
] |
| 71 |
} |
| 72 |
}, |
| 73 |
{ label => 'usage-prct', display_ok => 0, nlabel => 'memory.usage.percentage', set => { |
| 74 |
key_values => [ { name => 'prct_used' } ], |
| 75 |
output_template => 'memory used : %.2f %%', |
| 76 |
perfdatas => [ |
| 77 |
{ label => 'used_prct', value => 'prct_used', template => '%.2f', min => 0, max => 100, |
| 78 |
unit => '%' } |
| 79 |
] |
| 80 |
} |
| 81 |
} |
| 82 |
]; |
| 83 |
|
| 84 |
$self->{maps_counters}->{cluster} = [ |
| 85 |
{ label => 'cluster-usage-prct', nlabel => 'cluster.memory.usage.percentage', display_ok => 0, set => { |
| 86 |
key_values => [ { name => 'memory' } ], |
| 87 |
output_template => 'memory used: %.2f %%', |
| 88 |
perfdatas => [ |
| 89 |
{ value => 'memory', template => '%.2f', |
| 90 |
min => 0, max => 100, unit => '%', label_extra_instance => 1 }, |
| 91 |
] |
| 92 |
} |
| 93 |
} |
| 94 |
]; |
| 95 |
} |
| 96 |
|
| 97 |
sub new { |
| 98 |
my ($class, %options) = @_; |
| 99 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 100 |
bless $self, $class; |
| 101 |
|
| 102 |
$options{options}->add_options(arguments => { |
| 103 |
'cluster' => { name => 'cluster' } |
| 104 |
}); |
| 105 |
|
| 106 |
return $self; |
| 107 |
} |
| 108 |
|
| 109 |
my $oid_fgSystemInfo = '.1.3.6.1.4.1.12356.101.4.1'; |
| 110 |
my $oid_fgSysMemUsage = '.1.3.6.1.4.1.12356.101.4.1.4'; |
| 111 |
my $oid_fgSysMemCapacity = '.1.3.6.1.4.1.12356.101.4.1.5'; |
| 112 |
my $oid_fgHaSystemMode = '.1.3.6.1.4.1.12356.101.13.1.1'; # '.0' to have the mode |
| 113 |
my $oid_fgHaStatsMemUsage = '.1.3.6.1.4.1.12356.101.13.2.1.1.4'; |
| 114 |
my $oid_fgHaStatsHostname = '.1.3.6.1.4.1.12356.101.13.2.1.1.11'; |
| 115 |
|
| 116 |
my $maps_ha_mode = { 1 => 'standalone', 2 => 'activeActive', 3 => 'activePassive' }; |
| 117 |
|
| 118 |
sub memory_ha { |
| 119 |
my ($self, %options) = @_; |
| 120 |
|
| 121 |
$self->{cluster} = {}; |
| 122 |
foreach ($options{snmp}->oid_lex_sort(keys %{$options{snmp_result}->{$oid_fgHaStatsMemUsage}})) { |
| 123 |
/\.(\d+)$/; |
| 124 |
|
| 125 |
$self->{cluster}->{ $options{snmp_result}->{$oid_fgHaStatsHostname}->{$oid_fgHaStatsHostname . '.' . $1} } = { |
| 126 |
display => $options{snmp_result}->{$oid_fgHaStatsHostname}->{$oid_fgHaStatsHostname . '.' . $1}, |
| 127 |
memory => $options{snmp_result}->{$oid_fgHaStatsMemUsage}->{$_} |
| 128 |
}; |
| 129 |
} |
| 130 |
} |
| 131 |
|
| 132 |
sub manage_selection { |
| 133 |
my ($self, %options) = @_; |
| 134 |
|
| 135 |
my $table_oids = [ { oid => $oid_fgSystemInfo, start => $oid_fgSysMemUsage, end => $oid_fgSysMemCapacity } ]; |
| 136 |
if (defined($self->{option_results}->{cluster})) { |
| 137 |
push @$table_oids, { oid => $oid_fgHaSystemMode }, |
| 138 |
{ oid => $oid_fgHaStatsMemUsage }, |
| 139 |
{ oid => $oid_fgHaStatsHostname }; |
| 140 |
} |
| 141 |
|
| 142 |
my $snmp_result = $options{snmp}->get_multiple_table( |
| 143 |
oids => $table_oids, |
| 144 |
nothing_quit => 1 |
| 145 |
); |
| 146 |
|
| 147 |
$self->{memory} = { |
| 148 |
prct_used => $snmp_result->{$oid_fgSystemInfo}->{$oid_fgSysMemUsage . '.0'}, |
| 149 |
total => $snmp_result->{$oid_fgSystemInfo}->{$oid_fgSysMemCapacity . '.0'} * 1024 |
| 150 |
}; |
| 151 |
$self->{memory}->{prct_free} = 100 - $self->{memory}->{prct_used}; |
| 152 |
$self->{memory}->{used} = int(($self->{memory}->{total} * $self->{memory}->{prct_used}) / 100); |
| 153 |
$self->{memory}->{free} = $self->{memory}->{total} - $self->{memory}->{used}; |
| 154 |
|
| 155 |
if (defined($self->{option_results}->{cluster})) { |
| 156 |
my $ha_mode = $snmp_result->{$oid_fgHaSystemMode}->{$oid_fgHaSystemMode . '.0'}; |
| 157 |
my $ha_mode_str = defined($maps_ha_mode->{$ha_mode}) ? $maps_ha_mode->{$ha_mode} : 'unknown'; |
| 158 |
$self->{output}->output_add(long_msg => 'high availabily mode is ' . $ha_mode_str); |
| 159 |
if ($ha_mode_str =~ /active/) { |
| 160 |
$self->memory_ha(snmp => $options{snmp}, snmp_result => $snmp_result); |
| 161 |
} |
| 162 |
} |
| 163 |
} |
| 164 |
|
| 165 |
1; |
| 166 |
|
| 167 |
__END__ |
| 168 |
|
| 169 |
=head1 MODE |
| 170 |
|
| 171 |
Check system memory usage (FORTINET-FORTIGATE). |
| 172 |
|
| 173 |
=over 8 |
| 174 |
|
| 175 |
=item B<--warning-*> B<--critical-*> |
| 176 |
|
| 177 |
Thresholds. |
| 178 |
Can be: 'usage-free', 'usage-prct', 'cluster-usage-prct'. |
| 179 |
|
| 180 |
=item B<--cluster> |
| 181 |
|
| 182 |
Add cluster memory informations. |
| 183 |
|
| 184 |
=back |
| 185 |
|
| 186 |
=cut |