I have successfully managed to extract some fields from the message below:
DHCPDISCOVER from f0:2f:74:1a:d8:94 circuit-id 1:f6:1:7 remote-id 8c:ea:1b:9c:f:ca via 185.x.x.2: network 185.x.x.0/24: no free leases
Now I am facing a problem that the extracted remote-id field (which is the MAC address 8c:ea:1b:9c:f:ca) comes with stripped leading zeros (5th octet in this case).
I was hoping I could possibly use a pipeline or any other feature to update and add the leading zeros so it looks like this:
8c:ea:1b:9c:0f:ca and override that field with updated value.
I would appreciate if someone can point me out which function would help me accomplish my goal.
Thanks @gsmith for sharing this. This is a different problem as this guy had a problem with catching the MAC address via regex and I have accomplished this via GROK pattern.
I am step ahead. I am trying to enrich my extracted MAC address to add the leading zero wherever it’s missing (unfortunately the dhcpd truncates the leading zeros…) and I am not sure how to do it.
I came up with a logic that I would split the MAC address into 6 octets (which I did using the split function and that’s where I am stuck), then I would probably check which octet is a single character and I would add a 0 in front of it. Then join it all together.
I am not very language scripting person so I am looking for someone to give me a hint on which functions should I look into.
I would look at the regex_replace() function where you are looking for a single number/letter surrounded by “:”… you may want to temporarily attach a : to both ends to make the regex easier - or you could break it into constituent pieces and regex_replace each if it only finds one number/letter… oh for looping in graylog rules … its ugly but it could work.
@tmacgbay that’s definitely a way to go.
This is the test code for now:
let octet = split(":", to_string($message.dhcpd_remote_id));
let regex0 = regex_replace("^([0-9a-fA-F])$",to_string(octet[0]),"0$1");
let regex1 = regex_replace("^([0-9a-fA-F])$",to_string(octet[1]),"0$1");
let regex2 = regex_replace("^([0-9a-fA-F])$",to_string(octet[2]),"0$1");
let regex3 = regex_replace("^([0-9a-fA-F])$",to_string(octet[3]),"0$1");
let regex4 = regex_replace("^([0-9a-fA-F])$",to_string(octet[4]),"0$1");
let regex5 = regex_replace("^([0-9a-fA-F])$",to_string(octet[5]),"0$1");
It’s ugly but it does the job. Now, is there a smarter way of joining all the regex1-5 together apart from using a concat 100x times?