Changing snmp input with regex using telegraf pulls before influxdb

At the very end of the file try and add

[[processors.converter]]
    order = 2
    [processors.converter.fields]
      integer = ["cpuPercent","memUsed"]

You need to make a change in influxdb.

influxdb is expecting a string type value to be inserted into the cpuPercent field.

When I did this, I deleted all of the previous values, and then reloaded telegraf, which inserted the results as an integer.

DELETE FROM "snmp" WHERE "agent_host" = '192.168.2.21'

then reload telegraf

sudo systemctl reload telegraf

Hello,
Not without difficulty, I managed to run the “DELETE” command and relaunch the docker telegraf container.
But after I still have the error message:
> 2020-10-21T20:03:04Z E! [outputs.influxdb] When writing to : received error partial write: field type conflict: input field “cpuPercent” on measurement “snmp.HIK” is type integer, already exists as type string dropped=4; discarding points
> 2020-10-21T20:04:04Z E! [outputs.influxdb] When writing to : received error partial write: field type conflict: input field “memUsed” on measurement “snmp.HIK” is type integer, already exists as type string dropped=4; discarding points

So I tell myself that deleting the data is not enough. Wouldn’t it be rather the “snmp” table that had to be deleted and then rebuilt so that the “cpuPercent” and “memUsed” fields are created as numeric and not as strings?
If this is indeed it, then what are the instructions for dropping and rebuilding the “snmp” table?
Also, I deleted my docker containers (influxdb, telegraf and grafana) and rebuilt them but that didn’t change the problem.
Now if I delete the influxdb database completely and rebuild my containers, will it now be created with the correct type for the “cpuPercent” and “memUsed” fields?
What is influxdb based on to create the database? What files does it reread? HIK-DEVICE-MIB? If so then shouldn’t this file also be modified?
Sorry, that’s a lot of questioning but I want to understand the process.
cordially

A few things:

When I look back through your config, you are polling multiple devices.

agents = [  "192.168.2.21", "192.168.2.22", "192.168.2.23", "192.168.2.24" ]

You would need to do the delete for each IP

DELETE FROM "snmp" WHERE "agent_host" = '192.168.2.21'
DELETE FROM "snmp" WHERE "agent_host" = '192.168.2.22'
DELETE FROM "snmp" WHERE "agent_host" = '192.168.2.23'
DELETE FROM "snmp" WHERE "agent_host" = '192.168.2.24'

Yes, you can delete the table (or DROP the measurement as it is referred to in influxdb) but I did not want to instruct you to do that in case you had other data in that table you did not want to lose.

Influxdb “creates the table” based on what telegraf sends it. It automatically creates the fields (columns) based on the data it receives.

Stop telegraf, run all of the DELETE statements, or delete the table (DROP the measurement), then start telegraf back up.

Be careful that whatever data you send is formatted correctly, if you fix the telegraf statement for one IP, but the others are still sending strings, and they send the data first, the table will be created with strings once again.

Hello,
Yes, I have deleted the data for each agent declared.
I also did a “DROP MEASUREMENT” snmp ".
Then I relaunched the telegraf container and there: BINGO !!!
It is now working perfectly and I am recovering good numeric data for my two fields. GREAT !!!
Huge THANKS to you scikriffs for helping me solve this problem. THANKS also for your patience and for the time spent. I really appreciate.
cordially

That is great news! Glad to help.

@sickriffs
Hi,
I come back to you, because since the recently update of the telegraf image of version 1.17.3 to 1.18, I note that the [[prossessor.converter]] no longer works. I have no conversion to Integer.
For the following memory, here is the code included in my ‘telegraf.conf’ file that worked very well with version 1.17.3.

[[processors.strings]]
  order = 1
  # namepass = ["snmp"]
  [[processors.strings.trim]]
    field = "cpuPercent"
  [[processors.strings.trim]]
    field = "memUsed"
  [[processors.strings.trim_suffix]]
    field = "cpuPercent"
    suffix = "PERCENT"
  [[processors.strings.trim_suffix]]
    field = "memUsed"
    suffix = "PERCENT"
[[processors.converter]]
  order = 2
  [processors.converter.fields]
    integer = ["cpuPercent","memUsed"]

The only difference with the new version 1.18 is that I just commented on the ‘namepass’ line that generated a bug with the [[prossessors.strings]] (no more transformation of the initial value ‘10 PERCENT’ into ‘10’).

Would you please have an idea to suggest to solve this problem of conversion into Integer?
Thank you for your reply
cordially :grinning:

Hi,
Finally, with a little a lot of obstinacy I found it alone :innocent:, my mistake.
The [[processors.strings.trim]] part did not delete all ‘space’ and the chain after the [[processors.strings.trim_suffix]] with the '“PERCENT” suffix produced in the end the chain "10 " which does not could be converted to interger.
So I changed my code by this:

[[processors.strings]]
  order = 1
  [[processors.strings.trim_suffix]]
    field = "cpuPercent"
    suffix = " PERCENT"
  [[processors.strings.trim_suffix]]
    field = "memUsed"
    suffix = " PERCENT"
[[processors.converter]]
  order = 2
  [processors.converter.fields]
    integer = ["cpuPercent","memUsed"]

And now the conversion into Integer is effective. It’s great :hugs:
Hoping that this misadventure will be useful to others 

cordially :grinning: