update apache slotstates with counter class

This commit is contained in:
garnier-quentin 2019-04-18 17:18:34 +02:00
parent e704bd76d4
commit 023310fd55
1 changed files with 138 additions and 196 deletions

View File

@ -20,124 +20,20 @@
package apps::apache::serverstatus::mode::slotstates;
use base qw(centreon::plugins::mode);
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::http;
use centreon::plugins::values;
my $instance_mode;
my $maps_counters = {
global => {
'000_busy' => { set => {
key_values => [ { name => 'busy' }, { name => 'total' } ],
closure_custom_calc => \&custom_value_calc, closure_custom_calc_extra_options => { label_ref => 'busy' },
closure_custom_output => \&custom_value_output,
closure_custom_threshold_check => \&custom_value_threshold,
closure_custom_perfdata => \&custom_value_perfdata,
}
},
'001_free' => { set => {
key_values => [ { name => 'free' }, { name => 'total' } ],
closure_custom_calc => \&custom_value_calc, closure_custom_calc_extra_options => { label_ref => 'free' },
closure_custom_output => \&custom_value_output,
closure_custom_threshold_check => \&custom_value_threshold,
closure_custom_perfdata => \&custom_value_perfdata,
}
},
'002_waiting' => { set => {
key_values => [ { name => 'waiting' }, { name => 'total' } ],
closure_custom_calc => \&custom_value_calc, closure_custom_calc_extra_options => { label_ref => 'waiting' },
closure_custom_output => \&custom_value_output,
closure_custom_threshold_check => \&custom_value_threshold,
closure_custom_perfdata => \&custom_value_perfdata,
}
},
'003_starting' => { set => {
key_values => [ { name => 'starting' }, { name => 'total' } ],
closure_custom_calc => \&custom_value_calc, closure_custom_calc_extra_options => { label_ref => 'starting' },
closure_custom_output => \&custom_value_output,
closure_custom_threshold_check => \&custom_value_threshold,
closure_custom_perfdata => \&custom_value_perfdata,
}
},
'004_reading' => { set => {
key_values => [ { name => 'reading' }, { name => 'total' } ],
closure_custom_calc => \&custom_value_calc, closure_custom_calc_extra_options => { label_ref => 'reading' },
closure_custom_output => \&custom_value_output,
closure_custom_threshold_check => \&custom_value_threshold,
closure_custom_perfdata => \&custom_value_perfdata,
}
},
'005_sending' => { set => {
key_values => [ { name => 'sending' }, { name => 'total' } ],
closure_custom_calc => \&custom_value_calc, closure_custom_calc_extra_options => { label_ref => 'sending' },
closure_custom_output => \&custom_value_output,
closure_custom_threshold_check => \&custom_value_threshold,
closure_custom_perfdata => \&custom_value_perfdata,
}
},
'006_keepalive' => { set => {
key_values => [ { name => 'keepalive' }, { name => 'total' } ],
closure_custom_calc => \&custom_value_calc, closure_custom_calc_extra_options => { label_ref => 'keepalive' },
closure_custom_output => \&custom_value_output,
closure_custom_threshold_check => \&custom_value_threshold,
closure_custom_perfdata => \&custom_value_perfdata,
}
},
'007_dns-lookup' => { set => {
key_values => [ { name => 'dns_lookup' }, { name => 'total' } ],
closure_custom_calc => \&custom_value_calc, closure_custom_calc_extra_options => { label_ref => 'dns_lookup' },
closure_custom_output => \&custom_value_output,
closure_custom_threshold_check => \&custom_value_threshold,
closure_custom_perfdata => \&custom_value_perfdata,
}
},
'008_closing' => { set => {
key_values => [ { name => 'closing' }, { name => 'total' } ],
closure_custom_calc => \&custom_value_calc, closure_custom_calc_extra_options => { label_ref => 'closing' },
closure_custom_output => \&custom_value_output,
closure_custom_threshold_check => \&custom_value_threshold,
closure_custom_perfdata => \&custom_value_perfdata,
}
},
'009_logging' => { set => {
key_values => [ { name => 'logging' }, { name => 'total' } ],
closure_custom_calc => \&custom_value_calc, closure_custom_calc_extra_options => { label_ref => 'logging' },
closure_custom_output => \&custom_value_output,
closure_custom_threshold_check => \&custom_value_threshold,
closure_custom_perfdata => \&custom_value_perfdata,
}
},
'007_gracefuly-finished' => { set => {
key_values => [ { name => 'gracefuly_finished' }, { name => 'total' } ],
closure_custom_calc => \&custom_value_calc, closure_custom_calc_extra_options => { label_ref => 'gracefuly_finished' },
closure_custom_output => \&custom_value_output,
closure_custom_threshold_check => \&custom_value_threshold,
closure_custom_perfdata => \&custom_value_perfdata,
}
},
'007_idle-cleanup-worker' => { set => {
key_values => [ { name => 'idle_cleanup_worker' }, { name => 'total' } ],
closure_custom_calc => \&custom_value_calc, closure_custom_calc_extra_options => { label_ref => 'idle_cleanup_worker' },
closure_custom_output => \&custom_value_output,
closure_custom_threshold_check => \&custom_value_threshold,
closure_custom_perfdata => \&custom_value_perfdata,
}
},
},
};
sub custom_value_threshold {
my ($self, %options) = @_;
my $exit = 'ok';
if ($instance_mode->{option_results}->{units} eq '%') {
$exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{prct}, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{label}, exit_litteral => 'warning' } ]);
if ($self->{instance_mode}->{option_results}->{units} eq '%') {
$exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{prct}, threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } ]);
} else {
$exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{used}, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{label}, exit_litteral => 'warning' } ]);
$exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{used}, threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } ]);
}
return $exit;
}
@ -146,19 +42,22 @@ sub custom_value_perfdata {
my ($self, %options) = @_;
my ($warning, $critical);
if ($instance_mode->{option_results}->{units} eq '%') {
$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);
if ($self->{instance_mode}->{option_results}->{units} eq '%') {
$warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}, total => $self->{result_values}->{total}, cast_int => 1);
$critical = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}, total => $self->{result_values}->{total}, cast_int => 1);
} else {
$warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label});
$critical = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label});
$warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel});
$critical = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel});
}
$self->{output}->perfdata_add(label => $self->{result_values}->{label},
value => $self->{result_values}->{used},
warning => $warning,
critical => $critical,
min => 0, max => $self->{result_values}->{total});
$self->{output}->perfdata_add(
label => $self->{result_values}->{label},
nlabel => $self->{nlabel},
value => $self->{result_values}->{used},
warning => $warning,
critical => $critical,
min => 0, max => $self->{result_values}->{total}
);
}
sub custom_value_output {
@ -188,6 +87,113 @@ sub custom_value_calc {
return 0;
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0, cb_prefix_output => 'prefix_global_output', skipped_code => { -2 => 1 } }
];
$self->{maps_counters}->{global} = [
{ label => 'busy', nlabel => 'apache.slot.busy.count', set => {
key_values => [ { name => 'busy' }, { name => 'total' } ],
closure_custom_calc => $self->can('custom_value_calc'), closure_custom_calc_extra_options => { label_ref => 'busy' },
closure_custom_output => $self->can('custom_value_output'),
closure_custom_threshold_check => $self->can('custom_value_threshold'),
closure_custom_perfdata => $self->can('custom_value_perfdata'),
}
},
{ label => 'free', nlabel => 'apache.slot.free.count', set => {
key_values => [ { name => 'free' }, { name => 'total' } ],
closure_custom_calc => $self->can('custom_value_calc'), closure_custom_calc_extra_options => { label_ref => 'free' },
closure_custom_output => $self->can('custom_value_output'),
closure_custom_threshold_check => $self->can('custom_value_threshold'),
closure_custom_perfdata => $self->can('custom_value_perfdata'),
}
},
{ label => 'waiting', nlabel => 'apache.slot.waiting.count', set => {
key_values => [ { name => 'waiting' }, { name => 'total' } ],
closure_custom_calc => $self->can('custom_value_calc'), closure_custom_calc_extra_options => { label_ref => 'waiting' },
closure_custom_output => $self->can('custom_value_output'),
closure_custom_threshold_check => $self->can('custom_value_threshold'),
closure_custom_perfdata => $self->can('custom_value_perfdata'),
}
},
{ label => 'starting', nlabel => 'apache.slot.starting.count', set => {
key_values => [ { name => 'starting' }, { name => 'total' } ],
closure_custom_calc => $self->can('custom_value_calc'), closure_custom_calc_extra_options => { label_ref => 'starting' },
closure_custom_output => $self->can('custom_value_output'),
closure_custom_threshold_check => $self->can('custom_value_threshold'),
closure_custom_perfdata => $self->can('custom_value_perfdata'),
}
},
{ label => 'reading', nlabel => 'apache.slot.reading.count', set => {
key_values => [ { name => 'reading' }, { name => 'total' } ],
closure_custom_calc => $self->can('custom_value_calc'), closure_custom_calc_extra_options => { label_ref => 'reading' },
closure_custom_output => $self->can('custom_value_output'),
closure_custom_threshold_check => $self->can('custom_value_threshold'),
closure_custom_perfdata => $self->can('custom_value_perfdata'),
}
},
{ label => 'sending', nlabel => 'apache.slot.sending.count', set => {
key_values => [ { name => 'sending' }, { name => 'total' } ],
closure_custom_calc => $self->can('custom_value_calc'), closure_custom_calc_extra_options => { label_ref => 'sending' },
closure_custom_output => $self->can('custom_value_output'),
closure_custom_threshold_check => $self->can('custom_value_threshold'),
closure_custom_perfdata => $self->can('custom_value_perfdata'),
}
},
{ label => 'keepalive', nlabel => 'apache.slot.keepalive.count', set => {
key_values => [ { name => 'keepalive' }, { name => 'total' } ],
closure_custom_calc => $self->can('custom_value_calc'), closure_custom_calc_extra_options => { label_ref => 'keepalive' },
closure_custom_output => $self->can('custom_value_output'),
closure_custom_threshold_check => $self->can('custom_value_threshold'),
closure_custom_perfdata => $self->can('custom_value_perfdata'),
}
},
{ label => 'dns-lookup', nlabel => 'apache.slot.dnslookup.count', set => {
key_values => [ { name => 'dns_lookup' }, { name => 'total' } ],
closure_custom_calc => $self->can('custom_value_calc'), closure_custom_calc_extra_options => { label_ref => 'dns_lookup' },
closure_custom_output => $self->can('custom_value_output'),
closure_custom_threshold_check => $self->can('custom_value_threshold'),
closure_custom_perfdata => $self->can('custom_value_perfdata'),
}
},
{ label => 'closing', nlabel => 'apache.slot.closing.count', set => {
key_values => [ { name => 'closing' }, { name => 'total' } ],
closure_custom_calc => $self->can('custom_value_calc'), closure_custom_calc_extra_options => { label_ref => 'closing' },
closure_custom_output => $self->can('custom_value_output'),
closure_custom_threshold_check => $self->can('custom_value_threshold'),
closure_custom_perfdata => $self->can('custom_value_perfdata'),
}
},
{ label => 'logging', nlabel => 'apache.slot.logging.count', set => {
key_values => [ { name => 'logging' }, { name => 'total' } ],
closure_custom_calc => $self->can('custom_value_calc'), closure_custom_calc_extra_options => { label_ref => 'logging' },
closure_custom_output => $self->can('custom_value_output'),
closure_custom_threshold_check => $self->can('custom_value_threshold'),
closure_custom_perfdata => $self->can('custom_value_perfdata'),
}
},
{ label => 'gracefuly-finished', nlabel => 'apache.slot.gracefulyfinished.count', set => {
key_values => [ { name => 'gracefuly_finished' }, { name => 'total' } ],
closure_custom_calc => $self->can('custom_value_calc'), closure_custom_calc_extra_options => { label_ref => 'gracefuly_finished' },
closure_custom_output => $self->can('custom_value_output'),
closure_custom_threshold_check => $self->can('custom_value_threshold'),
closure_custom_perfdata => $self->can('custom_value_perfdata'),
}
},
{ label => 'idle-cleanup-worker', nlabel => 'apache.slot.idlecleanupworker.count', set => {
key_values => [ { name => 'idle_cleanup_worker' }, { name => 'total' } ],
closure_custom_calc => $self->can('custom_value_calc'), closure_custom_calc_extra_options => { label_ref => 'idle_cleanup_worker' },
closure_custom_output => $self->can('custom_value_output'),
closure_custom_threshold_check => $self->can('custom_value_threshold'),
closure_custom_perfdata => $self->can('custom_value_perfdata'),
}
},
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
@ -209,105 +215,41 @@ sub new {
});
$self->{http} = centreon::plugins::http->new(%options);
foreach my $key (('global')) {
foreach (keys %{$maps_counters->{$key}}) {
my ($id, $name) = split /_/;
if (!defined($maps_counters->{$key}->{$_}->{threshold}) || $maps_counters->{$key}->{$_}->{threshold} != 0) {
$options{options}->add_options(arguments => {
'warning-' . $name . ':s' => { name => 'warning-' . $name },
'critical-' . $name . ':s' => { name => 'critical-' . $name },
});
}
$maps_counters->{$key}->{$_}->{obj} = centreon::plugins::values->new(output => $self->{output},
perfdata => $self->{perfdata},
label => $name);
$maps_counters->{$key}->{$_}->{obj}->set(%{$maps_counters->{$key}->{$_}->{set}});
}
}
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
foreach my $key (('global')) {
foreach (keys %{$maps_counters->{$key}}) {
$maps_counters->{$key}->{$_}->{obj}->init(option_results => $self->{option_results});
}
}
$self->SUPER::check_options(%options);
$instance_mode = $self;
$self->{http}->set_options(%{$self->{option_results}});
}
sub run {
sub prefix_global_output {
my ($self, %options) = @_;
$self->manage_selection();
my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', '');
my @exits;
foreach (sort keys %{$maps_counters->{global}}) {
my $obj = $maps_counters->{global}->{$_}->{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 => "Slots $short_msg"
);
} else {
$self->{output}->output_add(short_msg => "Slots $long_msg");
}
$self->{output}->display();
$self->{output}->exit();
return 'Slots ';
}
sub manage_selection {
my ($self, %options) = @_;
my $webcontent = $self->{http}->request();
my ($webcontent) = $self->{http}->request();
my $ScoreBoard = "";
if ($webcontent =~ /^Scoreboard:\s+([^\s]+)/mi) {
$ScoreBoard = $1;
}
$self->{global} = { total => length($ScoreBoard),
free => ($ScoreBoard =~ tr/\.//),
busy => length($ScoreBoard) - ($ScoreBoard =~ tr/\.//),
waiting => ($ScoreBoard =~ tr/\_//), starting => ($ScoreBoard =~ tr/S//),
reading => ($ScoreBoard =~ tr/R//), sending => ($ScoreBoard =~ tr/W//),
keepalive => ($ScoreBoard =~ tr/K//), dns_lookup => ($ScoreBoard =~ tr/D//),
closing => ($ScoreBoard =~ tr/C//), logging => ($ScoreBoard =~ tr/L//),
gracefuly_finished => ($ScoreBoard =~ tr/G//), idle_cleanup_worker => ($ScoreBoard =~ tr/I//)};
$self->{global} = {
total => length($ScoreBoard),
free => ($ScoreBoard =~ tr/\.//),
busy => length($ScoreBoard) - ($ScoreBoard =~ tr/\.//),
waiting => ($ScoreBoard =~ tr/\_//), starting => ($ScoreBoard =~ tr/S//),
reading => ($ScoreBoard =~ tr/R//), sending => ($ScoreBoard =~ tr/W//),
keepalive => ($ScoreBoard =~ tr/K//), dns_lookup => ($ScoreBoard =~ tr/D//),
closing => ($ScoreBoard =~ tr/C//), logging => ($ScoreBoard =~ tr/L//),
gracefuly_finished => ($ScoreBoard =~ tr/G//), idle_cleanup_worker => ($ScoreBoard =~ tr/I//)
};
}
1;