监控报警是每一个运维人员面临的问题,而报警方式更是多样化,从原来的人肉报警,飞信,139邮箱,短信猫,短信接口,微信报警,语言报警.带内,带外的都有
python
起初咱们把报警方式整合了一块儿,经过一个HTTP接口方式报警,监控工具也是多样化,nagios,zabbix,自定义脚本,并且每次写接收报警人的时候都须要找他的电话号码....痛定思痛,我决定从新设计.
ios
一.发送报警shell
URL:http://alarm.ops.xxx.cn/send/bash
方法: POST,GET微信
参数:运维
键 | 值 | 描述 |
to | @dba 或 zhangsan 多个收件人使用英文逗号分隔(,) 必填 | 能够发送给dba组,或者 张三 单独一我的 |
msg | "10.1.1.1 http is error " 必填 | 报警信息,须要url编码 |
type | sms 或者 wechat 选填 若是不加为随机 | 指定报警方式, sms短信 wechat微信 |
GET 请求方式举例curl
Python 代码ide
#!/usr/bin/python #coding=utf-8 import urllib import urllib2 msg = "hello world" msg = urllib.quote(msg) #URL编码 res = urllib2.urlopen("http://alarm.ops.xxx.cn/send/?to=zhangsan&msg=%s&type=sms" % msg) #发给单用户张三 print res.read() res.close()
shell 代码工具
#!/bin/bash msg="hello world" #定义报警信息 msg=$(echo $msg|sed 's/ /%20/g') #URL编码空格转换为%20 curl "http://alarm.ops.xxx.cn/send/?to=zhangsan&msg=${msg}&type=sms" #发给单用户张三 curl "http://alarm.ops.xxx.cn/send/?to=@dba&msg=${msg}&type=sms" #发给DBA组全部成员
成功返回:编码
OK
错误返回为JSON:
例如:
{
msg: "user wanger not found",
code: "-2"
}
二.获取用户信息
URL: http://alarm.ops.xxx.cn/user/<username>/
方法: GET
参数: URI三级目录的名称
例如: http://alram.ops.xxx.cn/user/zhangsan/ #查看张三信息
返回:
{
message: "成功",
code: 0,
data:- {
username: "zhangsan",
wechat: "zhangsan655",
first_name: "张三",
sms: "13422211123",
id: 2
}
}
三. 获取组信息
URL:http://alarm.ops.xxx.cn/group/<groupname>/
方法: GET
参数: URI三级目录的名称
例如: http://alarm.ops.xxx.cn/user/sa/ #查看sa组人员名单
返回:
{
message: "成功",
code: 0,
data:- {
username: "张三 王五 赵六 "
}
}
整个系统为Python+Django编写