diff --git a/apps/mulesoft/restapi/mode/applications.pm b/apps/mulesoft/restapi/mode/applications.pm index 82cdfe4ac..e12a8d173 100644 --- a/apps/mulesoft/restapi/mode/applications.pm +++ b/apps/mulesoft/restapi/mode/applications.pm @@ -24,18 +24,12 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); sub custom_status_output { my ($self, %options) = @_; - 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; + return sprintf('Id: %s, Status: %s', $self->{result_values}->{id}, $self->{result_values}->{status}); } sub set_counters { @@ -48,40 +42,40 @@ sub set_counters { $self->{maps_counters}->{global} = [ { label => 'total', nlabel => 'mulesoft.applications.total.count', set => { - key_values => [ { name => 'total' } ], - output_template => "Total : %s", - perfdatas => [ { value => 'total_absolute', template => '%d', min => 0 } ], + key_values => [ { name => 'total' } ], + output_template => "Total : %s", + perfdatas => [ { value => 'total_absolute', template => '%d', min => 0 } ] } }, { label => 'started', nlabel => 'mulesoft.applications.status.started.count', set => { - key_values => [ { name => 'started' } ], - output_template => "Started : %s", - perfdatas => [ { value => 'started_absolute', template => '%d', min => 0 } ] + key_values => [ { name => 'started' } ], + output_template => "Started : %s", + perfdatas => [ { value => 'started_absolute', template => '%d', min => 0 } ] } }, { label => 'stopped', nlabel => 'mulesoft.applications.status.stopped.count', set => { - key_values => [ { name => 'stopped' } ], - output_template => "Stopped : %s", - perfdatas => [ { value => 'stopped_absolute', template => '%d', min => 0 } ] + key_values => [ { name => 'stopped' } ], + output_template => "Stopped : %s", + perfdatas => [ { value => 'stopped_absolute', template => '%d', min => 0 } ] } }, { label => 'failed', nlabel => 'mulesoft.applications.status.failed.count', set => { - key_values => [ { name => 'failed' } ], - output_template => "Failed : %s", - perfdatas => [ { value => 'failed_absolute', template => '%d', min => 0 } ] + key_values => [ { name => 'failed' } ], + output_template => "Failed : %s", + perfdatas => [ { value => 'failed_absolute', template => '%d', min => 0 } ] } } ]; $self->{maps_counters}->{applications} = [ { 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_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 } - }, + } ]; } @@ -91,9 +85,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; @@ -183,7 +177,6 @@ Set warning threshold for status (Default: ''). Threshold can be matched on %{name}, %{id} or %{status} and Regexp can be used. Typical syntax: --critical-status='%{status} ~= m/FAILED/' - =back =cut diff --git a/apps/mulesoft/restapi/mode/listapplications.pm b/apps/mulesoft/restapi/mode/listapplications.pm index 2b7641bec..1d24344fa 100644 --- a/apps/mulesoft/restapi/mode/listapplications.pm +++ b/apps/mulesoft/restapi/mode/listapplications.pm @@ -31,7 +31,7 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - "filter-name:s" => { name => 'filter_name' }, + 'filter-name:s' => { name => 'filter_name' }, }); return $self; @@ -56,10 +56,14 @@ sub run { next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && $application->{name} !~ /$self->{option_results}->{filter_name}/); - $self->{output}->output_add(long_msg => sprintf("[id = %s][name = %s][status = %s]", - $application->{id}, - $application->{name}, - $application->{lastReportedStatus})); + $self->{output}->output_add( + long_msg => sprintf( + "[id = %s][name = %s][status = %s]", + $application->{id}, + $application->{name}, + $application->{lastReportedStatus} + ) + ); } $self->{output}->output_add(severity => 'OK', short_msg => 'Mulesoft Anypoint Applications:'); diff --git a/apps/mulesoft/restapi/mode/listservers.pm b/apps/mulesoft/restapi/mode/listservers.pm index e774d5b2d..664bfd697 100644 --- a/apps/mulesoft/restapi/mode/listservers.pm +++ b/apps/mulesoft/restapi/mode/listservers.pm @@ -31,7 +31,7 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - "filter-name:s" => { name => 'filter_name' }, + 'filter-name:s' => { name => 'filter_name' }, }); return $self; @@ -42,12 +42,6 @@ sub check_options { $self->SUPER::init(%options); } -sub manage_selection { - my ($self, %options) = @_; - - $self->{data} = $options{custom}->list_servers(); -} - sub run { my ($self, %options) = @_; @@ -56,11 +50,14 @@ sub run { next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && $server->{name} !~ /$self->{option_results}->{filter_name}/); - $self->{output}->output_add(long_msg => sprintf("[id = %s][name = %s][status = %s]", - $server->{id}, - $server->{name}, - $server->{status} - )); + $self->{output}->output_add( + long_msg => sprintf( + "[id = %s][name = %s][status = %s]", + $server->{id}, + $server->{name}, + $server->{status} + ) + ); } $self->{output}->output_add(severity => 'OK', short_msg => 'Mulesoft Anypoint Servers:'); @@ -77,8 +74,8 @@ sub disco_format { sub disco_show { my ($self, %options) = @_; - $self->manage_selection(%options); - foreach my $server (@{$self->{data}}) { + my $result = $options{custom}->list_servers(); + foreach my $server (@{$result}) { $self->{output}->add_disco_entry( id => $server->{id}, name => $server->{name}, diff --git a/apps/mulesoft/restapi/mode/servers.pm b/apps/mulesoft/restapi/mode/servers.pm index 2bf7bc006..a3db2385d 100644 --- a/apps/mulesoft/restapi/mode/servers.pm +++ b/apps/mulesoft/restapi/mode/servers.pm @@ -24,18 +24,11 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); sub custom_status_output { my ($self, %options) = @_; - 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; + return sprintf('Id: %s, Status: %s', $self->{result_values}->{id}, $self->{result_values}->{status}); } sub set_counters { @@ -48,21 +41,21 @@ sub set_counters { $self->{maps_counters}->{global} = [ { label => 'total', nlabel => 'mulesoft.servers.total.count', set => { - key_values => [ { name => 'total' } ], - output_template => "Total : %s", - perfdatas => [ { value => 'total_absolute', template => '%d', min => 0 } ], + key_values => [ { name => 'total' } ], + output_template => 'Total : %s', + perfdatas => [ { value => 'total_absolute', template => '%d', min => 0 } ] } }, { label => 'running', nlabel => 'mulesoft.servers.status.running.count', set => { - key_values => [ { name => 'running' } ], - output_template => "Running : %s", - perfdatas => [ { value => 'running_absolute', template => '%d', min => 0 } ] + key_values => [ { name => 'running' } ], + output_template => 'Running : %s', + perfdatas => [ { value => 'running_absolute', template => '%d', min => 0 } ] } }, { label => 'disconnected', nlabel => 'mulesoft.servers.status.disconnected.count', set => { - key_values => [ { name => 'disconnected' } ], - output_template => "Disconnected : %s", - perfdatas => [ { value => 'disconnected_absolute', template => '%d', min => 0 } ] + key_values => [ { name => 'disconnected' } ], + output_template => 'Disconnected : %s', + perfdatas => [ { value => 'disconnected_absolute', template => '%d', min => 0 } ] } } ]; @@ -70,12 +63,12 @@ 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 => $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, + 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 } - }, + } ]; } @@ -85,9 +78,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; @@ -122,6 +115,7 @@ sub manage_selection { next if ( defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && $server->{name} !~ /$self->{option_results}->{filter_name}/ ); + $self->{servers}->{$server} = { display => $server, id => $server->{id}, @@ -175,7 +169,6 @@ Set warning threshold for status (Default: ''). Threshold can be matched on %{name}, %{id} or %{status} and Regexp can be used. Typical syntax: --critical-status='%{status} ~= m/DISCONNECTED/' - =back =cut