How to use the mqttwarn.vendor.ZabbixSender.ZabbixSender function in mqttwarn

To help you get started, we’ve selected a few mqttwarn examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jpmens / mqttwarn / mqttwarn / vendor / ZabbixSender.py View on Github external
so.connect((self.server_ip, self.server_port))
        wobj = so.makefile(u'wb')
        wobj.write(self.send_data)
        wobj.close()
        robj = so.makefile(u'rb')
        recv_data = robj.read()
        robj.close()
        so.close()
        tmp_data = struct.unpack("<4sBq" + str(len(recv_data) - struct.calcsize("<4sBq")) + "s", recv_data)
        recv_json = json.loads(tmp_data[3])
        #JPM return recv_data
        return recv_json


if __name__ == '__main__':
    sender = ZabbixSender(u'127.0.0.1')
    for num in range(0, 2):
        sender.AddData(u'HostA', u'AppX_Logger', u'sent data 第' + str(num))
    res = sender.Send()
    print(sender.send_data)
    print(res)
github jpmens / mqttwarn / mqttwarn / services / zabbix.py View on Github external
return True
        except Exception as e:
            srv.logging.warn("Trapper responded: %s" % e)
            return False

    # We are adding a normal item/value via the trapper
    key = item.data.get('key', None)
    if client is None or key is None:
        srv.logging.warn("Client or Key missing in item; ignoring")
        return False

    value = item.message

    try:
        # Send item/value for host to the trapper
        sender = ZabbixSender.ZabbixSender(trapper, server_port = int(port))
        sender.AddData(host=client, key=key, value=value)
        res = sender.Send()
        sender.ClearData()

        if res and 'info' in res:
            srv.logging.debug("Trapper for client=%s, item=%s, value=%s responds with %s" % (client, key, value, res['info']))

            return True
    except Exception as e:
        srv.logging.warn("Trapper responded: %s" % e)

    return False