openfalcon 添加自定义报警

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}]

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值