Merge pull request #132 from Sims24/map

CentreonMap 4 monitoring through Jolokia
This commit is contained in:
qgarnier 2015-08-14 10:02:43 +02:00
commit c535868f07
5 changed files with 568 additions and 0 deletions

View File

@ -0,0 +1,110 @@
# Copyright 2015 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::centreonmap::mode::eventqueue;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"warning:s" => { name => 'warning', },
"critical:s" => { name => 'critical', },
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
$self->{output}->option_exit();
}
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
$self->{output}->option_exit();
}
}
sub run {
my ($self, %options) = @_;
$self->{connector} = $options{custom};
$self->{request} = [
{ mbean => "com.merethis.studio:name=statistics,type=session" }
];
my $result = $self->{connector}->get_attributes(request => $self->{request}, nothing_quit => 0);
my $exit = $self->{perfdata}->threshold_check(value => $result->{"com.merethis.studio:name=statistics,type=session"}->{AverageEventQueueSize},
threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning'} ]);
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Average event queue size : %d",
$result->{"com.merethis.studio:name=statistics,type=session"}->{AverageEventQueueSize}));
$self->{output}->perfdata_add(label => 'events',
value => $result->{"com.merethis.studio:name=statistics,type=session"}->{AverageEventQueueSize},
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 Centreon Map Session event queue size
Example:
perl centreon_plugins.pl --plugin=apps::centreonmap::plugin --custommode=jolokia --url=http://10.30.2.22:8080/jolokia-war --mode=eventqueue
=over 8
=item B<--warning>
Set this threshold if you want a warning if global sessions event queue size match threshold
=item B<--critical>
Set this threshold if you want a warning if global sessions event queue size match threshold
=back
=cut

View File

@ -0,0 +1,183 @@
# Copyright 2015 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::centreonmap::mode::eventstatistics;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::plugins::statefile;
use Digest::MD5 qw(md5_hex);
my %mapping_eventtype = (
'EventCount' => 'global',
'EventTypeCreate' => 'create',
'EventTypeRemove' => 'remove',
'EventTypeUpdate' => 'update',
);
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"warning-global:s" => { name => 'warning_global', },
"critical-global:s" => { name => 'critical_global', },
"warning-create:s" => { name => 'warning_create', },
"critical-create:s" => { name => 'critical_create', },
"warning-update:s" => { name => 'warning_update', },
"critical-update:s" => { name => 'critical_update', },
"warning-remove:s" => { name => 'warning_remove', },
"critical-remove:s" => { name => 'critical_remove', },
});
$self->{statefile_cache} = centreon::plugins::statefile->new(%options);
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
foreach my $label ('warning_global', 'critical_global', 'warning_create', 'critical_create', 'warning_update', 'critical_update', 'warning_remove', 'critical_remove') {
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();
}
}
$self->{statefile_cache}->check_options(%options);
}
sub run {
my ($self, %options) = @_;
$self->{connector} = $options{custom};
$self->{request} = [
{ mbean => "com.merethis.studio:name=statistics,type=whatsup" }
];
my $result = $self->{connector}->get_attributes(request => $self->{request}, nothing_quit => 0);
my $new_datas = {};
$self->{statefile_cache}->read(statefile => 'tomcat_' . $self->{mode} . '-' . md5_hex($self->{connector}->{url}));
my $old_timestamp = $self->{statefile_cache}->get(name => 'last_timestamp');
$new_datas->{last_timestamp} = time();
if (defined($old_timestamp) && $new_datas->{last_timestamp} - $old_timestamp == 0) {
$self->{output}->add_option_msg(short_msg => "Need at least one second between two checks.");
$self->{output}->option_exit();
}
foreach my $type ('EventCount', 'EventTypeCreate', 'EventTypeUpdate', 'EventTypeRemove') {
$new_datas->{$type} = $result->{"com.merethis.studio:name=statistics,type=whatsup"}->{$type}->{andIncrement};
my $old_val = $self->{statefile_cache}->get(name => $type);
next if (!defined($old_val) || $result->{"com.merethis.studio:name=statistics,type=whatsup"}->{$type}->{andIncrement} < $old_val);
my $value = int(($result->{"com.merethis.studio:name=statistics,type=whatsup"}->{$type}->{andIncrement} - $old_val) / ($new_datas->{last_timestamp} - $old_timestamp));
$self->{output}->perfdata_add(label => $type,
value => $value,
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning_' . $mapping_eventtype{$type}),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical_' . $mapping_eventtype{$type}),
min => 0);
my $exit = $self->{perfdata}->threshold_check(value => $value,
threshold => [ { label => 'critical_' . $mapping_eventtype{$type}, exit_litteral => 'critical' },
{ label => 'warning_' . $mapping_eventtype{$type}, exit_litteral => 'warning' } ]);
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("%s = %d", $type, $value));
}
$self->{output}->output_add(severity => 'ok',
short_msg => sprintf("%s = %s", $type, $value));
}
$self->{statefile_cache}->write(data => $new_datas);
if (!defined($old_timestamp)) {
$self->{output}->output_add(severity => 'OK',
short_msg => "Buffer creation...");
}
$self->{output}->display();
$self->{output}->exit();
}
1;
__END__
=head1 MODE
Check Centreon Map Event Statistics
Example:
perl centreon_plugins.pl --plugin=apps::centreonmap::plugin --custommode=jolokia --url=http://10.30.2.22:8080/jolokia-war --mode=eventstatistics
=over 8
=item B<--warning-global>
Warning threshold for global event count
=item B<--critical-global>
Critical threshold for global event count
=item B<--warning-create>
Warning threshold for create event count
=item B<--critical-create>
Critical threshold for create event count
=item B<--warning-update>
Warning threshold for update event count
=item B<--critical-update>
Critical threshold for update event count
=item B<--warning-remove>
Warning threshold for remove event count
=item B<--critical-remove>
Critical threshold for remove event count
=back
=cut

