| 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::adva::fsp150::snmp::mode::systems; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
|
| 28 |
sub prefix_system_output { |
| 29 |
my ($self, %options) = @_; |
| 30 |
|
| 31 |
return "system '" . $options{instance_value}->{display} . "' "; |
| 32 |
} |
| 33 |
|
| 34 |
sub set_counters { |
| 35 |
my ($self, %options) = @_; |
| 36 |
|
| 37 |
$self->{maps_counters_type} = [ |
| 38 |
{ name => 'systems', type => 1, cb_prefix_output => 'prefix_system_output', message_multiple => 'All systems are ok' } |
| 39 |
]; |
| 40 |
|
| 41 |
$self->{maps_counters}->{systems} = [ |
| 42 |
{ label => 'cpu-utilization-15min', nlabel => 'system.cpu.utilization.15min.percentage', set => { |
| 43 |
key_values => [ |
| 44 |
{ name => 'cpu_average' }, { name => 'ne_name' }, { name => 'shelf_name' }, |
| 45 |
{ name => 'slot_name' }, { name => 'display' } |
| 46 |
], |
| 47 |
output_template => 'cpu usage: %.2f%% (15min)', |
| 48 |
closure_custom_perfdata => sub { |
| 49 |
my ($self) = @_; |
| 50 |
|
| 51 |
$self->{output}->perfdata_add( |
| 52 |
nlabel => $self->{nlabel}, |
| 53 |
unit => '%', |
| 54 |
instances => [ |
| 55 |
$self->{result_values}->{ne_name}, |
| 56 |
$self->{result_values}->{shelf_name}, |
| 57 |
$self->{result_values}->{slot_name} |
| 58 |
], |
| 59 |
value => sprintf('%.2f', $self->{result_values}->{cpu_average}), |
| 60 |
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), |
| 61 |
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}), |
| 62 |
min => 0, max => 100 |
| 63 |
); |
| 64 |
} |
| 65 |
} |
| 66 |
}, |
| 67 |
{ label => 'memory-usage', nlabel => 'system.memory.usage.bytes', set => { |
| 68 |
key_values => [ |
| 69 |
{ name => 'memory_used' }, { name => 'ne_name' }, { name => 'shelf_name' }, |
| 70 |
{ name => 'slot_name' }, { name => 'display' } |
| 71 |
], |
| 72 |
output_template => 'memory used: %s%s', |
| 73 |
output_change_bytes => 1, |
| 74 |
closure_custom_perfdata => sub { |
| 75 |
my ($self) = @_; |
| 76 |
|
| 77 |
$self->{output}->perfdata_add( |
| 78 |
nlabel => $self->{nlabel}, |
| 79 |
unit => 'B', |
| 80 |
instances => [ |
| 81 |
$self->{result_values}->{ne_name}, |
| 82 |
$self->{result_values}->{shelf_name}, |
| 83 |
$self->{result_values}->{slot_name} |
| 84 |
], |
| 85 |
value => $self->{result_values}->{memory_used}, |
| 86 |
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), |
| 87 |
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}), |
| 88 |
min => 0 |
| 89 |
); |
| 90 |
} |
| 91 |
} |
| 92 |
} |
| 93 |
]; |
| 94 |
} |
| 95 |
|
| 96 |
sub new { |
| 97 |
my ($class, %options) = @_; |
| 98 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 99 |
bless $self, $class; |
| 100 |
|
| 101 |
$options{options}->add_options(arguments => { |
| 102 |
'filter-network-element:s' => { name => 'filter_network_element' } |
| 103 |
}); |
| 104 |
|
| 105 |
return $self; |
| 106 |
} |
| 107 |
|
| 108 |
my $mapping = { |
| 109 |
cpu_average => { oid => '.1.3.6.1.4.1.2544.1.12.5.1.75.1.5' }, # f3CardStatsACU |
| 110 |
memory_used => { oid => '.1.3.6.1.4.1.2544.1.12.5.1.75.1.10' } # f3CardStatsIMU (KB) |
| 111 |
}; |
| 112 |
my $map_stat_index = { |
| 113 |
1 => '15min', 2 => '1day', 3 => 'rollover', 4 => '5min' |
| 114 |
}; |
| 115 |
|
| 116 |
sub manage_selection { |
| 117 |
my ($self, %options) = @_; |
| 118 |
|
| 119 |
my $snmp_result = $options{snmp}->get_multiple_table( |
| 120 |
oids => [ |
| 121 |
{ oid => $mapping->{cpu_average}->{oid} }, |
| 122 |
{ oid => $mapping->{memory_used}->{oid} } |
| 123 |
], |
| 124 |
return_type => 1, |
| 125 |
nothing_quit => 1 |
| 126 |
); |
| 127 |
|
| 128 |
my ($ne_indexes, $shelf_indexes, $slot_indexes) = ({}, {}, {}); |
| 129 |
foreach (keys %$snmp_result) { |
| 130 |
next if (! /^$mapping->{cpu_average}->{oid}\.(\d+)\.(\d+)\.(\d+)\./); |
| 131 |
$ne_indexes->{$1} = 1; |
| 132 |
$shelf_indexes->{$1 . '.' . $2} = 1; |
| 133 |
$slot_indexes->{$1 . '.' . $2 . '.' . $3} = 1; |
| 134 |
} |
| 135 |
|
| 136 |
my $oid_slotEntityIndex = '.1.3.6.1.4.1.2544.1.12.3.1.3.1.2'; |
| 137 |
my $oid_shelfEntityIndex = '.1.3.6.1.4.1.2544.1.12.3.1.2.1.2'; |
| 138 |
my $oid_neName = '.1.3.6.1.4.1.2544.1.12.3.1.1.1.2'; |
| 139 |
my $snmp_indexes = $options{snmp}->get_leef( |
| 140 |
oids => [ |
| 141 |
map($oid_neName . '.' . $_, keys(%$ne_indexes)), |
| 142 |
map($oid_shelfEntityIndex . '.' . $_, keys(%$shelf_indexes)), |
| 143 |
map($oid_slotEntityIndex . '.' . $_, keys(%$slot_indexes)) |
| 144 |
] |
| 145 |
); |
| 146 |
|
| 147 |
my $entity_indexes = {}; |
| 148 |
foreach (keys %$snmp_indexes) { |
| 149 |
$entity_indexes->{$snmp_indexes->{$_}} = 1 if (/^(?:$oid_shelfEntityIndex|$oid_slotEntityIndex)\./); |
| 150 |
} |
| 151 |
|
| 152 |
my $oid_entPhysicalName = '.1.3.6.1.2.1.47.1.1.1.1.7'; |
| 153 |
my $snmp_entities = $options{snmp}->get_leef( |
| 154 |
oids => [ |
| 155 |
map($oid_entPhysicalName . '.' . $_, keys(%$entity_indexes)) |
| 156 |
] |
| 157 |
); |
| 158 |
|
| 159 |
$self->{systems} = {}; |
| 160 |
foreach (keys %$snmp_result) { |
| 161 |
next if (! /^$mapping->{cpu_average}->{oid}\.(\d+)\.(\d+)\.(\d+)\.1/); # we want 15min |
| 162 |
my $instance = $1 . '.' . $2 . '.' . $3; |
| 163 |
my $ne_name = $snmp_indexes->{ $oid_neName . '.' . $1 }; |
| 164 |
my $shelf_name = $snmp_entities->{ $oid_entPhysicalName . '.' . $snmp_indexes->{ $oid_shelfEntityIndex . '.' . $1 . '.' . $2 } }; |
| 165 |
my $slot_name = $snmp_entities->{ $oid_entPhysicalName . '.' . $snmp_indexes->{ $oid_slotEntityIndex . '.' . $1 . '.' . $2 . '.' . $3 } }; |
| 166 |
|
| 167 |
my $result = $options{snmp}->map_instance( |
| 168 |
mapping => $mapping, |
| 169 |
results => $snmp_result, |
| 170 |
instance => $instance. '.1' |
| 171 |
); |
| 172 |
$result->{memory_used} *= 1024; |
| 173 |
my $display = $ne_name . ':' . $shelf_name . ':' . $slot_name; |
| 174 |
|
| 175 |
if (defined($self->{option_results}->{filter_network_element}) && $self->{option_results}->{filter_network_element} ne '' && |
| 176 |
$ne_name !~ /$self->{option_results}->{filter_network_element}/) { |
| 177 |
$self->{output}->output_add(long_msg => "skipping system '" . $display . "': no matching filter.", debug => 1); |
| 178 |
next; |
| 179 |
} |
| 180 |
|
| 181 |
$self->{systems}->{$instance} = { |
| 182 |
display => $display, |
| 183 |
ne_name => $ne_name, |
| 184 |
shelf_name => $shelf_name, |
| 185 |
slot_name => $slot_name, |
| 186 |
%$result |
| 187 |
}; |
| 188 |
} |
| 189 |
} |
| 190 |
|
| 191 |
1; |
| 192 |
|
| 193 |
__END__ |
| 194 |
|
| 195 |
=head1 MODE |
| 196 |
|
| 197 |
Check systems. |
| 198 |
|
| 199 |
=over 8 |
| 200 |
|
| 201 |
=item B<--filter-network-elemet> |
| 202 |
|
| 203 |
Filter by network element name (can be a regexp). |
| 204 |
|
| 205 |
=item B<--warning-*> B<--critical-*> |
| 206 |
|
| 207 |
Thresholds. |
| 208 |
Can be: 'cpu-utilization-15min', 'memory-usage'. |
| 209 |
|
| 210 |
=back |
| 211 |
|
| 212 |
=cut |