[processors.starlark] Traceback (most recent call last): :2:20: in apply Error: key "pdu_n05_usv_l1-A" not in Fields

Hi, I get this error, when I try to process some data. Can anyone help me?

Here’s my config:

[[inputs.snmp]]
agents = [“udp://xxx.xxx.xxx.xxx:161”] ## PDU USV SR1 ## Agent addresses to retrieve values from.
interval = “120s”
timeout = “15s” ## Timeout for each request.
version = 2 ## SNMP version; can be 1, 2, or 3.

community = “XXXXXXX” ## SNMP community string.
retries = 3 ## Number of retries to attempt.

[[inputs.snmp.field]]
oid = “1.3.6.1.4.1.31034.12.1.1.2.8.2.1.3.5.1”
name = “PDU_USV_SR1-N05_Temp”
conversion = “float(2)”

[[inputs.snmp.field]]
oid = “1.3.6.1.4.1.31034.12.1.1.2.6.1.1.5.5.1”
name = “pdu_n05_usv_l1-A”
conversion = “float(2)”

[[inputs.snmp.field]]
oid = “1.3.6.1.4.1.31034.12.1.1.2.6.1.1.7.5.1”
name = “pdu_n05_usv_l1-V”
conversion = “float(2)”

[[processors.starlark]]
source = ‘’’
def apply(metric):
A = metric.fields[‘pdu_n05_usv_l1-A’]
V = metric.fields[‘pdu_n05_usv_l1-V’]
metric.fields[‘pdu_n05_usv_l1-VA’] = A * V
return metric
‘’’

Error: key ” ” not in Fields

You need to check that the key you are searching for exists. It looks like a metric that is passed to starlark may not have the key you are referencing.

Hi, thank you for your response.

The complete error from the logs is:
2024-06-25T18:10:00Z E! [processors.starlark] Traceback (most recent call last):
2024-06-25T18:10:00Z E! [processors.starlark] :2:26: in apply
2024-06-25T18:10:00Z E! [processors.starlark] Error: key “pdu_n05_usv_l1-A” not in Fields
2024-06-25T18:10:00Z E! [processors.starlark] Error in plugin: key “pdu_n05_usv_l1-A” not in Fields

But in my config file ist pdu_n05_usv_l1-A defined and I do get the Data from the SNMP device
if I comment out the processors.starlark section.

Again, some metrics is coming into the starlark script that doesn’t have that field then. You can use metric.fields.get() to verify if the field exists and if not you can print it out to see what it is, return the metric un-edited, or do whatever other action you want.