update indent + fix bug with no result

This commit is contained in:
garnier-quentin 2020-01-24 14:17:20 +01:00
parent 3e0ca26bb6
commit 28616fd638
9 changed files with 150 additions and 154 deletions

View File

@ -42,15 +42,15 @@ sub new {
if (!defined($options{noptions})) {
$options{options}->add_options(arguments => {
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port' },
"proto:s" => { name => 'proto' },
"username:s" => { name => 'username' },
"password:s" => { name => 'password' },
"operator-user" => { name => 'operator_user' },
"api-path:s" => { name => 'api_path' },
"timeframe:s" => { name => 'timeframe' },
"timeout:s" => { name => 'timeout' },
'hostname:s' => { name => 'hostname' },
'port:s' => { name => 'port' },
'proto:s' => { name => 'proto' },
'username:s' => { name => 'username' },
'password:s' => { name => 'password' },
'operator-user' => { name => 'operator_user' },
'api-path:s' => { name => 'api_path' },
'timeframe:s' => { name => 'timeframe' },
'timeout:s' => { name => 'timeout' },
});
}
$options{options}->add_help(package => __PACKAGE__, sections => 'REST API OPTIONS', once => 1);
@ -150,7 +150,7 @@ sub get_session_cookie {
$encoded = JSON::XS->new->utf8->encode($form_post);
};
if ($@) {
$self->{output}->add_option_msg(short_msg => "Cannot encode json request");
$self->{output}->add_option_msg(short_msg => 'Cannot encode json request');
$self->{output}->option_exit();
}

View File

@ -104,10 +104,10 @@ sub new {
bless $self, $class;
$options{options}->add_options(arguments => {
"filter-edge-name:s" => { name => 'filter_edge_name' },
"filter-application-name:s" => { name => 'filter_application_name' },
"warning-status:s" => { name => 'warning_status', default => '' },
"critical-status:s" => { name => 'critical_status', default => '' },
'filter-edge-name:s' => { name => 'filter_edge_name' },
'filter-application-name:s' => { name => 'filter_application_name' },
'warning-status:s' => { name => 'warning_status', default => '' },
'critical-status:s' => { name => 'critical_status', default => '' },
});
return $self;
@ -125,10 +125,9 @@ sub check_options {
sub manage_selection {
my ($self, %options) = @_;
$self->{edges} = {};
my $results = $options{custom}->list_edges;
$self->{edges} = {};
foreach my $edge (@{$results}) {
if (defined($self->{option_results}->{filter_edge_name}) && $self->{option_results}->{filter_edge_name} ne '' &&
$edge->{name} !~ /$self->{option_results}->{filter_edge_name}/) {
@ -167,11 +166,6 @@ sub manage_selection {
$self->{output}->add_option_msg(short_msg => "No edge found.");
$self->{output}->option_exit();
}
foreach (keys %{$self->{edges}}) {
last if (defined($self->{edges}->{$_}->{apps}));
$self->{output}->add_option_msg(short_msg => "No applications found.");
$self->{output}->option_exit();
}
}
1;
@ -192,15 +186,9 @@ Filter edge by name (Can be a regexp).
Filter application by name (Can be a regexp).
=item B<--warning-*>
=item B<--warning-*> B<--critical-*>
Threshold warning.
Can be: 'traffic-in', 'traffic-out',
'packets-in', 'packets-out'.
=item B<--critical-*>
Threshold critical.
Thresholds.
Can be: 'traffic-in', 'traffic-out',
'packets-in', 'packets-out'.

View File

@ -104,10 +104,10 @@ sub new {
bless $self, $class;
$options{options}->add_options(arguments => {
"filter-edge-name:s" => { name => 'filter_edge_name' },
"filter-category-name:s" => { name => 'filter_category_name' },
"warning-status:s" => { name => 'warning_status', default => '' },
"critical-status:s" => { name => 'critical_status', default => '' },
'filter-edge-name:s' => { name => 'filter_edge_name' },
'filter-category-name:s' => { name => 'filter_category_name' },
'warning-status:s' => { name => 'warning_status', default => '' },
'critical-status:s' => { name => 'critical_status', default => '' },
});
return $self;
@ -125,10 +125,9 @@ sub check_options {
sub manage_selection {
my ($self, %options) = @_;
$self->{edges} = {};
my $results = $options{custom}->list_edges;
$self->{edges} = {};
foreach my $edge (@{$results}) {
if (defined($self->{option_results}->{filter_edge_name}) && $self->{option_results}->{filter_edge_name} ne '' &&
$edge->{name} !~ /$self->{option_results}->{filter_edge_name}/) {
@ -167,11 +166,6 @@ sub manage_selection {
$self->{output}->add_option_msg(short_msg => "No edge found.");
$self->{output}->option_exit();
}
foreach (keys %{$self->{edges}}) {
last if (defined($self->{edges}->{$_}->{categories}));
$self->{output}->add_option_msg(short_msg => "No category found.");
$self->{output}->option_exit();
}
}
1;
@ -192,15 +186,9 @@ Filter edge by name (Can be a regexp).
Filter category by name (Can be a regexp).
=item B<--warning-*>
=item B<--warning-*> B<--critical-*>
Threshold warning.
Can be: 'traffic-in', 'traffic-out',
'packets-in', 'packets-out'.
=item B<--critical-*>
Threshold critical.
Thresholds.
Can be: 'traffic-in', 'traffic-out',
'packets-in', 'packets-out'.

View File

@ -68,6 +68,7 @@ sub set_counters {
}
},
];
$self->{maps_counters}->{links} = [
{ label => 'qoe-voice', nlabel => 'link.qoe.voice.count', set => {
key_values => [ { name => 'voice' }, { name => 'display' }, { name => 'id' } ],
@ -123,8 +124,8 @@ sub new {
bless $self, $class;
$options{options}->add_options(arguments => {
"filter-edge-name:s" => { name => 'filter_edge_name' },
"filter-link-name:s" => { name => 'filter_link_name' },
"filter-edge-name:s' => { name => 'filter_edge_name' },
"filter-link-name:s' => { name => 'filter_link_name' },
});
return $self;
@ -135,17 +136,15 @@ sub check_options {
$self->SUPER::check_options(%options);
$self->{timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 900;
$self->change_macros(macros => ['warning_status', 'critical_status']);
}
sub manage_selection {
my ($self, %options) = @_;
$self->{edges} = {};
my $results = $options{custom}->list_edges;
$self->{edges} = {};
foreach my $edge (@{$results}) {
if (defined($self->{option_results}->{filter_edge_name}) && $self->{option_results}->{filter_edge_name} ne '' &&
$edge->{name} !~ /$self->{option_results}->{filter_edge_name}/) {
@ -197,11 +196,6 @@ sub manage_selection {
$self->{output}->add_option_msg(short_msg => "No edge found.");
$self->{output}->option_exit();
}
foreach (keys %{$self->{edges}}) {
last if (defined($self->{edges}->{$_}->{links}));
$self->{output}->add_option_msg(short_msg => "No link found.");
$self->{output}->option_exit();
}
}
1;
@ -222,14 +216,9 @@ Filter edge by name (Can be a regexp).
Filter link by name (Can be a regexp).
=item B<--warning-*>
=item B<--warning-*> B<--critical-*>
Threshold warning.
Can be: 'qoe-voice', 'qoe-video', 'qoe-transactional'.
=item B<--critical-*>
Threshold critical.
Thresholds.
Can be: 'qoe-voice', 'qoe-video', 'qoe-transactional'.
=back

View File

@ -29,11 +29,13 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold)
sub custom_status_output {
my ($self, %options) = @_;
return sprintf("State is '%s', Service State is '%s', HA State is '%s', Activation State is '%s'",
return sprintf(
"State is '%s', Service State is '%s', HA State is '%s', Activation State is '%s'",
$self->{result_values}->{edge_state},
$self->{result_values}->{service_state},
$self->{result_values}->{ha_state},
$self->{result_values}->{activation_state});
$self->{result_values}->{activation_state}
);
}
sub custom_status_calc {
@ -99,10 +101,9 @@ sub check_options {
sub manage_selection {
my ($self, %options) = @_;
$self->{edges} = {};
my $results = $options{custom}->list_edges;
$self->{edges} = {};
foreach my $edge (@{$results}) {
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
$edge->{name} !~ /$self->{option_results}->{filter_name}/) {

View File

@ -29,7 +29,8 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold
sub custom_status_output {
my ($self, %options) = @_;
return sprintf("status is '%s' [vpn state: '%s'] [backup state: '%s']",
return sprintf(
"status is '%s' [vpn state: '%s'] [backup state: '%s']",
$self->{result_values}->{state},
$self->{result_values}->{vpn_state},
$self->{result_values}->{backup_state}
@ -86,11 +87,11 @@ sub new {
bless $self, $class;
$options{options}->add_options(arguments => {
"filter-edge-name:s" => { name => 'filter_edge_name' },
"filter-link-name:s" => { name => 'filter_link_name' },
"unknown-status:s" => { name => 'unknown_status', default => '' },
"warning-status:s" => { name => 'warning_status', default => '' },
"critical-status:s" => { name => 'critical_status', default => '%{state} !~ /STABLE/ || %{vpn_state} !~ /STABLE/' },
'filter-edge-name:s' => { name => 'filter_edge_name' },
'filter-link-name:s' => { name => 'filter_link_name' },
'unknown-status:s' => { name => 'unknown_status', default => '' },
'warning-status:s' => { name => 'warning_status', default => '' },
'critical-status:s' => { name => 'critical_status', default => '%{state} !~ /STABLE/ || %{vpn_state} !~ /STABLE/' },
});
return $self;
@ -108,10 +109,9 @@ sub check_options {
sub manage_selection {
my ($self, %options) = @_;
$self->{edges} = {};
my $results = $options{custom}->list_edges;
$self->{edges} = {};
foreach my $edge (@{$results}) {
if (defined($self->{option_results}->{filter_edge_name}) && $self->{option_results}->{filter_edge_name} ne '' &&
$edge->{name} !~ /$self->{option_results}->{filter_edge_name}/) {
@ -148,11 +148,6 @@ sub manage_selection {
$self->{output}->add_option_msg(short_msg => "No edge found.");
$self->{output}->option_exit();
}
foreach (keys %{$self->{edges}}) {
last if (defined($self->{edges}->{$_}->{links}));
$self->{output}->add_option_msg(short_msg => "No link found.");
$self->{output}->option_exit();
}
}
1;

View File

@ -32,12 +32,36 @@ sub set_counters {
{ name => 'edges', type => 3, cb_prefix_output => 'prefix_edge_output', cb_long_output => 'long_output',
message_multiple => 'All edges links usage are ok', indent_long_output => ' ',
group => [
{ name => 'global', cb_prefix_output => 'prefix_global_output', type => 0, skipped_code => { -10 => 1 } },
{ name => 'links', display_long => 1, cb_prefix_output => 'prefix_link_output',
message_multiple => 'All links status are ok', type => 1 },
]
}
];
$self->{maps_counters}->{global} = [
{ label => 'links-traffic-in', nlabel => 'links.traffic.in.bitspersecond', set => {
key_values => [ { name => 'traffic_in' } ],
output_template => 'Total Traffic In: %s %s/s',
output_change_bytes => 2,
perfdatas => [
{ value => 'traffic_in_absolute', template => '%s',
min => 0, unit => 'b/s', label_extra_instance => 1 },
],
}
},
{ label => 'links-traffic-out', nlabel => 'links.traffic.out.bitspersecond', set => {
key_values => [ { name => 'traffic_out' } ],
output_template => 'Total Traffic Out: %s %s/s',
output_change_bytes => 2,
perfdatas => [
{ value => 'traffic_out_absolute', template => '%s',
min => 0, unit => 'b/s', label_extra_instance => 1 },
],
}
}
];
$self->{maps_counters}->{links} = [
{ label => 'traffic-in', nlabel => 'link.traffic.in.bitspersecond', set => {
key_values => [ { name => 'traffic_in' }, { name => 'display' }, { name => 'id' } ],
@ -140,8 +164,8 @@ sub new {
bless $self, $class;
$options{options}->add_options(arguments => {
"filter-edge-name:s" => { name => 'filter_edge_name' },
"filter-link-name:s" => { name => 'filter_link_name' },
'filter-edge-name:s' => { name => 'filter_edge_name' },
'filter-link-name:s' => { name => 'filter_link_name' },
});
return $self;
@ -159,10 +183,9 @@ sub check_options {
sub manage_selection {
my ($self, %options) = @_;
my $results = $options{custom}->list_edges();
$self->{edges} = {};
my $results = $options{custom}->list_edges;
foreach my $edge (@{$results}) {
if (defined($self->{option_results}->{filter_edge_name}) && $self->{option_results}->{filter_edge_name} ne '' &&
$edge->{name} !~ /$self->{option_results}->{filter_edge_name}/) {
@ -170,8 +193,12 @@ sub manage_selection {
next;
}
$self->{edges}->{$edge->{name}}->{id} = $edge->{id};
$self->{edges}->{$edge->{name}}->{display} = $edge->{name};
$self->{edges}->{$edge->{name}} = {
id => $edge->{id},
display => $edge->{name},
global => {},
links => {}
};
my $links = $options{custom}->get_links_metrics(
edge_id => $edge->{id},
@ -197,16 +224,17 @@ sub manage_selection {
packet_loss_out => $link->{bestLossPctTx},
packet_loss_in => $link->{bestLossPctRx},
};
if (!defined($self->{edges}->{$edge->{name}}->{global}->{traffic_in})) {
$self->{edges}->{$edge->{name}}->{global}->{traffic_in} = 0;
$self->{edges}->{$edge->{name}}->{global}->{traffic_out} = 0;
}
$self->{edges}->{$edge->{name}}->{global}->{traffic_in} += (int($link->{bytesRx} * 8 / $self->{timeframe}));
$self->{edges}->{$edge->{name}}->{global}->{traffic_out} += (int($link->{bytesTx} * 8 / $self->{timeframe}));
}
}
if (scalar(keys %{$self->{edges}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No edge found.");
$self->{output}->option_exit();
}
foreach (keys %{$self->{edges}}) {
last if (defined($self->{edges}->{$_}->{links}));
$self->{output}->add_option_msg(short_msg => "No link found.");
$self->{output}->add_option_msg(short_msg => 'no edge found.');
$self->{output}->option_exit();
}
}
@ -229,17 +257,11 @@ Filter edge by name (Can be a regexp).
Filter link by name (Can be a regexp).
=item B<--warning-*>
=item B<--warning-*> B<--critical-*>
Threshold warning.
Can be: 'traffic-in', 'traffic-out', 'latency-in',
'latency-out', 'jitter-in', 'jitter-out',
'packet-loss-in', 'packet-loss-out'.
=item B<--critical-*>
Threshold critical.
Can be: 'traffic-in', 'traffic-out', 'latency-in',
Thresholds.
Can be: 'links-traffic-in', 'links-traffic-out',
'traffic-in', 'traffic-out', 'latency-in',
'latency-out', 'jitter-in', 'jitter-out',
'packet-loss-in', 'packet-loss-out'.

View File

@ -57,8 +57,10 @@ sub run {
$edge->{haState}, $edge->{activationState}));
}
$self->{output}->output_add(severity => 'OK',
short_msg => 'List edges:');
$self->{output}->output_add(
severity => 'OK',
short_msg => 'List edges:'
);
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
$self->{output}->exit();
}
@ -66,8 +68,12 @@ sub run {
sub disco_format {
my ($self, %options) = @_;
$self->{output}->add_disco_format(elements => ['id', 'name', 'description', 'edge_state', 'service_state',
'ha_state', 'activation_state']);
$self->{output}->add_disco_format(
elements => [
'id', 'name', 'description', 'edge_state', 'service_state',
'ha_state', 'activation_state'
]
);
}
sub disco_show {

View File

@ -31,7 +31,7 @@ sub new {
bless $self, $class;
$options{options}->add_options(arguments => {
"filter-edge-name:s" => { name => 'filter_edge_name' },
'filter-edge-name:s' => { name => 'filter_edge_name' },
});
return $self;
@ -46,7 +46,6 @@ sub manage_selection {
my ($self, %options) = @_;
my $edges = $options{custom}->list_edges;
foreach my $edge (@{$edges}) {
if (defined($self->{option_results}->{filter_edge_name}) && $self->{option_results}->{filter_edge_name} ne '' &&
$edge->{name} !~ /$self->{option_results}->{filter_edge_name}/) {
@ -65,14 +64,20 @@ sub run {
$self->manage_selection(%options);
foreach my $link (@{$self->{links}}) {
$self->{output}->output_add(long_msg => sprintf("[id = %s][display_name = %s][name = %s][edge_id = %s]" .
$self->{output}->output_add(
long_msg => sprintf(
"[id = %s][display_name = %s][name = %s][edge_id = %s]" .
"[edge_name = %s][state = %s][vpn_state = %s]",
$link->{linkId}, $link->{link}->{displayName}, $link->{name}, $link->{link}->{edgeId},
$link->{edgeName}, $link->{link}->{state}, $link->{link}->{vpnState}));
$link->{edgeName}, $link->{link}->{state}, $link->{link}->{vpnState}
)
);
}
$self->{output}->output_add(severity => 'OK',
short_msg => 'List links:');
$self->{output}->output_add(
severity => 'OK',
short_msg => 'List links:'
);
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
$self->{output}->exit();
}
@ -80,8 +85,11 @@ sub run {
sub disco_format {
my ($self, %options) = @_;
$self->{output}->add_disco_format(elements => ['id', 'display_name', 'name', 'edge_id', 'edge_name', 'state',
'vpn_state']);
$self->{output}->add_disco_format(
elements => [
'id', 'display_name', 'name', 'edge_id', 'edge_name', 'state', 'vpn_state'
]
);
}
sub disco_show {
@ -118,4 +126,3 @@ Filter edge by name (Can be a regexp).
=back
=cut