This commit is contained in:
Kevin Duret 2014-04-30 16:26:34 +02:00
commit 893f7241a8
6 changed files with 21 additions and 16 deletions

View File

@ -54,7 +54,7 @@ sub new {
"critical-read:s" => { name => 'critical_read' },
"warning-write:s" => { name => 'warning_write' },
"critical-write:s" => { name => 'critical_write' },
"reload-cache-time:s" => { name => 'reload_cache_time' },
"reload-cache-time:s" => { name => 'reload_cache_time', default => 180 },
"name" => { name => 'use_name' },
"device:s" => { name => 'device' },
"regexp" => { name => 'use_regexp' },
@ -207,6 +207,7 @@ sub run {
sub reload_cache {
my ($self) = @_;
my $datas = {};
$datas->{last_timestamp} = time();
$datas->{all_ids} = [];
my $oid_diskIODevice = '.1.3.6.1.4.1.2021.13.15.1.1.2';
@ -236,8 +237,8 @@ sub manage_selection {
}
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))) {
if ($has_cache_file == 0 || !defined($timestamp_cache) ||
((time() - $timestamp_cache) > (($self->{option_results}->{reload_cache_time}) * 60))) {
$self->reload_cache();
$self->{statefile_cache}->read();
}

View File

@ -59,7 +59,7 @@ sub new {
"critical:s" => { name => 'critical' },
"units:s" => { name => 'units', default => '%' },
"free" => { name => 'free' },
"reload-cache-time:s" => { name => 'reload_cache_time' },
"reload-cache-time:s" => { name => 'reload_cache_time', default => 180 },
"diskpath:s" => { name => 'diskpath' },
"name" => { name => 'use_name' },
"regexp" => { name => 'use_regexp' },
@ -189,6 +189,7 @@ sub reload_cache {
my $datas = {};
my $result = $self->{snmp}->get_table(oid => $oid_dskPath);
$datas->{last_timestamp} = time();
$datas->{all_ids} = [];
my $last_num = 0;
foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) {
@ -216,8 +217,8 @@ sub manage_selection {
}
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))) {
if ($has_cache_file == 0 || !defined($timestamp_cache) ||
((time() - $timestamp_cache) > (($self->{option_results}->{reload_cache_time}) * 60))) {
$self->reload_cache();
$self->{statefile_cache}->read();
}

View File

@ -54,7 +54,7 @@ sub new {
{
"warning:s" => { name => 'warning' },
"critical:s" => { name => 'critical' },
"reload-cache-time:s" => { name => 'reload_cache_time' },
"reload-cache-time:s" => { name => 'reload_cache_time', default => 180 },
"name" => { name => 'use_name' },
"diskpath:s" => { name => 'diskpath' },
"regexp" => { name => 'use_regexp' },
@ -138,8 +138,8 @@ sub reload_cache {
my $datas = {};
my $result = $self->{snmp}->get_table(oid => $oid_dskPath);
$datas->{last_timestamp} = time();
$datas->{all_ids} = [];
my $last_num = 0;
foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) {
next if ($key !~ /\.([0-9]+)$/);
push @{$datas->{all_ids}}, $1;
@ -165,8 +165,8 @@ sub manage_selection {
}
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))) {
if ($has_cache_file == 0 || !defined($timestamp_cache) ||
((time() - $timestamp_cache) > (($self->{option_results}->{reload_cache_time}) * 60))) {
$self->reload_cache();
$self->{statefile_cache}->read();
}

View File

@ -65,7 +65,7 @@ sub new {
"critical-in-error:s" => { name => 'critical_in_error' },
"warning-out-error:s" => { name => 'warning_out_error' },
"critical-out-error:s" => { name => 'critical_out_error' },
"reload-cache-time:s" => { name => 'reload_cache_time' },
"reload-cache-time:s" => { name => 'reload_cache_time', default => 180 },
"name" => { name => 'use_name' },
"interface:s" => { name => 'interface' },
"skip" => { name => 'skip' },
@ -356,6 +356,7 @@ sub reload_cache {
$datas->{oid_filter} = $self->{option_results}->{oid_filter};
$datas->{oid_display} = $self->{option_results}->{oid_display};
$datas->{last_timestamp} = time();
$datas->{all_ids} = [];
my $result = $self->{snmp}->get_table(oid => $oids_iftable{$self->{option_results}->{oid_filter}});
foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) {
@ -395,7 +396,7 @@ sub manage_selection {
my $oid_filter = $self->{statefile_cache}->get(name => 'oid_filter');
if ($has_cache_file == 0 ||
($self->{option_results}->{oid_display} !~ /^($oid_display|$oid_filter)$/i || $self->{option_results}->{oid_filter} !~ /^($oid_display|$oid_filter)$/i) ||
(defined($timestamp_cache) && (time() - $timestamp_cache) > (($self->{option_results}->{reload_cache_time}) * 60))) {
!defined($timestamp_cache) || ((time() - $timestamp_cache) > (($self->{option_results}->{reload_cache_time}) * 60))) {
$self->reload_cache();
$self->{statefile_cache}->read();
}

View File

@ -95,7 +95,7 @@ sub new {
"critical:s" => { name => 'critical' },
"units:s" => { name => 'units', default => '%' },
"free" => { name => 'free' },
"reload-cache-time:s" => { name => 'reload_cache_time' },
"reload-cache-time:s" => { name => 'reload_cache_time', default => 180 },
"name" => { name => 'use_name' },
"storage:s" => { name => 'storage' },
"regexp" => { name => 'use_regexp' },
@ -251,6 +251,7 @@ sub reload_cache {
$datas->{oid_filter} = $self->{option_results}->{oid_filter};
$datas->{oid_display} = $self->{option_results}->{oid_display};
$datas->{last_timestamp} = time();
$datas->{all_ids} = [];
my $result = $self->{snmp}->get_table(oid => $oids_hrStorageTable{$self->{option_results}->{oid_filter}});
foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) {
@ -296,7 +297,7 @@ sub manage_selection {
my $oid_filter = $self->{statefile_cache}->get(name => 'oid_filter');
if ($has_cache_file == 0 ||
($self->{option_results}->{oid_display} !~ /^($oid_display|$oid_filter)$/i || $self->{option_results}->{oid_filter} !~ /^($oid_display|$oid_filter)$/i) ||
(defined($timestamp_cache) && (time() - $timestamp_cache) > (($self->{option_results}->{reload_cache_time}) * 60))) {
!defined($timestamp_cache) || ((time() - $timestamp_cache) > (($self->{option_results}->{reload_cache_time}) * 60))) {
$self->reload_cache();
$self->{statefile_cache}->read();
}

View File

@ -61,7 +61,7 @@ sub new {
"critical-in:s" => { name => 'critical_in' },
"warning-out:s" => { name => 'warning_out' },
"critical-out:s" => { name => 'critical_out' },
"reload-cache-time:s" => { name => 'reload_cache_time' },
"reload-cache-time:s" => { name => 'reload_cache_time', default => 180 },
"name" => { name => 'use_name' },
"interface:s" => { name => 'interface' },
"speed:s" => { name => 'speed' },
@ -305,6 +305,7 @@ sub reload_cache {
$datas->{oid_filter} = $self->{option_results}->{oid_filter};
$datas->{oid_display} = $self->{option_results}->{oid_display};
$datas->{last_timestamp} = time();
$datas->{all_ids} = [];
my $result = $self->{snmp}->get_table(oid => $oids_iftable{$self->{option_results}->{oid_filter}});
foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) {
@ -344,7 +345,7 @@ sub manage_selection {
my $oid_filter = $self->{statefile_cache}->get(name => 'oid_filter');
if ($has_cache_file == 0 ||
($self->{option_results}->{oid_display} !~ /^($oid_display|$oid_filter)$/i || $self->{option_results}->{oid_filter} !~ /^($oid_display|$oid_filter)$/i) ||
(defined($timestamp_cache) && (time() - $timestamp_cache) > (($self->{option_results}->{reload_cache_time}) * 60))) {
!defined($timestamp_cache) || ((time() - $timestamp_cache) > (($self->{option_results}->{reload_cache_time}) * 60))) {
$self->reload_cache();
$self->{statefile_cache}->read();
}