Open-Falcon-脚本推送-python

it2025-06-08  15

import json import requests import time import datetime #currTime = datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d %H:%M:%S') dtime = datetime.datetime.now() ans_time = time.mktime(dtime.timetuple()) #将python的datetime转换为unix时间戳 ans_time = int(ans_time) url = "http://192.168.198.133:1988/v1/push" headers = {'Content-Type': 'application/json'} datas = json.dumps([{"metric":"mem.swapfree.percent", "endpoint":"192.168.198.133", "timestamp":ans_time, "step":60, "value":60, "counterType":"GAUGE", "tags":"idc=lg,project=log,error=Testsqlexception"}]) print(datas) r = requests.post(url, data=datas, headers=headers) #r = requests.post(url=url, data=datas) print(r.text) print(r.status_code) print(r.reason)

-------------------------------------------------------------------

注意的地方:setp和value类型是int,之前用字符串,调试了很久才调对

最新回复(0)