+ add memory for vmware checks

This commit is contained in:
Quentin Garnier 2015-02-20 11:41:11 +01:00
parent 5bb268138d
commit 4d4a87ec74
3 changed files with 32 additions and 3 deletions

View File

@ -51,6 +51,7 @@ sub new {
"datacenter:s" => { name => 'datacenter' }, "datacenter:s" => { name => 'datacenter' },
"filter" => { name => 'filter' }, "filter" => { name => 'filter' },
"filter-time:s" => { name => 'filter_time', }, "filter-time:s" => { name => 'filter_time', },
"memory" => { name => 'memory', },
}); });
return $self; return $self;
} }
@ -92,6 +93,10 @@ Datacenter is a regexp.
Don't check alarm older (value in seconds). Don't check alarm older (value in seconds).
=item B<--memory>
Check new alarms only.
=back =back
=cut =cut

View File

@ -51,6 +51,7 @@ sub new {
"esx-hostname:s" => { name => 'esx_hostname' }, "esx-hostname:s" => { name => 'esx_hostname' },
"filter" => { name => 'filter' }, "filter" => { name => 'filter' },
"filter-time:s" => { name => 'filter_time', }, "filter-time:s" => { name => 'filter_time', },
"memory" => { name => 'memory', },
}); });
return $self; return $self;
} }
@ -92,6 +93,10 @@ Datacenter is a regexp.
Don't check alarm older (value in seconds). Don't check alarm older (value in seconds).
=item B<--memory>
Check new alarms only.
=back =back
=cut =cut

View File

@ -60,6 +60,7 @@ sub new {
$options{options}->add_help(package => __PACKAGE__, sections => 'RETENTION OPTIONS', once => 1); $options{options}->add_help(package => __PACKAGE__, sections => 'RETENTION OPTIONS', once => 1);
} }
$self->{error} = 0;
$self->{output} = $options{output}; $self->{output} = $options{output};
$self->{datas} = {}; $self->{datas} = {};
$self->{storable} = 0; $self->{storable} = 0;
@ -95,11 +96,22 @@ sub check_options {
$self->{statefile_suffix} = $options{option_results}->{statefile_suffix}; $self->{statefile_suffix} = $options{option_results}->{statefile_suffix};
} }
sub error {
my ($self) = shift;
if (@_) {
$self->{error} = $_[0];
}
return $self->{error};
}
sub read { sub read {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{statefile_suffix} = defined($options{statefile_suffix}) ? $options{statefile_suffix} : $self->{statefile_suffix};
$self->{statefile_dir} = defined($options{statefile_dir}) ? $options{statefile_dir} : $self->{statefile_dir}; $self->{statefile_dir} = defined($options{statefile_dir}) ? $options{statefile_dir} : $self->{statefile_dir};
$self->{statefile} = defined($options{statefile}) ? $options{statefile} . $self->{statefile_suffix} : $self->{statefile} = defined($options{statefile}) ? $options{statefile} . $self->{statefile_suffix} :
$self->{statefile}; $self->{statefile};
$self->{no_quit} = defined($options{no_quit}) && $options{no_quit} == 1 ? 1 : 0;
if (defined($self->{memcached})) { if (defined($self->{memcached})) {
# if "SUCCESS" or "NOT FOUND" is ok. Other with use the file # if "SUCCESS" or "NOT FOUND" is ok. Other with use the file
@ -118,13 +130,20 @@ sub read {
if (! -e $self->{statefile_dir} . "/" . $self->{statefile}) { if (! -e $self->{statefile_dir} . "/" . $self->{statefile}) {
if (! -w $self->{statefile_dir}) { if (! -w $self->{statefile_dir}) {
$self->error(1);
$self->{output}->add_option_msg(short_msg => "Cannot write statefile '" . $self->{statefile_dir} . "/" . $self->{statefile} . "'. Need write permissions on directory."); $self->{output}->add_option_msg(short_msg => "Cannot write statefile '" . $self->{statefile_dir} . "/" . $self->{statefile} . "'. Need write permissions on directory.");
if ($self->{no_quit} == 0) {
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
}
return 0; return 0;
} elsif (! -w $self->{statefile_dir} . "/" . $self->{statefile}) { } elsif (! -w $self->{statefile_dir} . "/" . $self->{statefile}) {
$self->error(1);
$self->{output}->add_option_msg(short_msg => "Cannot write statefile '" . $self->{statefile_dir} . "/" . $self->{statefile} . "'. Need write permissions on file."); $self->{output}->add_option_msg(short_msg => "Cannot write statefile '" . $self->{statefile_dir} . "/" . $self->{statefile} . "'. Need write permissions on file.");
if ($self->{no_quit} == 0) {
$self->{output}->option_exit(); $self->{output}->option_exit();
}
return 1;
} elsif (! -s $self->{statefile_dir} . "/" . $self->{statefile}) { } elsif (! -s $self->{statefile_dir} . "/" . $self->{statefile}) {
# Empty file. Not a problem. Maybe plugin not manage not values # Empty file. Not a problem. Maybe plugin not manage not values
return 0; return 0;