View File

@ -0,0 +1,113 @@
# Copyright 2015 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::centreonmap::mode::gates;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"warning:s" => { name => 'warning', },
"critical:s" => { name => 'critical', },
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
$self->{output}->option_exit();
}
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
$self->{output}->option_exit();
}
}
sub run {
my ($self, %options) = @_;
# $options{snmp} = snmp object
$self->{connector} = $options{custom};
$self->{request} = [
{ mbean => "com.merethis.map:name=BusinessGate,type=repo" }
];
my $result = $self->{connector}->get_attributes(request => $self->{request}, nothing_quit => 1);
my $gates = $result->{"com.merethis.map:name=BusinessGate,type=repo"}->{LoadedModelCount};
my $exit = $self->{perfdata}->threshold_check(value => $gates,
threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning'} ]);
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Business gates opened : %d",
$result->{"com.merethis.map:name=BusinessGate,type=repo"}->{LoadedModelCount}));
$self->{output}->perfdata_add(label => 'gates',
value => $result->{"com.merethis.map:name=BusinessGate,type=repo"}->{LoadedModelCount},
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 Centreon Map Open Gates
Example:
perl centreon_plugins.pl --plugin=apps::centreonmap::plugin --custommode=jolokia --url=http://10.30.2.22:8080/jolokia-war --mode=gates
=over 8
=item B<--warning>
Set this threshold if you want a warning if opened gates match condition
=item B<--critical>
Set this threshold if you want a warning if opened gates match condition
=back
=cut

View File

@ -0,0 +1,110 @@
# Copyright 2015 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::centreonmap::mode::sessions;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"warning:s" => { name => 'warning', },
"critical:s" => { name => 'critical', },
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
$self->{output}->option_exit();
}
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
$self->{output}->option_exit();
}
}
sub run {
my ($self, %options) = @_;
# $options{snmp} = snmp object
$self->{connector} = $options{custom};
$self->{request} = [
{ mbean => "com.merethis.studio:name=statistics,type=session" }
];
my $result = $self->{connector}->get_attributes(request => $self->{request}, nothing_quit => 0);
my $exit = $self->{perfdata}->threshold_check(value => $result->{"com.merethis.studio:name=statistics,type=session"}->{SessionCount},
threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning'} ]);
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Current sessions : %d",
$result->{"com.merethis.studio:name=statistics,type=session"}->{SessionCount}));
$self->{output}->perfdata_add(label => 'sessions',
value => $result->{"com.merethis.studio:name=statistics,type=session"}->{SessionCount},
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 Centreon Map Number of sessions
Example:
perl centreon_plugins.pl --plugin=apps::centreonmap::plugin --custommode=jolokia --url=http://10.30.2.22:8080/jolokia-war --mode=sessions
=over 8
=item B<--warning>
Set this threshold if you want a warning if current session number match condition
=item B<--critical>
Set this threshold if you want a warning if current session number match condition
=back
=cut

View File

@ -0,0 +1,52 @@
# Copyright 2015 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::centreonmap::plugin;
use strict;
use warnings;
use base qw(centreon::plugins::script_custom);
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
# $options->{options} = options object
$self->{version} = '0.1';
%{$self->{modes}} = (
'gates' => 'apps::centreonmap::mode::gates',
'sessions' => 'apps::centreonmap::mode::sessions',
'event-queue' => 'apps::centreonmap::mode::eventqueue',
'event-statistics' => 'apps::centreonmap::mode::eventstatistics',
);
$self->{custom_modes}{jolokia} = 'centreon::common::protocols::jmx::custom::jolokia';
return $self;
}
1;
__END__
=head1 PLUGIN DESCRIPTION
Check Centreon map informations. Need Jolokia agent and Map >= 4.0
=cut