From 5387ae53b81b576a2e13a9117029f7f92305f732 Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Tue, 19 Oct 2021 10:18:44 +0200 Subject: [PATCH] Tweak elasticsearch monitoring scripts --- zabbix_scripts/check_elasticsearch | 9 ++++++++- zabbix_scripts/disco_elasticsearch | 15 +++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/zabbix_scripts/check_elasticsearch b/zabbix_scripts/check_elasticsearch index 3851102..8cf4edd 100644 --- a/zabbix_scripts/check_elasticsearch +++ b/zabbix_scripts/check_elasticsearch @@ -66,7 +66,14 @@ $ua->env_proxy; if ($cluster){ $json = make_request('/_cluster/stats'); } 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){ $json = make_request('/_cluster/health/' . $index . '?level=indices')->{'indices'}->{$index}; } diff --git a/zabbix_scripts/disco_elasticsearch b/zabbix_scripts/disco_elasticsearch index bae9227..911b42a 100644 --- a/zabbix_scripts/disco_elasticsearch +++ b/zabbix_scripts/disco_elasticsearch @@ -60,18 +60,21 @@ my $ua = LWP::UserAgent->new( $ua->env_proxy; 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}, { - '{#ES_NODE_NAME}' => $_->{name}, - '{#ES_NODE_ROLE}' => $_->{'node.role'} + '{#ES_NODE_NAME}' => $_->{name}, + '{#ES_NODE_ROLE}' => $_->{role}, + '{#ES_NODE_ID}' => $_->{id}, + '{#ES_NODE_VERSION}' => $_->{version}, + '{#ES_NODE_MASTER}' => $_->{master} }; } } elsif ($indices){ foreach (@{make_request('/_cat/indices?format=json')}){ push @{$json}, { - '{#ES_INDICE_NAME}' => $_->{index}, - '{#ES_INDICE_STATUS}' => $_->{status}, - '{#ES_INDICE_UUID}' => $_->{uuid} + '{#ES_INDEX_NAME}' => $_->{index}, + '{#ES_INDEX_STATUS}' => $_->{status}, + '{#ES_INDEX_UUID}' => $_->{uuid} }; } }