1、前期准备
登录钉钉界面,创建钉钉群,创建机器人(自定义),记录weblook,后续配置需要,安全设置(自定义关键字“backup”),关键字必须是backup,否则脚本执行失败
2、配置钉钉脚本
[root@centos7 script]# cat dingding1.sh webhook='https://oapi.dingtalk.com/robot/send?access_token=5231ae645cf24e0af784XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX6946207fc68d' time0=$1 ip=$2 name=$3 size=$4 sf=$5 backupname=$6 function SendMsgToDingding() { curl $webhook -H 'Content-Type: application/json' -d " { 'msgtype': 'text', 'text': { 'content': 'backup $backupname 数据备份详情:\n备份时间:$time0, 主机ip: $ip ,文件名称: $name,数据量: $size ,\n备份状态: $sf ,\n请查收!\n' }, 'at': { 'isAtAll': true } }" } SendMsgToDingding
3、数据备份后触发告警
[root@centos7 script]# cat backup.sh backup=/data/ ip1=`ifconfig eth0 | grep "inet "|awk '{print $2}'` name1=`cd $backup && ls -lrt |tail -n1|awk '{print $NF}'` size1=`cd $backup && du -sh $name1 |awk '{print $1}'` time1=`date "+%Y-%m-%d_%H:%M:%S"` #数据备份命令写在if语句里,将下列语句对号入座即可 /server/script/dingding1.sh $time1 $ip1 $name1 $size1 成功 百度系统 /server/script/dingding1.sh $time1 $ip1 $name1 $size1 失败 百度系统
4、测试页面