Splunk Search

How to write the regex for multivalue field extraction (a list of IP addresses) for a very large event?

rubeniturrieta
Communicator

Hi to everyone:

I have a single event with 15,394 lines, and i can't write a regular expression for a field extraction (a list of ip addresses), like it can be seen in the attachment.

alt text

I have this:

//// a lot of lines
servidores
{
and
{
or
{
ip
{
ip1
ip2
ip3
}
}
}
/// another lot of lines 

And I need this:

field: ip
values: ip1, ip2 and ip3

How can I write this regular expression?

Any help, i'll be very grateful.

Regards

0 Karma
1 Solution

somesoni2
Revered Legend

Try something like this

Updated*

- props.conf
[YourSourcetype]
...other configurations...
EXTRACT-servidoresip = servidores([\r\n])\{([\r\n])and([\r\n])\{([\r\n])or([\r\n])\{\s*ip\s*\{(?<IP>[^\}]+)
REPORT-extract_ipaddresses = extract_ipaddresses


- transforms.conf
    [extract_ipaddresses]
SOURCE_KEY = IP
REGEX = (\d+\.\d+\.\d+\.\d)
FORMAT = ip::$1
MV_ADD = true

Sample test data used:

servidores1
{
and
{
or
{
ip
{
 54.54.54.54
 55.55.55.55
 66.66.66.66
}
}
}
servidores
{
and
{
or
{
ip
{
 10.10.10.10
 11.11.11.11
 12.12.12.12
}
}
}
servidores2
{
and
{
or
{
ip
{
 54.54.54.54
 55.55.55.55
 66.66.66.66
}
}
}

View solution in original post

somesoni2
Revered Legend

Try something like this

Updated*

- props.conf
[YourSourcetype]
...other configurations...
EXTRACT-servidoresip = servidores([\r\n])\{([\r\n])and([\r\n])\{([\r\n])or([\r\n])\{\s*ip\s*\{(?<IP>[^\}]+)
REPORT-extract_ipaddresses = extract_ipaddresses


- transforms.conf
    [extract_ipaddresses]
SOURCE_KEY = IP
REGEX = (\d+\.\d+\.\d+\.\d)
FORMAT = ip::$1
MV_ADD = true

Sample test data used:

servidores1
{
and
{
or
{
ip
{
 54.54.54.54
 55.55.55.55
 66.66.66.66
}
}
}
servidores
{
and
{
or
{
ip
{
 10.10.10.10
 11.11.11.11
 12.12.12.12
}
}
}
servidores2
{
and
{
or
{
ip
{
 54.54.54.54
 55.55.55.55
 66.66.66.66
}
}
}

rubeniturrieta
Communicator

Thank you very much someoni2, but I have several lists of IP addresses that correspond to different fields in the same event. How would it be then?

0 Karma

somesoni2
Revered Legend

So do you have any prefix or pattern before/after the list of IP you want to extract?

rubeniturrieta
Communicator

Yes, in the example, the word "servidores" is identifier for the field, and the regular pattern is

  "
and
{
or
{
ip
{
"

0 Karma

somesoni2
Revered Legend

See if the updated answer works for you. I'm extracting a temp field to get section servicedores and then getting a mv field with IP addresses present in it.

rubeniturrieta
Communicator

Wow, thanks you somesoni2, but it doesn't works yet for me, but i think you are very close. Maybe something about space characters?

    servidores
    {
        and
        {
            or
            {
                ip
                {
                    168.88.13.6
                    168.88.11.164
                    168.88.13.29
                    168.88.13.39
                    168.88.13.60
                    168.88.13.150
                    168.88.13.115

rubeniturrieta
Communicator

Yes, it was the space character. Thanks you very much somesoni2.

0 Karma
Get Updates on the Splunk Community!

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...

Detecting Remote Code Executions With the Splunk Threat Research Team

REGISTER NOWRemote code execution (RCE) vulnerabilities pose a significant risk to organizations. If ...

Observability | Use Synthetic Monitoring for Website Metadata Verification

If you are on Splunk Observability Cloud, you may already have Synthetic Monitoringin your observability ...