remove topic prefix

This commit is contained in:
Daniel Chote 2019-10-15 12:43:32 -04:00
parent 35371304d0
commit 44671ac3cd
4 changed files with 24 additions and 21 deletions

View File

@ -37,9 +37,6 @@ var (
// ClientID is how the name of the client // ClientID is how the name of the client
ClientID string ClientID string
// TopicPrefix is just that, a prefix for the presented data keys
TopicPrefix string
// Interval is the poll interval in seconds // Interval is the poll interval in seconds
Interval int Interval int
) )

View File

@ -6,11 +6,19 @@
"oidTopics": [ "oidTopics": [
{ {
"oid": ".1.3.6.1.2.1.31.1.1.1.6.4", "oid": ".1.3.6.1.2.1.31.1.1.1.6.4",
"topic": "router/bytesIn" "topic": "network/router/interfaces/wan/bytesIn"
}, },
{ {
"oid": ".1.3.6.1.2.1.31.1.1.1.10.4", "oid": ".1.3.6.1.2.1.31.1.1.1.10.4",
"topic": "router/bytesOut" "topic": "network/router/interfaces/wan/bytesOut"
},
{
"oid": ".1.3.6.1.2.1.31.1.1.1.6.2",
"topic": "network/router/interfaces/lan/bytesIn"
},
{
"oid": ".1.3.6.1.2.1.31.1.1.1.10.2",
"topic": "network/router/interfaces/lan/bytesOut"
} }
] ]
}, },
@ -20,11 +28,11 @@
"oidTopics": [ "oidTopics": [
{ {
"oid": ".1.3.6.1.4.1.318.1.1.12.2.3.1.1.2.1", "oid": ".1.3.6.1.4.1.318.1.1.12.2.3.1.1.2.1",
"topic": "rackPDU/totalLoad" "topic": "power/rackPDU/outputCurrentX10"
}, },
{ {
"oid": ".1.3.6.1.4.1.318.1.1.12.1.16.0", "oid": ".1.3.6.1.4.1.318.1.1.12.1.16.0",
"topic": "rackPDU/watts" "topic": "power/rackPDU/watts"
} }
] ]
}, },
@ -34,23 +42,23 @@
"oidTopics": [ "oidTopics": [
{ {
"oid": ".1.3.6.1.4.1.318.1.1.1.3.2.1.0", "oid": ".1.3.6.1.4.1.318.1.1.1.3.2.1.0",
"topic": "rackUPS/lineVoltage" "topic": "power/rackUPS/lineVoltage"
}, },
{ {
"oid": ".1.3.6.1.4.1.318.1.1.1.4.2.4.0", "oid": ".1.3.6.1.4.1.318.1.1.1.4.2.4.0",
"topic": "rackUPS/outputCurrent" "topic": "power/rackUPS/outputCurrent"
}, },
{ {
"oid": ".1.3.6.1.4.1.318.1.1.1.2.2.1.0", "oid": ".1.3.6.1.4.1.318.1.1.1.2.2.1.0",
"topic": "rackUPS/batteryCapacity" "topic": "power/rackUPS/batteryCapacity"
}, },
{ {
"oid": ".1.3.6.1.4.1.318.1.1.1.2.2.3.0", "oid": ".1.3.6.1.4.1.318.1.1.1.2.2.3.0",
"topic": "rackUPS/batteryRuntime" "topic": "power/rackUPS/batteryRuntime"
}, },
{ {
"oid": ".1.3.6.1.4.1.318.1.1.1.2.2.2.0", "oid": ".1.3.6.1.4.1.318.1.1.1.2.2.2.0",
"topic": "rackUPS/batteryTemperature" "topic": "power/rackUPS/batteryTemperature"
} }
] ]
}, },
@ -60,23 +68,23 @@
"oidTopics": [ "oidTopics": [
{ {
"oid": ".1.3.6.1.4.1.318.1.1.1.3.2.1.0", "oid": ".1.3.6.1.4.1.318.1.1.1.3.2.1.0",
"topic": "printerUPS/lineVoltage" "topic": "power/printerUPS/lineVoltage"
}, },
{ {
"oid": ".1.3.6.1.4.1.318.1.1.1.4.2.4.0", "oid": ".1.3.6.1.4.1.318.1.1.1.4.2.4.0",
"topic": "printerUPS/outputCurrent" "topic": "power/printerUPS/outputCurrent"
}, },
{ {
"oid": ".1.3.6.1.4.1.318.1.1.1.2.2.1.0", "oid": ".1.3.6.1.4.1.318.1.1.1.2.2.1.0",
"topic": "printerUPS/batteryCapacity" "topic": "power/printerUPS/batteryCapacity"
}, },
{ {
"oid": ".1.3.6.1.4.1.318.1.1.1.2.2.3.0", "oid": ".1.3.6.1.4.1.318.1.1.1.2.2.3.0",
"topic": "printerUPS/batteryRuntime" "topic": "power/printerUPS/batteryRuntime"
}, },
{ {
"oid": ".1.3.6.1.4.1.318.1.1.1.2.2.2.0", "oid": ".1.3.6.1.4.1.318.1.1.1.2.2.2.0",
"topic": "printerUPS/batteryTemperature" "topic": "power/printerUPS/batteryTemperature"
} }
] ]
} }

View File

@ -25,7 +25,6 @@ Options:
--endpoints_map=<endpoints_map> SNMP Endpoints Map File [default: ./endpoints.json] --endpoints_map=<endpoints_map> SNMP Endpoints Map File [default: ./endpoints.json]
--server=<server> MQTT server host/IP [default: 127.0.0.1] --server=<server> MQTT server host/IP [default: 127.0.0.1]
--port=<port> MQTT server port [default: 1883] --port=<port> MQTT server port [default: 1883]
--topic=<topic> MQTT topic prefix [default: snmp]
--clientid=<clientid> MQTT client identifier [default: snmp] --clientid=<clientid> MQTT client identifier [default: snmp]
--interval=<interval> Poll interval (seconds) [default: 5] --interval=<interval> Poll interval (seconds) [default: 5]
-h, --help Show this screen. -h, --help Show this screen.
@ -42,11 +41,10 @@ Options:
config.Server, _ = args.String("--server") config.Server, _ = args.String("--server")
config.Port, _ = args.Int("--port") config.Port, _ = args.Int("--port")
config.TopicPrefix, _ = args.String("--topic")
config.ClientID, _ = args.String("--clientid") config.ClientID, _ = args.String("--clientid")
config.Interval, _ = args.Int("--interval") config.Interval, _ = args.Int("--interval")
log.Printf("server: %s, port: %d, topic prefix: %s, client identifier: %s, poll interval: %d", config.Server, config.Port, config.TopicPrefix, config.ClientID, config.Interval) log.Printf("server: %s, port: %d, client identifier: %s, poll interval: %d", config.Server, config.Port, config.ClientID, config.Interval)
} }
// sigChannelListen basic handlers for inbound signals // sigChannelListen basic handlers for inbound signals

View File

@ -73,7 +73,7 @@ func Init() {
} }
log.Printf("%s = %s", oidTopic.Topic, convertedValue) log.Printf("%s = %s", oidTopic.Topic, convertedValue)
token := client.Publish(config.TopicPrefix+"/"+oidTopic.Topic, 0, false, convertedValue) token := client.Publish(oidTopic.Topic, 0, false, convertedValue)
token.Wait() token.Wait()
if token.Error() != nil { if token.Error() != nil {