#!/bin/bash
export PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:$PATH"
# 钉钉关键词: 20, ERROR, INFO, WARN
title="Dingtalk Test"
content="Hello"
atMobiles=("156xxx")
atUserIds=()
isAtAll="False"
dingtalk_text(){
webhook_url='https://oapi.dingtalk.com/robot/send?access_token=097cxxxxxxxxxxxxxxxxxxxc924'
current_time=$(date +"%Y-%m-%d %H:%M:%S")
if [[ $content != "" ]];then
title_date="【$(hostname) $title】 $current_time"
message="{
\"msgtype\": \"text\",
\"text\": {\"content\": \"$title_date\n$content\"},
\"at\": {\"atMobiles\":[\"$atMobiles\"],\"atUserIds\":[\"$atUserIds\"],\"isAtAll\": \"$isAtAll\"}
}"
curl -H "Content-Type: application/json" -d "$message" "$webhook_url"
fi
}
dingtalk_text