Shell脚本一键推送到钉钉告警并@指定人

 1. Shell脚本

  cat    /opt/monitor/device/device.sh
#!/bin/bash

# 域名列表文件绝对路径

text_file="/opt/monitor/device/device.txt"

#PG数据库密码环境变量
export PGPASSWORD='8888888888888888'


#结果为0代表正常设备,非0代表有异常设备
sql_cmd="select count(1) from aio_brm.device where (org_id = 99999999999999999 or org_id = 988888888888888881) and del_flag = '0' and status = '0'"


psql -U database_user -d  database_name  -p 88888 -h sh-postgres-8888888888.sql.tencentcdb.com   -c  "$sql_cmd" > $text_file



#钉钉webhook
prod_webhook_url="https://oapi.dingtalk.com/robot/send?access_token=9999999999999999999999999999999999999"
test_webhook_url="https://oapi.dingtalk.com/robot/send?access_token=9999999999999999999888888888888888888"


MESSAGE=$(cat "$text_file")



# 要@的用户手机号(多个用户用逗号分隔)
AT_MOBILES="13088888888,13099999999"

#JSON_DATA=$(cat <

2. 根据业务需求配置定时任务

[root@localhost]# crontab  -l
30  08,16,23   *   *   *    /opt/monitor/device/device.sh  >  /dev/null  2>&1

3. @具体人不生效

      消息内容content中要带上"@手机号",跟atMobiles参数结合使用,才有@效果,如下示例。

Shell脚本一键推送到钉钉告警并@指定人_第1张图片

你可能感兴趣的:(钉钉,shell,艾特,钉钉告警,告警,脚本)