| 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::infoblox::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( |
| 33 |
"high-availablity status is '%s'", |
| 34 |
$self->{result_values}->{ha_status} |
| 35 |
); |
| 36 |
} |
| 37 |
|
| 38 |
sub system_long_output { |
| 39 |
my ($self, %options) = @_; |
| 40 |
|
| 41 |
return "checking system '" . $options{instance_value}->{hw_type} . "'"; |
| 42 |
} |
| 43 |
|
| 44 |
sub set_counters { |
| 45 |
my ($self, %options) = @_; |
| 46 |
|
| 47 |
$self->{maps_counters_type} = [ |
| 48 |
{ name => 'system', type => 3, cb_long_output => 'system_long_output', indent_long_output => ' ', |
| 49 |
group => [ |
| 50 |
{ name => 'cpu', type => 0, display_short => 0, skipped_code => { -10 => 1 } }, |
| 51 |
{ name => 'memory', type => 0, display_short => 0, skipped_code => { -10 => 1 } }, |
| 52 |
{ name => 'swap', type => 0, display_short => 0, skipped_code => { -10 => 1 } }, |
| 53 |
{ name => 'temperature', type => 0, display_short => 0, skipped_code => { -10 => 1 } }, |
| 54 |
{ name => 'ha', type => 0, display_short => 0, skipped_code => { -10 => 1 } } |
| 55 |
] |
| 56 |
} |
| 57 |
]; |
| 58 |
|
| 59 |
$self->{maps_counters}->{cpu} = [ |
| 60 |
{ label => 'cpu-load', nlabel => 'cpu.utilization.percentage', set => { |
| 61 |
key_values => [ { name => 'cpu_load' } ], |
| 62 |
output_template => 'cpu load: %.2f %%', |
| 63 |
perfdatas => [ |
| 64 |
{ template => '%.2f', min => 0, max => 100, unit => '%' } |
| 65 |
] |
| 66 |
} |
| 67 |
} |
| 68 |
]; |
| 69 |
|
| 70 |
$self->{maps_counters}->{memory} = [ |
| 71 |
{ label => 'memory-usage', nlabel => 'memory.usage.percentage', set => { |
| 72 |
key_values => [ { name => 'memory_used' } ], |
| 73 |
output_template => 'memory used: %.2f %%', |
| 74 |
perfdatas => [ |
| 75 |
{ template => '%.2f', min => 0, max => 100, unit => '%' } |
| 76 |
] |
| 77 |
} |
| 78 |
} |
| 79 |
]; |
| 80 |
|
| 81 |
$self->{maps_counters}->{swap} = [ |
| 82 |
{ label => 'swap-usage', nlabel => 'swap.usage.percentage', set => { |
| 83 |
key_values => [ { name => 'swap_used' } ], |
| 84 |
output_template => 'swap used: %.2f %%', |
| 85 |
perfdatas => [ |
| 86 |
{ template => '%.2f', min => 0, max => 100, unit => '%' } |
| 87 |
] |
| 88 |
} |
| 89 |
} |
| 90 |
]; |
| 91 |
|
| 92 |
$self->{maps_counters}->{temperature} = [ |
| 93 |
{ label => 'cpu1-temperature', nlabel => 'system.cpu1.temperature.celsius', set => { |
| 94 |
key_values => [ { name => 'cpu1_temp' } ], |
| 95 |
output_template => 'cpu1 temperature: %.2f C', |
| 96 |
perfdatas => [ |
| 97 |
{ template => '%.2f', unit => 'C' } |
| 98 |
] |
| 99 |
} |
| 100 |
}, |
| 101 |
{ label => 'cpu2-temperature', nlabel => 'system.cpu2.temperature.celsius', set => { |
| 102 |
key_values => [ { name => 'cpu2_temp' } ], |
| 103 |
output_template => 'cpu2 temperature: %.2f C', |
| 104 |
perfdatas => [ |
| 105 |
{ template => '%.2f', unit => 'C' } |
| 106 |
] |
| 107 |
} |
| 108 |
} |
| 109 |
]; |
| 110 |
|
| 111 |
$self->{maps_counters}->{ha} = [ |
| 112 |
{ label => 'ha-status', type => 2, set => { |
| 113 |
key_values => [ { name => 'ha_status' }, ], |
| 114 |
closure_custom_output => $self->can('custom_ha_status_output'), |
| 115 |
closure_custom_perfdata => sub { return 0; }, |
| 116 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 117 |
} |
| 118 |
} |
| 119 |
]; |
| 120 |
} |
| 121 |
|
| 122 |
sub new { |
| 123 |
my ($class, %options) = @_; |
| 124 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 125 |
bless $self, $class; |
| 126 |
|
| 127 |
$options{options}->add_options(arguments => { |
| 128 |
}); |
| 129 |
|
| 130 |
return $self; |
| 131 |
} |
| 132 |
|
| 133 |
sub manage_selection { |
| 134 |
my ($self, %options) = @_; |
| 135 |
|
| 136 |
my $mapping = { |
| 137 |
hw_type => { oid => '.1.3.6.1.4.1.7779.3.1.1.2.1.4' }, # ibHardwareType |
| 138 |
cpu_load => { oid => '.1.3.6.1.4.1.7779.3.1.1.2.1.8.1.1' }, # ibSystemMonitorCpuUsage |
| 139 |
memory_used => { oid => '.1.3.6.1.4.1.7779.3.1.1.2.1.8.2.1' }, # ibSystemMonitorMemUsage |
| 140 |
swap_used => { oid => '.1.3.6.1.4.1.7779.3.1.1.2.1.8.3.1' }, # ibSystemMonitorSwapUsage |
| 141 |
ha_status => { oid => '.1.3.6.1.4.1.7779.3.1.1.2.1.13' }, # ibHaStatus |
| 142 |
cpu1_temp => { oid => '.1.3.6.1.4.1.7779.3.1.1.2.1.17' }, # ibCPU1Temperature |
| 143 |
cpu2_temp => { oid => '.1.3.6.1.4.1.7779.3.1.1.2.1.18' } # ibCPU2Temperature |
| 144 |
}; |
| 145 |
|
| 146 |
my $snmp_result = $options{snmp}->get_leef( |
| 147 |
oids => [ map($_->{oid} . '.0', values(%$mapping)) ], |
| 148 |
nothing_quit => 1 |
| 149 |
); |
| 150 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => 0); |
| 151 |
|
| 152 |
$self->{output}->output_add(short_msg => "System '" . $result->{hw_type} . "' is ok"); |
| 153 |
$result->{cpu1_temp} = defined($result->{cpu1_temp}) && $result->{cpu1_temp} > 0 ? sprintf('%.2f', $result->{cpu1_temp}) : undef; |
| 154 |
$result->{cpu2_temp} = defined($result->{cpu2_temp}) && $result->{cpu2_temp} > 0 ? sprintf('%.2f', $result->{cpu2_temp}) : undef; |
| 155 |
|
| 156 |
$self->{system} = { |
| 157 |
global => { |
| 158 |
hw_type => $result->{hw_type}, |
| 159 |
cpu => { cpu_load => $result->{cpu_load} }, |
| 160 |
memory => { memory_used => $result->{memory_used} }, |
| 161 |
swap => { swap_used => $result->{swap_used} }, |
| 162 |
temperature => { |
| 163 |
cpu1_temp => $result->{cpu1_temp}, |
| 164 |
cpu2_temp => $result->{cpu2_temp} |
| 165 |
}, |
| 166 |
ha => { ha_status => $result->{ha_status} } |
| 167 |
} |
| 168 |
}; |
| 169 |
} |
| 170 |
|
| 171 |
1; |
| 172 |
|
| 173 |
__END__ |
| 174 |
|
| 175 |
=head1 MODE |
| 176 |
|
| 177 |
Check system usage. |
| 178 |
|
| 179 |
=over 8 |
| 180 |
|
| 181 |
=item B<--filter-counters> |
| 182 |
|
| 183 |
Only display some counters (regexp can be used). |
| 184 |
Example: --filter-counters='^memory-usage$' |
| 185 |
|
| 186 |
=item B<--warning-ha-status> |
| 187 |
|
| 188 |
Define the conditions to match for the status to be WARNING. |
| 189 |
You can use the following variables: %{ha_status} |
| 190 |
|
| 191 |
=item B<--critical-ha-status> |
| 192 |
|
| 193 |
Define the conditions to match for the status to be CRITICAL. |
| 194 |
You can use the following variables: %{ha_status} |
| 195 |
|
| 196 |
=item B<--warning-*> B<--critical-*> |
| 197 |
|
| 198 |
Thresholds. |
| 199 |
Can be: 'cpu-load' (%), 'cpu1-temperature', 'cpu2-temperature', 'swap-usage' (%), 'memory-usage' (%). |
| 200 |
|
| 201 |
=back |
| 202 |
|
| 203 |
=cut |