remove useless code

This commit is contained in:
garnier-quentin 2020-07-03 15:58:24 +02:00
parent 1566299925
commit 00d27331c3
6 changed files with 59 additions and 73 deletions

View File

@ -93,11 +93,11 @@ sub check_options {
$self->{reload_cache_time} = (defined($self->{option_results}->{reload_cache_time})) ? $self->{option_results}->{reload_cache_time} : 180; $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}); $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 '' ) { 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}->add_option_msg(short_msg => "--environment-id and --organization-id must be set");
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
if (!defined($self->{api_username}) || $self->{api_username} eq '' || !defined($self->{api_password}) || $self->{api_password} eq '' ) { 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}->add_option_msg(short_msg => "--api-username and --api-password must be set");
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
@ -185,9 +185,6 @@ sub request_api {
$self->settings(content_type => 'application/x-www-form-urlencoded', environment_header => 1, organization_header => 1); $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); my $content = $self->{http}->request(%options);
if (!defined($content) || $content eq '') { if (!defined($content) || $content eq '') {
@ -201,7 +198,6 @@ sub request_api {
}; };
if ($@) { 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}->add_option_msg(short_msg => "Cannot decode response (add --debug option to display returned content)");
$self->{output}->option_exit(); $self->{output}->option_exit();
} }

View File

