码迷,mamicode.com
首页 > 微信 > 详细

Zabbix微信告警 iptables output 链设置

时间:2016-11-23 00:23:38      阅读:518      评论:0      收藏:0      [点我收藏+]

标签:zabbix微信告警 iptables 设置


查找微信使用的IP地址:

1、 域名查找

# nslookup

> weixin.qq.com

Server:114.114.114.114

Address:114.114.114.114#53


Non-authoritative answer:

weixin.qq.comcanonical name = minorshort.weixin.qq.com.

Name:minorshort.weixin.qq.com

Address: 140.206.160.234

Name:minorshort.weixin.qq.com

Address: 140.207.54.47

Name:minorshort.weixin.qq.com

Address: 140.207.135.125


2、连接数查找

运行脚本:  bash wechat.sh test 123456

  多运行几次,查看是否有不同的IP


netstat -nat

Active Internet connections (servers and established)

Proto Recv-Q Send-Q Local Address               Foreign Address             State      

  

tcp        0      0 0.0.0.0:33197        140.207.127.79:443          TIME_WAIT   

tcp        0      0 0.0.0.0:33196        140.207.127.79:443          TIME_WAIT 


3、 iptables 配置:


:OUTPUT DROP [8:1128]

-A OUTPUT -d 140.207.127.79/32 -p tcp -m tcp --dport 443 -j ACCEPT

-A OUTPUT -d 117.185.30.190/32 -p tcp -m tcp --dport 443 -j ACCEPT 

-A OUTPUT -d 140.207.135.125/32 -p tcp -m tcp --dport 443 -j ACCEPT 

-A OUTPUT -d 140.207.54.47/32 -p tcp -m tcp --dport 443 -j ACCEPT 

-A OUTPUT -d 140.206.160.234/32 -p tcp -m tcp --dport 443 -j ACCEPT

-A OUTPUT -p udp -m udp --dport 53 -j ACCEPT 



======================

bash 脚本:


[root@zabbix alertscripts]# cat wechat.sh
#!/bin/bash
# Functions: send messages to wechat app
# set variables
CropID=‘xxxxxx‘
Secret=‘M3FMhnFh8nTI6SxLAEbbLLZaj-1BpZIyqkJRskeMMUXObGx4mfQsAg7Jw-nUMXe9‘
GURL="https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$CropID&corpsecret=$Secret"
#get acccess_token
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=10                        #企业号中的应用id
local UserID="touser"                        #部门成员id,zabbix中定义的微信接收者
local PartyID=8                           #部门id,定义了范围,组内成员都可接收到消息
local Msg=$(echo "$@" | cut -d" " -f3-)   #过滤出zabbix传递的第三个参数
printf ‘{\n‘
printf ‘\t"touser": "‘"$UserID"\"",\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 $! $2 $3)" $PURL

#http://qydev.weixin.qq.com/wiki/index.php?title=消息类型及数据格式
#测试:

bash wechat.sh test hello.world!
{"errcode":0,"errmsg":"ok","invaliduser":"all user invalid"}


本文出自 “12213582” 博客,请务必保留此出处http://12223582.blog.51cto.com/12213582/1875404

Zabbix微信告警 iptables output 链设置

标签:zabbix微信告警 iptables 设置

原文地址:http://12223582.blog.51cto.com/12213582/1875404

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!