Hello, and thank you in advance for any help you may provide.
I have influxdb and telegraf running and collecting data.
I have a question about using regex to change the results of an snmp pull from an IP camera.
The results I get for some of the fields contain the word PERCENT with the data. So, instead of getting just a numerical value of “10”, I get “10 PERCENT.”
I have been using [[processors.regex]] to try and get rid of the “PERCENT” but I seem to be missing something.
Oh well, this is interesting, but sadly I can’t tell you why that happens, I can only guess. (The syntax itself is correct, and to me, it should work.)
A test I would do is to change the converter data type, to a different one (you are the one who knows which is the appropriate data type so pick the best one)
If you remove the converter plugin which result do you get?
it should be a number, but of string data type… so not really useful. that said, try to do so, maybe in the value there is an invalid char or something and that breaks the converter processor.
You might consider opening an issue on github for the panic error you are getting (and if you don’t I will)
I think the problem you’re having with the pattern/replacement config here is that you can’t use ${1} without including the selector parenthesis ( ) around the part of the regex you’re trying to select. eg: pattern = "([^0-9]+)"
In case someone stumbles on this thread and is looking for the answer.
Something to note, the plugin portion [[processors.regex]] and [processors.converter]] needs to be at the end of the file, after all of the [[inputs.snmp.field]] parts (if you have multiple)
I had the regex incorrect, which is corrected below.
The namepass portion was also incorrect, corrected below. The namepass should reference the inputs portions, and then the key, references the name of the inputs.snmp
Here was the solution:
[[inputs.snmp.field]]
name="cpuPercent"
oid = "HIK-DEVICE-MIB::cpuPercent.0"
[[processors.regex]]
order = 1
namepass = ["snmp"]
[[processors.regex.fields]]
key = "cpuPercent"
pattern = "^(\\d+).*"
replacement = "${1}"
[[processors.converter]]
order = 2
[processors.converter.fields]
integer = ["cpuPercent"]
Hello,
Sorry for my bad english (google translate is my friend) and i am a beginner.
I reproduced your example of conversion solution for the “cpuPercent” field like this:
So I conclude that the value extracted by [[proccessors.regex]] is not a string which can then be converted into Integer by [[proccessors.converter]].
Shouldn’t the pattern instead be: “^(\d{1,2})” to return a string of numbers?
I just wish I could retrieve the “XX” value as a numeric of the “XX PERCENT” value from the cupPercent and memUsed fields to keep track of it over time on a graph.
Please, can you explain to me what I need to do to fix this error.
Thank you for your kind response.
Cordially.
Hello,
Sorry, but I’m a little lost there.
I have remove all of the previous conversion portions. Then I have inserted this at the end of telegraf.conf file:
> [[processors.strings]]
> order = 1
> namepass = "snmp"
> [[processors.strings.left]]
> field = "cpuPercent"
> width = 2
> [[processors.strings.trim]]
> field = "cpuPercent"
> [[processors.strings.left]]
> field = "memUsed"
> width = 2
> [[processors.strings.trim]]
> field = "memUsed"`
I run the test and it produce thoses working results:
I am getting the correct values for cpuPercent and memUsed but they are not numeric.
If in addition, I add the portion [[processors.converter]] then telegraf fails with error.
Now , how then to convert this string to integer?
Cordially