break change: refacto tomcat web

This commit is contained in:
garnier-quentin 2019-07-04 17:07:08 +02:00
parent 617d43a31f
commit 46cf60a0b3
7 changed files with 358 additions and 824 deletions

View File

@ -20,122 +20,123 @@
package apps::tomcat::web::mode::applications;
use base qw(centreon::plugins::mode);
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::http;
sub custom_status_output {
my ($self, %options) = @_;
my $msg = 'state: ' . $self->{result_values}->{state};
return $msg;
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'application', type => 1, cb_prefix_output => 'prefix_application_output', message_multiple => 'All applications are ok' }
];
$self->{maps_counters}->{application} = [
{ label => 'status', threshold => 0, 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
}
},
{ label => 'sessions-active', nlabel => 'application.sessions.active.count', set => {
key_values => [ { name => 'sessions' }, { name => 'display' } ],
output_template => 'active sessions: %s',
perfdatas => [
{ value => 'sessions_absolute', template => '%s',
min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
];
}
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);
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port', default => '8080' },
"proto:s" => { name => 'proto' },
"credentials" => { name => 'credentials' },
"basic" => { name => 'basic' },
"username:s" => { name => 'username' },
"password:s" => { name => 'password' },
"timeout:s" => { name => 'timeout' },
"urlpath:s" => { name => 'url_path', default => '/manager/text/list' },
"name:s" => { name => 'name' },
"regexp" => { name => 'use_regexp' },
"regexp-isensitive" => { name => 'use_regexpi' },
"filter-path:s" => { name => 'filter_path', },
'hostname:s' => { name => 'hostname' },
'port:s' => { name => 'port', default => '8080' },
'proto:s' => { name => 'proto' },
'credentials' => { name => 'credentials' },
'basic' => { name => 'basic' },
'username:s' => { name => 'username' },
'password:s' => { name => 'password' },
'timeout:s' => { name => 'timeout' },
'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"' },
});
$self->{result} = {};
$self->{http} = centreon::plugins::http->new(%options);
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%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 {
my ($self, %options) = @_;
my $webcontent = $self->{http}->request();
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},
);
$self->{application} = {};
while ($webcontent =~ /^(.*?):(.*?):(.*?):(.*)/mg) {
my ($context, $state, $sessions, $contextpath) = ($1, $2, $3, $4);
next if (defined($self->{option_results}->{filter_path}) && $self->{option_results}->{filter_path} ne '' &&
$contextpath !~ /$self->{option_results}->{filter_path}/);
next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
$context !~ /$self->{option_results}->{filter_name}/);
next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi})
&& $context !~ /$self->{option_results}->{name}/i);
next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
&& $context !~ /$self->{option_results}->{name}/);
next if (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
&& $context ne $self->{option_results}->{name});
$self->{result}->{$context} = {state => $state,
sessions => $sessions,
contextpath => $contextpath};
$self->{application}->{$context} = {
display => $context,
state => $state,
sessions => $sessions,
contextpath => $contextpath
};
}
if (scalar(keys %{$self->{result}}) <= 0) {
if (defined($self->{option_results}->{name})) {
$self->{output}->add_option_msg(short_msg => "No contexts found for name '" . $self->{option_results}->{name} . "'.");
} else {
$self->{output}->add_option_msg(short_msg => "No contexts found.");
}
if (scalar(keys %{$self->{application}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No application found.");
$self->{output}->option_exit();
}
}
sub run {
my ($self, %options) = @_;
$self->manage_selection();
if (!defined($self->{option_results}->{name}) || defined($self->{option_results}->{use_regexp})) {
$self->{output}->output_add(severity => 'OK',
short_msg => 'All Contexts are ok.');
};
foreach my $name (sort(keys %{$self->{result}})) {
my $exit = 'OK';
my $staterc = '0';
if ($self->{result}->{$name}->{state} eq 'stopped') {
$exit = 'CRITICAL';
$staterc = '1';
} elsif ($self->{result}->{$name}->{state} ne 'running') {
$exit = 'UNKNOWN';
$staterc = '2';
};
$self->{output}->output_add(long_msg => sprintf("Context '%s' : %s", $name,
$self->{result}->{$name}->{state}));
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1) || (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp}))) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Context '%s' : %s", $name,
$self->{result}->{$name}->{state}));
}
my $extra_label;
$extra_label = '_' . $name if (!defined($self->{option_results}->{name}) || defined($self->{option_results}->{use_regexp}));
$self->{output}->perfdata_add(
label => 'status',
instances => $extra_label,
value => sprintf("%.1f", $staterc),
min => 0
);
};
$self->{output}->display();
$self->{output}->exit();
};
1;
__END__
@ -188,23 +189,47 @@ Path to the Tomcat Manager List (Default: Tomcat 7 '/manager/text/list')
Tomcat 6: '/manager/list'
Tomcat 7: '/manager/text/list'
=item B<--name>
=item B<--fitler-name>
Set the Context name (empty means 'check all contexts')
=item B<--regexp>
Allows to use regexp to filter contexts (with option --name).
=item B<--regexp-isensitive>
Allows to use regexp non case-sensitive (with --regexp).
Filter context name (regexp can be used)
=item B<--filter-path>
Filter Context Path (regexp can be used).
Can be for example: '/STORAGE/context/test1'.
=item B<--unknown-http-status>
Threshold unknown for http response code (Default: '%{http_code} < 200 or %{http_code} >= 300')
=item B<--warning-http-status>
Threshold warning for http response code
=item B<--critical-http-status>
Threshold critical for http response code
=item B<--unknown-status>
Set unknown threshold for status (Default: '%{state} ne "running"').
Can used special variables like: %{state}, %{display}
=item B<--warning-status>
Set warning threshold for status (Default: '').
Can used special variables like: %{state}, %{display}
=item B<--critical-status>
Set critical threshold for status (Default: '%{state} eq "stopped"').
Can used special variables like: %{state}, %{display}
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'sessions-active'.
=back
=cut

