diff --git a/centreon-plugins/apps/tomcat/web/mode/applications.pm b/centreon-plugins/apps/tomcat/web/mode/applications.pm index eb8e3382a..3dbfc9b3f 100644 --- a/centreon-plugins/apps/tomcat/web/mode/applications.pm +++ b/centreon-plugins/apps/tomcat/web/mode/applications.pm @@ -24,14 +24,19 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); use centreon::plugins::http; sub custom_status_output { my ($self, %options) = @_; - my $msg = 'state: ' . $self->{result_values}->{state}; - return $msg; + return 'state: ' . $self->{result_values}->{state}; +} + +sub prefix_application_output { + my ($self, %options) = @_; + + return "Application '" . $options{instance_value}->{display} . "' "; } sub set_counters { @@ -42,32 +47,24 @@ sub set_counters { ]; $self->{maps_counters}->{application} = [ - { label => 'status', threshold => 0, set => { + { label => 'status', type => 2, unknown_default => '%{state} ne "running"', critical_default => '%{state} eq "stopped"', set => { key_values => [ { name => 'state' }, { name => 'contextpath' }, { name => 'display' } ], - closure_custom_calc => \&catalog_status_calc, closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold + closure_custom_threshold_check => \&catalog_status_threshold_ng } }, { label => 'sessions-active', nlabel => 'application.sessions.active.count', set => { key_values => [ { name => 'sessions' }, { name => 'display' } ], output_template => 'active sessions: %s', perfdatas => [ - { value => 'sessions', template => '%s', - min => 0, label_extra_instance => 1, instance_use => 'display' }, - ], + { template => '%s', min => 0, label_extra_instance => 1, instance_use => 'display' } + ] } - }, + } ]; } -sub prefix_application_output { - my ($self, %options) = @_; - - return "Application '" . $options{instance_value}->{display} . "' "; -} - sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); @@ -85,12 +82,9 @@ sub new { 'urlpath:s' => { name => 'url_path', default => '/manager/text/list' }, 'filter-name:s' => { name => 'filter_name' }, 'filter-path:s' => { name => 'filter_path', }, - 'unknown-http-status:s' => { name => 'unknown_http_status', default => '%{http_code} < 200 or %{http_code} >= 300' }, - 'warning-http-status:s' => { name => 'warning_http_status' }, - 'critical-http-status:s' => { name => 'critical_http_status' }, - 'unknown-status:s' => { name => 'unknown_status', default => '%{state} ne "running"' }, - 'warning-status:s' => { name => 'warning_status', default => '' }, - 'critical-status:s' => { name => 'critical_status', default => '%{state} eq "stopped"' }, + 'unknown-http-status:s' => { name => 'unknown_http_status', default => '%{http_code} < 200 or %{http_code} >= 300' }, + 'warning-http-status:s' => { name => 'warning_http_status', default => '' }, + 'critical-http-status:s' => { name => 'critical_http_status', default => '' } }); $self->{http} = centreon::plugins::http->new(%options); @@ -100,9 +94,8 @@ sub new { sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); - + $self->{http}->set_options(%{$self->{option_results}}); - $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']); } sub manage_selection { @@ -111,7 +104,7 @@ sub manage_selection { my $webcontent = $self->{http}->request( unknown_status => $self->{option_results}->{unknown_http_status}, warning_status => $self->{option_results}->{warning_http_status}, - critical_status => $self->{option_results}->{critical_http_status}, + critical_status => $self->{option_results}->{critical_http_status} ); $self->{application} = {}; @@ -130,7 +123,7 @@ sub manage_selection { contextpath => $contextpath }; } - + if (scalar(keys %{$self->{application}}) <= 0) { $self->{output}->add_option_msg(short_msg => "No application found."); $self->{output}->option_exit(); diff --git a/centreon-plugins/apps/tomcat/web/mode/connectors.pm b/centreon-plugins/apps/tomcat/web/mode/connectors.pm index b48a997a8..c47a06e26 100644 --- a/centreon-plugins/apps/tomcat/web/mode/connectors.pm +++ b/centreon-plugins/apps/tomcat/web/mode/connectors.pm @@ -76,8 +76,8 @@ sub set_counters { output_template => 'Threads Current : %s', perfdatas => [ { label => 'threads_current', template => '%.2f', min => 0, max => 'maxThreads', - label_extra_instance => 1 }, - ], + label_extra_instance => 1 } + ] } }, { label => 'threads-busy', nlabel => 'connector.threads.busy.count', set => { @@ -85,8 +85,8 @@ sub set_counters { output_template => 'Threads Busy : %s', perfdatas => [ { label => 'threads_busy', template => '%.2f', min => 0, max => 'maxThreads', - label_extra_instance => 1 }, - ], + label_extra_instance => 1 } + ] } }, { label => 'traffic-in', nlabel => 'connector.traffic.in.bitspersecond', set => { @@ -96,8 +96,8 @@ sub set_counters { threshold_use => 'traffic', perfdatas => [ { label => 'traffic_in', value => 'traffic', template => '%.2f', min => 0, max => 'speed', - unit => 'b/s', label_extra_instance => 1 }, - ], + unit => 'b/s', label_extra_instance => 1 } + ] } }, { label => 'traffic-in-prct', display_ok => 0, nlabel => 'connector.traffic.in.percent', set => { @@ -118,8 +118,8 @@ sub set_counters { threshold_use => 'traffic', perfdatas => [ { label => 'traffic_out', value => 'traffic', template => '%.2f', min => 0, max => 'speed', - unit => 'b/s', label_extra_instance => 1 }, - ], + unit => 'b/s', label_extra_instance => 1 } + ] } }, { label => 'traffic-out-prct', display_ok => 0, nlabel => 'connector.traffic.out.percent', set => { @@ -129,8 +129,8 @@ sub set_counters { output_use => 'traffic_prct', threshold_use => 'traffic_prct', perfdatas => [ { label => 'traffic_out_prct', value => 'traffic_prct', template => '%.2f', min => 0, max => 100, - unit => '%', label_extra_instance => 1 }, - ], + unit => '%', label_extra_instance => 1 } + ] } }, { label => 'requests-processingtime-total', nlabel => 'connector.requests.processingtime.total.milliseconds', set => { @@ -138,8 +138,8 @@ sub set_counters { output_template => 'Requests Total Processing Time : %s ms', perfdatas => [ { label => 'requests_processingtime_total', template => '%s', min => 0, - unit => 'ms', label_extra_instance => 1 }, - ], + unit => 'ms', label_extra_instance => 1 } + ] } }, { label => 'requests-errors', nlabel => 'connector.requests.errors.count', set => { @@ -147,8 +147,8 @@ sub set_counters { output_template => 'Requests Errors : %s', perfdatas => [ { label => 'requests_errors', template => '%s', min => 0, - label_extra_instance => 1 }, - ], + label_extra_instance => 1 } + ] } }, { label => 'requests-total', nlabel => 'connector.requests.total.count', set => { @@ -156,10 +156,10 @@ sub set_counters { output_template => 'Requests Total : %s', perfdatas => [ { label => 'requests_total', template => '%s', min => 0, - label_extra_instance => 1 }, - ], + label_extra_instance => 1 } + ] } - }, + } ]; } diff --git a/centreon-plugins/apps/tomcat/web/mode/memory.pm b/centreon-plugins/apps/tomcat/web/mode/memory.pm index 9b2fe71f0..7ef535af1 100644 --- a/centreon-plugins/apps/tomcat/web/mode/memory.pm +++ b/centreon-plugins/apps/tomcat/web/mode/memory.pm @@ -30,13 +30,14 @@ use XML::XPath; sub custom_memory_output { my ($self, %options) = @_; - my $msg = sprintf("Memory Total: %s %s Used: %s %s (%.2f%%) Free: %s %s (%.2f%%)", + return sprintf( + "Memory Total: %s %s Used: %s %s (%.2f%%) Free: %s %s (%.2f%%)", $self->{perfdata}->change_bytes(value => $self->{result_values}->{total}), $self->{perfdata}->change_bytes(value => $self->{result_values}->{used}), $self->{result_values}->{prct_used}, $self->{perfdata}->change_bytes(value => $self->{result_values}->{free}), - $self->{result_values}->{prct_free}); - return $msg; + $self->{result_values}->{prct_free} + ); } sub set_counters { @@ -51,28 +52,26 @@ sub set_counters { key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ], closure_custom_output => $self->can('custom_memory_output'), perfdatas => [ - { value => 'used', template => '%d', min => 0, max => 'total', - unit => 'B', cast_int => 1 }, - ], + { template => '%d', min => 0, max => 'total', unit => 'B', cast_int => 1 } + ] } }, { label => 'usage-free', display_ok => 0, nlabel => 'memory.free.bytes', set => { key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ], closure_custom_output => $self->can('custom_memory_output'), perfdatas => [ - { value => 'free', template => '%d', min => 0, max => 'total', - unit => 'B', cast_int => 1 }, - ], + { template => '%d', min => 0, max => 'total', unit => 'B', cast_int => 1 } + ] } }, { label => 'usage-prct', display_ok => 0, nlabel => 'memory.usage.percentage', set => { key_values => [ { name => 'prct_used' } ], output_template => 'Memory Used : %.2f %%', perfdatas => [ - { value => 'prct_used', template => '%.2f', min => 0, max => 100, unit => '%' }, - ], + { template => '%.2f', min => 0, max => 100, unit => '%' } + ] } - }, + } ]; } @@ -90,7 +89,7 @@ sub new { 'username:s' => { name => 'username' }, 'password:s' => { name => 'password' }, 'timeout:s' => { name => 'timeout' }, - 'urlpath:s' => { name => 'url_path', default => '/manager/status?XML=true' }, + 'urlpath:s' => { name => 'url_path', default => '/manager/status?XML=true' } }); $self->{http} = centreon::plugins::http->new(%options);