shell - alertmanager屏蔽

2022-12-21
#!/bin/bash
basepath=$(cd $(dirname $0); pwd)
source ${basepath}/../config.sh

type=$1
if [[ -z ${type} ]];then
     echo "error"
     exit
fi
rule_file=${PROMETHEUS_RULE_PATH}/${type}*.yml
alert_lists=$(cat ${rule_file} |grep alert | grep -vi 'disk\|TCP_tw' |awk '{print $NF}' | sort | uniq)

declare -A dict
dict=([ecs]="InstanceName" [rds]="DBInstanceDescription" [queue]="queue")
function silencesAlert() {
    for alert_list in ${alert_lists}
    do

        ${AMTOOL_BIN} silence add --duration="24h" --comment="永久屏蔽"  alertname=${alert_list} ${dict[${type}]}=~${line} --alertmanager.url=http://${MASTER_IP}:${ALERTMANAGER_PORT}
        ${AMTOOL_BIN} silence add --duration="24h" --comment="永久屏蔽"  alertname=${alert_list} ${dict[${type}]}=~${line} --alertmanager.url=http://${MASTER_IP_K8S}:${ALERTMANAGER_PORT}
    done
}

cat ${basepath}/silence-${type}-list | grep -v '\#' | while read line
do
    silencesAlert
done

标题:shell - alertmanager屏蔽
地址:https://blog.njqhome.com:8443/articles/2022/12/21/1671591968042.html