add nodes-total gorgone rest api

This commit is contained in:
garnier-quentin 2020-08-06 09:54:08 +02:00
parent b80a7b2087
commit b8afa9fd39
1 changed files with 15 additions and 1 deletions

View File

@ -35,9 +35,21 @@ sub set_counters {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{maps_counters_type} = [ $self->{maps_counters_type} = [
{ name => 'global', type => 0 },
{ name => 'nodes', type => 1, cb_prefix_output => 'prefix_node_output', message_multiple => 'All nodes are ok' } { name => 'nodes', type => 1, cb_prefix_output => 'prefix_node_output', message_multiple => 'All nodes are ok' }
]; ];
$self->{maps_counters}->{global} = [
{ label => 'nodes-total', nlabel => 'nodes.total.count', set => {
key_values => [ { name => 'total' } ],
output_template => 'total nodes: %s',
perfdatas => [
{ template => '%s', min => 0 }
]
}
}
];
$self->{maps_counters}->{nodes} = [ $self->{maps_counters}->{nodes} = [
{ label => 'ping-received-lasttime', nlabel => 'node.ping.received.lasttime.seconds', set => { { label => 'ping-received-lasttime', nlabel => 'node.ping.received.lasttime.seconds', set => {
key_values => [ { name => 'last_ping_recv' }, { name => 'display' }, ], key_values => [ { name => 'last_ping_recv' }, { name => 'display' }, ],
@ -67,6 +79,7 @@ sub manage_selection {
my $nodes = $options{custom}->request_api(endpoint => '/api/internal/constatus'); my $nodes = $options{custom}->request_api(endpoint => '/api/internal/constatus');
$self->{global} = { total => 0 };
$self->{nodes} = {}; $self->{nodes} = {};
foreach my $node_id (keys %{$nodes->{data}}) { foreach my $node_id (keys %{$nodes->{data}}) {
if (defined($self->{option_results}->{filter_node_id}) && $self->{option_results}->{filter_node_id} ne '' && if (defined($self->{option_results}->{filter_node_id}) && $self->{option_results}->{filter_node_id} ne '' &&
@ -80,6 +93,7 @@ sub manage_selection {
last_ping_recv => defined($nodes->{data}->{$node_id}->{last_ping_recv}) ? last_ping_recv => defined($nodes->{data}->{$node_id}->{last_ping_recv}) ?
time() - $nodes->{data}->{$node_id}->{last_ping_recv} : -1 time() - $nodes->{data}->{$node_id}->{last_ping_recv} : -1
}; };
$self->{global}->{total}++;
} }
} }
@ -100,7 +114,7 @@ Filter nodes (can be a regexp).
=item B<--warning-*> B<--critical-*> =item B<--warning-*> B<--critical-*>
Thresholds. Thresholds.
Can be: 'ping-received-lasttime' (s). Can be: 'nodes-total', 'ping-received-lasttime' (s).
=back =back