关闭

Zabbix_AlertScript

标签: zabbix脚本
190人阅读 评论(0) 收藏 举报
分类:

Mail:

sendmail.sh 
#!/bin/bash
 
LOGFILE="/var/log/zabbix/sendmail-$(date +%Y-%m).log"
if [ ! -f $LOGFILE ];then
touch $LOGFILE
fi

to=$1
subject=$2
body=$3
 
cat <<EOF | mail -s "$subject" "$to"
$body
EOF

echo "$body" >>$LOGFILE


SMS:

阿里大于

sms.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import top.api
import sys

req=top.api.AlibabaAliqinFcSmsNumSendRequest("gw.api.taobao.com","80")
req.set_app_info(top.appinfo("key","passwd"))

req.sms_type="normal"
req.sms_free_sign_name="大鱼测试"

Message=sys.argv[3]

req.sms_param="{\"errormessage\": \"%s\" }" % sys.argv[3]
req.rec_num=sys.argv[1]
req.sms_template_code="SMS_***"
try:
    resp= req.getResponse()
    print(resp)
except Exception,e:
    print(e)




sendSMS.sh

#!/bin/bash

LOGFILE="/var/log/zabbix/SMS-$(date +%Y-%m).log"
if [ ! -f $LOGFILE ];then
touch $LOGFILE
fi

:>>$LOGFILE
exec 1>>$LOGFILE
exec 2>&1
echo "#$(date +%Y-%m-%d_%H:%M:%S)##" >>$LOGFILE

APP_CODE=**
MOBILE_NUMBER=$1
MESSAGE_UTF8=$3

XXD="/usr/bin/xxd"
CURL="/usr/bin/curl"
TIMEOUT=10

MESSAGE_ENCODE=$(echo "$MESSAGE_UTF8" | ${XXD} -ps | sed 's/\(..\)/%\1/g' | tr -d '\n')
URL="http://****.***.com/smsSend.do"
set -x
${CURL} -s --connect-timeout ${TIMEOUT} -H "Content-Type:textml;charset=utf-8" --data "{\"appCode\":\"${APP_CODE}\",\"sms\":{\"phone\":\"${MOBILE_NUMBER}\",\"message\":\"${MESSAGE_ENCODE}\"}}" "${URL}"


WeiXin:

weixin.sh 
#!/bin/bash

CropID='*****'
Secret='*************
GURL="https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$CropID&corpsecret=$Secret" 
Gtoken=$(/usr/bin/curl -s -G $GURL | awk -F\" '{print $4}')

PURL="https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=$Gtoken"

function body() {
        local int AppID=1
        local UserID=$1
        local PartyID=1
        local Msg=$(echo "$@" | cut -d" " -f3-)
        printf '{\n'
        printf '\t"touser": "'"$User"\"",\n"
        printf '\t"toparty": "'"$PartyID"\"",\n"
        printf '\t"msgtype": "text",\n'
        printf '\t"agentid": "'" $AppID "\"",\n"
        printf '\t"text": {\n'
        printf '\t\t"content": "'"$Msg"\""\n"
        printf '\t},\n'
        printf '\t"safe":"0"\n'
        printf '}\n'
}
/usr/bin/curl --data-ascii "$(body $1 $2 $3)" $PURL



0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:16309次
    • 积分:584
    • 等级:
    • 排名:千里之外
    • 原创:45篇
    • 转载:2篇
    • 译文:0篇
    • 评论:1条
    文章分类