|
|
@ -0,0 +1,40 @@ |
|
|
|
#!/usr/bin/env python3 |
|
|
|
|
|
|
|
|
|
|
|
from pyzabbix import ZabbixMetric, ZabbixSender # py-zabbix module |
|
|
|
import requests |
|
|
|
import json |
|
|
|
import os |
|
|
|
import sys |
|
|
|
|
|
|
|
|
|
|
|
class ZabbixSenderSwn: |
|
|
|
def __init__(self, server, host, data): |
|
|
|
self.server = server |
|
|
|
self.host = host |
|
|
|
self.data = data |
|
|
|
self.packet = [] |
|
|
|
|
|
|
|
def make_packet(self): |
|
|
|
if len(self.packet) != 0: |
|
|
|
return self.packet |
|
|
|
for line in self.data: |
|
|
|
self.packet.append(ZabbixMetric(self.host, line[0], line[1])) |
|
|
|
|
|
|
|
def send_packet(self): |
|
|
|
if len(self.packet) == 0: |
|
|
|
self.make_packet() |
|
|
|
return ZabbixSender(self.server).send(self.packet) |
|
|
|
|
|
|
|
|
|
|
|
def read_conf(): |
|
|
|
path = os.path.dirname(os.path.realpath(__file__)) |
|
|
|
conf_file = os.path.join(path, 'config.json') |
|
|
|
with open(conf_file) as f: |
|
|
|
conf = json.load(f) |
|
|
|
return conf |
|
|
|
|
|
|
|
def just_send(data): |
|
|
|
conf = read_conf() |
|
|
|
s = ZabbixSenderSwn(conf["zabbix_server"], conf["host"], data = []) |
|
|
|
s.send_packet() |