refactoring kingdee: done

This commit is contained in:
garnier-quentin 2020-01-20 09:59:15 +01:00
parent a90e0231f8
commit 9f61a3aade
11 changed files with 197 additions and 293 deletions

View File

@ -21,66 +21,79 @@
package apps::kingdee::eas::mode::activeusers;
use base qw(centreon::plugins::mode);
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0, skipped_code => { -10 => 1 } },
{ name => 'global_time', type => 0, cb_prefix_output => 'prefix_time_output', skipped_code => { -10 => 1 } },
];
$self->{maps_counters}->{global} = [
{ label => 'users-active-total', nlabel => 'system.users.active.total.count', set => {
key_values => [ { name => 'total' } ],
output_template => 'total users active: %s',
perfdatas => [
{ value => 'total_absolute', template => '%s', min => 0 },
],
}
}
];
$self->{maps_counters}->{global_time} = [];
foreach (('1m', '5m', '15m', '30m', '1h', '3h', '8h')) {
push @{$self->{maps_counters}->{global_time}},
{ label => 'users-active-' . $_, nlabel => 'system.users.active.' . $_ . '.count', set => {
key_values => [ { name => 'users_' . $_ } ],
output_template => '%s (' . $_ . ')',
perfdatas => [
{ value => 'users_' . $_ . '_absolute', template => '%s', min => 0 },
],
}
};
}
}
sub prefix_time_output {
my ($self, %options) = @_;
return 'active users: ';
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments =>
{
"urlpath:s" => { name => 'url_path', default => "/easportal/tools/nagios/checkactiveusers.jsp" },
"warning:s" => { name => 'warning' },
"critical:s" => { name => 'critical' },
$options{options}->add_options(arguments => {
'urlpath:s' => { name => 'url_path', default => "/easportal/tools/nagios/checkactiveusers.jsp" },
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
$self->{output}->option_exit();
}
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
$self->{output}->option_exit();
}
}
sub run {
sub manage_selection {
my ($self, %options) = @_;
my $webcontent = $options{custom}->request(path => $self->{option_results}->{url_path});
if ($webcontent !~ /.*ActiveUsers_1m=.*/i) {
$self->{output}->output_add(
severity => 'UNKNOWN',
short_msg => "Cannot find eas actvie users info."
);
$self->{output}->add_option_msg(short_msg => 'cannot find eas actvie users info.');
$self->{output}->option_exit();
}
my @activeusers = split(" ",$webcontent);
my $info;
foreach $info (@activeusers) {
if ($info =~ /(.*)=(.*)/) {
my ($counttype, $num) = ($1, $2);
$self->{output}->output_add(severity => "ok", short_msg => $info);
$self->{output}->perfdata_add(label => $counttype, unit => '',value => $num);
# ActiveUsers_1m=0 ActiveUsers_5m=0 ActiveUsers_15m=0 ActiveUsers_30m=0 ActiveUsers_1h=0 ActiveUsers_3h=0 ActiveUsers_8h=0 TotalUsers=0
$self->{global} = {};
$self->{global}->{total} = $1 if ($webcontent =~ /TotalUsers=(\d+)/mi);
$self->{global_time} = {};
while ($webcontent =~ /activeusers_(\S+?)=(\d+)/mig) {
$self->{global_time}->{'users_' . $1} = $2;
}
}
$self->{output}->display();
$self->{output}->exit();
}
1;
@ -97,13 +110,12 @@ Check eas active users info.
Set path to get status page. (Default: '/easportal/tools/nagios/checkclassloading.jsp')
=item B<--warning>
=item B<--warning-*> B<--critical-*>
Warning Threshold.
=item B<--critical>
Critical Threshold.
Thresholds.
Can be: 'sers-active-total', 'users-active-1m',
'users-active-5m', 'users-active-15m', 'users-active-30m',
'users-active-1h', 'users-active-3h', 'users-active-8h'.
=back

View File

@ -25,6 +25,7 @@ use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
sub set_counters {
my ($self, %options) = @_;
@ -71,7 +72,7 @@ sub manage_selection {
my $webcontent = $options{custom}->request(path => $self->{option_results}->{url_path});
if ($webcontent !~ /(LoadedClassCount|UnloadedClassCount)/i) {
$self->{output}->add_option_msg(short_msg => 'Cannot find classloading status.');
$self->{output}->add_option_msg(short_msg => 'cannot find classloading status.');
$self->{output}->option_exit();
}

View File

@ -25,6 +25,7 @@ use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
sub set_counters {
my ($self, %options) = @_;

View File

@ -1,107 +0,0 @@
#
# Copyright 2020 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.
#
# Author : CHEN JUN , aladdin.china@gmail.com
package apps::kingdee::eas::mode::easlicense;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$options{options}->add_options(arguments =>
{
"urlpath:s" => { name => 'url_path', default => "/easportal/tools/nagios/checkeaslicense.jsp" },
"warning:s" => { name => 'warning' },
"critical:s" => { name => 'critical' },
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
$self->{output}->option_exit();
}
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
$self->{output}->option_exit();
}
}
sub run {
my ($self, %options) = @_;
my $webcontent = $options{custom}->request(path => $self->{option_results}->{url_path});
if ($webcontent !~ /.*BOS=.*/i) {
$self->{output}->output_add(severity => 'UNKNOWN',
short_msg => "Cannot find eas license usage info.");
$self->{output}->option_exit();
}
my @licenseinfo = split(" ",$webcontent);
my $info;
foreach $info (@licenseinfo) {
if ($info =~ /(.*)=(.*)/) {
my ($modname, $num) = ($1, $2);
$self->{output}->output_add(severity => "ok", short_msg => $info);
$self->{output}->perfdata_add(label => $modname, unit => '',value => $num);
}
}
$self->{output}->display();
$self->{output}->exit();
}
1;
__END__
=head1 MODE
Check eas license usage info.
=over 8
=item B<--urlpath>
Set path to get status page. (Default: '/easportal/tools/nagios/checkclassloading.jsp')
=item B<--warning>
Warning Threshold.
=item B<--critical>
Critical Threshold.
=back
=cut

View File

@ -25,6 +25,7 @@ use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
sub set_counters {
my ($self, %options) = @_;

View File

@ -21,78 +21,90 @@
package apps::kingdee::eas::mode::oraclejvmgc;
use base qw(centreon::plugins::mode);
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', cb_prefix_output => 'prefix_global_output', type => 0 },
];
$self->{maps_counters}->{global} = [
{ label => 'gc-minor', nlabel => 'java.gc.minor.count', set => {
key_values => [ { name => 'minor_gc_count', diff => 1 } ],
output_template => 'minor count: %s',
perfdatas => [
{ value => 'minor_gc_count_absolute', template => '%s', min => 0 },
],
}
},
{ label => 'gc-minor-time', nlabel => 'java.gc.minor.time.milliseconds', set => {
key_values => [ { name => 'minor_gc_time', diff => 1 } ],
output_template => 'minor time: %s ms',
perfdatas => [
{ value => 'minor_gc_time_absolute', template => '%s', min => 0, unit => 'ms' },
],
}
},
{ label => 'gc-full', nlabel => 'java.gc.full.count', set => {
key_values => [ { name => 'full_gc_count', diff => 1 } ],
output_template => 'full count: %s',
perfdatas => [
{ value => 'full_gc_count_absolute', template => '%s', min => 0 },
],
}
},
{ label => 'gc-full-time', nlabel => 'java.gc.full.time.milliseconds', set => {
key_values => [ { name => 'full_gc_time', diff => 1 } ],
output_template => 'full time: %s ms',
perfdatas => [
{ value => 'full_gc_time_absolute', template => '%s', min => 0, unit => 'ms' },
],
}
},
];
}
sub prefix_global_output {
my ($self, %options) = @_;
return 'garbage collector ';
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments =>
{
"urlpath:s" => { name => 'url_path', default => "/easportal/tools/nagios/checkgc_ps.jsp" },
"warning:s" => { name => 'warning' },
"critical:s" => { name => 'critical' },
$options{options}->add_options(arguments => {
'urlpath:s' => { name => 'url_path', default => "/easportal/tools/nagios/checkgc_ps.jsp" },
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
$self->{output}->option_exit();
}
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
$self->{output}->option_exit();
}
}
sub run {
sub manage_selection {
my ($self, %options) = @_;
my $webcontent = $options{custom}->request(path => $self->{option_results}->{url_path});
if ( $webcontent !~ /MinorGCCount=\d+/mi ) {
$self->{output}->output_add(
severity => 'UNKNOWN',
short_msg => "Cannot find jvm gc status."
);
if ($webcontent !~ /MinorGCCount=(\d+)/mi) {
$self->{output}->add_option_msg(short_msg => 'cannot find jvm gc status.');
$self->{output}->option_exit();
}
my ($minorgccount, $minorgctime, $fullgccount, $fullgctime) = (0, 0, 0, 0);
($minorgccount, $minorgctime, $fullgccount, $fullgctime) = ($1, $2, $3, $4) if ($webcontent =~ /MinorGCCount=(\d+)\sMinorGCTime=(\d+)\sFullGCCount=(\d+)\sFullGCTime=(\d+)/mi);
$self->{output}->output_add(severity => "ok", short_msg => sprintf("MinorGCCount: %d", $minorgccount));
$self->{output}->output_add(severity => "ok", short_msg => sprintf("MinorGCTime: %dms", $minorgctime));
$self->{output}->output_add(severity => "ok", short_msg => sprintf("FullGCCount: %d", $fullgccount));
$self->{output}->output_add(severity => "ok", short_msg => sprintf("FullGCTime: %dms", $fullgctime));
$self->{output}->perfdata_add(label => "c[MinorGCCount]", unit => '',
value => sprintf("%d", $minorgccount),
);
$self->{output}->perfdata_add(label => "c[MinorGCTime]", unit => 'ms',
value => sprintf("%d", $minorgctime),
);
$self->{output}->perfdata_add(label => "c[FullGCCount]", unit => '',
value => sprintf("%d", $fullgccount),
);
$self->{output}->perfdata_add(label => "c[FullGCTime]", unit => 'ms',
value => sprintf("%d", $fullgctime),
);
$self->{output}->display();
$self->{output}->exit();
$self->{global} = { minor_gc_count => 0 };
$self->{global}->{minor_gc_time} = $1 if ($webcontent =~ /MinorGCTime=\s*(\d+)/mi);
$self->{global}->{full_gc_count} = $1 if ($webcontent =~ /FullGCCount=\s*(\d+)/mi);
$self->{global}->{full_gc_time} = $1 if ($webcontent =~ /FullGCTime=\s*(\d+)/mi);
$self->{cache_name} = 'kingdee_' . $self->{mode} . '_' . $options{custom}->get_hostname() . '_' . $options{custom}->get_port() . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
}
1;
@ -109,13 +121,10 @@ Check EAS application jvm gc status.
Set path to get status page. (Default: '/easportal/tools/nagios/checkgc_ps.jsp')
=item B<--warning>
=item B<--warning-*> B<--critical-*>
Warning Threshold for class loaded
=item B<--critical>
Critical Threshold for class unloaded
Thresholds.
Can be: 'gc-minor', 'gc-minor-time', 'gc-full', 'gc-full-time'.
=back

View File

@ -43,7 +43,7 @@ sub set_counters {
}
},
{ label => 'oracle-redolog-active', nlabel => 'datasource.oracle.redolog.active.count', set => {
key_values => [ { name => 'inactive' } ],
key_values => [ { name => 'active' } ],
output_template => 'active: %s',
perfdatas => [
{ value => 'active_absolute', template => '%s', min => 0, label_extra_instance => 1 },

View File

@ -115,7 +115,7 @@ sub manage_selection {
$self->{datasource}->{$self->{option_results}->{datasource}}->{active} + $self->{datasource}->{$self->{option_results}->{datasource}}->{inactive};
$webcontent = $options{custom}->request(path => $self->{option_results}->{url_path} . '&groupby=wait_class&status=ACTIVE');
if ($webcontent !~ /^WAIT_CLASS=.*?COUNT=\d+/i) {
if ($webcontent !~ /^WAIT_CLASS=.*?COUNT=\d+/mi) {
$self->{output}->add_option_msg(short_msg => 'Cannot find oracle session info.');
$self->{output}->option_exit();
}

View File

@ -2,7 +2,7 @@
# Copyright 2020 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure application monitoring for
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
@ -14,105 +14,93 @@
# 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
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Author : CHEN JUN , aladdin.china@gmail.com
package apps::kingdee::eas::mode::oracletable;
use base qw(centreon::plugins::mode);
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'datasource', type => 1, cb_prefix_output => 'prefix_datasource_output', skipped_code => { -10 => 1 } },
];
$self->{maps_counters}->{datasource} = [
{ label => 'table-rows', nlabel => 'datasource.table.rows.count', set => {
key_values => [ { name => 'num_rows' } ],
output_template => 'number of rows: %s',
perfdatas => [
{ value => 'num_rows_absolute', template => '%s', min => 0, label_extra_instance => 1 },
],
}
},
{ label => 'table-actual-rows', nlabel => 'datasource.table.actual.rows.count', set => {
key_values => [ { name => 'actual_num_rows' } ],
output_template => 'number of actual rows: %s',
perfdatas => [
{ value => 'actual_num_rows_absolute', template => '%s', min => 0, label_extra_instance => 1 },
],
}
}
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments =>
{
"urlpath:s" => { name => 'url_path', default => "/easportal/tools/nagios/checkoracletable.jsp" },
"datasource:s" => { name => 'datasource' },
"tablename:s" => { name => 'tablename' , default => "T_GL_VOUCHER"},
"actualrows:s" => { name => 'actualrows', default => "false" },
"warning:s" => { name => 'warning' },
"critical:s" => { name => 'critical' },
$options{options}->add_options(arguments => {
'urlpath:s' => { name => 'url_path', default => "/easportal/tools/nagios/checkoracletable.jsp" },
'datasource:s' => { name => 'datasource' },
'tablename:s' => { name => 'tablename' , default => 'T_GL_VOUCHER' },
'actualrows:s' => { name => 'actualrows', default => 'false' },
});
return $self;
}
sub check_options {
sub prefix_datasource_output {
my ($self, %options) = @_;
$self->SUPER::init(%options);
if (!defined($self->{option_results}->{datasource}) || $self->{option_results}->{datasource} eq "") {
$self->{output}->add_option_msg(short_msg => "Missing datasource name.");
$self->{output}->option_exit();
}
$self->{option_results}->{url_path} .= "?ds=" . $self->{option_results}->{datasource}
. "\&tablename=" . $self->{option_results}->{tablename}
. "\&actual=" . $self->{option_results}->{actualrows};
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
$self->{output}->option_exit();
}
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
$self->{output}->option_exit();
}
return "Datasource table '" . $options{instance_value}->{display} . "' ";
}
sub run {
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
if (!defined($self->{option_results}->{datasource}) || $self->{option_results}->{datasource} eq "") {
$self->{output}->add_option_msg(short_msg => 'Missing datasource name.');
$self->{output}->option_exit();
}
$self->{option_results}->{url_path} .=
"?ds=" . $self->{option_results}->{datasource}
. "\&tablename=" . $self->{option_results}->{tablename}
. "\&actual=" . $self->{option_results}->{actualrows};
}
sub manage_selection {
my ($self, %options) = @_;
my $webcontent = $options{custom}->request(path => $self->{option_results}->{url_path});
if ($webcontent !~ /^TABLE_NAME=\w+/i) {
$self->{output}->output_add(
severity => 'UNKNOWN',
short_msg => "Cannot find oracle table status. \n" . $webcontent
);
$self->{output}->add_option_msg(short_msg => 'cannot find oracle table status');
$self->{output}->option_exit();
}
my ($num_rows, $actual_num_rows) = (-1, -1);
$num_rows = $1 if $webcontent =~ /NUM_ROWS=(\d+)/i;
$actual_num_rows = $1 if $webcontent =~ /ACTUAL_NUM_ROWS=(\d+)/i;
my $exit;
if ($actual_num_rows == -1) {
$exit = $self->{perfdata}->threshold_check(value => $num_rows, threshold => [
{ label => 'critical', 'exit_litteral' => 'critical' },
{ label => 'warning', exit_litteral => 'warning' } ]
);
$self->{output}->output_add(severity => $exit, short_msg => sprintf("NUM_ROWS: %d", $num_rows));
$self->{output}->perfdata_add(label => "NUM_ROWS", unit => '',
value => sprintf("%d", $num_rows),
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
);
} else {
$self->{output}->perfdata_add(label => "NUM_ROWS", unit => '', value => sprintf("%d", $num_rows));
$exit = $self->{perfdata}->threshold_check(value => $actual_num_rows, threshold => [
{ label => 'critical', 'exit_litteral' => 'critical' },
{ label => 'warning', exit_litteral => 'warning' } ]
);
$self->{output}->output_add(severity => $exit, short_msg => sprintf("ACTUAL_NUM_ROWS: %d", $actual_num_rows));
$self->{output}->perfdata_add(label => "ACTUAL_NUM_ROWS", unit => '',
value => sprintf("%d", $actual_num_rows),
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
);
}
$self->{output}->output_add(severity => $exit, short_msg => $webcontent);
$self->{output}->display();
$self->{output}->exit();
my $name = $self->{option_results}->{datasource} . ':' . $self->{option_results}->{tablename};
$self->{datasource}->{$name} = { display => $name };
$self->{datasource}->{$name}->{num_rows} = $1 if ($webcontent =~ /NUM_ROWS=(\d+)/mi);
$self->{datasource}->{$name}->{actual_num_rows} = $1 if ($webcontent =~ /ACTUAL_NUM_ROWS=(\d+)/mi);
}
1;
@ -142,13 +130,10 @@ Specify the table name , MUST BE uppercase.
Specify whether check actual rows of table or not , true or false.
MAY have performance problem for large table if specify true.
=item B<--warning>
=item B<--warning-*> B<--critical-*>
Warning Threshold for num_rows , or actual_num_rows if actualrows is true.
=item B<--critical>
Critical Threshold for num_rows , or actual_num_rows if actualrows is true.
Thresholds.
Can be: 'table-rows', 'table-actual-rows'.
=back

View File

@ -25,6 +25,7 @@ use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
sub set_counters {
my ($self, %options) = @_;
@ -102,7 +103,7 @@ sub set_counters {
key_values => [ { name => 'processed_service_count', diff => 1 } ],
output_template => 'processed service: %s',
perfdatas => [
{ value => 'processed_service_count', template => '%s', min => 0 },
{ value => 'processed_service_count_absolute', template => '%s', min => 0 },
],
}
},

View File

@ -25,6 +25,7 @@ use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
sub set_counters {
my ($self, %options) = @_;