View File

@ -18,7 +18,7 @@
# limitations under the License.
#
package apps::tomcat::web::mode::traffic;
package apps::tomcat::web::mode::connectors;
use base qw(centreon::plugins::templates::counter);
@ -29,69 +29,6 @@ use Digest::MD5 qw(md5_hex);
use XML::XPath;
use URI::Escape;
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'connector', type => 1, cb_prefix_output => 'prefix_connector_output', message_multiple => 'All connector traffics are ok' },
];
$self->{maps_counters}->{connector} = [
{ label => 'in', set => {
key_values => [ { name => 'in', diff => 1 }, { name => 'display' } ],
per_second => 1,
closure_custom_calc => $self->can('custom_traffic_calc'), closure_custom_calc_extra_options => { label_ref => 'in' },
closure_custom_output => $self->can('custom_traffic_output'),
closure_custom_perfdata => $self->can('custom_traffic_perfdata'),
closure_custom_threshold_check => $self->can('custom_traffic_threshold'),
}
},
{ label => 'out', set => {
key_values => [ { name => 'out', diff => 1 }, { name => 'display' } ],
per_second => 1,
closure_custom_calc => $self->can('custom_traffic_calc'), closure_custom_calc_extra_options => { label_ref => 'out' },
closure_custom_output => $self->can('custom_traffic_output'),
closure_custom_perfdata => $self->can('custom_traffic_perfdata'),
closure_custom_threshold_check => $self->can('custom_traffic_threshold'),
}
},
];
}
sub custom_traffic_perfdata {
my ($self, %options) = @_;
my ($warning, $critical);
if ($self->{instance_mode}->{option_results}->{units_traffic} eq '%' && defined($self->{result_values}->{speed})) {
$warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}, total => $self->{result_values}->{speed}, cast_int => 1);
$critical = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}, total => $self->{result_values}->{speed}, cast_int => 1);
} elsif ($self->{instance_mode}->{option_results}->{units_traffic} eq 'b/s') {
$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 => 'traffic_' . $self->{result_values}->{label}, unit => 'b/s',
instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef,
value => sprintf("%.2f", $self->{result_values}->{traffic}),
warning => $warning,
critical => $critical,
min => 0, max => $self->{result_values}->{speed}
);
}
sub custom_traffic_threshold {
my ($self, %options) = @_;
my $exit = 'ok';
if ($self->{instance_mode}->{option_results}->{units_traffic} eq '%' && defined($self->{result_values}->{speed})) {
$exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{traffic_prct}, threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } ]);
} elsif ($self->{instance_mode}->{option_results}->{units_traffic} eq 'b/s') {
$exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{traffic}, threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } ]);
}
return $exit;
}
sub custom_traffic_output {
my ($self, %options) = @_;
@ -118,10 +55,116 @@ sub custom_traffic_calc {
if (defined($self->{instance_mode}->{option_results}->{'speed_' . $self->{result_values}->{label}}) && $self->{instance_mode}->{option_results}->{'speed_' . $self->{result_values}->{label}} =~ /[0-9]/) {
$self->{result_values}->{traffic_prct} = $self->{result_values}->{traffic} * 100 / ($self->{instance_mode}->{option_results}->{'speed_' . $self->{result_values}->{label}} * 1000 * 1000);
$self->{result_values}->{speed} = $self->{instance_mode}->{option_results}->{'speed_' . $self->{result_values}->{label}} * 1000 * 1000;
} elsif (defined($options{extra_options}->{type}) && $options{extra_options}->{type} eq 'prct') {
return -10;
}
return 0;
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'connector', type => 1, cb_prefix_output => 'prefix_connector_output', message_multiple => 'All connectors are ok', skipped_code => { -10 => 1 } },
];
$self->{maps_counters}->{connector} = [
{ label => 'threads-current', nlabel => 'connector.threads.current.count', set => {
key_values => [ { name => 'currentThreadCount' }, { name => 'maxThreads' }, { name => 'display' } ],
output_template => 'Threads Current : %s',
perfdatas => [
{ label => 'threads_current', value => 'currentThreadCount_absolute', template => '%.2f', min => 0, max => 'maxThreads_absolute',
label_extra_instance => 1 },
],
}
},
{ label => 'threads-busy', nlabel => 'connector.threads.busy.count', set => {
key_values => [ { name => 'currentThreadsBusy' }, { name => 'maxThreads' }, { name => 'display' } ],
output_template => 'Threads Busy : %s',
perfdatas => [
{ label => 'threads_busy', value => 'currentThreadsBusy_absolute', template => '%.2f', min => 0, max => 'maxThreads_absolute',
label_extra_instance => 1 },
],
}
},
{ label => 'traffic-in', nlabel => 'connector.traffic.in.bitspersecond', set => {
key_values => [ { name => 'in', diff => 1 }, { name => 'display' } ],
per_second => 1,
closure_custom_calc => $self->can('custom_traffic_calc'), closure_custom_calc_extra_options => { label_ref => 'in' },
closure_custom_output => $self->can('custom_traffic_output'),
threshold_use => 'traffic',
perfdatas => [
{ label => 'traffic_in', value => 'traffic', template => '%.2f', min => 0, max => 'speed',
unit => 'b/s', label_extra_instance => 1 },
],
}
},
{ label => 'traffic-in-prct', display_ok => 0, nlabel => 'connector.traffic.in.percent', set => {
key_values => [ { name => 'in', diff => 1 }, { name => 'display' } ],
per_second => 1,
closure_custom_calc => $self->can('custom_traffic_calc'), closure_custom_calc_extra_options => { label_ref => 'in', type => 'prct' },
output_template => 'Traffic In Used : %.2f %%',
output_use => 'traffic_prct', threshold_use => 'traffic_prct',
perfdatas => [
{ label => 'traffic_in_prct', value => 'traffic_prct', template => '%.2f', min => 0, max => 100,
unit => '%', label_extra_instance => 1 },
],
}
},
{ label => 'traffic-out', nlabel => 'connector.traffic.out.bitspersecond', set => {
key_values => [ { name => 'out', diff => 1 }, { name => 'display' } ],
per_second => 1,
closure_custom_calc => $self->can('custom_traffic_calc'), closure_custom_calc_extra_options => { label_ref => 'out' },
closure_custom_output => $self->can('custom_traffic_output'),
threshold_use => 'traffic',
perfdatas => [
{ label => 'traffic_out', value => 'traffic', template => '%.2f', min => 0, max => 'speed',
unit => 'b/s', label_extra_instance => 1 },
],
}
},
{ label => 'traffic-out-prct', display_ok => 0, nlabel => 'connector.traffic.out.percent', set => {
key_values => [ { name => 'out', diff => 1 }, { name => 'display' } ],
per_second => 1,
closure_custom_calc => $self->can('custom_traffic_calc'), closure_custom_calc_extra_options => { label_ref => 'out', type => 'prct' },
output_template => 'Traffic Out Used : %.2f %%',
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 },
],
}
},
{ label => 'requests-processingtime-total', nlabel => 'connector.requests.processingtime.total.milliseconds', set => {
key_values => [ { name => 'requestInfo_processingTime', diff => 1 }, { name => 'display' } ],
output_template => 'Requests Total Processing Time : %s ms',
perfdatas => [
{ label => 'requests_processingtime_total', value => 'requestInfo_processingTime_absolute', template => '%s', min => 0,
unit => 'ms', label_extra_instance => 1 },
],
}
},
{ label => 'requests-errors', nlabel => 'connector.requests.errors.count', set => {
key_values => [ { name => 'requestInfo_errorCount', diff => 1 }, { name => 'display' } ],
output_template => 'Requests Errors : %s',
perfdatas => [
{ label => 'requests_errors', value => 'requestInfo_errorCount_absolute', template => '%s', min => 0,
label_extra_instance => 1 },
],
}
},
{ label => 'requests-total', nlabel => 'connector.requests.total.count', set => {
key_values => [ { name => 'requestInfo_requestCount', diff => 1 }, { name => 'display' } ],
output_template => 'Requests Total : %s',
perfdatas => [
{ label => 'requests_total', value => 'requestInfo_requestCount_absolute', template => '%s', min => 0,
label_extra_instance => 1 },
],
}
},
];
}
sub prefix_connector_output {
my ($self, %options) = @_;
@ -134,19 +177,18 @@ sub new {
bless $self, $class;
$options{options}->add_options(arguments => {
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port', default => '8080' },
"proto:s" => { name => 'proto' },
"credentials" => { name => 'credentials' },
"basic" => { name => 'basic' },
"username:s" => { name => 'username' },
"password:s" => { name => 'password' },
"timeout:s" => { name => 'timeout' },
"urlpath:s" => { name => 'url_path', default => '/manager/status?XML=true' },
"filter-name:s" => { name => 'filter_name' },
"speed-in:s" => { name => 'speed_in' },
"speed-out:s" => { name => 'speed_out' },
"units-traffic:s" => { name => 'units_traffic', default => '%' },
'hostname:s' => { name => 'hostname' },
'port:s' => { name => 'port', default => '8080' },
'proto:s' => { name => 'proto' },
'credentials' => { name => 'credentials' },
'basic' => { name => 'basic' },
'username:s' => { name => 'username' },
'password:s' => { name => 'password' },
'timeout:s' => { name => 'timeout' },
'urlpath:s' => { name => 'url_path', default => '/manager/status?XML=true' },
'filter-name:s' => { name => 'filter_name' },
'speed-in:s' => { name => 'speed_in' },
'speed-out:s' => { name => 'speed_out' },
});
$self->{http} = centreon::plugins::http->new(%options);
@ -161,13 +203,20 @@ sub check_options {
if (!defined($self->{hostname})) {
$self->{hostname} = 'me';
}
$self->{http}->set_options(%{$self->{option_results}});
}
my %xpath_to_check = (
in => '/status/connector/requestInfo/@bytesReceived',
out => '/status/connector/requestInfo/@bytesSent',
requestInfo_maxTime => '/status/connector/requestInfo/@maxTime',
requestInfo_processingTime => '/status/connector/requestInfo/@processingTime',
requestInfo_requestCount => '/status/connector/requestInfo/@requestCount',
requestInfo_errorCount => '/status/connector/requestInfo/@errorCount',
maxThreads => '/status/connector/threadInfo/@maxThreads',
currentThreadCount => '/status/connector/threadInfo/@currentThreadCount',
currentThreadsBusy => '/status/connector/threadInfo/@currentThreadsBusy',
in => '/status/connector/requestInfo/@bytesReceived',
out => '/status/connector/requestInfo/@bytesSent',
);
sub manage_selection {
@ -233,21 +282,17 @@ sub manage_selection {
next;
}
next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi})
&& $connector_name !~ /$self->{option_results}->{name}/i);
next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
&& $connector_name !~ /$self->{option_results}->{name}/);
next if (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
&& $connector_name ne $self->{option_results}->{name});
$self->{connector}->{$connector_name} = { display => $connector_name } if (!defined($self->{connector}->{$connector_name}));
my $value = $node->string_value();
if ($value =~ /^"?([0-9.]+)"?$/) {
$self->{connector}->{$connector_name}->{$label} = $1 * 8;
$self->{connector}->{$connector_name}->{$label} = $1;
if ($label =~ /^in|out/) {
$self->{connector}->{$connector_name}->{$label} *= 8;
}
}
}
}
if (scalar(keys %{$self->{connector}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No information found.");
$self->{output}->option_exit();
@ -264,7 +309,7 @@ __END__
=head1 MODE
Check Tomcat Application Servers Traffic for each Connector
Check Tomcat Application Servers Connectors
=over 8
@ -310,21 +355,15 @@ Path to the Tomcat Manager XML (Default: '/manager/status?XML=true')
=item B<--filter-name>
Filter by context name (can be a regexp).
Filter by connector name (can be a regexp).
=item B<--warning-*>
=item B<--warning-*> B<--critical-*>
Threshold warning.
Can be: 'in', 'out'.
=item B<--critical-*>
Threshold critical.
Can be: 'in', 'out'.
=item B<--units-traffic>
Units of thresholds for the traffic (Default: '%') ('%', 'b/s').
Thresholds.
Can be: 'traffic-in' (b), 'traffic-in-prct' (%),
'traffic-out' (b), 'traffic-out-prct' (%),
'threads-current', 'threads-busy', 'requests-processingtime-total' (ms),
'requests-errors', 'requests-total'.
=item B<--speed-in>

View File

@ -20,48 +20,87 @@
package apps::tomcat::web::mode::memory;
use base qw(centreon::plugins::mode);
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::http;
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%%)",
$self->{perfdata}->change_bytes(value => $self->{result_values}->{total_absolute}),
$self->{perfdata}->change_bytes(value => $self->{result_values}->{used_absolute}),
$self->{result_values}->{prct_used_absolute},
$self->{perfdata}->change_bytes(value => $self->{result_values}->{free_absolute}),
$self->{result_values}->{prct_free_absolute});
return $msg;
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0, skipped_code => { -10 => 1 } },
];
$self->{maps_counters}->{global} = [
{ label => 'usage', nlabel => 'memory.usage.bytes', set => {
key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ],
closure_custom_output => $self->can('custom_memory_output'),
perfdatas => [
{ label => 'mem_used', value => 'used_absolute', template => '%d', min => 0, max => 'total_absolute',
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_absolute', template => '%d', min => 0, max => 'total_absolute',
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_absolute', template => '%.2f', min => 0, max => 100,
unit => '%', 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 => {
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port', default => '8080' },
"proto:s" => { name => 'proto' },
"credentials" => { name => 'credentials' },
"basic" => { name => 'basic' },
"username:s" => { name => 'username' },
"password:s" => { name => 'password' },
"timeout:s" => { name => 'timeout' },
"urlpath:s" => { name => 'url_path', default => '/manager/status?XML=true' },
"warning:s" => { name => 'warning' },
"critical:s" => { name => 'critical' },
'hostname:s' => { name => 'hostname' },
'port:s' => { name => 'port', default => '8080' },
'proto:s' => { name => 'proto' },
'credentials' => { name => 'credentials' },
'basic' => { name => 'basic' },
'username:s' => { name => 'username' },
'password:s' => { name => 'password' },
'timeout:s' => { name => 'timeout' },
'urlpath:s' => { name => 'url_path', default => '/manager/status?XML=true' },
});
$self->{result} = {};
$self->{http} = centreon::plugins::http->new(%options);
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();
}
$self->SUPER::check_options(%options);
$self->{http}->set_options(%{$self->{option_results}});
}
@ -72,11 +111,10 @@ my %xpath_to_check = (
memTotal => '/status/jvm/memory/@total',
);
sub run {
sub manage_selection {
my ($self, %options) = @_;
my $webcontent = $self->{http}->request();
my $port = $self->{option_results}->{port};
#EXAMPLE 1:
#<status>
@ -116,56 +154,31 @@ sub run {
#</connector>
#</status>
#GET XML DATA
my $xpath = XML::XPath->new( xml => $webcontent );
my %xpath_check_results;
my $result = {};
my $xpath = XML::XPath->new(xml => $webcontent);
foreach my $xpath_check (keys %xpath_to_check) {
my $nodeset = $xpath->find($xpath_to_check{$xpath_check});
foreach my $xpath_check ( keys %xpath_to_check ) {
my $singlepath = $xpath_to_check{$xpath_check};
$singlepath =~ s{\$port}{$port};
my $nodeset = $xpath->find($singlepath);
foreach my $node ($nodeset->get_nodelist) {
foreach my $node ($nodeset->get_nodelist()) {
my $value = $node->string_value();
if ( $value =~ /^"?([0-9.]+)"?$/ ) {
$self->{result}->{$xpath_check} = $1;
} else {
$self->{result}->{$xpath_check} = "not_numeric";
};
if ($value =~ /^"?([0-9.]+)"?$/) {
$result->{$xpath_check} = $1;
}
};
};
my $memTotal = $self->{result}->{memTotal};
my $memFree = $self->{result}->{memFree};
my $memMax = $self->{result}->{memMax};
my $memUsed = $memTotal - $memFree;
my $memUsed_prct = $memUsed * 100 / $memTotal;
if (!defined($memTotal) || !defined($memFree) || !defined($memUsed) || !defined($memUsed_prct)) {
$self->{output}->add_option_msg(short_msg => "Some informations missing.");
if (!defined($result->{memTotal}) || !defined($result->{memFree})) {
$self->{output}->add_option_msg(short_msg => "some informations missing.");
$self->{output}->option_exit();
}
my $exit = $self->{perfdata}->threshold_check(value => $memUsed_prct, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
my ($memTotal_value, $memTotal_unit) = $self->{perfdata}->change_bytes(value => $memTotal);
my ($memFree_value, $memFree_unit) = $self->{perfdata}->change_bytes(value => $memFree);
my ($memMax_value, $memMax_unit) = $self->{perfdata}->change_bytes(value => $memMax);
my ($memUsed_value, $memUsed_unit) = $self->{perfdata}->change_bytes(value => $memUsed);
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Memory used %s (%.2f%%)",
$memUsed_value . " " . $memUsed_unit, $memUsed_prct));
$self->{output}->perfdata_add(label => "used", unit => 'B',
value => $memUsed,
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $memTotal),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $memTotal),
min => 0, max => $memTotal);
$self->{output}->display();
$self->{output}->exit();
$self->{global} = {
total => $result->{memTotal},
free => $result->{memFree},
used => $result->{memTotal} - $result->{memFree},
prct_free => $result->{memFree} * 100 / $result->{memMax},
prct_used => ($result->{memTotal} - $result->{memFree}) * 100 / $result->{memMax},
};
};
1;
@ -218,13 +231,10 @@ Threshold for HTTP timeout
Path to the Tomcat Manager XML (Default: '/manager/status?XML=true')
=item B<--warning>
=item B<--warning-*> B<--critical-*>
Threshold warning in percent.
=item B<--critical>
Threshold critical in percent.
Thresholds.
Can be: 'usage' (B), 'usage-free' (B), 'usage-prct' (%).
=back

View File

@ -35,31 +35,18 @@ sub new {
bless $self, $class;
$options{options}->add_options(arguments => {
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port', default => '8080' },
"proto:s" => { name => 'proto' },
"credentials" => { name => 'credentials' },
"basic" => { name => 'basic' },
"username:s" => { name => 'username' },
"password:s" => { name => 'password' },
"timeout:s" => { name => 'timeout' },
"urlpath:s" => { name => 'url_path', default => '/manager/status?XML=true' },
"name:s" => { name => 'name' },
"regexp" => { name => 'use_regexp' },
"regexp-isensitive" => { name => 'use_regexpi' },
"warning-maxtime:s" => { name => 'warning_maxtime' },
"critical-maxtime:s" => { name => 'critical_maxtime' },
"warning-processingtime:s" => { name => 'warning_processingtime' },
"critical-processingtime:s" => { name => 'critical_processingtime' },
"warning-requestcount:s" => { name => 'warning_requestcount' },
"critical-requestcount:s" => { name => 'critical_requestcount' },
"warning-errorcount:s" => { name => 'warning_errorcount' },
"critical-errorcount:s" => { name => 'critical_errorcount' },
'hostname:s' => { name => 'hostname' },
'port:s' => { name => 'port', default => '8080' },
'proto:s' => { name => 'proto' },
'credentials' => { name => 'credentials' },
'basic' => { name => 'basic' },
'username:s' => { name => 'username' },
'password:s' => { name => 'password' },
'timeout:s' => { name => 'timeout' },
'urlpath:s' => { name => 'url_path', default => '/manager/status?XML=true' },
'filter-name:s' => { name => 'filter_name' },
});
$self->{result} = {};
$self->{hostname} = undef;
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
$self->{http} = centreon::plugins::http->new(%options);
return $self;
}
@ -114,12 +101,7 @@ sub check_options {
$self->{http}->set_options(%{$self->{option_results}});
}
my %xpath_to_check = (
requestInfo_maxTime => '/status/connector/requestInfo/@maxTime', #
requestInfo_processingTime => '/status/connector/requestInfo/@processingTime', #to last
requestInfo_requestCount => '/status/connector/requestInfo/@requestCount', #to last
requestInfo_errorCount => '/status/connector/requestInfo/@errorCount', #to last
);
sub manage_selection {
my ($self, %options) = @_;
@ -371,17 +353,9 @@ Threshold for HTTP timeout
Path to the Tomcat Manager XML (Default: '/manager/status?XML=true')
=item B<--name>
=item B<--filter-name>
Set the filter name (empty means 'check all contexts')
=item B<--regexp>
Allows to use regexp to filter (with option --name).
=item B<--regexp-isensitive>
Allows to use regexp non case-sensitive (with --regexp).
Filter the connector name (can be regexp)
=item B<--warning-maxtime>

View File

@ -1,226 +0,0 @@
#
# Copyright 2019 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.
#
package apps::tomcat::web::mode::sessions;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::plugins::http;
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$options{options}->add_options(arguments => {
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port', default => '8080' },
"proto:s" => { name => 'proto' },
"credentials" => { name => 'credentials' },
"basic" => { name => 'basic' },
"username:s" => { name => 'username' },
"password:s" => { name => 'password' },
"timeout:s" => { name => 'timeout' },
"urlpath:s" => { name => 'url_path', default => '/manager/text/list' },
"warning:s" => { name => 'warning' },
"critical:s" => { name => 'critical' },
"name:s" => { name => 'name' },
"regexp" => { name => 'use_regexp' },
"regexp-isensitive" => { name => 'use_regexpi' },
"filter-state:s" => { name => 'filter_state' },
"filter-path:s" => { name => 'filter_path', },
});
$self->{result} = {};
$self->{http} = centreon::plugins::http->new(%options);
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();
}
$self->{http}->set_options(%{$self->{option_results}});
}
sub manage_selection {
my ($self, %options) = @_;
my $webcontent = $self->{http}->request();
while ($webcontent =~ /(.*):(.*):(\d+):(.*)/g) {
my ($context, $state, $sessions, $contextpath) = ($1, $2, $3, $4);
next if (defined($self->{option_results}->{filter_state}) && $self->{option_results}->{filter_state} ne '' &&
$state !~ /$self->{option_results}->{filter_state}/);
next if (defined($self->{option_results}->{filter_path}) && $self->{option_results}->{filter_path} ne '' &&
$contextpath !~ /$self->{option_results}->{filter_path}/);
next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi})
&& $context !~ /$self->{option_results}->{name}/i);
next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
&& $context !~ /$self->{option_results}->{name}/);
next if (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
&& $context ne $self->{option_results}->{name});
$self->{result}->{$context} = {state => $state, sessions => $sessions, contextpath => $contextpath};
}
if (scalar(keys %{$self->{result}}) <= 0) {
if (defined($self->{option_results}->{name})) {
$self->{output}->add_option_msg(short_msg => "No session information found for name '" . $self->{option_results}->{name} . "'.");
} else {
$self->{output}->add_option_msg(short_msg => "No session information found.");
}
$self->{output}->option_exit();
}
}
sub run {
my ($self, %options) = @_;
$self->manage_selection();
if (!defined($self->{option_results}->{name}) || defined($self->{option_results}->{use_regexp})) {
$self->{output}->output_add(severity => 'OK',
short_msg => 'All Sessions are ok.');
};
foreach my $name (sort(keys %{$self->{result}})) {
my $exit = $self->{perfdata}->threshold_check(value => $self->{result}->{$name}->{sessions}, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
$self->{output}->output_add(long_msg => sprintf("Context '%s' sessions : %s", $name,
$self->{result}->{$name}->{sessions}));
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1) || (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp}))) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Context '%s' sessions : %s", $name,
$self->{result}->{$name}->{sessions}));
}
my $extra_label;
$extra_label = '_' . $name if (!defined($self->{option_results}->{name}) || defined($self->{option_results}->{use_regexp}));
$self->{output}->perfdata_add(
label => 'sessions',
instances => $extra_label,
value => sprintf("%.2f", $self->{result}->{$name}->{sessions}),
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
min => 0
);
};
$self->{output}->display();
$self->{output}->exit();
};
1;
__END__
=head1 MODE
Check Tomcat Application Servers Number of Sessions for each Context
=over 8
=item B<--hostname>
IP Address or FQDN of the Tomcat Application Server
=item B<--port>
Port used by Tomcat
=item B<--proto>
Protocol used http or https
=item B<--credentials>
Specify this option if you access server-status page with authentication
=item B<--username>
Specify username for authentication (Mandatory if --credentials is specified)
=item B<--password>
Specify password for authentication (Mandatory if --credentials is specified)
=item B<--basic>
Specify this option if you access server-status page over basic authentication and don't want a '401 UNAUTHORIZED' error to be logged on your webserver.
Specify this option if you access server-status page over hidden basic authentication or you'll get a '404 NOT FOUND' error.
(Use with --credentials)
=item B<--timeout>
Threshold for HTTP timeout
=item B<--urlpath>
Path to the Tomcat Manager List (Default: Tomcat 7 '/manager/text/list')
Tomcat 6: '/manager/list'
Tomcat 7: '/manager/text/list'
=item B<--warning>
Warning Threshold for Number of Sessions
=item B<--critical>
Critical Threshold for Number of Sessions
=item B<--name>
Set the Context name (empty means 'check all contexts')
=item B<--regexp>
Allows to use regexp to filter contexts (with option --name).
=item B<--regexp-isensitive>
Allows to use regexp non case-sensitive (with --regexp).
=item B<--filter-state>
Filter state (regexp can be used).
Can be for example: 'running' or 'stopped'.
=item B<--filter-path>
Filter Context Path (regexp can be used).
Can be for example: '/STORAGE/context/test1'.
=back
=cut

