From b47977ced88ee6a074a5041a4b454f5ee7190ce1 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 3 Jul 2020 15:58:24 +0200 Subject: [PATCH] remove useless code --- apps/mulesoft/restapi/custom/api.pm | 20 +++++------ apps/mulesoft/restapi/mode/applications.pm | 11 +++--- apps/mulesoft/restapi/mode/clusters.pm | 42 +++++++++------------- apps/mulesoft/restapi/mode/messages.pm | 35 +++++++++--------- apps/mulesoft/restapi/mode/servers.pm | 12 +++---- apps/mulesoft/restapi/plugin.pm | 12 +++---- 6 files changed, 59 insertions(+), 73 deletions(-) diff --git a/apps/mulesoft/restapi/custom/api.pm b/apps/mulesoft/restapi/custom/api.pm index 021f0f60f..562b68257 100644 --- a/apps/mulesoft/restapi/custom/api.pm +++ b/apps/mulesoft/restapi/custom/api.pm @@ -93,14 +93,14 @@ sub check_options { $self->{reload_cache_time} = (defined($self->{option_results}->{reload_cache_time})) ? $self->{option_results}->{reload_cache_time} : 180; $self->{cache}->check_options(option_results => $self->{option_results}); - if (!defined($self->{environment_id}) || $self->{environment_id} eq '' || !defined($self->{organization_id}) || $self->{organization_id} eq '' ) { - $self->{output}->add_option_msg(short_msg => "--environment-id and --organization-id must be set"); - $self->{output}->option_exit(); - } - if (!defined($self->{api_username}) || $self->{api_username} eq '' || !defined($self->{api_password}) || $self->{api_password} eq '' ) { - $self->{output}->add_option_msg(short_msg => "--api-username and --api-password must be set"); - $self->{output}->option_exit(); - } + if ($self->{environment_id} eq '' || $self->{organization_id} eq '' ) { + $self->{output}->add_option_msg(short_msg => "--environment-id and --organization-id must be set"); + $self->{output}->option_exit(); + } + if ($self->{api_username} eq '' || $self->{api_password} eq '' ) { + $self->{output}->add_option_msg(short_msg => "--api-username and --api-password must be set"); + $self->{output}->option_exit(); + } return 0; } @@ -185,9 +185,6 @@ sub request_api { $self->settings(content_type => 'application/x-www-form-urlencoded', environment_header => 1, organization_header => 1); - $self->{output}->output_add(long_msg => "URL: '" . $self->{proto} . '://' . $self->{hostname} . ':' . $self->{port} . - $options{url_path} . "'", debug => 1); - my $content = $self->{http}->request(%options); if (!defined($content) || $content eq '') { @@ -201,7 +198,6 @@ sub request_api { }; if ($@) { - $self->{output}->output_add(long_msg => $content, debug => 1); $self->{output}->add_option_msg(short_msg => "Cannot decode response (add --debug option to display returned content)"); $self->{output}->option_exit(); } diff --git a/apps/mulesoft/restapi/mode/applications.pm b/apps/mulesoft/restapi/mode/applications.pm index 2ab8f3a00..ab10e6dc1 100644 --- a/apps/mulesoft/restapi/mode/applications.pm +++ b/apps/mulesoft/restapi/mode/applications.pm @@ -24,7 +24,7 @@ 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::templates::catalog_functions qw(catalog_status_threshold); sub custom_status_output { my ($self, %options) = @_; @@ -44,25 +44,25 @@ sub set_counters { { label => 'total', nlabel => 'mulesoft.applications.total.count', set => { key_values => [ { name => 'total' } ], output_template => "Total : %s", - perfdatas => [ { value => 'total', template => '%d', min => 0 } ] + perfdatas => [ { template => '%d', min => 0 } ] } }, { label => 'started', nlabel => 'mulesoft.applications.status.started.count', set => { key_values => [ { name => 'started' } ], output_template => "Started : %s", - perfdatas => [ { value => 'started', template => '%d', min => 0 } ] + perfdatas => [ { template => '%d', min => 0 } ] } }, { label => 'stopped', nlabel => 'mulesoft.applications.status.stopped.count', set => { key_values => [ { name => 'stopped' } ], output_template => "Stopped : %s", - perfdatas => [ { value => 'stopped', template => '%d', min => 0 } ] + perfdatas => [ { template => '%d', min => 0 } ] } }, { label => 'failed', nlabel => 'mulesoft.applications.status.failed.count', set => { key_values => [ { name => 'failed' } ], output_template => "Failed : %s", - perfdatas => [ { value => 'failed', template => '%d', min => 0 } ] + perfdatas => [ { template => '%d', min => 0 } ] } } ]; @@ -70,7 +70,6 @@ sub set_counters { $self->{maps_counters}->{applications} = [ { label => 'status', threshold => 0, set => { key_values => [ { name => 'id' }, { name => 'status' }, { name => 'name'}, { 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 diff --git a/apps/mulesoft/restapi/mode/clusters.pm b/apps/mulesoft/restapi/mode/clusters.pm index f2e9d2a38..81ac7d14c 100644 --- a/apps/mulesoft/restapi/mode/clusters.pm +++ b/apps/mulesoft/restapi/mode/clusters.pm @@ -31,13 +31,6 @@ sub custom_status_output { return my $msg = sprintf('Id: %s, Status: %s', $self->{result_values}->{id}, $self->{result_values}->{status}); } -sub custom_status_calc { - my ($self, %options) = @_; - $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'}; - $self->{result_values}->{id} = $options{new_datas}->{$self->{instance} . '_id'}; - return 0; -} - sub set_counters { my ($self, %options) = @_; @@ -48,34 +41,33 @@ sub set_counters { $self->{maps_counters}->{global} = [ { label => 'total', nlabel => 'mulesoft.clusters.total.count', set => { - key_values => [ { name => 'total' } ], - output_template => "Total : %s", - perfdatas => [ { value => 'total', template => '%d', min => 0 } ], + key_values => [ { name => 'total' } ], + output_template => "Total : %s", + perfdatas => [ { template => '%d', min => 0 } ] } }, { label => 'running', nlabel => 'mulesoft.clusters.status.running.count', set => { - key_values => [ { name => 'running' } ], - output_template => "Running : %s", - perfdatas => [ { value => 'running', template => '%d', min => 0 } ] + key_values => [ { name => 'running' } ], + output_template => "Running : %s", + perfdatas => [ { template => '%d', min => 0 } ] } }, { label => 'disconnected', nlabel => 'mulesoft.clusters.status.disconnected.count', set => { - key_values => [ { name => 'disconnected' } ], - output_template => "Disconnected : %s", - perfdatas => [ { value => 'disconnected', template => '%d', min => 0 } ] + key_values => [ { name => 'disconnected' } ], + output_template => "Disconnected : %s", + perfdatas => [ { template => '%d', min => 0 } ] } } ]; $self->{maps_counters}->{clusters} = [ { label => 'status', threshold => 0, set => { - key_values => [ { name => 'id' }, { name => 'status' }, { name => 'name'}, { name => 'display' } ], - 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, + key_values => [ { name => 'id' }, { name => 'status' }, { name => 'name'}, { name => 'display' } ], + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold } - }, + } ]; } @@ -85,9 +77,9 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - "filter-name:s" => { name => 'filter_name' }, - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '' }, + 'filter-name:s' => { name => 'filter_name' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '' } }); return $self; diff --git a/apps/mulesoft/restapi/mode/messages.pm b/apps/mulesoft/restapi/mode/messages.pm index ad0ea09ae..afad062f4 100644 --- a/apps/mulesoft/restapi/mode/messages.pm +++ b/apps/mulesoft/restapi/mode/messages.pm @@ -45,40 +45,40 @@ sub set_counters { $self->{maps_counters}->{queues} = [ { label => 'total', nlabel => 'mulesoft.mq.messages.total.count', set => { key_values => [ { name => 'total' }, { name => 'display' } ], - output_template => "Total : %s", - perfdatas => [ { value => 'total', template => '%d', min => 0, cast_int => 1, label_extra_instance => 1, instance_use => 'display' } ] + output_template => 'Total : %s', + perfdatas => [ { template => '%d', min => 0, cast_int => 1, label_extra_instance => 1, instance_use => 'display' } ] } }, { label => 'inflight', nlabel => 'mulesoft.mq.inflight.count', set => { key_values => [ { name => 'inflight' }, { name => 'display' } ], - output_template => "inflight : %s", - perfdatas => [ { value => 'inflight', template => '%d', min => 0, cast_int => 1, label_extra_instance => 1, instance_use => 'display' } ] + output_template => 'inflight : %s', + perfdatas => [ { template => '%d', min => 0, cast_int => 1, label_extra_instance => 1, instance_use => 'display' } ] } }, { label => 'received', nlabel => 'mulesoft.mq.received.count', set => { key_values => [ { name => 'received' }, { name => 'display' } ], - output_template => "received : %s", - perfdatas => [ { value => 'received', template => '%d', min => 0, cast_int => 1, label_extra_instance => 1, instance_use => 'display' } ] + output_template => 'received : %s', + perfdatas => [ { template => '%d', min => 0, cast_int => 1, label_extra_instance => 1, instance_use => 'display' } ] } }, { label => 'sent', nlabel => 'mulesoft.mq.sent.count', set => { key_values => [ { name => 'sent' }, { name => 'display' } ], - output_template => "sent : %s", - perfdatas => [ { value => 'sent', template => '%d', min => 0, cast_int => 1, label_extra_instance => 1, instance_use => 'display' } ] + output_template => 'sent : %s', + perfdatas => [ { template => '%d', min => 0, cast_int => 1, label_extra_instance => 1, instance_use => 'display' } ] } }, { label => 'visible', nlabel => 'mulesoft.mq.visible.count', set => { key_values => [ { name => 'visible' }, { name => 'display' } ], - output_template => "visible : %s", - perfdatas => [ { value => 'visible', template => '%d', min => 0, cast_int => 1, label_extra_instance => 1, instance_use => 'display' } ] + output_template => 'visible : %s', + perfdatas => [ { template => '%d', min => 0, cast_int => 1, label_extra_instance => 1, instance_use => 'display' } ] } }, { label => 'acked', nlabel => 'mulesoft.mq.acked.count', set => { key_values => [ { name => 'acked' }, { name => 'display' } ], - output_template => "acked : %s", - perfdatas => [ { value => 'acked', template => '%d', min => 0, cast_int => 1, label_extra_instance => 1, instance_use => 'display' } ] + output_template => 'acked : %s', + perfdatas => [ { template => '%d', min => 0, cast_int => 1, label_extra_instance => 1, instance_use => 'display' } ] } - }, + } ]; } @@ -88,10 +88,10 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - 'filter-name:s' => { name => 'filter_name' }, - 'region-id:s' => { name => 'region_id' }, - 'timeframe:s' => { name => 'timeframe', default => '600' }, - 'period:s' => { name => 'period', default => '60' } + 'filter-name:s' => { name => 'filter_name' }, + 'region-id:s' => { name => 'region_id' }, + 'timeframe:s' => { name => 'timeframe', default => '600' }, + 'period:s' => { name => 'period', default => '60' } }); return $self; @@ -107,7 +107,6 @@ sub check_options { } } - sub manage_selection { my ($self, %options) = @_; diff --git a/apps/mulesoft/restapi/mode/servers.pm b/apps/mulesoft/restapi/mode/servers.pm index d84585f5f..dbd595e86 100644 --- a/apps/mulesoft/restapi/mode/servers.pm +++ b/apps/mulesoft/restapi/mode/servers.pm @@ -24,10 +24,11 @@ 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::templates::catalog_functions qw(catalog_status_threshold); sub custom_status_output { my ($self, %options) = @_; + return sprintf('Id: %s, Status: %s', $self->{result_values}->{id}, $self->{result_values}->{status}); } @@ -43,19 +44,19 @@ sub set_counters { { label => 'total', nlabel => 'mulesoft.servers.total.count', set => { key_values => [ { name => 'total' } ], output_template => '%s', - perfdatas => [ { value => 'total', template => '%d', min => 0 } ] + perfdatas => [ { template => '%d', min => 0 } ] } }, { label => 'running', nlabel => 'mulesoft.servers.status.running.count', set => { key_values => [ { name => 'running' } ], output_template => 'running : %s', - perfdatas => [ { value => 'running', template => '%d', min => 0 } ] + perfdatas => [ { template => '%d', min => 0 } ] } }, { label => 'disconnected', nlabel => 'mulesoft.servers.status.disconnected.count', set => { key_values => [ { name => 'disconnected' } ], output_template => 'disconnected : %s', - perfdatas => [ { value => 'disconnected', template => '%d', min => 0 } ] + perfdatas => [ { template => '%d', min => 0 } ] } } ]; @@ -63,7 +64,6 @@ sub set_counters { $self->{maps_counters}->{servers} = [ { label => 'status', threshold => 0, set => { key_values => [ { name => 'id' }, { name => 'status' }, { name => 'name'}, { 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 @@ -96,7 +96,7 @@ sub check_options { sub prefix_global_output { my ($self, %options) = @_; - return "Total servers :"; + return 'Total servers :'; } sub prefix_server_output { diff --git a/apps/mulesoft/restapi/plugin.pm b/apps/mulesoft/restapi/plugin.pm index e397a9e51..447c3df18 100644 --- a/apps/mulesoft/restapi/plugin.pm +++ b/apps/mulesoft/restapi/plugin.pm @@ -30,17 +30,17 @@ sub new { bless $self, $class; $self->{version} = '1.0'; - %{$self->{modes}} = ( + $self->{modes} = { 'applications' => 'apps::mulesoft::restapi::mode::applications', 'clusters' => 'apps::mulesoft::restapi::mode::clusters', - 'messages' => 'apps::mulesoft::restapi::mode::messages', - 'servers' => 'apps::mulesoft::restapi::mode::servers', 'list-applications' => 'apps::mulesoft::restapi::mode::listapplications', 'list-queues' => 'apps::mulesoft::restapi::mode::listqueues', - 'list-servers' => 'apps::mulesoft::restapi::mode::listservers' - ); + 'list-servers' => 'apps::mulesoft::restapi::mode::listservers', + 'messages' => 'apps::mulesoft::restapi::mode::messages', + 'servers' => 'apps::mulesoft::restapi::mode::servers' + }; - $self->{custom_modes}{restapi} = 'apps::mulesoft::restapi::custom::api'; + $self->{custom_modes}->{restapi} = 'apps::mulesoft::restapi::custom::api'; return $self; }