Help starlark simple script

Hi all,
I would like to calculate directly in telegraf the percentage of memory occupied on my devices (procurve switch).
I would like to do this using starlark.
Here is my configuration file “test.conf”
[[inputs.snmp]]
agents = [ “10.0.0.250:161” ]
version = 2
community = “public”
interval = “60s”
timeout = “10s”
retries = 3

[[inputs.snmp.field]]
name = “MemoryUsed”
oid = “SNMPv2-SMI::enterprises.11.2.14.11.5.1.1.2.1.1.1.5.1”

[[inputs.snmp.field]]
name = “MemoryTotal”
oid = “SNMPv2-SMI::enterprises.11.2.14.11.5.1.1.2.1.1.1.7.1”

[[processors.starlark]]
source = ‘’’
def apply(metric):
used = float(metric.fields[‘MemoryUsed’])
total = float(metric.fields[‘MemoryTotal’])
metric.fields[‘usage’] = (used / total) * 100
return metric

To do the tests I run this command:
telegraf --test --config /etc/telegraf/telegraf.d/test.conf -debug

and this is the output:
2021-09-16T13:44:06Z I! Starting Telegraf 1.19.3

2021-09-16T13:44:06Z D! [agent] Initializing plugins

2021-09-16T13:44:06Z E! [telegraf] Error running agent: could not initialize processor starlark: processor.starlark:1:8: got indent, want primary expression

What am I doing wrong?

Thanks

Hello @pietro.ficeli,
You just have a indent problem see this community question for an example of how to fix it:

source = '''
def apply(metric):
    used = float(metric.fields[‘MemoryUsed’])
    total = float(metric.fields[‘MemoryTotal’])
    metric.fields[‘usage’] = (used / total) * 100
    return metric

I believe that should work.