Tweak elasticsearch monitoring scripts

This commit is contained in:
Daniel Berteaud 2021-10-19 10:18:44 +02:00
parent 415c608252
commit 5387ae53b8
2 changed files with 17 additions and 7 deletions

View File

@ -66,7 +66,14 @@ $ua->env_proxy;
if ($cluster){ if ($cluster){
$json = make_request('/_cluster/stats'); $json = make_request('/_cluster/stats');
} elsif (defined $node){ } elsif (defined $node){
$json = make_request('/_nodes/' . $node); my $resp = make_request('/_nodes/' . $node)->{'nodes'};
# We can specify node by ID, name or IP
if (defined $resp->{$node}){
$json = $resp->{$node};
} else {
my $node_id = (keys %{$resp})[0];
$json = $resp->{$node_id};
}
} elsif (defined $index){ } elsif (defined $index){
$json = make_request('/_cluster/health/' . $index . '?level=indices')->{'indices'}->{$index}; $json = make_request('/_cluster/health/' . $index . '?level=indices')->{'indices'}->{$index};
} }

View File

@ -60,18 +60,21 @@ my $ua = LWP::UserAgent->new(
$ua->env_proxy; $ua->env_proxy;
if ($nodes){ if ($nodes){
foreach (@{make_request('/_cat/nodes?format=json')}){ foreach (@{make_request('/_cat/nodes?format=json&full_id&h=ip,role,master,name,id,version')}){
push @{$json}, { push @{$json}, {
'{#ES_NODE_NAME}' => $_->{name}, '{#ES_NODE_NAME}' => $_->{name},
'{#ES_NODE_ROLE}' => $_->{'node.role'} '{#ES_NODE_ROLE}' => $_->{role},
'{#ES_NODE_ID}' => $_->{id},
'{#ES_NODE_VERSION}' => $_->{version},
'{#ES_NODE_MASTER}' => $_->{master}
}; };
} }
} elsif ($indices){ } elsif ($indices){
foreach (@{make_request('/_cat/indices?format=json')}){ foreach (@{make_request('/_cat/indices?format=json')}){
push @{$json}, { push @{$json}, {
'{#ES_INDICE_NAME}' => $_->{index}, '{#ES_INDEX_NAME}' => $_->{index},
'{#ES_INDICE_STATUS}' => $_->{status}, '{#ES_INDEX_STATUS}' => $_->{status},
'{#ES_INDICE_UUID}' => $_->{uuid} '{#ES_INDEX_UUID}' => $_->{uuid}
}; };
} }
} }