From 135d97af5c5dece138a20af15a7a4db9794b9ce9 Mon Sep 17 00:00:00 2001 From: Sims24 Date: Thu, 13 Aug 2015 14:59:41 +0200 Subject: [PATCH 1/5] Create plugin.pm --- apps/centreonmap/plugin.pm | 52 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 apps/centreonmap/plugin.pm diff --git a/apps/centreonmap/plugin.pm b/apps/centreonmap/plugin.pm new file mode 100644 index 000000000..f0e92ae68 --- /dev/null +++ b/apps/centreonmap/plugin.pm @@ -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 From 709882a0ece47135edb6b78204c8a889e48d644d Mon Sep 17 00:00:00 2001 From: Sims24 Date: Thu, 13 Aug 2015 15:05:01 +0200 Subject: [PATCH 2/5] Create sessions.pm --- apps/centreonmap/mode/sessions.pm | 110 ++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 apps/centreonmap/mode/sessions.pm diff --git a/apps/centreonmap/mode/sessions.pm b/apps/centreonmap/mode/sessions.pm new file mode 100644 index 000000000..200a39127 --- /dev/null +++ b/apps/centreonmap/mode/sessions.pm @@ -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 + From 2b6959b70e12b6936f1afba241f5ddc1b1304cce Mon Sep 17 00:00:00 2001 From: Sims24 Date: Thu, 13 Aug 2015 15:05:46 +0200 Subject: [PATCH 3/5] Create gates.pm --- apps/centreonmap/mode/gates.pm | 113 +++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 apps/centreonmap/mode/gates.pm diff --git a/apps/centreonmap/mode/gates.pm b/apps/centreonmap/mode/gates.pm new file mode 100644 index 000000000..1a329ab30 --- /dev/null +++ b/apps/centreonmap/mode/gates.pm @@ -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 + From 78da2e7f9f792c162b2c60ef24b0bc3d8e2b2482 Mon Sep 17 00:00:00 2001 From: Sims24 Date: Thu, 13 Aug 2015 15:07:06 +0200 Subject: [PATCH 4/5] Create eventstatistics.pm --- apps/centreonmap/mode/eventstatistics.pm | 183 +++++++++++++++++++++++ 1 file changed, 183 insertions(+) create mode 100644 apps/centreonmap/mode/eventstatistics.pm diff --git a/apps/centreonmap/mode/eventstatistics.pm b/apps/centreonmap/mode/eventstatistics.pm new file mode 100644 index 000000000..b91f29fd3 --- /dev/null +++ b/apps/centreonmap/mode/eventstatistics.pm @@ -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 + From 735be8766777de81982284bffc3814486adfa3d4 Mon Sep 17 00:00:00 2001 From: Sims24 Date: Thu, 13 Aug 2015 15:08:58 +0200 Subject: [PATCH 5/5] Create eventqueue.pm --- apps/centreonmap/mode/eventqueue.pm | 110 ++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 apps/centreonmap/mode/eventqueue.pm diff --git a/apps/centreonmap/mode/eventqueue.pm b/apps/centreonmap/mode/eventqueue.pm new file mode 100644 index 000000000..0d06bab08 --- /dev/null +++ b/apps/centreonmap/mode/eventqueue.pm @@ -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 +