enhance indent

This commit is contained in:
garnier-quentin 2020-04-21 14:14:22 +02:00
parent e3c8ca1e35
commit 5582615789
4 changed files with 63 additions and 76 deletions

View File

@ -24,18 +24,12 @@ 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); use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc);
sub custom_status_output { sub custom_status_output {
my ($self, %options) = @_; my ($self, %options) = @_;
return my $msg = sprintf('Id: %s, Status: %s', $self->{result_values}->{id}, $self->{result_values}->{status});
}
sub custom_status_calc { return sprintf('Id: %s, Status: %s', $self->{result_values}->{id}, $self->{result_values}->{status});
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 {
@ -48,40 +42,40 @@ sub set_counters {
$self->{maps_counters}->{global} = [ $self->{maps_counters}->{global} = [
{ 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_absolute', template => '%d', min => 0 } ], perfdatas => [ { value => 'total_absolute', 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_absolute', template => '%d', min => 0 } ] perfdatas => [ { value => 'started_absolute', 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_absolute', template => '%d', min => 0 } ] perfdatas => [ { value => 'stopped_absolute', 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_absolute', template => '%d', min => 0 } ] perfdatas => [ { value => 'failed_absolute', template => '%d', min => 0 } ]
} }
} }
]; ];
$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 => $self->can('custom_status_calc'), 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
} }
}, }
]; ];
} }
@ -91,9 +85,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;
@ -183,7 +177,6 @@ Set warning threshold for status (Default: '').
Threshold can be matched on %{name}, %{id} or %{status} and Regexp can be used. Threshold can be matched on %{name}, %{id} or %{status} and Regexp can be used.
Typical syntax: --critical-status='%{status} ~= m/FAILED/' Typical syntax: --critical-status='%{status} ~= m/FAILED/'
=back =back
=cut =cut

View File

@ -31,7 +31,7 @@ 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' },
}); });
return $self; return $self;
@ -56,10 +56,14 @@ sub run {
next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne ''
&& $application->{name} !~ /$self->{option_results}->{filter_name}/); && $application->{name} !~ /$self->{option_results}->{filter_name}/);
$self->{output}->output_add(long_msg => sprintf("[id = %s][name = %s][status = %s]", $self->{output}->output_add(
$application->{id}, long_msg => sprintf(
$application->{name}, "[id = %s][name = %s][status = %s]",
$application->{lastReportedStatus})); $application->{id},
$application->{name},
$application->{lastReportedStatus}
)
);
} }
$self->{output}->output_add(severity => 'OK', short_msg => 'Mulesoft Anypoint Applications:'); $self->{output}->output_add(severity => 'OK', short_msg => 'Mulesoft Anypoint Applications:');

View File

@ -31,7 +31,7 @@ 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' },
}); });
return $self; return $self;
@ -42,12 +42,6 @@ sub check_options {
$self->SUPER::init(%options); $self->SUPER::init(%options);
} }
sub manage_selection {
my ($self, %options) = @_;
$self->{data} = $options{custom}->list_servers();
}
sub run { sub run {
my ($self, %options) = @_; my ($self, %options) = @_;
@ -56,11 +50,14 @@ sub run {
next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne ''
&& $server->{name} !~ /$self->{option_results}->{filter_name}/); && $server->{name} !~ /$self->{option_results}->{filter_name}/);
$self->{output}->output_add(long_msg => sprintf("[id = %s][name = %s][status = %s]", $self->{output}->output_add(
$server->{id}, long_msg => sprintf(
$server->{name}, "[id = %s][name = %s][status = %s]",
$server->{status} $server->{id},
)); $server->{name},
$server->{status}
)
);
} }
$self->{output}->output_add(severity => 'OK', short_msg => 'Mulesoft Anypoint Servers:'); $self->{output}->output_add(severity => 'OK', short_msg => 'Mulesoft Anypoint Servers:');
@ -77,8 +74,8 @@ sub disco_format {
sub disco_show { sub disco_show {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->manage_selection(%options); my $result = $options{custom}->list_servers();
foreach my $server (@{$self->{data}}) { foreach my $server (@{$result}) {
$self->{output}->add_disco_entry( $self->{output}->add_disco_entry(
id => $server->{id}, id => $server->{id},
name => $server->{name}, name => $server->{name},

View File

@ -24,18 +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); use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc);
sub custom_status_output { sub custom_status_output {
my ($self, %options) = @_; my ($self, %options) = @_;
return my $msg = 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});
}
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 {
@ -48,21 +41,21 @@ sub set_counters {
$self->{maps_counters}->{global} = [ $self->{maps_counters}->{global} = [
{ 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 => "Total : %s", output_template => 'Total : %s',
perfdatas => [ { value => 'total_absolute', template => '%d', min => 0 } ], perfdatas => [ { value => 'total_absolute', 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_absolute', template => '%d', min => 0 } ] perfdatas => [ { value => 'running_absolute', 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_absolute', template => '%d', min => 0 } ] perfdatas => [ { value => 'disconnected_absolute', template => '%d', min => 0 } ]
} }
} }
]; ];
@ -70,12 +63,12 @@ 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 => $self->can('custom_status_calc'), 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
} }
}, }
]; ];
} }
@ -85,9 +78,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;
@ -122,6 +115,7 @@ sub manage_selection {
next if ( defined($self->{option_results}->{filter_name}) next if ( defined($self->{option_results}->{filter_name})
&& $self->{option_results}->{filter_name} ne '' && $self->{option_results}->{filter_name} ne ''
&& $server->{name} !~ /$self->{option_results}->{filter_name}/ ); && $server->{name} !~ /$self->{option_results}->{filter_name}/ );
$self->{servers}->{$server} = { $self->{servers}->{$server} = {
display => $server, display => $server,
id => $server->{id}, 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. Threshold can be matched on %{name}, %{id} or %{status} and Regexp can be used.
Typical syntax: --critical-status='%{status} ~= m/DISCONNECTED/' Typical syntax: --critical-status='%{status} ~= m/DISCONNECTED/'
=back =back
=cut =cut