diff --git a/centreon-plugins/apps/tomcat/jmx/mode/datasourceusage.pm b/centreon-plugins/apps/tomcat/jmx/mode/datasourceusage.pm index 334255c9f..889ec55f4 100644 --- a/centreon-plugins/apps/tomcat/jmx/mode/datasourceusage.pm +++ b/centreon-plugins/apps/tomcat/jmx/mode/datasourceusage.pm @@ -30,9 +30,9 @@ sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'datasource', type => 1, cb_prefix_output => 'prefix_ds_output', message_multiple => 'All datasources are ok' }, + { name => 'datasource', type => 1, cb_prefix_output => 'prefix_ds_output', message_multiple => 'All datasources are ok' } ]; - + $self->{maps_counters}->{datasource} = [ { label => 'num-active', set => { key_values => [ { name => 'numActive' }, { name => 'maxActive' }, { name => 'display' } ], @@ -40,7 +40,7 @@ sub set_counters { closure_custom_calc_extra_options => { label_ref => 'Active', message => 'Current Num Active' }, closure_custom_output => $self->can('custom_usage_output'), closure_custom_threshold_check => $self->can('custom_usage_threshold'), - closure_custom_perfdata => $self->can('custom_usage_perfdata'), + closure_custom_perfdata => $self->can('custom_usage_perfdata') } }, { label => 'num-idle', set => { @@ -49,9 +49,9 @@ sub set_counters { closure_custom_calc_extra_options => { label_ref => 'Idle', message => 'Current Num Idle' }, closure_custom_output => $self->can('custom_usage_output'), closure_custom_threshold_check => $self->can('custom_usage_threshold'), - closure_custom_perfdata => $self->can('custom_usage_perfdata'), + closure_custom_perfdata => $self->can('custom_usage_perfdata') } - }, + } ]; } @@ -133,12 +133,12 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - + $options{options}->add_options(arguments => { - "filter-name:s" => { name => 'filter_name' }, - "units:s" => { name => 'units', default => '%' }, + 'filter-name:s' => { name => 'filter_name' }, + 'units:s' => { name => 'units', default => '%' } }); - + return $self; } @@ -147,41 +147,49 @@ sub manage_selection { # maxActive or maxTotal $self->{request} = [ - { mbean => "*:type=DataSource,class=*,context=*,host=*,name=*", attributes => - [ { name => 'numActive' }, { name => 'numIdle' }, { name => 'maxIdle' }, { name => 'maxTotal' }, { name => 'maxActive' } ] }, - { mbean => "*:type=DataSource,class=*,path=*,host=*,name=*", attributes => - [ { name => 'numActive' }, { name => 'numIdle' }, { name => 'maxIdle' }, { name => 'maxTotal' }, { name => 'maxActive' } ] }, + { mbean => "*:type=DataSource,class=*,context=*,host=*,name=*", attributes => + [ { name => 'numActive' }, { name => 'numIdle' }, { name => 'maxIdle' }, { name => 'maxTotal' }, { name => 'maxActive' } ] }, + { mbean => "*:type=DataSource,class=*,path=*,host=*,name=*", attributes => + [ { name => 'numActive' }, { name => 'numIdle' }, { name => 'maxIdle' }, { name => 'maxTotal' }, { name => 'maxActive' } ] }, + { mbean => "*:type=DataSource,class=*,name=*", attributes => + [ { name => 'numActive' }, { name => 'numIdle' }, { name => 'maxIdle' }, { name => 'maxTotal' }, { name => 'maxActive' } ] } ]; - + my $result = $options{custom}->get_attributes(request => $self->{request}, nothing_quit => 1); $self->{datasource} = {}; foreach my $key (keys %$result) { - $key =~ /(?:[:,])host=(.*?)(?:,|$)/; - my $ds_name = $1; - $key =~ /(?:[:,])(?:path|context)=(.*?)(?:,|$)/; - $ds_name .= '.' . $1; - $key =~ /(?:[:,])name=(.*?)(?:,|$)/; # double quote a virer + my ($ds_name, $append) = ('', ''); + + if ($key =~ /(?:[:,])host=(.*?)(?:,|$)/) { + $ds_name = $1; + $append = '.'; + } + if ($key =~ /(?:[:,])(?:path|context)=(.*?)(?:,|$)/) { + $ds_name .= $append . $1; + $append = '.'; + } + $key =~ /(?:[:,])name=(.*?)(?:,|$)/; my $tmp_name = $1; $tmp_name =~ s/^"(.*)"$/$1/; - $ds_name .= '.' . $tmp_name; - + $ds_name .= $append . $tmp_name; + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && $ds_name !~ /$self->{option_results}->{filter_name}/) { $self->{output}->output_add(long_msg => "skipping '" . $ds_name . "': no matching filter.", debug => 1); next; } - + $self->{datasource}->{$ds_name} = { display => $ds_name, numActive => $result->{$key}->{numActive}, maxActive => defined($result->{$key}->{maxTotal}) ? $result->{$key}->{maxTotal} : $result->{$key}->{maxActive}, numIdle => $result->{$key}->{numIdle}, - maxIdle => $result->{$key}->{maxIdle}, + maxIdle => $result->{$key}->{maxIdle} }; } - - $self->{cache_name} = "tomcat_" . $self->{mode} . '_' . md5_hex($options{custom}->get_connection_info()) . '_' . + + $self->{cache_name} = 'tomcat_' . $self->{mode} . '_' . md5_hex($options{custom}->get_connection_info()) . '_' . (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' . (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')); } diff --git a/centreon-plugins/apps/tomcat/jmx/mode/listdatasources.pm b/centreon-plugins/apps/tomcat/jmx/mode/listdatasources.pm index db13bebe5..abf0f3376 100644 --- a/centreon-plugins/apps/tomcat/jmx/mode/listdatasources.pm +++ b/centreon-plugins/apps/tomcat/jmx/mode/listdatasources.pm @@ -29,13 +29,12 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $options{options}->add_options(arguments => - { - "filter-host:s" => { name => 'filter_host' }, - "filter-path:s" => { name => 'filter_path' }, - }); - $self->{ds} = {}; + + $options{options}->add_options(arguments => { + 'filter-host:s' => { name => 'filter_host' }, + 'filter-path:s' => { name => 'filter_path' } + }); + return $self; } @@ -47,21 +46,36 @@ sub check_options { sub manage_selection { my ($self, %options) = @_; - $self->{request} = [ - { mbean => "*:type=DataSource,class=*,context=*,host=*,name=*", attributes => - [ { name => 'numActive' } ] }, - ]; - my $result = $options{custom}->get_attributes(request => $self->{request}); + my $mbeans = $options{custom}->get_attributes( + request => [ + { mbean => "*:type=DataSource,class=*,context=*,host=*,name=*", attributes => + [ { name => 'numActive' } ] }, + { mbean => "*:type=DataSource,class=*,path=*,host=*,name=*", attributes => + [ { name => 'numActive' } ] }, + { mbean => "*:type=DataSource,class=*,name=*", attributes => + [ { name => 'numActive' } ] } + ] + ); - foreach my $mbean (keys %{$result}) { - $mbean =~ /(?:[:,])host=(.*?)(?:,|$)/; - my $host = $1; - $mbean =~ /(?:[:,])(?:path|context)=(.*?)(?:,|$)/; - my $path = $1; + my $results = {}; + foreach my $mbean (keys %$mbeans) { + my ($ds_name, $path, $host, $append) = ('', '', '', ''); + + if ($mbean =~ /(?:[:,])host=(.*?)(?:,|$)/) { + $host = $1; + $ds_name = $host; + $append = '.'; + } + if ($mbean =~ /(?:[:,])(?:path|context)=(.*?)(?:,|$)/) { + $path = $1; + $ds_name .= $append . $path; + $append = '.'; + } $mbean =~ /(?:[:,])name=(.*?)(?:,|$)/; my $name = $1; $name =~ s/^"(.*)"$/$1/; - + $ds_name .= $append . $name; + if (defined($self->{option_results}->{filter_host}) && $self->{option_results}->{filter_host} ne '' && $host !~ /$self->{option_results}->{filter_host}/) { $self->{output}->output_add(long_msg => "skipping '" . $host . "': no matching filter.", debug => 1); @@ -72,43 +86,52 @@ sub manage_selection { $self->{output}->output_add(long_msg => "skipping '" . $path . "': no matching filter.", debug => 1); next; } - - $self->{ds}->{$host . '.' . $path} = { - host => $host, path => $path, name => $name, + + $results->{$ds_name} = { + host => $host, + path => $path, + name => $name, + fullname => $ds_name }; } + + return $results; } sub run { my ($self, %options) = @_; - - $self->manage_selection(%options); - foreach my $instance (sort keys %{$self->{ds}}) { - $self->{output}->output_add(long_msg => '[host = ' . $self->{ds}->{$instance}->{host} . "]" . - " [path = '" . $self->{ds}->{$instance}->{path} . "']" . - " [name = '" . $self->{ds}->{$instance}->{name} . "']" + + my $results = $self->manage_selection(%options); + foreach my $instance (sort keys %$results) { + $self->{output}->output_add( + long_msg => + '[host = ' . $results->{$instance}->{host} . "]" . + " [path = '" . $results->{$instance}->{path} . "']" . + " [name = '" . $results->{$instance}->{name} . "']" ); } - - $self->{output}->output_add(severity => 'OK', - short_msg => 'List data sources:'); + + $self->{output}->output_add( + severity => 'OK', + short_msg => 'List data sources:' + ); $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->exit(); } sub disco_format { my ($self, %options) = @_; - - $self->{output}->add_disco_format(elements => ['host', 'path', 'name']); + + $self->{output}->add_disco_format(elements => ['host', 'path', 'name', 'fullname']); } sub disco_show { my ($self, %options) = @_; - $self->manage_selection(%options); - foreach my $instance (sort keys %{$self->{ds}}) { + my $results = $self->manage_selection(%options); + foreach my $instance (sort keys %$results) { $self->{output}->add_disco_entry( - %{$self->{ds}->{$instance}} + %{$results->{$instance}} ); } } diff --git a/centreon-plugins/apps/tomcat/jmx/plugin.pm b/centreon-plugins/apps/tomcat/jmx/plugin.pm index edc436434..2a5b490de 100644 --- a/centreon-plugins/apps/tomcat/jmx/plugin.pm +++ b/centreon-plugins/apps/tomcat/jmx/plugin.pm @@ -30,7 +30,7 @@ sub new { bless $self, $class; $self->{version} = '0.1'; - %{$self->{modes}} = ( + $self->{modes} = { 'class-count' => 'centreon::common::jvm::mode::classcount', 'connector-usage' => 'apps::tomcat::jmx::mode::connectorusage', 'cpu-load' => 'centreon::common::jvm::mode::cpuload', @@ -43,10 +43,10 @@ sub new { 'memory' => 'centreon::common::jvm::mode::memory', 'memory-detailed' => 'centreon::common::jvm::mode::memorydetailed', 'threads' => 'centreon::common::jvm::mode::threads', - 'webapps-sessions' => 'apps::tomcat::jmx::mode::webappssessions', - ); + 'webapps-sessions' => 'apps::tomcat::jmx::mode::webappssessions' + }; - $self->{custom_modes}{jolokia} = 'centreon::common::protocols::jmx::custom::jolokia'; + $self->{custom_modes}->{jolokia} = 'centreon::common::protocols::jmx::custom::jolokia'; return $self; }