diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="VcsDirectoryMappings"> + <mapping directory="$PROJECT_DIR$" vcs="Git" /> + </component> +</project> \ No newline at end of file diff --git a/config.json b/config.json new file mode 100644 index 0000000..af5df6b --- /dev/null +++ b/config.json @@ -0,0 +1,4 @@ +{ + "hostname": "hostname1", + "zabbix_server": "10.3.2.5" +} diff --git a/main.py b/main.py new file mode 100644 index 0000000..5f7ce86 --- /dev/null +++ b/main.py @@ -0,0 +1 @@ +#!/usr/bin/env python3 \ No newline at end of file diff --git a/modPyZabbixSwn.py b/modPyZabbixSwn.py new file mode 100644 index 0000000..3aadede --- /dev/null +++ b/modPyZabbixSwn.py @@ -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()