@ -24,7 +24,7 @@ use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; 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 { sub custom_status_output {
my ($self, %options) = @_; my ($self, %options) = @_;
@ -44,25 +44,25 @@ sub set_counters {
{ label => 'total', nlabel => 'mulesoft.applications.total.count', set => { { label => 'total', nlabel => 'mulesoft.applications.total.count', set => {
key_values => [ { name => 'total' } ], key_values => [ { name => 'total' } ],
output_template => "Total : %s", 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 => { { label => 'started', nlabel => 'mulesoft.applications.status.started.count', set => {
key_values => [ { name => 'started' } ], key_values => [ { name => 'started' } ],
output_template => "Started : %s", 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 => { { label => 'stopped', nlabel => 'mulesoft.applications.status.stopped.count', set => {
key_values => [ { name => 'stopped' } ], key_values => [ { name => 'stopped' } ],
output_template => "Stopped : %s", 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 => { { label => 'failed', nlabel => 'mulesoft.applications.status.failed.count', set => {
key_values => [ { name => 'failed' } ], key_values => [ { name => 'failed' } ],
output_template => "Failed : %s", 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} = [ $self->{maps_counters}->{applications} = [
{ label => 'status', threshold => 0, set => { { label => 'status', threshold => 0, set => {
key_values => [ { name => 'id' }, { name => 'status' }, { name => 'name'}, { name => 'display' } ], 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_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; }, closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold closure_custom_threshold_check => \&catalog_status_threshold

View File

@ -31,13 +31,6 @@ sub custom_status_output {
return my $msg = sprintf('Id: %s, Status: %s', $self->{result_values}->{id}, $self->{result_values}->{status}); 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 { sub set_counters {
my ($self, %options) = @_; my ($self, %options) = @_;
@ -50,19 +43,19 @@ sub set_counters {
{ label => 'total', nlabel => 'mulesoft.clusters.total.count', set => { { label => 'total', nlabel => 'mulesoft.clusters.total.count', set => {
key_values => [ { name => 'total' } ], key_values => [ { name => 'total' } ],
output_template => "Total : %s", output_template => "Total : %s",
perfdatas => [ { value => 'total', template => '%d', min => 0 } ], perfdatas => [ { template => '%d', min => 0 } ]
} }
}, },
{ label => 'running', nlabel => 'mulesoft.clusters.status.running.count', set => { { label => 'running', nlabel => 'mulesoft.clusters.status.running.count', set => {
key_values => [ { name => 'running' } ], key_values => [ { name => 'running' } ],
output_template => "Running : %s", output_template => "Running : %s",
perfdatas => [ { value => 'running', template => '%d', min => 0 } ] perfdatas => [ { template => '%d', min => 0 } ]
} }
}, },
{ label => 'disconnected', nlabel => 'mulesoft.clusters.status.disconnected.count', set => { { label => 'disconnected', nlabel => 'mulesoft.clusters.status.disconnected.count', set => {
key_values => [ { name => 'disconnected' } ], key_values => [ { name => 'disconnected' } ],
output_template => "Disconnected : %s", output_template => "Disconnected : %s",
perfdatas => [ { value => 'disconnected', template => '%d', min => 0 } ] perfdatas => [ { template => '%d', min => 0 } ]
} }
} }
]; ];
@ -70,12 +63,11 @@ sub set_counters {
$self->{maps_counters}->{clusters} = [ $self->{maps_counters}->{clusters} = [
{ label => 'status', threshold => 0, set => { { label => 'status', threshold => 0, set => {
key_values => [ { name => 'id' }, { name => 'status' }, { name => 'name'}, { name => 'display' } ], 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_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; }, closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold, closure_custom_threshold_check => \&catalog_status_threshold
}
} }
},
]; ];
} }
@ -85,9 +77,9 @@ sub new {
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
"filter-name:s" => { name => 'filter_name' }, 'filter-name:s' => { name => 'filter_name' },
"warning-status:s" => { name => 'warning_status', default => '' }, 'warning-status:s' => { name => 'warning_status', default => '' },
"critical-status:s" => { name => 'critical_status', default => '' }, 'critical-status:s' => { name => 'critical_status', default => '' }
}); });
return $self; return $self;

View File

@ -45,40 +45,40 @@ sub set_counters {
$self->{maps_counters}->{queues} = [ $self->{maps_counters}->{queues} = [
{ label => 'total', nlabel => 'mulesoft.mq.messages.total.count', set => { { label => 'total', nlabel => 'mulesoft.mq.messages.total.count', set => {
key_values => [ { name => 'total' }, { name => 'display' } ], key_values => [ { name => 'total' }, { name => 'display' } ],
output_template => "Total : %s", output_template => 'Total : %s',
perfdatas => [ { value => 'total', template => '%d', min => 0, cast_int => 1, label_extra_instance => 1, instance_use => 'display' } ] perfdatas => [ { template => '%d', min => 0, cast_int => 1, label_extra_instance => 1, instance_use => 'display' } ]
} }
}, },
{ label => 'inflight', nlabel => 'mulesoft.mq.inflight.count', set => { { label => 'inflight', nlabel => 'mulesoft.mq.inflight.count', set => {
key_values => [ { name => 'inflight' }, { name => 'display' } ], key_values => [ { name => 'inflight' }, { name => 'display' } ],
output_template => "inflight : %s", output_template => 'inflight : %s',
perfdatas => [ { value => 'inflight', template => '%d', min => 0, cast_int => 1, label_extra_instance => 1, instance_use => 'display' } ] perfdatas => [ { template => '%d', min => 0, cast_int => 1, label_extra_instance => 1, instance_use => 'display' } ]
} }
}, },
{ label => 'received', nlabel => 'mulesoft.mq.received.count', set => { { label => 'received', nlabel => 'mulesoft.mq.received.count', set => {
key_values => [ { name => 'received' }, { name => 'display' } ], key_values => [ { name => 'received' }, { name => 'display' } ],
output_template => "received : %s", output_template => 'received : %s',
perfdatas => [ { value => 'received', template => '%d', min => 0, cast_int => 1, label_extra_instance => 1, instance_use => 'display' } ] perfdatas => [ { template => '%d', min => 0, cast_int => 1, label_extra_instance => 1, instance_use => 'display' } ]
} }
}, },
{ label => 'sent', nlabel => 'mulesoft.mq.sent.count', set => { { label => 'sent', nlabel => 'mulesoft.mq.sent.count', set => {
key_values => [ { name => 'sent' }, { name => 'display' } ], key_values => [ { name => 'sent' }, { name => 'display' } ],
output_template => "sent : %s", output_template => 'sent : %s',
perfdatas => [ { value => 'sent', template => '%d', min => 0, cast_int => 1, label_extra_instance => 1, instance_use => 'display' } ] perfdatas => [ { template => '%d', min => 0, cast_int => 1, label_extra_instance => 1, instance_use => 'display' } ]
} }
}, },
{ label => 'visible', nlabel => 'mulesoft.mq.visible.count', set => { { label => 'visible', nlabel => 'mulesoft.mq.visible.count', set => {
key_values => [ { name => 'visible' }, { name => 'display' } ], key_values => [ { name => 'visible' }, { name => 'display' } ],
output_template => "visible : %s", output_template => 'visible : %s',
perfdatas => [ { value => 'visible', template => '%d', min => 0, cast_int => 1, label_extra_instance => 1, instance_use => 'display' } ] perfdatas => [ { template => '%d', min => 0, cast_int => 1, label_extra_instance => 1, instance_use => 'display' } ]
} }
}, },
{ label => 'acked', nlabel => 'mulesoft.mq.acked.count', set => { { label => 'acked', nlabel => 'mulesoft.mq.acked.count', set => {
key_values => [ { name => 'acked' }, { name => 'display' } ], key_values => [ { name => 'acked' }, { name => 'display' } ],
output_template => "acked : %s", output_template => 'acked : %s',
perfdatas => [ { value => 'acked', template => '%d', min => 0, cast_int => 1, label_extra_instance => 1, instance_use => 'display' } ] perfdatas => [ { template => '%d', min => 0, cast_int => 1, label_extra_instance => 1, instance_use => 'display' } ]
}
} }
},
]; ];
} }
@ -107,7 +107,6 @@ sub check_options {
} }
} }
sub manage_selection { sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;

View File

@ -24,10 +24,11 @@ use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; 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 { sub custom_status_output {
my ($self, %options) = @_; my ($self, %options) = @_;
return sprintf('Id: %s, Status: %s', $self->{result_values}->{id}, $self->{result_values}->{status}); 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 => { { label => 'total', nlabel => 'mulesoft.servers.total.count', set => {
key_values => [ { name => 'total' } ], key_values => [ { name => 'total' } ],
output_template => '%s', output_template => '%s',
perfdatas => [ { value => 'total', template => '%d', min => 0 } ] perfdatas => [ { template => '%d', min => 0 } ]
} }
}, },
{ label => 'running', nlabel => 'mulesoft.servers.status.running.count', set => { { label => 'running', nlabel => 'mulesoft.servers.status.running.count', set => {
key_values => [ { name => 'running' } ], key_values => [ { name => 'running' } ],
output_template => 'running : %s', 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 => { { label => 'disconnected', nlabel => 'mulesoft.servers.status.disconnected.count', set => {
key_values => [ { name => 'disconnected' } ], key_values => [ { name => 'disconnected' } ],
output_template => 'disconnected : %s', 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} = [ $self->{maps_counters}->{servers} = [
{ label => 'status', threshold => 0, set => { { label => 'status', threshold => 0, set => {
key_values => [ { name => 'id' }, { name => 'status' }, { name => 'name'}, { name => 'display' } ], 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_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; }, closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold closure_custom_threshold_check => \&catalog_status_threshold
@ -96,7 +96,7 @@ sub check_options {
sub prefix_global_output { sub prefix_global_output {
my ($self, %options) = @_; my ($self, %options) = @_;
return "Total servers :"; return 'Total servers :';
} }
sub prefix_server_output { sub prefix_server_output {

View File

@ -30,17 +30,17 @@ sub new {
bless $self, $class; bless $self, $class;
$self->{version} = '1.0'; $self->{version} = '1.0';
%{$self->{modes}} = ( $self->{modes} = {
'applications' => 'apps::mulesoft::restapi::mode::applications', 'applications' => 'apps::mulesoft::restapi::mode::applications',
'clusters' => 'apps::mulesoft::restapi::mode::clusters', '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-applications' => 'apps::mulesoft::restapi::mode::listapplications',
'list-queues' => 'apps::mulesoft::restapi::mode::listqueues', '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; return $self;
} }