From 7e742218994e1579346aa9337eca4cedb29b3aaf Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Tue, 30 Jun 2015 10:51:20 +0200 Subject: [PATCH] + Enhance for plugin tomcat --- apps/tomcat/jmx/plugin.pm | 3 +- centreon/common/jvm/mode/classcount.pm | 32 +++++----- centreon/common/jvm/mode/cpuload.pm | 52 ++++++++-------- centreon/common/jvm/mode/fdusage.pm | 19 +++--- centreon/common/jvm/mode/loadaverage.pm | 17 +++-- centreon/common/jvm/mode/memory.pm | 30 +++++---- centreon/common/jvm/mode/memorydetailed.pm | 72 +++++++++------------- centreon/common/jvm/mode/threadcount.pm | 21 +++---- 8 files changed, 108 insertions(+), 138 deletions(-) diff --git a/apps/tomcat/jmx/plugin.pm b/apps/tomcat/jmx/plugin.pm index ea021ba7d..0de2638cd 100644 --- a/apps/tomcat/jmx/plugin.pm +++ b/apps/tomcat/jmx/plugin.pm @@ -54,7 +54,6 @@ sub new { 'thread-count' => 'centreon::common::jvm::mode::threadcount', 'cpu-load' => 'centreon::common::jvm::mode::cpuload', 'class-count' => 'centreon::common::jvm::mode::classcount', - 'test' => 'centreon::common::jvm::mode::test', ); $self->{custom_modes}{jolokia} = 'centreon::common::protocols::jmx::custom::jolokia'; @@ -67,6 +66,6 @@ __END__ =head1 PLUGIN DESCRIPTION -TOMCAT JMX plugin. Need Jolokia agent. +Check Tomcat in JMX. Need Jolokia agent. =cut diff --git a/centreon/common/jvm/mode/classcount.pm b/centreon/common/jvm/mode/classcount.pm index a9adf1491..8d3ae2318 100644 --- a/centreon/common/jvm/mode/classcount.pm +++ b/centreon/common/jvm/mode/classcount.pm @@ -48,10 +48,10 @@ sub new { $self->{version} = '1.0'; $options{options}->add_options(arguments => { - "warning-loaded:s" => { name => 'warning_loaded', default => '5000' }, - "critical-loaded:s" => { name => 'critical_loaded', default => '5000' }, - "warning-total:s" => { name => 'warning_total', default => '5500' }, - "critical-total:s" => { name => 'critical_total', default => '5500' }, + "warning-loaded:s" => { name => 'warning_loaded' }, + "critical-loaded:s" => { name => 'critical_loaded' }, + "warning-total:s" => { name => 'warning_total' }, + "critical-total:s" => { name => 'critical_total' }, }); return $self; } @@ -61,22 +61,21 @@ sub check_options { $self->SUPER::init(%options); if (($self->{perfdata}->threshold_validate(label => 'warning-loaded', value => $self->{option_results}->{warning_loaded})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning-loaded threshold '" . $self->{warning} . "'."); - $self->{output}->option_exit(); + $self->{output}->add_option_msg(short_msg => "Wrong warning-loaded threshold '" . $self->{option_results}->{warning_loaded} . "'."); + $self->{output}->option_exit(); } if (($self->{perfdata}->threshold_validate(label => 'critical-loaded', value => $self->{option_results}->{critical_loaded})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical-loaded threshold '" . $self->{critical} . "'."); - $self->{output}->option_exit(); + $self->{output}->add_option_msg(short_msg => "Wrong critical-loaded threshold '" . $self->{option_results}->{critical_loaded} . "'."); + $self->{output}->option_exit(); } if (($self->{perfdata}->threshold_validate(label => 'warning-total', value => $self->{option_results}->{warning_total})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning-total threshold '" . $self->{warning} . "'."); - $self->{output}->option_exit(); + $self->{output}->add_option_msg(short_msg => "Wrong warning-total threshold '" . $self->{option_results}->{warning_total} . "'."); + $self->{output}->option_exit(); } if (($self->{perfdata}->threshold_validate(label => 'critical-total', value => $self->{option_results}->{critical_total})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical-total threshold '" . $self->{critical} . "'."); - $self->{output}->option_exit(); + $self->{output}->add_option_msg(short_msg => "Wrong critical-total threshold '" . $self->{option_results}->{critical_total} . "'."); + $self->{output}->option_exit(); } - } sub run { @@ -89,18 +88,17 @@ sub run { ]; my $result = $self->{connector}->get_attributes(request => $self->{request}, nothing_quit => 1); - my $exit1 = $self->{perfdata}->threshold_check(value => $result->{"java.lang:type=ClassLoading"}->{TotalLoadedClassCount}, - threshold => [ { label => 'critical-total', exit_litteral => 'critical' }, { label => 'warning-total', 'exit_litteral' => 'warning'} ]); + threshold => [ { label => 'critical-total', exit_litteral => 'critical' }, { label => 'warning-total', exit_litteral => 'warning'} ]); my $exit2 = $self->{perfdata}->threshold_check(value => $result->{"java.lang:type=ClassLoading"}->{LoadedClassCount}, - threshold => [ { label => 'critical-loaded', exit_litteral => 'critical' }, { label => 'warning-loaded', 'exit_litteral' => 'warning'} ]); + threshold => [ { label => 'critical-loaded', exit_litteral => 'critical' }, { label => 'warning-loaded', exit_litteral => 'warning'} ]); my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2 ]); $self->{output}->output_add(severity => $exit, short_msg => sprintf("Loaded Class Count : %i, Total Loaded Class : %i, Unloaded Class Count : %i", $result->{"java.lang:type=ClassLoading"}->{LoadedClassCount}, $result->{"java.lang:type=ClassLoading"}->{TotalLoadedClassCount}, - $result->{"java.lang:type=ClassLoading"}->{UnloadedClassCount})); + $result->{"java.lang:type=ClassLoading"}->{UnloadedClassCount})); $self->{output}->perfdata_add(label => 'TotalLoadedClassCount', value => $result->{"java.lang:type=ClassLoading"}->{TotalLoadedClassCount}, diff --git a/centreon/common/jvm/mode/cpuload.pm b/centreon/common/jvm/mode/cpuload.pm index 79b65dab9..5a5978532 100644 --- a/centreon/common/jvm/mode/cpuload.pm +++ b/centreon/common/jvm/mode/cpuload.pm @@ -48,10 +48,10 @@ sub new { $self->{version} = '1.0'; $options{options}->add_options(arguments => { - "warning-system:s" => { name => 'warning_system', default => '80' }, - "critical-system:s" => { name => 'critical_system', default => '90' }, - "warning-process:s" => { name => 'warning_process', default => '80' }, - "critical-process:s" => { name => 'critical_process', default => '90' } + "warning-system:s" => { name => 'warning_system' }, + "critical-system:s" => { name => 'critical_system' }, + "warning-process:s" => { name => 'warning_process' }, + "critical-process:s" => { name => 'critical_process' } }); return $self; } @@ -61,23 +61,21 @@ sub check_options { $self->SUPER::init(%options); if (($self->{perfdata}->threshold_validate(label => 'warning-system', value => $self->{option_results}->{warning_system})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning-system threshold '" . $self->{warning} . "'."); - $self->{output}->option_exit(); + $self->{output}->add_option_msg(short_msg => "Wrong warning-system threshold '" . $self->{option_results}->{warning_system} . "'."); + $self->{output}->option_exit(); } if (($self->{perfdata}->threshold_validate(label => 'critical-system', value => $self->{option_results}->{critical_system})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical-system threshold '" . $self->{critical} . "'."); - $self->{output}->option_exit(); + $self->{output}->add_option_msg(short_msg => "Wrong critical-system threshold '" . $self->{option_results}->{critical_system} . "'."); + $self->{output}->option_exit(); } if (($self->{perfdata}->threshold_validate(label => 'warning-process', value => $self->{option_results}->{warning_process})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning-process threshold '" . $self->{warning} . "'."); - $self->{output}->option_exit(); + $self->{output}->add_option_msg(short_msg => "Wrong warning-process threshold '" . $self->{option_results}->{warning_process} . "'."); + $self->{output}->option_exit(); } if (($self->{perfdata}->threshold_validate(label => 'critical-process', value => $self->{option_results}->{critical_process})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical-process threshold '" . $self->{critical} . "'."); - $self->{output}->option_exit(); - } - - + $self->{output}->add_option_msg(short_msg => "Wrong critical-process threshold '" . $self->{option_results}->{critical_process} . "'."); + $self->{output}->option_exit(); + } } sub run { @@ -90,25 +88,25 @@ sub run { ]; my $result = $self->{connector}->get_attributes(request => $self->{request}, nothing_quit => 1); - - my $exit1 = $self->{perfdata}->threshold_check(value => $result->{"java.lang:type=OperatingSystem"}->{SystemCpuLoad} * 100, - threshold => [ { label => 'critical-system', exit_litteral => 'critical' }, { label => 'warning-system', 'exit_litteral' => 'warning' } ]); - my $exit2 = $self->{perfdata}->threshold_check(value => $result->{"java.lang:type=OperatingSystem"}->{ProcessCpuLoad} * 100, - threshold => [ { label => 'critical-process', exit_litteral => 'critical' }, { label => 'warning-process', 'exit_litteral' => 'warning'} ]); - - my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2 ]); - + my $exit = $self->{perfdata}->threshold_check(value => $result->{"java.lang:type=OperatingSystem"}->{SystemCpuLoad} * 100, + threshold => [ { label => 'critical-system', exit_litteral => 'critical' }, { label => 'warning-system', exit_litteral => 'warning' } ]); $self->{output}->output_add(severity => $exit, - short_msg => sprintf("SystemCpuLoad: %.2f%% - ProcessCpuLoad: %.2f%%", - $result->{"java.lang:type=OperatingSystem"}->{SystemCpuLoad} * 100, $result->{"java.lang:type=OperatingSystem"}->{ProcessCpuLoad} * 100)); + short_msg => sprintf("SystemCpuLoad: %.2f%%", + $result->{"java.lang:type=OperatingSystem"}->{SystemCpuLoad} * 100)); - $self->{output}->perfdata_add(label => 'SystemCpuLoad', + $exit = $self->{perfdata}->threshold_check(value => $result->{"java.lang:type=OperatingSystem"}->{ProcessCpuLoad} * 100, + threshold => [ { label => 'critical-process', exit_litteral => 'critical' }, { label => 'warning-process', exit_litteral => 'warning'} ]); + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("ProcessCpuLoad: %.2f%%", + $result->{"java.lang:type=OperatingSystem"}->{ProcessCpuLoad} * 100)); + + $self->{output}->perfdata_add(label => 'SystemCpuLoad', unit => '%', value => $result->{"java.lang:type=OperatingSystem"}->{SystemCpuLoad} * 100, warning => $self->{option_results}->{warning_system}, critical => $self->{option_results}->{critical_system}, min => 0, max => 100); - $self->{output}->perfdata_add(label => 'ProcessCpuLoad', + $self->{output}->perfdata_add(label => 'ProcessCpuLoad', unit => '%', value => $result->{"java.lang:type=OperatingSystem"}->{ProcessCpuLoad} * 100, warning => $self->{option_results}->{warning_process}, critical => $self->{option_results}->{critical_process}, diff --git a/centreon/common/jvm/mode/fdusage.pm b/centreon/common/jvm/mode/fdusage.pm index 25b8daa6f..2f0013cdf 100644 --- a/centreon/common/jvm/mode/fdusage.pm +++ b/centreon/common/jvm/mode/fdusage.pm @@ -48,8 +48,8 @@ sub new { $self->{version} = '1.0'; $options{options}->add_options(arguments => { - "warning:s" => { name => 'warning', default => '80' }, - "critical:s" => { name => 'critical', default => '90' }, + "warning:s" => { name => 'warning' }, + "critical:s" => { name => 'critical' }, }); return $self; } @@ -59,14 +59,13 @@ sub check_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->{warning} . "'."); - $self->{output}->option_exit(); + $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->{critical} . "'."); - $self->{output}->option_exit(); + $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); + $self->{output}->option_exit(); } - } sub run { @@ -77,13 +76,11 @@ sub run { $self->{request} = [ { mbean => "java.lang:type=OperatingSystem", attributes => [ { name => 'MaxFileDescriptorCount' }, { name => 'OpenFileDescriptorCount' } ] } ]; - my $result = $self->{connector}->get_attributes(request => $self->{request}, nothing_quit => 1); - my $prct_fd = $result->{"java.lang:type=OperatingSystem"}->{OpenFileDescriptorCount} / $result->{"java.lang:type=OperatingSystem"}->{MaxFileDescriptorCount} * 100; my $exit = $self->{perfdata}->threshold_check(value => $prct_fd, - threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', 'exit_litteral' => 'warning' } ]); + threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); $self->{output}->perfdata_add(label => 'fd', value => $result->{"java.lang:type=OperatingSystem"}->{OpenFileDescriptorCount}, @@ -92,7 +89,7 @@ sub run { min => 0, max => $result->{"java.lang:type=OperatingSystem"}->{MaxFileDescriptorCount}); $self->{output}->output_add(severity => $exit, - short_msg => sprintf("File descriptor percentage usage: %2.f%%", $prct_fd)); + short_msg => sprintf("File descriptor percentage usage: %.2f%%", $prct_fd)); $self->{output}->display(); $self->{output}->exit(); diff --git a/centreon/common/jvm/mode/loadaverage.pm b/centreon/common/jvm/mode/loadaverage.pm index 4a5ece528..c2cbe842b 100644 --- a/centreon/common/jvm/mode/loadaverage.pm +++ b/centreon/common/jvm/mode/loadaverage.pm @@ -48,8 +48,8 @@ sub new { $self->{version} = '1.0'; $options{options}->add_options(arguments => { - "warning:s" => { name => 'warning', default => '2' }, - "critical:s" => { name => 'critical', default => '3' }, + "warning:s" => { name => 'warning' }, + "critical:s" => { name => 'critical' }, }); return $self; } @@ -59,14 +59,13 @@ sub check_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->{warning} . "'."); - $self->{output}->option_exit(); + $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->{critical} . "'."); - $self->{output}->option_exit(); + $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); + $self->{output}->option_exit(); } - } sub run { @@ -79,11 +78,9 @@ sub run { ]; my $result = $self->{connector}->get_attributes(request => $self->{request}, nothing_quit => 1); - my $load = $result->{"java.lang:type=OperatingSystem"}->{SystemLoadAverage}; - my $exit = $self->{perfdata}->threshold_check(value => $load, - threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', 'exit_litteral' => 'warning' } ]); + threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); $self->{output}->perfdata_add(label => 'load', value => $result->{"java.lang:type=OperatingSystem"}->{SystemLoadAverage}, diff --git a/centreon/common/jvm/mode/memory.pm b/centreon/common/jvm/mode/memory.pm index 41b2c7b28..d2a603a82 100644 --- a/centreon/common/jvm/mode/memory.pm +++ b/centreon/common/jvm/mode/memory.pm @@ -48,10 +48,10 @@ sub new { $self->{version} = '1.0'; $options{options}->add_options(arguments => { - "warning-heap:s" => { name => 'warning_heap', default => '80' }, - "critical-heap:s" => { name => 'critical_heap', default => '90' }, - "warning-nonheap:s" => { name => 'warning_nonheap', default => '80' }, - "critical-nonheap:s" => { name => 'critical_nonheap', default => '90' }, + "warning-heap:s" => { name => 'warning_heap' }, + "critical-heap:s" => { name => 'critical_heap' }, + "warning-nonheap:s" => { name => 'warning_nonheap' }, + "critical-nonheap:s" => { name => 'critical_nonheap' }, }); return $self; } @@ -61,22 +61,21 @@ sub check_options { $self->SUPER::init(%options); if (($self->{perfdata}->threshold_validate(label => 'warning-heap', value => $self->{option_results}->{warning_heap})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning-heap threshold '" . $self->{warning} . "'."); - $self->{output}->option_exit(); + $self->{output}->add_option_msg(short_msg => "Wrong warning-heap threshold '" . $self->{option_results}->{warning_heap} . "'."); + $self->{output}->option_exit(); } if (($self->{perfdata}->threshold_validate(label => 'critical-heap', value => $self->{option_results}->{critical_heap})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical-heap threshold '" . $self->{critical} . "'."); - $self->{output}->option_exit(); + $self->{output}->add_option_msg(short_msg => "Wrong critical-heap threshold '" . $self->{option_results}->{critical_heap} . "'."); + $self->{output}->option_exit(); } if (($self->{perfdata}->threshold_validate(label => 'warning-nonheap', value => $self->{option_results}->{warning_nonheap})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning-nonheap threshold '" . $self->{warning} . "'."); - $self->{output}->option_exit(); + $self->{output}->add_option_msg(short_msg => "Wrong warning-nonheap threshold '" . $self->{option_results}->{warning_nonheap} . "'."); + $self->{output}->option_exit(); } if (($self->{perfdata}->threshold_validate(label => 'critical-nonheap', value => $self->{option_results}->{critical_nonheap})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical-nonheap threshold '" . $self->{critical} . "'."); - $self->{output}->option_exit(); + $self->{output}->add_option_msg(short_msg => "Wrong critical-nonheap threshold '" . $self->{option_results}->{critical_nonheap} . "'."); + $self->{output}->option_exit(); } - } sub run { @@ -94,10 +93,9 @@ sub run { my $prct_nonheap = $result->{"java.lang:type=Memory"}->{NonHeapMemoryUsage}->{used} / $result->{"java.lang:type=Memory"}->{NonHeapMemoryUsage}->{max} * 100; my $exit1 = $self->{perfdata}->threshold_check(value => $prct_heap, - threshold => [ { label => 'critical-heap', exit_litteral => 'critical' }, { label => 'warning-heap', 'exit_litteral' => 'warning' } ]); + threshold => [ { label => 'critical-heap', exit_litteral => 'critical' }, { label => 'warning-heap', exit_litteral => 'warning' } ]); my $exit2 = $self->{perfdata}->threshold_check(value => $prct_nonheap, - threshold => [ { label => 'critical-nonheap', exit_litteral => 'critical' }, { label => 'warning-nonheap', 'exit_litteral' => 'warning'} ]); - + threshold => [ { label => 'critical-nonheap', exit_litteral => 'critical' }, { label => 'warning-nonheap', exit_litteral => 'warning'} ]); my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2 ]); $self->{output}->output_add(severity => $exit, diff --git a/centreon/common/jvm/mode/memorydetailed.pm b/centreon/common/jvm/mode/memorydetailed.pm index fa1647578..bbda025f9 100644 --- a/centreon/common/jvm/mode/memorydetailed.pm +++ b/centreon/common/jvm/mode/memorydetailed.pm @@ -63,16 +63,16 @@ sub new { $self->{version} = '1.0'; $options{options}->add_options(arguments => { - "warning-eden:s" => { name => 'warning_eden', default => '80' }, - "critical-eden:s" => { name => 'critical_eden', default => '90' }, - "warning-survivor:s" => { name => 'warning_survivor', default => '80' }, - "critical-survivor:s" => { name => 'critical_survivor', default => '90' }, - "warning-tenured:s" => { name => 'warning_tenured', default => '80' }, - "critical-tenured:s" => { name => 'critical_tenured', default => '90' }, - "warning-permanent:s" => { name => 'warning_permanent', default => '80' }, - "critical-permanent:s" => { name => 'critical_permanent', default => '90' }, - "warning-code:s" => { name => 'warning_code', default => '80' }, - "critical-code:s" => { name => 'critical_code', default => '90' } + "warning-eden:s" => { name => 'warning_eden' }, + "critical-eden:s" => { name => 'critical_eden' }, + "warning-survivor:s" => { name => 'warning_survivor' }, + "critical-survivor:s" => { name => 'critical_survivor' }, + "warning-tenured:s" => { name => 'warning_tenured' }, + "critical-tenured:s" => { name => 'critical_tenured' }, + "warning-permanent:s" => { name => 'warning_permanent' }, + "critical-permanent:s" => { name => 'critical_permanent' }, + "warning-code:s" => { name => 'warning_code' }, + "critical-code:s" => { name => 'critical_code' } }); return $self; } @@ -82,65 +82,51 @@ sub check_options { $self->SUPER::init(%options); foreach my $label ('warning_eden', 'critical_eden', 'warning_survivor', 'critical_survivor', 'warning_tenured', 'critical_tenured', 'warning_permanent', 'critical_permanent', 'warning_code', 'critical_code') { - if (($self->{perfdata}->threshold_validate(label => $label, value => $self->{option_results}->{$label})) == 0) { - my ($label_opt) = $label; - $label_opt =~ tr/_/-/; - $self->{output}->add_option_msg(short_msg => "Wrong " . $label_opt . " threshold '" . $self->{option_results}->{$label} . "'."); - $self->{output}->option_exit(); - } - } - + if (($self->{perfdata}->threshold_validate(label => $label, value => $self->{option_results}->{$label})) == 0) { + my ($label_opt) = $label; + $label_opt =~ tr/_/-/; + $self->{output}->add_option_msg(short_msg => "Wrong " . $label_opt . " threshold '" . $self->{option_results}->{$label} . "'."); + $self->{output}->option_exit(); + } + } } sub run { my ($self, %options) = @_; $self->{connector} = $options{custom}; - my %prct; - my $exit; - my @exits; - - $self->{request} = [ + $self->{request} = [ { mbean => "java.lang:type=MemoryPool,name=*", attributes => [ { name => 'Usage' } ] } ]; - my $result = $self->{connector}->get_attributes(request => $self->{request}, nothing_quit => 1); $self->{output}->output_add(severity => 'OK', - short_msg => 'All memories within bounds'); - + short_msg => 'All memories within bounds'); foreach my $key (keys %$result) { - $key =~ /name=(.*?),type/; my $memtype = $1; - - $prct{$memtype} = $result->{"java.lang:name=".$memtype.",type=MemoryPool"}->{Usage}->{used} / $result->{"java.lang:name=".$memtype.",type=MemoryPool"}->{Usage}->{max} * 100; + my $prct = $result->{"java.lang:name=".$memtype.",type=MemoryPool"}->{Usage}->{used} / $result->{"java.lang:name=".$memtype.",type=MemoryPool"}->{Usage}->{max} * 100; $self->{output}->perfdata_add(label => $mapping_memory{$memtype}, - value => $result->{"java.lang:name=".$memtype.",type=MemoryPool"}->{Usage}->{used}, - warning => $self->{option_results}->{'warning_'.$mapping_memory{$memtype}} / 100 * $result->{"java.lang:name=".$memtype.",type=MemoryPool"}->{Usage}->{used}, - critical => $self->{option_results}->{'critical_'.$mapping_memory{$memtype}} / 100 * $result->{"java.lang:name=".$memtype.",type=MemoryPool"}->{Usage}->{used}, + value => $result->{"java.lang:name=" . $memtype . ",type=MemoryPool"}->{Usage}->{used}, + warning => $self->{option_results}->{'warning_' . $mapping_memory{$memtype}} / 100 * $result->{"java.lang:name=" . $memtype . ",type=MemoryPool"}->{Usage}->{used}, + critical => $self->{option_results}->{'critical_' . $mapping_memory{$memtype}} / 100 * $result->{"java.lang:name=" . $memtype . ",type=MemoryPool"}->{Usage}->{used}, min => 0, max => $result->{"java.lang:name=".$memtype.",type=MemoryPool"}->{Usage}->{max}); - $exit = $self->{perfdata}->threshold_check(value => $prct{$memtype}, - threshold => [ { label => 'critical_'.$mapping_memory{$memtype}, exit_litteral => 'critical' }, - { label => 'warning_'.$mapping_memory{$memtype}, 'exit_litteral' => 'warning'} ]); + my $exit = $self->{perfdata}->threshold_check(value => $prct, + threshold => [ { label => 'critical_' . $mapping_memory{$memtype}, exit_litteral => 'critical' }, + { label => 'warning_' . $mapping_memory{$memtype}, exit_litteral => 'warning' } ]); - $self->{output}->output_add(long_msg => sprintf("%s usage is %.2f%%", $memtype, $prct{$memtype})); - push @exits, $exit; - if ($exit ne 'ok') { + $self->{output}->output_add(long_msg => sprintf("%s usage is %.2f%%", $memtype, $prct)); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, - short_msg => sprintf("%s usage:%.2f%% ", $memtype, $prct{$memtype})); + short_msg => sprintf("%s usage:%.2f%% ", $memtype, $prct})); } } - $exit = $self->{output}->get_most_critical(status => [ @exits ]); - - $self->{output}->output_add(severity => $exit); - $self->{output}->display(); $self->{output}->exit(); diff --git a/centreon/common/jvm/mode/threadcount.pm b/centreon/common/jvm/mode/threadcount.pm index 4bd1f817b..1762acdb4 100644 --- a/centreon/common/jvm/mode/threadcount.pm +++ b/centreon/common/jvm/mode/threadcount.pm @@ -48,8 +48,8 @@ sub new { $self->{version} = '1.0'; $options{options}->add_options(arguments => { - "warning:s" => { name => 'warning', default => '80' }, - "critical:s" => { name => 'critical', default => '90' }, + "warning:s" => { name => 'warning' }, + "critical:s" => { name => 'critical' }, }); return $self; } @@ -59,15 +59,13 @@ sub check_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->{warning} . "'."); - $self->{output}->option_exit(); + $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->{critical} . "'."); - $self->{output}->option_exit(); + $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); + $self->{output}->option_exit(); } - - } sub run { @@ -82,17 +80,16 @@ sub run { my $result = $self->{connector}->get_attributes(request => $self->{request}, nothing_quit => 1); my $exit = $self->{perfdata}->threshold_check(value => $result->{"java.lang:type=Threading"}->{ThreadCount}, - threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', 'exit_litteral' => 'warning' } ]); + threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); $self->{output}->perfdata_add(label => 'ThreadCount', unit => 'thread', value => $result->{"java.lang:type=Threading"}->{ThreadCount}, warning => $self->{option_results}->{warning}, critical => $self->{option_results}->{critical}, - min => 0 - ); + min => 0); $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Thread Count : %i", $result->{"java.lang:type=Threading"}->{ThreadCount})); + short_msg => sprintf("Thread Count : %i", $result->{"java.lang:type=Threading"}->{ThreadCount})); $self->{output}->display(); $self->{output}->exit(); }