S
S
SpeakeazyYT12019-10-16 20:09:47
linux
SpeakeazyYT1, 2019-10-16 20:09:47

How to convert messages from MQTT broker to SNMP?

Hello. I have a code written in Python that can be used to receive messages from an MQTT broker:

#!/usr/bin/python
import paho.mqtt.client as mqtt
import time
import sys

mqttusername = "***"
mqttpassword = "***"
mqttserver = "***"
mqttport = 1883

subscribe = {
    '#',
}

def on_connect(client, userdata, flags, rc):
    print('MQTT CONNECTED!')
    for topic in subscribe:
        print('mqtt subscribe on "' + topic + '"')
        client.subscribe(topic, 0)

def on_disconnect(client, userdata, rc):
    print("MQTT disconnected with code "+str(rc))
    sys.exit(1)
  
def on_message(client, userdata, msg):
    print('mqtt ' + msg.topic + ' ' + msg.payload.decode('utf-8'))

# MQTT
client = mqtt.Client(client_id="mqtt-to-snmp")
client.on_connect = on_connect
client.on_message = on_message
client.on_disconnect = on_disconnect
client.username_pw_set(mqttusername, mqttpassword)
client.connect(mqttserver, mqttport, 60)

# Update Loop
client.loop_start()
while True:
    print('...')
    time.sleep(5)
client.loop_stop()

13ad641b9f.png
The task is as follows - you need to convert received messages from the MQTT broker to SNMP and transfer them to another server. How can this be done?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Артем Пастухов, 2019-10-24
@past

Случай xyproblem.info

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question