From 78ca8adb1134fc3b321ba89e0cab7cda987d4729 Mon Sep 17 00:00:00 2001 From: Colin Gagnaire Date: Mon, 28 Jan 2019 19:04:44 +0100 Subject: [PATCH] refacto centreon map --- apps/centreon/map/jmx/mode/brokerstats.pm | 172 ++++++++++++++++++ apps/centreon/map/jmx/mode/enginestats.pm | 155 ++++++++++++++++ apps/centreon/map/jmx/mode/events.pm | 147 +++++++++++++++ apps/centreon/map/jmx/mode/openviews.pm | 110 +++++++++++ apps/centreon/map/jmx/mode/sessions.pm | 97 ++++++---- apps/centreon/map/jmx/plugin.pm | 12 +- .../{map => map4}/jmx/mode/elements.pm | 4 +- .../{map => map4}/jmx/mode/eventqueue.pm | 2 +- .../{map => map4}/jmx/mode/eventstatistics.pm | 2 +- apps/centreon/{map => map4}/jmx/mode/gates.pm | 2 +- apps/centreon/map4/jmx/mode/sessions.pm | 109 +++++++++++ apps/centreon/map4/jmx/plugin.pm | 52 ++++++ 12 files changed, 813 insertions(+), 51 deletions(-) create mode 100644 apps/centreon/map/jmx/mode/brokerstats.pm create mode 100644 apps/centreon/map/jmx/mode/enginestats.pm create mode 100644 apps/centreon/map/jmx/mode/events.pm create mode 100644 apps/centreon/map/jmx/mode/openviews.pm rename apps/centreon/{map => map4}/jmx/mode/elements.pm (97%) rename apps/centreon/{map => map4}/jmx/mode/eventqueue.pm (98%) rename apps/centreon/{map => map4}/jmx/mode/eventstatistics.pm (99%) rename apps/centreon/{map => map4}/jmx/mode/gates.pm (98%) create mode 100644 apps/centreon/map4/jmx/mode/sessions.pm create mode 100644 apps/centreon/map4/jmx/plugin.pm diff --git a/apps/centreon/map/jmx/mode/brokerstats.pm b/apps/centreon/map/jmx/mode/brokerstats.pm new file mode 100644 index 000000000..8ec699f67 --- /dev/null +++ b/apps/centreon/map/jmx/mode/brokerstats.pm @@ -0,0 +1,172 @@ +# 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::centreon::map::jmx::mode::brokerstats; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use Digest::MD5 qw(md5_hex); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = sprintf("Packets Delta: %d [%d/%d]", + $self->{result_values}->{diff_packets}, + $self->{result_values}->{processed_packets}, + $self->{result_values}->{received_packets}); + return $msg; +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{received_packets} = $options{new_datas}->{$self->{instance} . '_ReceivedPackets'}; + $self->{result_values}->{processed_packets} = $options{new_datas}->{$self->{instance} . '_ProcessedPackets'}; + $self->{result_values}->{diff_packets} = $self->{result_values}->{received_packets} - $self->{result_values}->{processed_packets}; + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 }, + ]; + + $self->{maps_counters}->{global} = [ + { label => 'status', set => { + key_values => [ { name => 'ReceivedPackets', diff => 1 }, { name => 'ProcessedPackets', diff => 1 } ], + closure_custom_calc => $self->can('custom_status_calc'), + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + { label => 'received-packets-rate', set => { + key_values => [ { name => 'ReceivedPackets', diff => 1 } ], + output_template => 'Received Packets: %.2f/s', + per_second => 1, + perfdatas => [ + { label => 'received_packets_rate', value => 'ReceivedPackets_per_second', template => '%.2f', + min => 0, unit => 'packets/s' }, + ], + } + }, + { label => 'processed-packets-rate', set => { + key_values => [ { name => 'ProcessedPackets', diff => 1 } ], + output_template => 'Processed Packets: %.2f/s', + per_second => 1, + perfdatas => [ + { label => 'processed_packets_rate', value => 'ProcessedPackets_per_second', template => '%.2f', + min => 0, unit => 'packets/s' }, + ], + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "filter-counters:s" => { name => 'filter_counters', default => '' }, + "warning-status:s" => { name => 'warning_status', default => '' }, + "critical-status:s" => { name => 'critical_status', default => '%{processed_packets} < %{received_packets}' }, + }); + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); +} + +my $mbean_broker = "com.centreon.studio.map:type=broker,name=statistics"; + +sub manage_selection { + my ($self, %options) = @_; + + $self->{cache_name} = "centreon_map_" . md5_hex($options{custom}->{url}) . '_' . $self->{mode} . '_' . + (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); + + $self->{request} = [ + { mbean => $mbean_broker } + ]; + + my $result = $options{custom}->get_attributes(request => $self->{request}, nothing_quit => 0); + + $self->{global} = {}; + + $self->{global} = { + ReceivedPackets => $result->{$mbean_broker}->{ReceivedPackets}->{andIncrement}, + ProcessedPackets => $result->{$mbean_broker}->{ProcessedPackets}->{andIncrement}, + }; +} + +1; + +__END__ + +=head1 MODE + +Check broker packets rate received and processed. + +Example: + +perl centreon_plugins.pl --plugin=apps::centreon::map::jmx::plugin --custommode=jolokia +--url=http://10.30.2.22:8080/jolokia-war --mode=broker-stats + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +(Example: --filter-counters='session') + +=item B<--warning-status> + +Set warning threshold for status. (Default: ''). +Can use special variables like: %{processed_packets}, %{received_packets}, %{diff_packets}. + +=item B<--critical-status> + +Set critical threshold for status. (Default: '%{processed_packets} < %{received_packets}'). +Can use special variables like: %{processed_packets}, %{received_packets}, %{diff_packets}. + +=item B<--warning-*> + +Threshold warning. +Can be: 'received-packets-rate', 'processed-packets-rate'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'received-packets-rate', 'processed-packets-rate'. + +=back + +=cut + diff --git a/apps/centreon/map/jmx/mode/enginestats.pm b/apps/centreon/map/jmx/mode/enginestats.pm new file mode 100644 index 000000000..2ae5984dc --- /dev/null +++ b/apps/centreon/map/jmx/mode/enginestats.pm @@ -0,0 +1,155 @@ +# 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::centreon::map::jmx::mode::enginestats; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use Digest::MD5 qw(md5_hex); + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 }, + ]; + + $self->{maps_counters}->{global} = [ + { label => 'drilldown-candidates-queue', set => { + key_values => [ { name => 'DrilldownCandidatesQueue' } ], + output_template => 'Drilldown Canditates Queue: %d', + perfdatas => [ + { label => 'drilldown_candidates_queue', value => 'DrilldownCandidatesQueue_absolute', template => '%d', + min => 0 }, + ], + } + }, + { label => 'cutback-computation-rate', set => { + key_values => [ { name => 'Cutbackcomputation', diff => 1 } ], + output_template => 'Cutback Computation: %.2f/s', + per_second => 1, + perfdatas => [ + { label => 'cutback_computation_rate', value => 'Cutbackcomputation_per_second', template => '%.2f', + min => 0 }, + ], + } + }, + { label => 'minimal-computation-rate', set => { + key_values => [ { name => 'Minimalcomputation', diff => 1 } ], + output_template => 'Minimal Computation: %.2f/s', + per_second => 1, + perfdatas => [ + { label => 'minimal_computation_rate', value => 'Minimalcomputation_per_second', template => '%.2f', + min => 0 }, + ], + } + }, + { label => 'recursive-computation-rate', set => { + key_values => [ { name => 'Recursivecomputation', diff => 1 } ], + output_template => 'Recursive Computation: %.2f/s', + per_second => 1, + perfdatas => [ + { label => 'recursive_computation_rate', value => 'Recursivecomputation_per_second', template => '%.2f', + min => 0 }, + ], + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "filter-counters:s" => { name => 'filter_counters', default => '' }, + }); + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); +} + +my $mbean_engine = "com.centreon.studio.map:type=engine,name=statistics"; + +sub manage_selection { + my ($self, %options) = @_; + + $self->{cache_name} = "centreon_map_" . md5_hex($options{custom}->{url}) . '_' . $self->{mode} . '_' . + (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); + + $self->{request} = [ + { mbean => $mbean_engine } + ]; + + my $result = $options{custom}->get_attributes(request => $self->{request}, nothing_quit => 0); + + $self->{global} = {}; + + $self->{global} = { + DrilldownCandidatesQueue => $result->{$mbean_engine}->{DrilldownCandidatesQueue}, + Cutbackcomputation => $result->{$mbean_engine}->{Cutbackcomputation}->{andIncrement}, + Recursivecomputation => $result->{$mbean_engine}->{Recursivecomputation}->{andIncrement}, + Minimalcomputation => $result->{$mbean_engine}->{Minimalcomputation}->{andIncrement}, + }; +} + +1; + +__END__ + +=head1 MODE + +Check computation engine statistics. + +Example: + +perl centreon_plugins.pl --plugin=apps::centreon::map::jmx::plugin --custommode=jolokia +--url=http://10.30.2.22:8080/jolokia-war --mode=engine-stats + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +(Example: --filter-counters='computation') + +=item B<--warning-*> + +Threshold warning. +Can be: ''drilldown-candidates-queue', 'cutback-computation-rate', +'minimal-computation-rate', 'recursive-computation-rate'. + +=item B<--critical-*> + +Threshold critical. +Can be: ''drilldown-candidates-queue', 'cutback-computation-rate', +'minimal-computation-rate', 'recursive-computation-rate'. + +=back + +=cut + diff --git a/apps/centreon/map/jmx/mode/events.pm b/apps/centreon/map/jmx/mode/events.pm new file mode 100644 index 000000000..ea1186d86 --- /dev/null +++ b/apps/centreon/map/jmx/mode/events.pm @@ -0,0 +1,147 @@ +# 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::centreon::map::jmx::mode::events; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use Digest::MD5 qw(md5_hex); + +my @map_counters = ( + 'OPEN_GATE', 'CLOSE_GATE', 'ADD_RESOURCE', 'POLLER_RESTART', 'UPDATE_RESOURCE', + 'SESSION_EXPIRED', 'UPDATE_ACL_CHILDREN', 'SYNC_CHILDREN', 'REMOVE_CHILD', + 'UPDATE_STATUS_RESOURCE', 'REMOVE_RESOURCE', 'UPDATE_STATUS_INHERITED', 'ADD_CHILD', 'REMOVE_SELF', + 'REMOVE_PARENT', 'ADD_PREFERENCE', 'CREATE_GATE', 'ADD_PARENT', 'UPDATE_ACL', 'REMOVE_PREFERENCE', + 'UPDATE_SELF', 'ADD_SELF', 'DESYNC_CHILDREN', 'UPDATE_PREFERENCE', +); + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 }, + ]; + + foreach my $counter (@map_counters) { + my $label_perf = lc($counter); + my $label = lc($counter); + my $output = lc($counter); + $label =~ s/_/-/g; + $output =~ s/_/ /g; + my $entry = { label => $label . '-rate', set => { + key_values => [ { name => $counter, diff => 1 } ], + output_template => ucfirst($output) . ': %.2f/s', + per_second => 1, + perfdatas => [ + { label => $label_perf . '_rate', value => $counter . '_per_second', template => '%.2f', + min => 0, unit => '/s' }, + ], + } + }; + push @{$self->{maps_counters}->{global}}, $entry; + } +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "filter-counters:s" => { name => 'filter_counters', default => '' }, + }); + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); +} + +my $mbean_event = "com.centreon.studio.map:type=event,name=statistics"; + +sub manage_selection { + my ($self, %options) = @_; + + $self->{cache_name} = "centreon_map_" . md5_hex($options{custom}->{url}) . '_' . $self->{mode} . '_' . + (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); + + $self->{request} = [ + { mbean => $mbean_event } + ]; + + my $result = $options{custom}->get_attributes(request => $self->{request}, nothing_quit => 0); + my $event_counters = $1 if ($result->{$mbean_event}->{EventCounter} =~ /\{(.*?)\}/); + + $self->{global} = {}; + + foreach my $counter (split(',', $event_counters)) { + next if ($counter !~ /(\w+)\=(\d+)/); + $self->{global}->{$1} = $2; + } +} + +1; + +__END__ + +=head1 MODE + +Check event types rate. + +Example: + +perl centreon_plugins.pl --plugin=apps::centreon::map::jmx::plugin --custommode=jolokia +--url=http://10.30.2.22:8080/jolokia-war --mode=events + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +(Example: --filter-counters='session') + +=item B<--warning-*> + +Threshold warning. +Can be: 'open-gate-rate', 'close-gate-rate', 'add-resource-rate', 'poller-restart-rate', 'update-resource-rate', +'session-expired-rate', 'update-acl-children-rate', 'sync-children-rate', 'remove-child-rate', +'update-status-resource-rate', 'remove-resource-rate', 'update-status-inherited-rate', 'add-child-rate', +'remove-self-rate',' remove-parent-rate','add-preference-rate', 'create-gate-rate', 'add-parent-rate', +'update-acl-rate', 'remove-preference-rate', 'update-self-rate', 'add-self-rate', 'desync-children-rate', +'update-preference-rate'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'open-gate-rate', 'close-gate-rate', 'add-resource-rate', 'poller-restart-rate', 'update-resource-rate', +'session-expired-rate', 'update-acl-children-rate', 'sync-children-rate', 'remove-child-rate', +'update-status-resource-rate', 'remove-resource-rate', 'update-status-inherited-rate', 'add-child-rate', +'remove-self-rate',' remove-parent-rate','add-preference-rate', 'create-gate-rate', 'add-parent-rate', +'update-acl-rate', 'remove-preference-rate', 'update-self-rate', 'add-self-rate', 'desync-children-rate', +'update-preference-rate'. + +=back + +=cut + diff --git a/apps/centreon/map/jmx/mode/openviews.pm b/apps/centreon/map/jmx/mode/openviews.pm new file mode 100644 index 000000000..f6f0e6459 --- /dev/null +++ b/apps/centreon/map/jmx/mode/openviews.pm @@ -0,0 +1,110 @@ +# 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::centreon::map::jmx::mode::openviews; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 }, + ]; + + $self->{maps_counters}->{global} = [ + { label => 'open-views', set => { + key_values => [ { name => 'OpenContextCount' } ], + output_template => 'Open Views: %d', + perfdatas => [ + { label => 'open_views', value => 'OpenContextCount_absolute', template => '%d', + min => 0, unit => 'views' }, + ], + } + }, + ]; +} + +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 => + { + }); + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +my $mbean_context = "com.centreon.studio.map:type=context,name=statistics"; + +sub manage_selection { + my ($self, %options) = @_; + + $self->{request} = [ + { mbean => $mbean_context } + ]; + + my $result = $options{custom}->get_attributes(request => $self->{request}, nothing_quit => 0); + + $self->{global} = {}; + + $self->{global} = { + OpenContextCount => $result->{$mbean_context}->{OpenContextCount}, + }; +} + +1; + +__END__ + +=head1 MODE + +Check open views count. + +Example: + +perl centreon_plugins.pl --plugin=apps::centreon::map::jmx::plugin --custommode=jolokia +--url=http://10.30.2.22:8080/jolokia-war --mode=open-views + +=over 8 + +=item B<--warning-*> + +Threshold warning. +Can be: 'open-views'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'open-views'. + +=back + +=cut + diff --git a/apps/centreon/map/jmx/mode/sessions.pm b/apps/centreon/map/jmx/mode/sessions.pm index d22a0781e..74fc5eb12 100644 --- a/apps/centreon/map/jmx/mode/sessions.pm +++ b/apps/centreon/map/jmx/mode/sessions.pm @@ -19,66 +19,75 @@ package apps::centreon::map::jmx::mode::sessions; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::counter); use strict; use warnings; +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 }, + ]; + + $self->{maps_counters}->{global} = [ + { label => 'active-session', set => { + key_values => [ { name => 'SessionCount' } ], + output_template => 'Active Sessions: %d', + perfdatas => [ + { label => 'active_sessions', value => 'SessionCount_absolute', template => '%d', + min => 0, unit => 'sessions' }, + ], + } + }, + { label => 'queue-size', set => { + key_values => [ { name => 'AverageEventQueueSize' } ], + output_template => 'Average Event Queue Size: %d', + perfdatas => [ + { label => 'queue_size', value => 'AverageEventQueueSize_absolute', template => '%d', + min => 0 }, + ], + } + }, + ]; +} + 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', }, + { + "filter-counters:s" => { name => 'filter_counters', default => '' }, }); - 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 $mbean_session = "com.centreon.studio.map:type=session,name=statistics"; + +sub manage_selection { my ($self, %options) = @_; - $self->{connector} = $options{custom}; $self->{request} = [ - { mbean => "com.centreon.studio:name=statistics,type=session" } + { mbean => $mbean_session } ]; - my $result = $self->{connector}->get_attributes(request => $self->{request}, nothing_quit => 0); - - my $exit = $self->{perfdata}->threshold_check(value => $result->{"com.centreon.studio:name=statistics,type=session"}->{SessionCount}, - threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning'} ]); + my $result = $options{custom}->get_attributes(request => $self->{request}, nothing_quit => 0); - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Current sessions : %d", - $result->{"com.centreon.studio:name=statistics,type=session"}->{SessionCount})); - - $self->{output}->perfdata_add(label => 'sessions', - value => $result->{"com.centreon.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(); + $self->{global} = {}; + $self->{global} = { + SessionCount => $result->{$mbean_session}->{SessionCount}, + AverageEventQueueSize => $result->{$mbean_session}->{AverageEventQueueSize}, + }; } 1; @@ -87,21 +96,29 @@ __END__ =head1 MODE -Check Centreon Map Number of sessions +Check active sessions count and the number of whatsup events by user session (queue size). Example: -perl centreon_plugins.pl --plugin=apps::centreon::map::jmx::plugin --custommode=jolokia --url=http://10.30.2.22:8080/jolokia-war --mode=sessions +perl centreon_plugins.pl --plugin=apps::centreon::map::jmx::plugin --custommode=jolokia +--url=http://10.30.2.22:8080/jolokia-war --mode=sessions =over 8 -=item B<--warning> +=item B<--filter-counters> -Set this threshold if you want a warning if current session number match condition +Only display some counters (regexp can be used). +(Example: --filter-counters='session') -=item B<--critical> +=item B<--warning-*> -Set this threshold if you want a warning if current session number match condition +Threshold warning. +Can be: 'active-session', 'queue-size'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'active-session', 'queue-size'. =back diff --git a/apps/centreon/map/jmx/plugin.pm b/apps/centreon/map/jmx/plugin.pm index 19e42bf1d..c4fbbafb8 100644 --- a/apps/centreon/map/jmx/plugin.pm +++ b/apps/centreon/map/jmx/plugin.pm @@ -30,11 +30,11 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'gates' => 'apps::centreon::map::jmx::mode::gates', - 'elements' => 'apps::centreon::map::jmx::mode::elements', - 'sessions' => 'apps::centreon::map::jmx::mode::sessions', - 'event-queue' => 'apps::centreon::map::jmx::mode::eventqueue', - 'event-statistics' => 'apps::centreon::map::jmx::mode::eventstatistics', + 'broker-stats' => 'apps::centreon::map::jmx::mode::brokerstats', + 'events' => 'apps::centreon::map::jmx::mode::events', + 'engine-stats' => 'apps::centreon::map::jmx::mode::enginestats', + 'open-views' => 'apps::centreon::map::jmx::mode::openviews', + 'sessions' => 'apps::centreon::map::jmx::mode::sessions', ); $self->{custom_modes}{jolokia} = 'centreon::common::protocols::jmx::custom::jolokia'; @@ -47,6 +47,6 @@ __END__ =head1 PLUGIN DESCRIPTION -Check Centreon Map informations. Need Jolokia agent and Map >= 4.0. +Check statistic counters of Centreon Map >= 18.10 (Needs Jolokia). =cut diff --git a/apps/centreon/map/jmx/mode/elements.pm b/apps/centreon/map4/jmx/mode/elements.pm similarity index 97% rename from apps/centreon/map/jmx/mode/elements.pm rename to apps/centreon/map4/jmx/mode/elements.pm index d9a6d9f26..ef5adc299 100644 --- a/apps/centreon/map/jmx/mode/elements.pm +++ b/apps/centreon/map4/jmx/mode/elements.pm @@ -1,4 +1,4 @@ -# Copyright 2015 Centreon (http://www.centreon.com/) +# 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 @@ -17,7 +17,7 @@ # limitations under the License. # -package apps::centreon::map::jmx::mode::elements; +package apps::centreon::map4::jmx::mode::elements; use base qw(centreon::plugins::mode); diff --git a/apps/centreon/map/jmx/mode/eventqueue.pm b/apps/centreon/map4/jmx/mode/eventqueue.pm similarity index 98% rename from apps/centreon/map/jmx/mode/eventqueue.pm rename to apps/centreon/map4/jmx/mode/eventqueue.pm index fc092774d..81d92264a 100644 --- a/apps/centreon/map/jmx/mode/eventqueue.pm +++ b/apps/centreon/map4/jmx/mode/eventqueue.pm @@ -17,7 +17,7 @@ # limitations under the License. # -package apps::centreon::map::jmx::mode::eventqueue; +package apps::centreon::map4::jmx::mode::eventqueue; use base qw(centreon::plugins::mode); diff --git a/apps/centreon/map/jmx/mode/eventstatistics.pm b/apps/centreon/map4/jmx/mode/eventstatistics.pm similarity index 99% rename from apps/centreon/map/jmx/mode/eventstatistics.pm rename to apps/centreon/map4/jmx/mode/eventstatistics.pm index 55b41c2c1..2909b7cca 100644 --- a/apps/centreon/map/jmx/mode/eventstatistics.pm +++ b/apps/centreon/map4/jmx/mode/eventstatistics.pm @@ -17,7 +17,7 @@ # limitations under the License. # -package apps::centreon::map::jmx::mode::eventstatistics; +package apps::centreon::map4::jmx::mode::eventstatistics; use base qw(centreon::plugins::mode); diff --git a/apps/centreon/map/jmx/mode/gates.pm b/apps/centreon/map4/jmx/mode/gates.pm similarity index 98% rename from apps/centreon/map/jmx/mode/gates.pm rename to apps/centreon/map4/jmx/mode/gates.pm index c8c0504c7..74392ed0e 100644 --- a/apps/centreon/map/jmx/mode/gates.pm +++ b/apps/centreon/map4/jmx/mode/gates.pm @@ -17,7 +17,7 @@ # limitations under the License. # -package apps::centreon::map::jmx::mode::gates; +package apps::centreon::map4::jmx::mode::gates; use base qw(centreon::plugins::mode); diff --git a/apps/centreon/map4/jmx/mode/sessions.pm b/apps/centreon/map4/jmx/mode/sessions.pm new file mode 100644 index 000000000..c0321efc0 --- /dev/null +++ b/apps/centreon/map4/jmx/mode/sessions.pm @@ -0,0 +1,109 @@ +# 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::centreon::map4::jmx::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) = @_; + $self->{connector} = $options{custom}; + + $self->{request} = [ + { mbean => "com.centreon.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.centreon.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.centreon.studio:name=statistics,type=session"}->{SessionCount})); + + $self->{output}->perfdata_add(label => 'sessions', + value => $result->{"com.centreon.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::centreon::map::jmx::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 + diff --git a/apps/centreon/map4/jmx/plugin.pm b/apps/centreon/map4/jmx/plugin.pm new file mode 100644 index 000000000..b1609ad02 --- /dev/null +++ b/apps/centreon/map4/jmx/plugin.pm @@ -0,0 +1,52 @@ +# 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::centreon::map4::jmx::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; + + $self->{version} = '0.1'; + %{$self->{modes}} = ( + 'gates' => 'apps::centreon::map4::jmx::mode::gates', + 'elements' => 'apps::centreon::map4::jmx::mode::elements', + 'sessions' => 'apps::centreon::map4::jmx::mode::sessions', + 'event-queue' => 'apps::centreon::map4::jmx::mode::eventqueue', + 'event-statistics' => 'apps::centreon::map4::jmx::mode::eventstatistics', + ); + + $self->{custom_modes}{jolokia} = 'centreon::common::protocols::jmx::custom::jolokia'; + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Centreon Map 4 informations. Need Jolokia agent and Map >= 4.0. + +=cut