View File

@ -1,285 +0,0 @@
#
# Copyright 2019 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.
#
package apps::tomcat::web::mode::threads;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::plugins::http;
use XML::XPath;
use URI::Escape;
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$options{options}->add_options(arguments => {
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port', default => '8080' },
"proto:s" => { name => 'proto' },
"credentials" => { name => 'credentials' },
"basic" => { name => 'basic' },
"username:s" => { name => 'username' },
"password:s" => { name => 'password' },
"timeout:s" => { name => 'timeout' },
"urlpath:s" => { name => 'url_path', default => '/manager/status?XML=true' },
"warning:s" => { name => 'warning' },
"critical:s" => { name => 'critical' },
"name:s" => { name => 'name' },
"regexp" => { name => 'use_regexp' },
"regexp-isensitive" => { name => 'use_regexpi' },
});
$self->{result} = {};
$self->{hostname} = undef;
$self->{http} = centreon::plugins::http->new(%options);
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();
}
$self->{http}->set_options(%{$self->{option_results}});
}
my %xpath_to_check = (
maxThreads => '/status/connector/threadInfo/@maxThreads',
currentThreadCount => '/status/connector/threadInfo/@currentThreadCount',
currentThreadsBusy => '/status/connector/threadInfo/@currentThreadsBusy',
);
sub manage_selection {
my ($self, %options) = @_;
my $webcontent = $self->{http}->request();
my $port = $self->{option_results}->{port};
#EXAMPLE 1:
#<status>
# <connector name="http-0">
# <threadInfo currentThreadCount="0" currentThreadsBusy="0" maxThreads="200"/>
# <requestInfo bytesReceived="0" bytesSent="0" errorCount="0" maxTime="0" processingTime="0" requestCount="0"/>
# <workers></workers>
# </connector>
# <connector name="http-8080">
# <threadInfo currentThreadCount="158" currentThreadsBusy="10" maxThreads="200"/>
# <requestInfo bytesReceived="297" bytesSent="19350704517" errorCount="192504" maxTime="249349" processingTime="2242513592" requestCount="983650"/>
# <workers>
# </workers>
# </connector>
#</status>
#EXAMPLE 2:
#<status>
#<jvm>
# <memory free='409303928' total='518979584' max='518979584'/>
# <memorypool name='Eden Space' type='Heap memory' usageInit='143130624' usageCommitted='143130624' usageMax='143130624' usageUsed='56881560'/>
# <memorypool name='Survivor Space' type='Heap memory' usageInit='17891328' usageCommitted='17891328' usageMax='17891328' usageUsed='17891328'/>
# <memorypool name='Tenured Gen' type='Heap memory' usageInit='357957632' usageCommitted='357957632' usageMax='357957632' usageUsed='34902768'/>
# <memorypool name='Code Cache' type='Non-heap memory' usageInit='2555904' usageCommitted='2555904' usageMax='50331648' usageUsed='1899840'/>
# <memorypool name='Perm Gen' type='Non-heap memory' usageInit='21757952' usageCommitted='21757952' usageMax='85983232' usageUsed='21372688'/>
#</jvm>
#<connector name='"http-bio-10.1.80.149-22002"'><threadInfo maxThreads="5" currentThreadCount="2" currentThreadsBusy="1" />
# <requestInfo maxTime="1216" processingTime="1216" requestCount="1" errorCount="1" bytesReceived="0" bytesSent="2474" />
# <workers>
# <worker stage="S" requestProcessingTime="23" requestBytesSent="0" requestBytesReceived="0" remoteAddr="10.1.80.149" virtualHost="examplehost" method="GET" currentUri="/manager/status" currentQueryString="XML=true" protocol="HTTP/1.1" />
# </workers>
#</connector>
#<connector name='"ajp-bio-10.1.80.149-22001"'><threadInfo maxThreads="150" currentThreadCount="0" currentThreadsBusy="0" />
# <requestInfo maxTime="0" processingTime="0" requestCount="0" errorCount="0" bytesReceived="0" bytesSent="0" />
# <workers>
# </workers>
#</connector>
#</status>
#GET XML DATA
my $xpath = XML::XPath->new( xml => $webcontent );
my %xpath_check_results;
foreach my $xpath_check ( keys %xpath_to_check ) {
my $singlepath = $xpath_to_check{$xpath_check};
$singlepath =~ s{\$port}{$port};
my $nodeset = $xpath->find($singlepath);
foreach my $node ($nodeset->get_nodelist) {
my $connector_name = $node->getParentNode()->getParentNode()->getAttribute("name");
$connector_name =~ s/^["'\s]+//;
$connector_name =~ s/["'\s]+$//;
$connector_name = uri_unescape($connector_name);
next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi})
&& $connector_name !~ /$self->{option_results}->{name}/i);
next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
&& $connector_name !~ /$self->{option_results}->{name}/);
next if (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
&& $connector_name ne $self->{option_results}->{name});
my $value = $node->string_value();
if ( $value =~ /^"?([0-9.]+)"?$/ ) {
$self->{result}->{$connector_name}{$xpath_check} = $1;
} else {
$self->{result}->{$connector_name}{$xpath_check} = "not_numeric";
};
};
if (scalar(keys %{$self->{result}}) <= 0) {
if (defined($self->{option_results}->{name})) {
$self->{output}->add_option_msg(short_msg => "No information found for name '" . $self->{option_results}->{name} . "'.");
} else {
$self->{output}->add_option_msg(short_msg => "No information found.");
}
$self->{output}->option_exit();
};
};
};
sub run {
my ($self, %options) = @_;
$self->manage_selection();
if (!defined($self->{option_results}->{name}) || defined($self->{option_results}->{use_regexp})) {
$self->{output}->output_add(severity => 'OK',
short_msg => 'All Threads are ok.');
};
foreach my $name (sort(keys %{$self->{result}})) {
my $exit = $self->{perfdata}->threshold_check(value => $self->{result}->{$name}->{currentThreadsBusy}, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
$self->{output}->output_add(long_msg => sprintf("Thread '%s' currentThreadsBusy : %s", $name,
$self->{result}->{$name}->{currentThreadsBusy}));
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1) || (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp}))) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Thread '%s' currentThreadsBusy : %s", $name,
$self->{result}->{$name}->{currentThreadsBusy}));
}
my $extra_label;
$extra_label = '_' . $name if (!defined($self->{option_results}->{name}) || defined($self->{option_results}->{use_regexp}));
$self->{output}->perfdata_add(
label => 'currentThreadsBusy',
instances => $extra_label,
value => $self->{result}->{$name}->{currentThreadsBusy},
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
min => 0,
max => $self->{result}->{$name}->{maxThreads}
);
$self->{output}->perfdata_add(
label => 'currentThreadCount',
instances => $extra_label,
value => $self->{result}->{$name}->{currentThreadCount},
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
min => 0,
max => $self->{result}->{$name}->{maxThreads}
);
};
$self->{output}->display();
$self->{output}->exit();
};
1;
__END__
=head1 MODE
Check Tomcat Application Servers Threads for each Connector
=over 8
=item B<--hostname>
IP Address or FQDN of the Tomcat Application Server
=item B<--port>
Port used by Tomcat
=item B<--proto>
Protocol used http or https
=item B<--credentials>
Specify this option if you access server-status page with authentication
=item B<--username>
Specify username for authentication (Mandatory if --credentials is specified)
=item B<--password>
Specify password for authentication (Mandatory if --credentials is specified)
=item B<--basic>
Specify this option if you access server-status page over basic authentication and don't want a '401 UNAUTHORIZED' error to be logged on your webserver.
Specify this option if you access server-status page over hidden basic authentication or you'll get a '404 NOT FOUND' error.
(Use with --credentials)
=item B<--timeout>
Threshold for HTTP timeout
=item B<--urlpath>
Path to the Tomcat Manager XML (Default: '/manager/status?XML=true')
=item B<--warning>
Warning Threshold for Number of Threads
=item B<--critical>
Critical Threshold for Number of Threads
=item B<--name>
Set the filter name (empty means 'check all contexts')
=item B<--regexp>
Allows to use regexp to filter (with option --name).
=item B<--regexp-isensitive>
Allows to use regexp non case-sensitive (with --regexp).
=back
=cut

View File

@ -31,14 +31,11 @@ sub new {
$self->{version} = '0.1';
%{$self->{modes}} = (
'applications' => 'apps::tomcat::web::mode::applications',
'list-application' => 'apps::tomcat::web::mode::listapplication',
'sessions' => 'apps::tomcat::web::mode::sessions',
'threads' => 'apps::tomcat::web::mode::threads',
'requestinfo' => 'apps::tomcat::web::mode::requestinfo',
'memory' => 'apps::tomcat::web::mode::memory',
'traffic' => 'apps::tomcat::web::mode::traffic',
);
'applications' => 'apps::tomcat::web::mode::applications',
'connectors' => 'apps::tomcat::web::mode::connectors',
'list-application' => 'apps::tomcat::web::mode::listapplication',
'memory' => 'apps::tomcat::web::mode::memory',
);
return $self;
}