WIP catalog functions
This commit is contained in:
parent
c9bf84d279
commit
7eafc453ae
|
@ -27,8 +27,7 @@ use warnings;
|
||||||
use Time::HiRes qw(gettimeofday);
|
use Time::HiRes qw(gettimeofday);
|
||||||
use XML::XPath;
|
use XML::XPath;
|
||||||
use WWW::Selenium;
|
use WWW::Selenium;
|
||||||
|
use centreon::plugins::templates::catalog_functions;
|
||||||
my $instance_mode;
|
|
||||||
|
|
||||||
my %handlers = (ALRM => {} );
|
my %handlers = (ALRM => {} );
|
||||||
|
|
||||||
|
@ -84,30 +83,6 @@ sub custom_count_calc {
|
||||||
return 0;
|
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 {
|
sub custom_state_output {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
@ -186,7 +161,7 @@ sub set_counters {
|
||||||
closure_custom_calc => $self->can('custom_state_calc'),
|
closure_custom_calc => $self->can('custom_state_calc'),
|
||||||
closure_custom_output => $self->can('custom_state_output'),
|
closure_custom_output => $self->can('custom_state_output'),
|
||||||
closure_custom_perfdata => sub { return 0; },
|
closure_custom_perfdata => sub { return 0; },
|
||||||
closure_custom_threshold_check => $self->can('custom_state_threshold'),
|
closure_custom_threshold_check => ¢reon::plugins::templates::catalog_functions::catalog_status_threshold,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ label => 'time-step', set => {
|
{ label => 'time-step', set => {
|
||||||
|
@ -260,7 +235,6 @@ sub check_options {
|
||||||
$self->{output}->option_exit();
|
$self->{output}->option_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
$instance_mode = $self;
|
|
||||||
$self->change_macros();
|
$self->change_macros();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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__
|
||||||
|
|
|
@ -106,6 +106,7 @@ sub new {
|
||||||
$_->{obj} = centreon::plugins::values->new(statefile => $self->{statefile_value},
|
$_->{obj} = centreon::plugins::values->new(statefile => $self->{statefile_value},
|
||||||
output => $self->{output}, perfdata => $self->{perfdata},
|
output => $self->{output}, perfdata => $self->{perfdata},
|
||||||
label => $_->{label});
|
label => $_->{label});
|
||||||
|
$_->{obj}->{instance_mode} = $self;
|
||||||
$_->{obj}->set(%{$_->{set}});
|
$_->{obj}->set(%{$_->{set}});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,35 +24,7 @@ use base qw(centreon::plugins::templates::counter);
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
|
use centreon::plugins::templates::catalog_functions;
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
sub custom_status_output {
|
sub custom_status_output {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
@ -82,7 +54,7 @@ sub set_counters {
|
||||||
closure_custom_calc => $self->can('custom_status_calc'),
|
closure_custom_calc => $self->can('custom_status_calc'),
|
||||||
closure_custom_output => $self->can('custom_status_output'),
|
closure_custom_output => $self->can('custom_status_output'),
|
||||||
closure_custom_perfdata => sub { return 0; },
|
closure_custom_perfdata => sub { return 0; },
|
||||||
closure_custom_threshold_check => $self->can('custom_threshold_output'),
|
closure_custom_threshold_check => \¢reon::plugins::templates::catalog_functions::catalog_status_threshold,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ label => 'load', set => {
|
{ label => 'load', set => {
|
||||||
|
@ -153,7 +125,6 @@ sub check_options {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
$self->SUPER::check_options(%options);
|
$self->SUPER::check_options(%options);
|
||||||
|
|
||||||
$instance_mode = $self;
|
|
||||||
$self->change_macros();
|
$self->change_macros();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue