Assign a text value to a number


I’m collecting information from an iDrac server using snmp. This gives me stuff like


plus a few others. The problem I’m facing is that the values for these fields are simply numbers from 1 - 6

In Grafana i can map these values to text values for my dashboards so

1 = other alert
2 = unknown alert
3= OK
4 = non critical alert
5 = critical alert
6 = non recoverable alert.

How can i assign the above text values as a tag? So when my data arrives i have say

memory-status: 1
status_name: other alert

psu-status: 6
status_name: non recoverable

I tried to use the enum processor but this invalidates my config so i thought I might be able to use Kapacitors lambda and if statements to do this but this causes the datapoints to be dropped as soon as they’re evaluated. I assume the name of the field “psu-status” is being overwritten by the value from the if statement so i can’t trigger an alert.

Any ideas?


Could you share what you tried there? That sounds like the right kind of approach using a processor to enrich the data collected before sending it on. Are you reusing the same field names/getting a data type error ?

Hi @FixTestRepeat thanks for replying

This is the config i have so far,

## Name of the field to map
field = “memory-status”

## Name of the tag to map
 #tag = ""

## Destination tag or field to be used for the mapped value.  By default the
## source tag or field is used, overwriting the original value.
dest = "status"

## Default value to be used for all values not contained in the mapping
## table.  When unset and no match is found, the original field will remain 
## unmodified and the destination tag or field will not be created.
# default = 0

## Table of mappings
  Other = 1
  Unknown = 2
  OK = 3
  nonCritical = 4
  Critical = 5
  nonRecoverable = 6 

What i think that should do though is assign the numerical value to text values. What i need to do is try it the other way around so when memory-status = 1 i get a status tag with the value “Other”

I’ve tried the above, which causes telegraf to fail to start. Also tried swapping them around so it was

1 = Other
2 = Unknown
3 = OK
4 = nonCritical
5 = Critical
6 = nonRecoverable

Ah , I’ve not used/displayed categorical data as yet. I’d be interested to see a screenshot of what you end up with, and what graphana can display.

The way you have your config currently would assume your raw data is text, and converting to numbers.

But if I understand, you want to go the other way - numbers into text, so just swap the strings and values either side of the equal sign assignments. Also note that sometimes the values you read in are in quotes instead of raw numbers, so you may need to experiment further with quotes (both sides)

1 Like

I think one of my main issues at the moment is the version of telegraf I’m running. The windows version will work with the enum plugin, but if i enable tags it fails. Our linux agent i think might be a different version, as soon as i enable the config it becomes invalid so i suspect i have the windows version where enum was introduced, which didn’t support tags. The linux version is older and doesn’t support the plugin. Which is a bugger as i’m collecting this with a linux agent.

I think i might need to sort that first.

Hello @philb,
You might find the starlark processor plugin interesting too.

Ok so I managed to get some test data coming in with powershell and exec. It seems if i pass a text value in then the processor will assign a numerical value as well. If i try the other way around then the data is just inserted as is, no text value assigned. I don;t think the processor plugin will work how i need it to.

Thanks for the suggestion @Anaisdg but after checking the documentation it looks that the version required to run that plugin hasn’t been released yet :frowning:

Next option is to try and create the values using Kapacitors lambda functions.