Help needed with telegraf, modbus and starlark plugin

Hi Dennis,

The error you are seeing is complaining about the lack of indentation in your Starlark script.

I added indention after the apply, made sure comment lines had a #, fixed your source quote marks and changed your field identifiers to “”. I think the below will get you past that error around indent:

source = '''
def apply(metric):
    #Register 512-515 into var
    pos1 = int(metric.fields["Active energy_pos1"])
    pos2 = int(metric.fields["Active energy_pos2"])
    pos3 = int(metric.fields["Active energy_pos3"])
    pos4 = int(metric.fields["Active energy_pos4"])

    #calc new field
    metric.fields["Netz_Bezug"] = ((pos1 * 281474976710656) + (pos2 * 4294967296) + (pos3 * 65536) + pos4) / 10000

    #Register 516-519 into var
    neg1 = int(metric.fields["Active energy_neg1"])
    neg2 = int(metric.fields["Active energy_neg2"])
    neg3 = int(metric.fields["Active energy_neg3"])
    neg4 = int(metric.fields["Active energy_neg4"])

    #calc new field
    metric.fields["Netz_Einspeisung"] = ((neg1 * 281474976710656) + (neg2 * 4294967296) + (neg3 * 65536) + neg4) / 10000

    return metric

'''

Also if you add debug = true into the agent part of your config it can also help with further debugging.

Let me know if that helps, thanks!