WIP catalog functions

This commit is contained in:
garnier-quentin 2019-01-14 15:11:33 +01:00
parent c9bf84d279
commit 7eafc453ae
4 changed files with 63 additions and 59 deletions

View File

@ -27,8 +27,7 @@ use warnings;
use Time::HiRes qw(gettimeofday);
use XML::XPath;
use WWW::Selenium;
my $instance_mode;
use centreon::plugins::templates::catalog_functions;
my %handlers = (ALRM => {} );
@ -84,30 +83,6 @@ sub custom_count_calc {
return 0;
}
sub custom_state_threshold {
my ($self, %options) = @_;
my $status = 'ok';
my $message;
eval {
local $SIG{__WARN__} = sub { $message = $_[0]; };
local $SIG{__DIE__} = sub { $message = $_[0]; };
if (defined($instance_mode->{option_results}->{critical_state}) && $instance_mode->{option_results}->{critical_state} ne '' &&
eval "$instance_mode->{option_results}->{critical_state}") {
$status = 'critical';
} elsif (defined($instance_mode->{option_results}->{warning_state}) && $instance_mode->{option_results}->{warning_state} ne '' &&
eval "$instance_mode->{option_results}->{warning_state}") {
$status = 'warning';
}
};
if (defined($message)) {
$self->{output}->output_add(long_msg => 'filter status issue: ' . $message);
}
return $status;
}
sub custom_state_output {
my ($self, %options) = @_;
@ -186,7 +161,7 @@ sub set_counters {
closure_custom_calc => $self->can('custom_state_calc'),
closure_custom_output => $self->can('custom_state_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => $self->can('custom_state_threshold'),
closure_custom_threshold_check => &centreon::plugins::templates::catalog_functions::catalog_status_threshold,
}
},
{ label => 'time-step', set => {
@ -260,7 +235,6 @@ sub check_options {
$self->{output}->option_exit();
}
$instance_mode = $self;
$self->change_macros();
}

View File

@ -0,0 +1,58 @@
#
# Copyright 2018 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package centreon::plugins::templates::catalog_functions;
use strict;
use warnings;
sub catalog_status_threshold {
my ($self, %options) = @_;
my $status = 'ok';
my $message;
eval {
local $SIG{__WARN__} = sub { $message = $_[0]; };
local $SIG{__DIE__} = sub { $message = $_[0]; };
my $label = $self->{label};
$label =~ s/-/_/g;
if (defined($self->{instance_mode}->{option_results}->{'critical_' . $label}) && $self->{instance_mode}->{option_results}->{'critical_' . $label} ne '' &&
eval "$self->{instance_mode}->{option_results}->{'critical_' . $label}") {
$status = 'critical';
} elsif (defined($self->{instance_mode}->{option_results}->{'warning_' . $label}) && $self->{instance_mode}->{option_results}->{'warning_' . $label} ne '' &&
eval "$self->{instance_mode}->{option_results}->{'warning_' . $label}") {
$status = 'warning';
} elsif (defined($self->{instance_mode}->{option_results}->{'unknown_' . $label}) && $self->{instance_mode}->{option_results}->{'unknown_' . $label} ne '' &&
eval "$self->{instance_mode}->{option_results}->{'unknown_' . $label}") {
$status = 'unknown';
}
};
if (defined($message)) {
$self->{output}->output_add(long_msg => 'filter status issue: ' . $message);
}
return $status;
}
1;
__END__

View File

@ -106,6 +106,7 @@ sub new {
$_->{obj} = centreon::plugins::values->new(statefile => $self->{statefile_value},
output => $self->{output}, perfdata => $self->{perfdata},
label => $_->{label});
$_->{obj}->{instance_mode} = $self;
$_->{obj}->set(%{$_->{set}});
}
}

View File

@ -24,35 +24,7 @@ use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
my $instance_mode;
sub custom_threshold_output {
my ($self, %options) = @_;
my $status = 'ok';
my $message;
eval {
local $SIG{__WARN__} = sub { $message = $_[0]; };
local $SIG{__DIE__} = sub { $message = $_[0]; };
if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' &&
eval "$instance_mode->{option_results}->{critical_status}") {
$status = 'critical';
} elsif (defined($instance_mode->{option_results}->{warning_status}) && $instance_mode->{option_results}->{warning_status} ne '' &&
eval "$instance_mode->{option_results}->{warning_status}") {
$status = 'warning';
} elsif (defined($instance_mode->{option_results}->{unknown_status}) && $instance_mode->{option_results}->{unknown_status} ne '' &&
eval "$instance_mode->{option_results}->{unknown_status}") {
$status = 'unknown';
}
};
if (defined($message)) {
$self->{output}->output_add(long_msg => 'filter status issue: ' . $message);
}
return $status;
}
use centreon::plugins::templates::catalog_functions;
sub custom_status_output {
my ($self, %options) = @_;
@ -82,7 +54,7 @@ sub set_counters {
closure_custom_calc => $self->can('custom_status_calc'),
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => $self->can('custom_threshold_output'),
closure_custom_threshold_check => \&centreon::plugins::templates::catalog_functions::catalog_status_threshold,
}
},
{ label => 'load', set => {
@ -153,7 +125,6 @@ sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$instance_mode = $self;
$self->change_macros();
}