My goal is to use starlark to compare data from two different snmp agents, each with its own MIB and OID. From my limited understanding of telegraf, each row ends up with one null entry from each agent when it tries to snmpget an OID that doesn’t exist. I suspect I need to join these rows but so far I haven’t been able to figure that out. Here’s my basic config file:
[global_tags]
[agent]
interval = "5s"
round_interval = true
metric_batch_size = 1000
metric_buffer_limit = 10000
collection_jitter = "0s"
flush_interval = "5s"
flush_jitter = "0s"
precision = ""
debug = false
quiet = false
logfile = ""
hostname = ""
omit_hostname = false
#[[outputs.influxdb]]
# urls = ["http://127.0.0.1:8086"] # required
# database = "telegraf" # required
[[outputs.file]]
files = ["/tmp/starlarkTest.txt"]
[[inputs.snmp]]
agents = ["udp://UPS-DEVICE.com:161", "udp://ATS-DEVICE.com:161"]
version = 1
community = "public"
name = "starlarkTest"
[[inputs.snmp.field]]
is_tag = true
name = "sysName"
oid = "SNMPv2-MIB::sysName.0"
[[inputs.snmp.field]]
# is_tag = true
name = "upsInputSource"
oid = "XUPS-MIB::xupsInputSource.0"
# ATS Input Voltage
[[inputs.snmp.field]]
# is_tag = true
name = "atsSourceOneInputVoltage"
oid = "EATON-ATS2-MIB::ats2InputStatusVoltage.1"
[[inputs.snmp.field]]
name = "atsSourceTwoInputVoltage"
oid = "EATON-ATS2-MIB::ats2InputStatusVoltage.2"
# run a Starlark script to detect if the generator is running or not
[[processors.starlark]]
# fieldpass controls which input fields get processed. See also 'namepass, namedrop' etc.
fieldpass = ['atsSourceOneInputVoltage', 'atsSourceTwoInputVoltage', 'upsInputSource']
source = '''
def apply(metric):
if metric.fields['atsSourceOneInputVoltage'] == 1 and metric.fields['upsInputSource'] == 3:
metric.fields['generatorStatus'] = "off"
else:
metric.fields['generatorStatus'] = "unknown"
return metric
'''