Trimming values from tags


I need to trim trailing values from some tags. I know i can use something like {{index .Fields “Percent_Free_Space” | printf “%0.2f”}}% to trim the value to decimal places no problem, however i am not trying to do this with a field.

In my templates i turn my fields into tags and create an alert payload (this was the cleanest way to get data into MS Flow) so i end up with something like this
|eval(lambda: float(“Free_Megabytes”),
lambda: float(“Free_Megabytes” / 1024.0),
lambda: float(“Percent_Free_Space”),
lambda: string(“Percent_Free_Space”), // Var1
lambda: string(host), //Var2
lambda: string(float(“Free_Megabytes” / 1024.0)), //Var3
lambda: string(source), // Alert Source
lambda: string(metric), // Alert Metric
lambda: string(unit), // Unit - %, MB, GB, Seconds, Minutes
lambda: string(module), // Module - Agent
lambda: string(priority)

Now in my alert message, the {{index .Fields}} method works fine and the value is trimmed, however the value in Var1 and Var3 tags contains too many digits. I can’t use the message or fields from Kapacitor in the MS API, its a nightmare to parse the JSON efficiently.

How can i remove the trailing values for Var1 and Var3 so i end up with a cleaner number?

Hello @philb,
Have you checked out the strings plugin at all? Could that be a solution for you?

Hi @Anaisdg

I’ve had a look at the string processor (we’re using it to force all tags to uppercase at the moment) but I’m not sure how i would use it for this.

i get values like 12.5339 which is converted to a tag, idealy this value would be closer to 12.5

I see i can use trim_right and provide a cutset. If i use the decimal point though as the cut set then i would get the value 12 with everything else removed