Compare commits
2 commits
Author | SHA1 | Date | |
---|---|---|---|
|
6da4d9735f | ||
|
50d33da3c5 |
5 changed files with 76 additions and 4 deletions
|
@ -64,8 +64,19 @@ if [ ! -e "/usr/bin/jq" ]; then
|
|||
exit 3
|
||||
fi
|
||||
|
||||
nb_shards=$(curl -s -k -u ${CREDENTIALS} https://127.0.0.1:9200/_cat/allocation/${NODE_ID}?h=shards)
|
||||
nb_shards_max=$(curl -s -k -u ${CREDENTIALS} https://127.0.0.1:9200/_cluster/settings?flat_settings | jq -r ".persistent[]" )
|
||||
if [ -z ${CREDENTIALS} ]; then
|
||||
nb_shards=$(curl -s 127.0.0.1:9200/_cat/allocation/${NODE_ID}?h=shards | head -n1)
|
||||
nb_shards_max=$(curl -s 127.0.0.1:9200/_cluster/settings?flat_settings | jq -r ".persistent[]" )
|
||||
else
|
||||
nb_shards=$(curl -s -k -u ${CREDENTIALS} https://127.0.0.1:9200/_cat/allocation/${NODE_ID}?h=shards | head -n1)
|
||||
nb_shards_max=$(curl -s -k -u ${CREDENTIALS} https://127.0.0.1:9200/_cluster/settings?flat_settings | jq -r ".persistent[]" )
|
||||
fi
|
||||
|
||||
re='^[0-9]+$'
|
||||
if ! [[ $nb_shards_max =~ $re ]] ; then
|
||||
printf "UNKNWON - max_shards_per_node (NaN)"
|
||||
exit 3
|
||||
fi
|
||||
|
||||
nb_shards_avail=$(( $nb_shards_max - $nb_shards ))
|
||||
|
||||
|
@ -79,7 +90,7 @@ fi
|
|||
|
||||
nb_shards_crit=$(( $nb_shards_warn / 4 ))
|
||||
|
||||
# debug…
|
||||
# debug
|
||||
# printf '%d out of %d, avail: %d, warn: %d, crit: %d' $nb_shards $nb_shards_max $nb_shards_avail $nb_shards_warn $nb_shards_crit
|
||||
|
||||
if [ "${nb_shards_avail}" -le "${nb_shards_crit}" ]; then
|
|
@ -1,7 +1,11 @@
|
|||
---
|
||||
|
||||
- name: restart elasticsearch
|
||||
ansible.builtin.systemd:
|
||||
daemon_reload: yes
|
||||
name: elasticsearch
|
||||
state: restarted
|
||||
|
||||
- name: restart nagios-nrpe-server
|
||||
ansible.builtin.service:
|
||||
name: nagios-nrpe-server
|
||||
state: restarted
|
||||
|
|
|
@ -19,3 +19,5 @@
|
|||
|
||||
- ansible.builtin.include: curator.yml
|
||||
when: elasticsearch_curator | bool
|
||||
|
||||
- ansible.builtin.include: nrpe.yml
|
||||
|
|
48
elasticsearch/tasks/nrpe.yml
Normal file
48
elasticsearch/tasks/nrpe.yml
Normal file
|
@ -0,0 +1,48 @@
|
|||
---
|
||||
|
||||
- name: is NRPE present ?
|
||||
ansible.builtin.stat:
|
||||
path: /etc/nagios/nrpe.d/evolix.cfg
|
||||
check_mode: no
|
||||
register: nrpe_evolix_config
|
||||
tags:
|
||||
- elasticsearch
|
||||
- nrpe
|
||||
|
||||
- block:
|
||||
- name: Install dependencies
|
||||
ansible.builtin.apt:
|
||||
name:
|
||||
- jq
|
||||
|
||||
- ansible.builtin.include_role:
|
||||
name: evolix/remount-usr
|
||||
|
||||
- name: Copy Nagios check for Elasticsearch shards
|
||||
ansible.builtin.copy:
|
||||
src: check_elasticsearch_shards
|
||||
dest: /usr/local/lib/nagios/plugins/
|
||||
mode: "0755"
|
||||
|
||||
# - name: Create a password for NRPE
|
||||
# ansible.builtin.command:
|
||||
# cmd: "apg -n 1 -m 16 -M lcN"
|
||||
# register: elasticsearch_nrpe_password
|
||||
# check_mode: no
|
||||
# changed_when: False
|
||||
|
||||
# - name: Create nrpe user
|
||||
# todo:
|
||||
|
||||
- name: Add NRPE check
|
||||
ansible.builtin.lineinfile:
|
||||
name: /etc/nagios/nrpe.d/evolix.cfg
|
||||
regexp: '^command\[check_elasticsearch_shards\]='
|
||||
line: 'command[check_elasticsearch_shards]=/usr/local/lib/nagios/plugins/check_elasticsearch_shards --crendentials TODO(user:password) --nodeid TODO(nodeid)'
|
||||
notify: restart nagios-nrpe-server
|
||||
|
||||
when:
|
||||
- nrpe_evolix_config.stat.exists
|
||||
tags:
|
||||
- elasticsearch
|
||||
- nrpe
|
|
@ -577,6 +577,13 @@ ServiceName: elasticsearch
|
|||
ipServicePort: 9200
|
||||
ServiceType: http
|
||||
ServiceVersion: Elasticsearch ${elasticsearch_version}
|
||||
|
||||
dn: ServiceName=elasticsearch_shards,${computer_dn}
|
||||
NagiosEnabled: TRUE
|
||||
objectClass: EvoService
|
||||
ServiceName: elasticsearch_shards
|
||||
ServiceType: disk
|
||||
ServiceVersion: Elasticsearch ${elasticsearch_version}
|
||||
EOT
|
||||
fi
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue