+ add mode for h3c plugin (memory and cpu)
This commit is contained in:
parent
1fd3180a21
commit
ef40bca891
|
@ -33,72 +33,33 @@
|
|||
#
|
||||
####################################################################################
|
||||
|
||||
package network::extreme::snmp::mode::cpu;
|
||||
package network::h3c::snmp::mode::cpu;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::values;
|
||||
use centreon::plugins::statefile;
|
||||
|
||||
my $oid_entPhysicalEntry = '.1.3.6.1.2.1.47.1.1.1.1';
|
||||
my $oid_entPhysicalDescr = '.1.3.6.1.2.1.47.1.1.1.1.2';
|
||||
my $oid_entPhysicalContainedIn = '.1.3.6.1.2.1.47.1.1.1.1.4';
|
||||
my $oid_entPhysicalClass = '.1.3.6.1.2.1.47.1.1.1.1.5';
|
||||
my $oid_entPhysicalName = '.1.3.6.1.2.1.47.1.1.1.1.7';
|
||||
|
||||
my $maps_counters = {
|
||||
cpu => {
|
||||
'000_5secs' => { set => {
|
||||
key_values => [ { name => 'extremeCpuMonitorSystemUtilization5secs' }, { name => 'num' }, ],
|
||||
output_template => '5 seconds : %.2f %%',
|
||||
'000_usage' => { set => {
|
||||
key_values => [ { name => 'EntityExtCpuUsage' }, { name => 'num' }, ],
|
||||
output_template => ' : %.2f %%',
|
||||
perfdatas => [
|
||||
{ label => 'cpu_5secs', value => 'extremeCpuMonitorSystemUtilization5secs_absolute', template => '%.2f',
|
||||
min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'num_absolute' },
|
||||
],
|
||||
}
|
||||
},
|
||||
'001_10secs' => { set => {
|
||||
key_values => [ { name => 'extremeCpuMonitorSystemUtilization10secs' }, { name => 'num' }, ],
|
||||
output_template => '10 seconds : %.2f %%',
|
||||
perfdatas => [
|
||||
{ label => 'cpu_10secs', value => 'extremeCpuMonitorSystemUtilization10secs_absolute', template => '%.2f',
|
||||
min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'num_absolute' },
|
||||
],
|
||||
}
|
||||
},
|
||||
'002_30secs' => { set => {
|
||||
key_values => [ { name => 'extremeCpuMonitorSystemUtilization30secs' }, { name => 'num' }, ],
|
||||
output_template => '10 seconds : %.2f %%',
|
||||
perfdatas => [
|
||||
{ label => 'cpu_30secs', value => 'extremeCpuMonitorSystemUtilization30secs_absolute', template => '%.2f',
|
||||
min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'num_absolute' },
|
||||
],
|
||||
}
|
||||
},
|
||||
'003_1min' => { set => {
|
||||
key_values => [ { name => 'extremeCpuMonitorSystemUtilization1min' }, { name => 'num' }, ],
|
||||
output_template => '10 seconds : %.2f %%',
|
||||
perfdatas => [
|
||||
{ label => 'cpu_1min', value => 'extremeCpuMonitorSystemUtilization1min_absolute', template => '%.2f',
|
||||
min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'num_absolute' },
|
||||
],
|
||||
}
|
||||
},
|
||||
'004_5min' => { set => {
|
||||
key_values => [ { name => 'extremeCpuMonitorSystemUtilization5mins' }, { name => 'num' }, ],
|
||||
output_template => '10 seconds : %.2f %%',
|
||||
perfdatas => [
|
||||
{ label => 'cpu_5min', value => 'extremeCpuMonitorSystemUtilization5mins_absolute', template => '%.2f',
|
||||
{ label => 'cpu', value => 'EntityExtCpuUsage_absolute', template => '%.2f',
|
||||
min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'num_absolute' },
|
||||
],
|
||||
}
|
||||
},
|
||||
},
|
||||
total => {
|
||||
'000_total' => { set => {
|
||||
key_values => [ { name => 'total' } ],
|
||||
output_template => 'CPU Usage : %.2f %%',
|
||||
perfdatas => [
|
||||
{ label => 'cpu_total', value => 'total_absolute', template => '%.2f', min => 0, max => 100, unit => '%' },
|
||||
],
|
||||
}
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
sub new {
|
||||
|
@ -108,10 +69,12 @@ sub new {
|
|||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
{
|
||||
"reload-cache-time:s" => { name => 'reload_cache_time', default => 180 },
|
||||
"display-entity-name" => { name => 'display_entity_name' },
|
||||
});
|
||||
|
||||
foreach my $key (('cpu', 'total')) {
|
||||
foreach my $key (('cpu')) {
|
||||
foreach (keys %{$maps_counters->{$key}}) {
|
||||
my ($id, $name) = split /_/;
|
||||
if (!defined($maps_counters->{$key}->{$_}->{threshold}) || $maps_counters->{$key}->{$_}->{threshold} != 0) {
|
||||
|
@ -126,6 +89,8 @@ sub new {
|
|||
}
|
||||
}
|
||||
|
||||
$self->{statefile_cache} = centreon::plugins::statefile->new(%options);
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
@ -133,52 +98,13 @@ sub check_options {
|
|||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
foreach my $key (('cpu', 'total')) {
|
||||
foreach my $key (('cpu')) {
|
||||
foreach (keys %{$maps_counters->{$key}}) {
|
||||
$maps_counters->{$key}->{$_}->{obj}->init(option_results => $self->{option_results});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub check_total {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', '');
|
||||
my @exits = ();
|
||||
foreach (sort keys %{$maps_counters->{total}}) {
|
||||
my $obj = $maps_counters->{total}->{$_}->{obj};
|
||||
$obj->set(instance => 'global');
|
||||
|
||||
my ($value_check) = $obj->execute(values => $self->{global});
|
||||
|
||||
if ($value_check != 0) {
|
||||
$long_msg .= $long_msg_append . $obj->output_error();
|
||||
$long_msg_append = ', ';
|
||||
next;
|
||||
}
|
||||
my $exit2 = $obj->threshold_check();
|
||||
push @exits, $exit2;
|
||||
|
||||
my $output = $obj->output();
|
||||
$long_msg .= $long_msg_append . $output;
|
||||
$long_msg_append = ', ';
|
||||
|
||||
if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) {
|
||||
$short_msg .= $short_msg_append . $output;
|
||||
$short_msg_append = ', ';
|
||||
}
|
||||
|
||||
$obj->perfdata();
|
||||
}
|
||||
|
||||
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
|
||||
if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) {
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => "Total $short_msg"
|
||||
);
|
||||
} else {
|
||||
$self->{output}->output_add(short_msg => "Total $long_msg");
|
||||
}
|
||||
|
||||
$self->{statefile_cache}->check_options(%options);
|
||||
}
|
||||
|
||||
sub run {
|
||||
|
@ -192,13 +118,7 @@ sub run {
|
|||
if (scalar(keys %{$self->{cpu}}) == 1) {
|
||||
$multiple = 0;
|
||||
}
|
||||
|
||||
if ($multiple == 1) {
|
||||
$self->check_total();
|
||||
}
|
||||
|
||||
####
|
||||
# By CPU
|
||||
if ($multiple == 1) {
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => 'All CPU usages are ok');
|
||||
|
@ -233,7 +153,7 @@ sub run {
|
|||
$maps_counters->{cpu}->{$_}->{obj}->perfdata(extra_instance => $multiple);
|
||||
}
|
||||
|
||||
$self->{output}->output_add(long_msg => "CPU '" . $self->{cpu}->{$id}->{num} . "' Usage $long_msg");
|
||||
$self->{output}->output_add(long_msg => "CPU '" . $self->{cpu}->{$id}->{num} . "' Usage $long_msg [entity = '" . $self->{cpu}->{$id}->{name} . "']");
|
||||
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
|
||||
if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) {
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
|
@ -250,35 +170,96 @@ sub run {
|
|||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
my $mapping = {
|
||||
extremeCpuMonitorSystemUtilization5secs => { oid => '.1.3.6.1.4.1.1916.1.32.1.4.1.5' },
|
||||
extremeCpuMonitorSystemUtilization10secs => { oid => '.1.3.6.1.4.1.1916.1.32.1.4.1.6' },
|
||||
extremeCpuMonitorSystemUtilization30secs => { oid => '.1.3.6.1.4.1.1916.1.32.1.4.1.7' },
|
||||
extremeCpuMonitorSystemUtilization1min => { oid => '.1.3.6.1.4.1.1916.1.32.1.4.1.8' },
|
||||
extremeCpuMonitorSystemUtilization5mins => { oid => '.1.3.6.1.4.1.1916.1.32.1.4.1.9' },
|
||||
};
|
||||
sub check_cache {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{hostname} = $self->{snmp}->get_hostname();
|
||||
$self->{snmp_port} = $self->{snmp}->get_port();
|
||||
|
||||
# init cache file
|
||||
$self->{write_cache} = 0;
|
||||
my $has_cache_file = $self->{statefile_cache}->read(statefile => 'cache_h3c_entity_' . $self->{hostname} . '_' . $self->{snmp_port});
|
||||
my $timestamp_cache = $self->{statefile_cache}->get(name => 'last_timestamp');
|
||||
if ($has_cache_file == 0 ||
|
||||
!defined($timestamp_cache) || ((time() - $timestamp_cache) > (($self->{option_results}->{reload_cache_time}) * 60))) {
|
||||
push @{$self->{snmp_request}}, { oid => $oid_entPhysicalEntry, start => $oid_entPhysicalDescr, end => $oid_entPhysicalName };
|
||||
$self->{write_cache} = 1;
|
||||
}
|
||||
}
|
||||
|
||||
sub write_cache {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if ($self->{write_cache} == 1) {
|
||||
my $datas = {};
|
||||
$datas->{last_timestamp} = time();
|
||||
$datas->{oids} = $self->{results}->{$oid_entPhysicalEntry};
|
||||
$self->{statefile_cache}->write(data => $datas);
|
||||
} else {
|
||||
$self->{results}->{$oid_entPhysicalEntry} = $self->{statefile_cache}->get(name => 'oids');
|
||||
}
|
||||
}
|
||||
|
||||
sub get_long_name {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my @names = ($self->{results}->{$oid_entPhysicalEntry}->{$oid_entPhysicalDescr . '.' . $options{instance}});
|
||||
my %loop = ($options{instance} => 1);
|
||||
my $child = $self->{results}->{$oid_entPhysicalEntry}->{$oid_entPhysicalContainedIn . '.' . $options{instance}};
|
||||
while (1) {
|
||||
last if (!defined($child) || defined($loop{$child}) || !defined($self->{results}->{$oid_entPhysicalEntry}->{$oid_entPhysicalDescr . '.' . $child}));
|
||||
|
||||
unshift @names, $self->{results}->{$oid_entPhysicalEntry}->{$oid_entPhysicalDescr . '.' . $child};
|
||||
$loop{$child} = 1;
|
||||
$child = $self->{results}->{$oid_entPhysicalEntry}->{$oid_entPhysicalContainedIn . '.' . $child};
|
||||
}
|
||||
|
||||
return join(' > ', @names);
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $oid_extremeCpuMonitorSystemEntry = '.1.3.6.1.4.1.1916.1.32.1.4.1';
|
||||
my $oid_extremeCpuMonitorTotalUtilization = '.1.3.6.1.4.1.1916.1.32.1.2'; # without .0
|
||||
$self->{results} = $self->{snmp}->get_multiple_table(oids => [
|
||||
{ oid => $oid_extremeCpuMonitorTotalUtilization },
|
||||
{ oid => $oid_extremeCpuMonitorSystemEntry },
|
||||
],
|
||||
, nothing_quit => 1);
|
||||
my $oid_h3cEntityExtCpuUsage = '.1.3.6.1.4.1.2011.10.2.6.1.1.1.1.6';
|
||||
my $oid_hh3cEntityExtCpuUsage = '.1.3.6.1.4.1.25506.2.6.1.1.1.1.6';
|
||||
$self->{snmp_request} = [
|
||||
{ oid => $oid_h3cEntityExtCpuUsage },
|
||||
{ oid => $oid_hh3cEntityExtCpuUsage },
|
||||
];
|
||||
$self->check_cache() if (defined($self->{option_results}->{display_entity_name}));
|
||||
|
||||
$self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{snmp_request},
|
||||
nothing_quit => 1);
|
||||
$self->write_cache() if (defined($self->{option_results}->{display_entity_name}));
|
||||
$self->{branch} = $oid_hh3cEntityExtCpuUsage;
|
||||
if (defined($self->{results}->{$oid_h3cEntityExtCpuUsage}) && scalar(keys %{$self->{results}->{$oid_h3cEntityExtCpuUsage}}) > 0) {
|
||||
$self->{branch} = $oid_h3cEntityExtCpuUsage;
|
||||
}
|
||||
|
||||
my $mapping = {
|
||||
EntityExtCpuUsage => { oid => $self->{branch} . '.6' },
|
||||
};
|
||||
|
||||
$self->{cpu} = {};
|
||||
foreach my $oid (keys %{$self->{results}->{$oid_extremeCpuMonitorSystemEntry}}) {
|
||||
next if ($oid !~ /^$mapping->{extremeCpuMonitorSystemUtilization1min}->{oid}\.(.*)$/);
|
||||
foreach my $oid (keys %{$self->{results}->{$self->{branch}}}) {
|
||||
$oid =~ /^$mapping->{EntityExtCpuUsage}->{oid}\.(.*)$/;
|
||||
my $instance = $1;
|
||||
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_extremeCpuMonitorSystemEntry}, instance => $instance);
|
||||
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$self->{branch}}, instance => $instance);
|
||||
|
||||
$self->{cpu}->{$instance} = {num => $instance, %$result};
|
||||
if (defined($result->{EntityExtCpuUsage}) && $result->{EntityExtCpuUsage} > 0) {
|
||||
my $name = '-';
|
||||
|
||||
if (defined($self->{option_results}->{display_entity_name})) {
|
||||
$name = $self->get_long_name(instance => $instance);
|
||||
}
|
||||
$self->{cpu}->{$instance} = { num => $instance, name => $name, %$result};
|
||||
}
|
||||
}
|
||||
|
||||
if (scalar(keys %{$self->{cpu}}) <= 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "No entry found.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
$self->{global} = { total => $self->{results}->{$oid_extremeCpuMonitorTotalUtilization}->{$oid_extremeCpuMonitorTotalUtilization . '.0'} };
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -291,15 +272,21 @@ Check CPU usages.
|
|||
|
||||
=over 8
|
||||
|
||||
=item B<--warning-*>
|
||||
=item B<--warning-usage>
|
||||
|
||||
Threshold warning.
|
||||
Can be: 'total', '5sec', '10sec', '30sec, '1min', '5min'.
|
||||
|
||||
=item B<--critical-*>
|
||||
=item B<--critical-usage>
|
||||
|
||||
Threshold critical.
|
||||
Can be: 'total', '5sec', '10sec', '30sec, '1min', '5min'.
|
||||
|
||||
=item B<--reload-cache-time>
|
||||
|
||||
Time in seconds before reloading cache file (default: 180).
|
||||
|
||||
=item B<--display-entity-name>
|
||||
|
||||
Display entity name of the component. A cache file will be used.
|
||||
|
||||
=back
|
||||
|
||||
|
|
|
@ -253,16 +253,16 @@ sub get_long_name {
|
|||
}
|
||||
|
||||
sub get_instance_class {
|
||||
my ($self, %options) = @_;
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my @instances = ();
|
||||
foreach (keys %{$self->{results}->{$oid_entPhysicalEntry}}) {
|
||||
my @instances = ();
|
||||
foreach (keys %{$self->{results}->{$oid_entPhysicalEntry}}) {
|
||||
if (/^$oid_entPhysicalClass\.(\d+)/ && defined($options{class}->{$self->{results}->{$oid_entPhysicalEntry}->{$_}})) {
|
||||
push @instances, $1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return @instances;
|
||||
return @instances;
|
||||
}
|
||||
|
||||
sub run {
|
||||
|
|
|
@ -33,18 +33,25 @@
|
|||
#
|
||||
####################################################################################
|
||||
|
||||
package network::extreme::snmp::mode::memory;
|
||||
package network::h3c::snmp::mode::memory;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::values;
|
||||
use centreon::plugins::statefile;
|
||||
|
||||
my $oid_entPhysicalEntry = '.1.3.6.1.2.1.47.1.1.1.1';
|
||||
my $oid_entPhysicalDescr = '.1.3.6.1.2.1.47.1.1.1.1.2';
|
||||
my $oid_entPhysicalContainedIn = '.1.3.6.1.2.1.47.1.1.1.1.4';
|
||||
my $oid_entPhysicalClass = '.1.3.6.1.2.1.47.1.1.1.1.5';
|
||||
my $oid_entPhysicalName = '.1.3.6.1.2.1.47.1.1.1.1.7';
|
||||
|
||||
my $maps_counters = {
|
||||
'000_usage' => { set => {
|
||||
key_values => [
|
||||
{ name => 'display' }, { name => 'free' }, { name => 'total' },
|
||||
{ name => 'display' }, { name => 'used_prct' }, { name => 'total' },
|
||||
],
|
||||
closure_custom_calc => \&custom_usage_calc,
|
||||
closure_custom_output => \&custom_usage_output,
|
||||
|
@ -61,11 +68,20 @@ sub custom_usage_perfdata {
|
|||
if (!defined($options{extra_instance}) || $options{extra_instance} != 0) {
|
||||
$extra_label .= '_' . $self->{result_values}->{display};
|
||||
}
|
||||
$self->{output}->perfdata_add(label => 'used' . $extra_label, unit => 'B',
|
||||
value => $self->{result_values}->{used},
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, total => $self->{result_values}->{total}, cast_int => 1),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, total => $self->{result_values}->{total}, cast_int => 1),
|
||||
min => 0, max => $self->{result_values}->{total});
|
||||
|
||||
if ($self->{result_values}->{total} == 4294967295) {
|
||||
$self->{output}->perfdata_add(label => 'used' . $extra_label, unit => 'B',
|
||||
value => $self->{result_values}->{used},
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, total => $self->{result_values}->{total}, cast_int => 1),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, total => $self->{result_values}->{total}, cast_int => 1),
|
||||
min => 0, max => $self->{result_values}->{total});
|
||||
} else {
|
||||
$self->{output}->perfdata_add(label => 'used' . $extra_label, unit => '%',
|
||||
value => $self->{result_values}->{prtc_used},
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}),
|
||||
min => 0, max => 100);
|
||||
}
|
||||
}
|
||||
|
||||
sub custom_usage_threshold {
|
||||
|
@ -78,14 +94,20 @@ sub custom_usage_threshold {
|
|||
sub custom_usage_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total});
|
||||
my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
|
||||
my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
|
||||
|
||||
my $msg = sprintf("Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)",
|
||||
my $msg;
|
||||
if ($self->{result_values}->{total} == 4294967295) {
|
||||
$msg = sprintf("Used: %.2f%% Free: %.2f%%",
|
||||
$self->{result_values}->{prct_used},
|
||||
$self->{result_values}->{prct_free});
|
||||
} else {
|
||||
my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total});
|
||||
my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
|
||||
my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
|
||||
$msg = sprintf("Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)",
|
||||
$total_size_value . " " . $total_size_unit,
|
||||
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
|
||||
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free});
|
||||
}
|
||||
return $msg;
|
||||
}
|
||||
|
||||
|
@ -94,10 +116,10 @@ sub custom_usage_calc {
|
|||
|
||||
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
|
||||
$self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'};
|
||||
$self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_total'} + $options{new_datas}->{$self->{instance} . '_free'};
|
||||
$self->{result_values}->{free} = $options{new_datas}->{$self->{instance} . '_free'};
|
||||
$self->{result_values}->{prct_free} = $self->{result_values}->{free} * 100 / $self->{result_values}->{total};
|
||||
$self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total};
|
||||
$self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_total'} * $options{new_datas}->{$self->{instance} . '_used_prct'} / 100;
|
||||
$self->{result_values}->{free} = $options{new_datas}->{$self->{instance} . '_total'} - $self->{result_values}->{used};
|
||||
$self->{result_values}->{prct_free} = 100 - $options{new_datas}->{$self->{instance} . '_used_prct'};
|
||||
$self->{result_values}->{prct_used} = $options{new_datas}->{$self->{instance} . '_used_prct'};
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -108,7 +130,9 @@ sub new {
|
|||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
{
|
||||
"reload-cache-time:s" => { name => 'reload_cache_time', default => 180 },
|
||||
"display-entity-name" => { name => 'display_entity_name' },
|
||||
});
|
||||
|
||||
foreach (keys %{$maps_counters}) {
|
||||
|
@ -124,6 +148,8 @@ sub new {
|
|||
$maps_counters->{$_}->{obj}->set(%{$maps_counters->{$_}->{set}});
|
||||
}
|
||||
|
||||
$self->{statefile_cache} = centreon::plugins::statefile->new(%options);
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
@ -134,6 +160,8 @@ sub check_options {
|
|||
foreach (keys %{$maps_counters}) {
|
||||
$maps_counters->{$_}->{obj}->init(option_results => $self->{option_results});
|
||||
}
|
||||
|
||||
$self->{statefile_cache}->check_options(%options);
|
||||
}
|
||||
|
||||
sub run {
|
||||
|
@ -181,7 +209,7 @@ sub run {
|
|||
$maps_counters->{$_}->{obj}->perfdata(extra_instance => $multiple);
|
||||
}
|
||||
|
||||
$self->{output}->output_add(long_msg => "Memory '" . $self->{memory_selected}->{$id}->{display} . "' $long_msg");
|
||||
$self->{output}->output_add(long_msg => "Memory '" . $self->{memory_selected}->{$id}->{display} . "' $long_msg [entity = '" . $self->{cpu}->{$id}->{name} . "']");
|
||||
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
|
||||
if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) {
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
|
@ -198,25 +226,108 @@ sub run {
|
|||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
my $mapping = {
|
||||
extremeMemoryMonitorSystemFree => { oid => '.1.3.6.1.4.1.1916.1.32.2.2.1.3' },
|
||||
extremeMemoryMonitorSystemTotal => { oid => '.1.3.6.1.4.1.1916.1.32.2.2.1.2' },
|
||||
};
|
||||
|
||||
sub check_cache {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{hostname} = $self->{snmp}->get_hostname();
|
||||
$self->{snmp_port} = $self->{snmp}->get_port();
|
||||
|
||||
# init cache file
|
||||
$self->{write_cache} = 0;
|
||||
my $has_cache_file = $self->{statefile_cache}->read(statefile => 'cache_h3c_entity_' . $self->{hostname} . '_' . $self->{snmp_port});
|
||||
my $timestamp_cache = $self->{statefile_cache}->get(name => 'last_timestamp');
|
||||
if ($has_cache_file == 0 ||
|
||||
!defined($timestamp_cache) || ((time() - $timestamp_cache) > (($self->{option_results}->{reload_cache_time}) * 60))) {
|
||||
push @{$self->{snmp_request}}, { oid => $oid_entPhysicalEntry, start => $oid_entPhysicalDescr, end => $oid_entPhysicalName };
|
||||
$self->{write_cache} = 1;
|
||||
}
|
||||
}
|
||||
|
||||
sub write_cache {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if ($self->{write_cache} == 1) {
|
||||
my $datas = {};
|
||||
$datas->{last_timestamp} = time();
|
||||
$datas->{oids} = $self->{results}->{$oid_entPhysicalEntry};
|
||||
$self->{statefile_cache}->write(data => $datas);
|
||||
} else {
|
||||
$self->{results}->{$oid_entPhysicalEntry} = $self->{statefile_cache}->get(name => 'oids');
|
||||
}
|
||||
}
|
||||
|
||||
sub get_long_name {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my @names = ($self->{results}->{$oid_entPhysicalEntry}->{$oid_entPhysicalDescr . '.' . $options{instance}});
|
||||
my %loop = ($options{instance} => 1);
|
||||
my $child = $self->{results}->{$oid_entPhysicalEntry}->{$oid_entPhysicalContainedIn . '.' . $options{instance}};
|
||||
while (1) {
|
||||
last if (!defined($child) || defined($loop{$child}) || !defined($self->{results}->{$oid_entPhysicalEntry}->{$oid_entPhysicalDescr . '.' . $child}));
|
||||
|
||||
unshift @names, $self->{results}->{$oid_entPhysicalEntry}->{$oid_entPhysicalDescr . '.' . $child};
|
||||
$loop{$child} = 1;
|
||||
$child = $self->{results}->{$oid_entPhysicalEntry}->{$oid_entPhysicalContainedIn . '.' . $child};
|
||||
}
|
||||
|
||||
return join(' > ', @names);
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $oid_h3cEntityExtStateEntry = '.1.3.6.1.4.1.2011.10.2.6.1.1.1.1';
|
||||
my $oid_hh3cEntityExtStateEntry = '.1.3.6.1.4.1.25506.2.6.1.1.1.1';
|
||||
my $oid_hh3cEntityExtMemUsage = '.1.3.6.1.4.1.25506.2.6.1.1.1.1.8';
|
||||
my $oid_hh3cEntityExtMemSize = '.1.3.6.1.4.1.25506.2.6.1.1.1.1.10';
|
||||
my $oid_h3cEntityExtMemUsage = '.1.3.6.1.4.1.2011.10.2.6.1.1.1.1.8';
|
||||
my $oid_h3cEntityExtMemSize = '.1.3.6.1.4.1.2011.10.2.6.1.1.1.1.10';
|
||||
|
||||
$self->{snmp_request} = [
|
||||
{ oid => $oid_hh3cEntityExtMemUsage },
|
||||
{ oid => $oid_hh3cEntityExtMemSize },
|
||||
{ oid => $oid_h3cEntityExtMemUsage },
|
||||
{ oid => $oid_h3cEntityExtMemSize },
|
||||
];
|
||||
$self->check_cache() if (defined($self->{option_results}->{display_entity_name}));
|
||||
|
||||
$self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{snmp_request},
|
||||
nothing_quit => 1);
|
||||
$self->write_cache() if (defined($self->{option_results}->{display_entity_name}));
|
||||
$self->{branch} = $oid_hh3cEntityExtStateEntry;
|
||||
if (defined($self->{results}->{$oid_h3cEntityExtMemUsage}) && scalar(keys %{$self->{results}->{$oid_h3cEntityExtMemUsage}}) > 0) {
|
||||
$self->{branch} = $oid_h3cEntityExtStateEntry;
|
||||
}
|
||||
|
||||
my $mapping = {
|
||||
EntityExtMemUsage => { oid => $self->{branch} . '.8' },
|
||||
};
|
||||
my $mapping2 = {
|
||||
EntityExtMemSize => { oid => $self->{branch} . '.10' },
|
||||
};
|
||||
|
||||
$self->{memory_selected} = {};
|
||||
my $oid_extremeMemoryMonitorSystemEntry = '.1.3.6.1.4.1.1916.1.32.2.2.1';
|
||||
$self->{results} = $self->{snmp}->get_table(oid => $oid_extremeMemoryMonitorSystemEntry,
|
||||
nothing_quit => 1);
|
||||
foreach my $oid (keys %{$self->{results}}) {
|
||||
next if ($oid !~ /^$mapping->{extremeMemoryMonitorSystemFree}->{oid}\.(\d+)/);
|
||||
foreach my $oid (keys %{$self->{results}->{$self->{branch} . '.8'}}) {
|
||||
next if ($oid !~ /^$self->{branch}\.8\.(\d+)/);
|
||||
my $instance = $1;
|
||||
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}, instance => $instance);
|
||||
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$self->{branch} . '.8'}, instance => $instance);
|
||||
my $result2 = $self->{snmp}->map_instance(mapping => $mapping2, results => $self->{results}->{$self->{branch} . '.10'}, instance => $instance);
|
||||
|
||||
$self->{memory_selected}->{$instance} = { display => $instance,
|
||||
free => $result->{extremeMemoryMonitorSystemFree} * 1024, total => $result->{extremeMemoryMonitorSystemTotal} * 1024};
|
||||
if (defined($result2->{EntityExtMemSize}) && $result2->{EntityExtMemSize} > 0) {
|
||||
my $name = '-';
|
||||
|
||||
if (defined($self->{option_results}->{display_entity_name})) {
|
||||
$name = $self->get_long_name(instance => $instance);
|
||||
}
|
||||
$self->{memory_selected}->{$instance} = { display => $instance, name => $name,
|
||||
used_prct => $result->{EntityExtMemUsage}, total => $result2->{EntityExtMemSize}};
|
||||
}
|
||||
}
|
||||
|
||||
if (scalar(keys %{$self->{memory_selected}}) <= 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "No entry found.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -238,6 +349,14 @@ Threshold warning (in percent).
|
|||
|
||||
Threshold critical (in percent).
|
||||
|
||||
=item B<--reload-cache-time>
|
||||
|
||||
Time in seconds before reloading cache file (default: 180).
|
||||
|
||||
=item B<--display-entity-name>
|
||||
|
||||
Display entity name of the component. A cache file will be used.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
|
|
@ -47,10 +47,10 @@ sub new {
|
|||
|
||||
$self->{version} = '1.0';
|
||||
%{$self->{modes}} = (
|
||||
#'cpu' => 'network::h3c::snmp::mode::cpu',
|
||||
'cpu' => 'network::h3c::snmp::mode::cpu',
|
||||
'hardware' => 'network::h3c::snmp::mode::hardware',
|
||||
'list-interfaces' => 'snmp_standard::mode::listinterfaces',
|
||||
#'memory' => 'network::h3c::snmp::mode::memory',
|
||||
'memory' => 'network::h3c::snmp::mode::memory',
|
||||
'traffic' => 'snmp_standard::mode::traffic',
|
||||
);
|
||||
|
||||
|
|
Loading…
Reference in New Issue