告警通知如何根据告警类型分别处理(shell方式处理)

有时候我们需要根据不同的告警内容,进行不同处理,比如进程告警和主机告警需要分别处理,下面以shell脚本为例说明
我们在已经配置好的告警脚本基础上,进行如下改造,下面脚本仅为模板参考,具体处理需要自己填充下
#!/bin/bash
# -*- coding: utf-8 -*-
###SCRIPT_NAME:weixin.sh###
###send message from weixin for monitoring###
###leo###
content=${@:1} #告警内容
content=${content//\ /}
time3=$(date "+%H:%M:%S")
content="$time3,$content"
#content=${content//\,/\\n}  #告警信息若需要换行显示,去掉此行注释
echo "告警信息 : $content"
  
#告警内容输出到warn.log文件,测试完成注释掉即可
echo "warn content is : $content" >> ./warn.log

#告警内容具体处理如下,具体根据告警内容包含的特有字符串进行判断是什么类型告警,然后进行处理
if [[ $content =~ "当前内存使用率为" ]]
then
    echo "内存告警处理......"
elif [[ $content =~ "当前系统负载(5分钟)为" ]]
then
    echo "系统负载(5分钟)告警处理......"
elif [[ $content =~ "当前CPU使用率为" ]]
then
    echo "CPU告警告警处理......"
elif [[ $content =~ "当前上行传输速率为" ]]
then
    echo "上行传输速率告警处理......"
elif [[ $content =~ "当前下行传输速率为" ]]
then
    echo "下行传输速率告警处理......"
elif [[ $content =~ "SMART健康检测结果为" ]]
then
    echo "磁盘告警SMART处理......"
elif [[ $content =~ "主机磁盘告警" ]]
then
    echo "主机磁盘告警处理......"
elif [[ $content =~ "CPU当前温度为" ]]
then
    echo "CPU温度告警处理......"
elif [[ $content =~ "响应状态码为" ]]
then
    echo "服务接口检测告警/恢复处理......"
elif [[ $content =~ "数通设备" ]]
then
    echo "数通设备PING超时告警/恢复处理......"
elif [[ $content =~ "snmp设备" ]]
then
    echo "snmp设备PING超时告警/恢复处理......"
elif [[ $content =~ "主机可能已下线" ]] || [[ $content =~ "主机已恢复上线" ]]
then
    echo "主机下线/恢复告警处理......"
elif [[ $content =~ "进程可能已下线" ]] || [[ $content =~ "进程已恢复上线" ]]
then
    echo "进程下线/恢复告警处理......"
elif [[ $content =~ "docker可能已下线" ]] || [[ $content =~ "docker已恢复上线" ]]
then
    echo "docker下线/恢复告警处理......"
elif [[ $content =~ "端口telnet不通" ]] || [[ $content =~ "端口已恢复上线" ]]
then
    echo "端口telnet不通告警/恢复处理......"
elif [[ $content =~ "文件防篡改监测可能已下线" ]] || [[ $content =~ "文件防篡改监测已恢复上线" ]]
then
    echo "文件防篡改下线/恢复告警处理......"
elif [[ $content =~ "数据源连接失败" ]] || [[ $content =~ "数据源已恢复上线" ]]
then
    echo "数据源下线/恢复告警处理......"
elif [[ $content =~ "数据表告警" ]]
then
    echo "数据表告警处理......"
elif [[ $content =~ "日志监控告警" ]]
then
    echo "日志监控告警处理......"
elif [[ $content =~ "指令内容" ]]
then
    echo "下发指令告警处理......"
else
    echo "告警内容为其他处理......"
fi

echo "数据表告警处理......",我们在这里写入我们的处理逻辑