This commit is contained in:
garnier-quentin 2020-01-29 13:24:13 +01:00
parent 289c261a3a
commit e69ecb43b8
3 changed files with 52 additions and 40 deletions

View File

@ -52,14 +52,18 @@ sub run {
$self->manage_selection(%options); $self->manage_selection(%options);
foreach my $node_id (sort keys %{$self->{nodes}}) { foreach my $node_id (sort keys %{$self->{nodes}}) {
$self->{output}->output_add(long_msg => '[id = ' . $node_id . "]" . $self->{output}->output_add(
"[name = '" . $self->{nodes}->{$node_id}->{Name} . "']" . long_msg =>
"[state = '" . $self->{nodes}->{$node_id}->{State} . "']" '[id = ' . $node_id . "]" .
"[name = '" . $self->{nodes}->{$node_id}->{Name} . "']" .
"[state = '" . $self->{nodes}->{$node_id}->{State} . "']"
); );
} }
$self->{output}->output_add(severity => 'OK', $self->{output}->output_add(
short_msg => 'List Nodes:'); severity => 'OK',
short_msg => 'List nodes:'
);
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
$self->{output}->exit(); $self->{output}->exit();
} }

View File

@ -29,9 +29,8 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold)
sub custom_status_output { sub custom_status_output {
my ($self, %options) = @_; my ($self, %options) = @_;
my $msg = 'state : ' . $self->{result_values}->{state};
return $msg; return 'state : ' . $self->{result_values}->{state};
} }
sub custom_status_calc { sub custom_status_calc {
@ -39,7 +38,6 @@ sub custom_status_calc {
$self->{result_values}->{state} = $options{new_datas}->{$self->{instance} . '_state'}; $self->{result_values}->{state} = $options{new_datas}->{$self->{instance} . '_state'};
$self->{result_values}->{name} = $options{new_datas}->{$self->{instance} . '_name'}; $self->{result_values}->{name} = $options{new_datas}->{$self->{instance} . '_name'};
return 0; return 0;
} }
@ -69,8 +67,10 @@ sub custom_memory_perfdata {
sub custom_memory_threshold { sub custom_memory_threshold {
my ($self, %options) = @_; my ($self, %options) = @_;
my $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{prct_used}, my $exit = $self->{perfdata}->threshold_check(
threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } ]); value => $self->{result_values}->{prct_used},
threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } ]
);
return $exit; return $exit;
} }
@ -81,11 +81,12 @@ sub custom_memory_output {
my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used}); my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free}); my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
my $msg = sprintf("Memory Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", return sprintf(
'Memory Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)',
$total_size_value . " " . $total_size_unit, $total_size_value . " " . $total_size_unit,
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}); $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}
return $msg; );
} }
sub custom_memory_calc { sub custom_memory_calc {
@ -116,8 +117,10 @@ sub custom_swap_perfdata {
sub custom_swap_threshold { sub custom_swap_threshold {
my ($self, %options) = @_; my ($self, %options) = @_;
my $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{prct_used}, my $exit = $self->{perfdata}->threshold_check(
threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } ]); value => $self->{result_values}->{prct_used},
threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } ]
);
return $exit; return $exit;
} }
@ -128,11 +131,12 @@ sub custom_swap_output {
my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used}); my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free}); my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
my $msg = sprintf("Swap Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", return sprintf(
'Swap Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)',
$total_size_value . " " . $total_size_unit, $total_size_value . " " . $total_size_unit,
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}); $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}
return $msg; );
} }
sub custom_swap_calc { sub custom_swap_calc {
@ -163,8 +167,10 @@ sub custom_fs_perfdata {
sub custom_fs_threshold { sub custom_fs_threshold {
my ($self, %options) = @_; my ($self, %options) = @_;
my $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{prct_used}, my $exit = $self->{perfdata}->threshold_check(
threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } ]); value => $self->{result_values}->{prct_used},
threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } ]
);
return $exit; return $exit;
} }
@ -175,11 +181,12 @@ sub custom_fs_output {
my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used}); my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free}); my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
my $msg = sprintf("Root Filesystem Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", return sprintf(
'Root Filesystem Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)',
$total_size_value . " " . $total_size_unit, $total_size_value . " " . $total_size_unit,
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}); $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}
return $msg; );
} }
sub custom_fs_calc { sub custom_fs_calc {
@ -198,8 +205,7 @@ sub set_counters {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{maps_counters_type} = [ $self->{maps_counters_type} = [
{ name => 'nodes', type => 1, cb_prefix_output => 'prefix_nodes_output', { name => 'nodes', type => 1, cb_prefix_output => 'prefix_nodes_output', message_multiple => 'All nodes are ok', skipped_code => { -10 => 1, -11 => 1 } },
message_multiple => 'All nodes are ok', skipped_code => { -11 => 1 } },
]; ];
$self->{maps_counters}->{nodes} = [ $self->{maps_counters}->{nodes} = [
@ -310,7 +316,8 @@ sub manage_selection {
memory_usage => $result->{$node_id}->{Stats}->{memory}->{used}, memory_usage => $result->{$node_id}->{Stats}->{memory}->{used},
memory_total => $result->{$node_id}->{Stats}->{memory}->{total}, memory_total => $result->{$node_id}->{Stats}->{memory}->{total},
swap_usage => $result->{$node_id}->{Stats}->{swap}->{used}, swap_usage => $result->{$node_id}->{Stats}->{swap}->{used},
swap_total => $result->{$node_id}->{Stats}->{swap}->{total}, swap_total =>
defined($result->{$node_id}->{Stats}->{swap}->{total}) && $result->{$node_id}->{Stats}->{swap}->{total} > 0 ? $result->{$node_id}->{Stats}->{swap}->{total} : undef,
fs_usage => $result->{$node_id}->{Stats}->{rootfs}->{used}, fs_usage => $result->{$node_id}->{Stats}->{rootfs}->{used},
fs_total => $result->{$node_id}->{Stats}->{rootfs}->{total}, fs_total => $result->{$node_id}->{Stats}->{rootfs}->{total},
}; };

View File

@ -29,9 +29,8 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold)
sub custom_status_output { sub custom_status_output {
my ($self, %options) = @_; my ($self, %options) = @_;
my $msg = 'state : ' . $self->{result_values}->{state};
return $msg; return 'state : ' . $self->{result_values}->{state};
} }
sub custom_status_calc { sub custom_status_calc {
@ -39,7 +38,6 @@ sub custom_status_calc {
$self->{result_values}->{state} = $options{new_datas}->{$self->{instance} . '_state'}; $self->{result_values}->{state} = $options{new_datas}->{$self->{instance} . '_state'};
$self->{result_values}->{name} = $options{new_datas}->{$self->{instance} . '_name'}; $self->{result_values}->{name} = $options{new_datas}->{$self->{instance} . '_name'};
return 0; return 0;
} }
@ -49,7 +47,6 @@ sub custom_cpu_calc {
my $delta_cpu_total = $options{new_datas}->{$self->{instance} . '_cpu_total_usage'} - $options{old_datas}->{$self->{instance} . '_cpu_total_usage'}; my $delta_cpu_total = $options{new_datas}->{$self->{instance} . '_cpu_total_usage'} - $options{old_datas}->{$self->{instance} . '_cpu_total_usage'};
$self->{result_values}->{prct_cpu} = $delta_cpu_total * 100; $self->{result_values}->{prct_cpu} = $delta_cpu_total * 100;
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
return 0; return 0;
} }
@ -69,8 +66,10 @@ sub custom_memory_perfdata {
sub custom_memory_threshold { sub custom_memory_threshold {
my ($self, %options) = @_; my ($self, %options) = @_;
my $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{prct_used}, my $exit = $self->{perfdata}->threshold_check(
threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } ]); value => $self->{result_values}->{prct_used},
threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } ]
);
return $exit; return $exit;
} }
@ -81,11 +80,12 @@ sub custom_memory_output {
my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used}); my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free}); my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
my $msg = sprintf("Memory Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", return sprintf(
$total_size_value . " " . $total_size_unit, 'Memory Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)',
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, $total_size_value . " " . $total_size_unit,
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}); $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
return $msg; $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}
);
} }
sub custom_memory_calc { sub custom_memory_calc {
@ -128,11 +128,12 @@ sub custom_swap_output {
my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used}); my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free}); my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
my $msg = sprintf("Swap Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", return sprintf(
'Swap Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)',
$total_size_value . " " . $total_size_unit, $total_size_value . " " . $total_size_unit,
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}); $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}
return $msg; );
} }
sub custom_swap_calc { sub custom_swap_calc {