#测试连通性,密码信息请根据情况修改
shell 脚本:
mkdir /usr/local/zabbix/shell
cd /usr/local/zabbix/shell
vi es_status.sh
#!/bin/bash
case $1 in
cluster_name)
curl -u user:123456 -s -XGET 'http://127.0.0.1:9200/_cluster/health?pretty' |awk -F\" '/cluster_name/ {print $4}' ;;
status)
curl -u user:123456 -s -XGET 'http://127.0.0.1:9200/_cluster/health?pretty' |awk -F\" 'NR==3 {print $4}' ;;
timed_out)
curl -u user:123456 -s -XGET 'http://127.0.0.1:9200/_cluster/health?pretty' |awk -F\, 'NR==4 {print $1}' |awk -F: '{print $2}' ;;
number_nodes)
curl -u user:123456 -s -XGET 'http://127.0.0.1:9200/_cluster/health?pretty' |awk -F\, 'NR==5 {print $1}' |awk -F: '{print $2}' ;;
data_nodes)
curl -u user:123456 -s -XGET 'http://127.0.0.1:9200/_cluster/health?pretty' |awk -F\, 'NR==6 {print $1}' |awk -F: '{print $2}' ;;
active_primary_shards)
curl -u user:123456 -s -XGET 'http://127.0.0.1:9200/_cluster/health?pretty' |awk -F\, 'NR==7 {print $1}' |awk -F: '{print $2}' ;;
active_shards)
curl -u user:123456 -s -XGET 'http://127.0.0.1:9200/_cluster/health?pretty' |awk -F\, 'NR==8 {print $1}' |awk -F: '{print $2}' ;;
relocating_shards)
curl -u user:123456 -s -XGET 'http://127.0.0.1:9200/_cluster/health?pretty' |awk -F\, 'NR==9 {print $1}' |awk -F: '{print $2}' ;;
initializing_shards)
curl -u user:123456 -s -XGET 'http://127.0.0.1:9200/_cluster/health?pretty' |awk -F\, 'NR==10 {print $1}' |awk -F: '{print $2}' ;;
unassigned_shards)
curl -u user:123456 -s -XGET 'http://127.0.0.1:9200/_cluster/health?pretty' |awk -F\, 'NR==11 {print $1}' |awk -F: '{print $2}' ;;
*)
echo "Usage: $0 { cluster_name | status | timed_out | number_nodes | data_nodes | active_primary_shards | active_shards | relocating_shards | initializing_shards | unassigned_shards}" ;;
esac
chmod +x es_status.sh
vi /usr/local/zabbix/etc/zabbix_agentd.conf #尾部加入以下
UnsafeUserParameters=1
UserParameter=cluster_name,/usr/local/zabbix/shell/es_status.sh cluster_name
UserParameter=status,/usr/local/zabbix/shell/es_status.sh status
UserParameter=timed_out,/usr/local/zabbix/shell/es_status.sh timed_out
UserParameter=number_nodes,/usr/local/zabbix/shell/es_status.sh number_nodes
UserParameter=data_nodes,/usr/local/zabbix/shell/es_status.sh data_nodes
UserParameter=active_primary_shards,/usr/local/zabbix/shell/es_status.sh active_primary_shards
UserParameter=active_shards,/usr/local/zabbix/shell/es_status.sh active_shards
UserParameter=relocating_shards,/usr/local/zabbix/shell/es_status.sh relocating_shards
UserParameter=initializing_shards,/usr/local/zabbix/shell/es_status.sh initializing_shards
UserParameter=unassigned_shards,/usr/local/zabbix/shell/es_status.sh unassigned_shards
service zabbix_agentd restart