1、falcon 添加自定义报警 虽然和zabbix 相似 但是还是有区别
2、目标是ping 三个ip 哪个不通 自动报出是哪个ip
falcon
plush 机制要求上报的数据格式如下:
root@host01:/path/to/plugins/plugin/sys/ntp]#./600_ntp.py
[{“endpoint”: “host01”, “tags”: “”, “timestamp”: 1431349763, “metric”: “sys.ntp.offset”, “value”: 0.73699999999999999, “counterType”: “GAUGE”, “step”: 600}]
并且文件名是 时间_xxx.py
上述endpoint 是主机名
tags 变量不同的ip
imestamp 时间戳
metric 监控项
value 如果是变化值 或者是0 是好 1是不好
counterType 是固定的
step 时间
import socket, time, json
import requests
import os,subprocess,socket
from optparse import OptionParser
def go(tag=False):
req = requests.Session()
ceshi = {"online_ip": "1.1.1.1", "huidu_ip": "2.2.2.2", "ceshi_ip": "3.3.3.3"}
output = []
for key, value in ceshi.items():
t = {}
t['endpoint'] = socket.gethostname()
t['timestamp'] = int(time.time())
t['step'] = 60
t['counterType'] = 'GAUGE'
t['metric'] = 'ping'
t['tags'] = 'ip={},name={}'.format(value,key)
cmd = "ping -w 2 -c1 %s &>/dev/null" % value
res = subprocess.call(cmd, shell=True)
if res == 0:
t['value']=0
output.append(t)
else:
t['value']=1
output.append(t)
print json.dumps(output)
return json.dumps(output)
if __name__ == '__main__':
go()
输出格式为:
[{‘endpoint’: ‘onlie-123’, ‘tags’: ‘ip=1.1.1.1,name=huidu_ip’, ‘timestamp’: 1594195677, ‘metric’: ‘ping’, ‘value’
: 0, ‘counterType’: ‘GAUGE’, ‘step’: 60}, {‘endpoint’: ‘online-123’, ‘tags’: ‘ip=2.2.2.2,name=cehsi_ip’, ‘timestamp’: 15
94195677, ‘metric’: ‘ping’, ‘value’: 0, ‘counterType’: ‘GAUGE’, ‘step’: 60}, {‘endpoint’: ‘online-123’, ‘tags’: ‘ip=3.3.3.3,name=online_ip’, ‘timestamp’: 1594195677, ‘metric’: ‘ping’, ‘value’: 0, ‘counterType’: ‘GAUGE’, ‘step’: 60}]