1. Shell监控redis集群fail节点
[root@xor-IR-redis02 ~]# cat /root/hxy/redis_status.sh
#!/bin/bash
REDIS_NODE="172.16.167.191:7018"
REDIS_PASSWORD="Xorrds268"
DINGDING_WEBHOOK="http://oapi.dingtalk.com/robot/send?access_token=4ff92016951904d668485d760efef44a4012f1ea605ece99fe83168ccf4477a6"
output=$(redis-cli -h "${REDIS_NODE%:*}" -p "${REDIS_NODE#*:}" -a "$REDIS_PASSWORD" cluster nodes)
if [[ $output == *"fail"* ]]; then
send_alert_message "智能推荐——Redis集群中存在失败节点"
else
echo "redis集群正常哦"
fi
send_alert_message() {
local message="$1"
local body="{\"msgtype\":\"text\",\"text\":{\"content\":\"${message}\"}}"
curl -s -H "Content-Type: application/json" -d "${body}" "${DINGDING_WEBHOOK}" >/dev/null 2>&1
}