Input strings in double quotes not handled properly

Hi everyone,

I’m debugging an issue with returning strings from OIDs wich are wrapped in double quotes.
First things first.

Telegraf Version: 1.27.4 with influxdb2

This is my snmp target config

# CW1
  ## Agent addresses to retrieve values from.
  agents = [""]

  ## Timeout for each request.
  timeout = "5s"

  version = 2
  community = "stats"

    name = "SysName"
    oid = ""
    is_tag = true

    oid = ""
    name = "chillerstatus"

    oid = ""
    name = "Compressor Utilization"

  ## Trim leading characters in cutset
     field = "chillerstatus"
     cutset = "\""

  ## Trim trailing characters in cutset
     field = "chillerstatus"
     cutset = "\""

  command = "/opt/scripts/"
  data_format = "influx"

As you can see I already tried using string trim.
I also used regex before and even external scripts to remove double quotes.
The thing is, if I set the cutset to “N” instead of “"” it cuts the first letter as exptected.

This is the output from snmpwalk (same with snmpget)

root@grafana-dc:~# snmpwalk -v2c -c stats
iso. = STRING: “Normal with Warning”

root@grafana-dc:~# snmpget -v2c -c stats
iso. = STRING: “Normal with Warning”

I got a ton of strings to handle wich are all wrapped in double quotes and as far as I understand the code correctly, the double quotes should be removed here:

if conv == "" {
    // Handle cases where no conversion is specified (e.g., default string handling).
    // If the SNMP value is []byte, it's converted to a string.
    if bs, ok := ent.Value.([]byte); ok {
        return string(bs), nil
    return ent.Value, nil

But somehow they are still present.
Futhermore they even get preserved!

I also configured an external script as an input (as you can see in my config above)

This script does it simply:


# Run snmpwalk and format output as InfluxDB line protocol
output=$(snmpwalk -v2c -c stats | awk -F': ' '{gsub(/"/, "", $2); gsub(/ /, "_", $2); print "snmp chillerstatus=\"" $2 "\""}')

# Print output
echo "$output"

And even then the double quotes are still present.

This is the output from the test run:

root@grafana-dc:~# telegraf  --test | grep snmp
2023-08-31T07:27:34Z I! Loading config: /etc/telegraf/telegraf.conf
2023-08-31T07:27:34Z I! Starting Telegraf 1.27.4
2023-08-31T07:27:34Z I! Available plugins: 237 inputs, 9 aggregators, 28 processors, 23 parsers, 59 outputs, 4 secret-stores
2023-08-31T07:27:34Z I! Loaded inputs: cpu disk diskio ethtool exec ipmi_sensor ipset kernel mem processes snmp (7x) swap system
2023-08-31T07:27:34Z I! Loaded aggregators: 
2023-08-31T07:27:34Z I! Loaded processors: strings
2023-08-31T07:27:34Z I! Loaded secretstores: 
2023-08-31T07:27:34Z W! Outputs are not used in testing mode!
2023-08-31T07:27:34Z I! Tags enabled: host=grafana-dc
> snmp,SysName=environment-HV-USV,agent_host=,host=grafana-dc HV-USV\ -\ Humidity=39.9,HV-USV\ -\ Temperatur=24.2 1693466855000000000
> snmp,host=grafana-dc chillerstatus="Normal_with_Warning" 1693466855000000000
> snmp,SysName=CW\ 1,agent_host=,host=grafana-dc Compressor\ Utilization=25,chillerstatus="Normal with Warning" 1693466855000000000
> snmp,SysName=sensor2,agent_host=,host=grafana-dc A.C5\ -\ Raised\ Floor\ Humidity=61,A.C5\ -\ Raised\ Floor\ Temp=17 1693466855000000000
> snmp,SysName=sensor3,agent_host=,host=grafana-dc A.Q1\ -\ Raised\ Floor\ Temp=17.5,A.T2\ -\ Raised\ Floor\ Temp=16.6 1693466855000000000
> snmp,SysName=sensor1,agent_host=,host=grafana-dc Routing\ -\ Raised\ Floor\ Temp=17.3,Routing\ -\ Room\ Temp=26.5 1693466855000000000
> snmp,SysName=Sensor-Raum-C,agent_host=,host=grafana-dc Raum\ C\ -\ Raised\ Floor\ Temp=17.3,Raum\ C\ -\ Room\ Temp=25.1 1693466855000000000
> snmp,SysName=environment-sensor-NSHV,agent_host=,host=grafana-dc NSHV\ -\ Humidity=48.6,NSHV\ -\ Temperatur=23.4 1693466855000000000

In both approaches with trims or with external script the double quotes are still present and as a result not parsed to influx.

Is there any workaround I can build to address this issue?
Any help would be much appreciated.


chillerstatus=“Normal with Warning”

It is not the OID that is wrapped in double quotes, it is the value, which is a string. Strings needs to be in quotes :wink:

TLDR but in the past I have used unicode to get specific “null” string characters from a device. maybe this could be a hint in the right direction?

   	key = "String"
   	pattern = '\x00'
   	replacement = ""