Conditional IF and ELIF in set processor

I'm setting the value of a field named "customer" depending on the value of field "destination.ip" via ingest pipeline. Currently I'm using two independent Set processors via ingest pipeline for IPv4 and IPv6. But it would be nicer to have it all together. So what I have now looks like that:

ctx['netflow'].containsKey('destination_ipv4_address') && ctx?.netflow?.destination_ipv4_address =~ /^(192.168.0.(1|2|3|4|5)|127.22.3.(1|2|3|4|5))$/

How could I have this condition all in one? I mean something like that:

ctx['netflow'].containsKey('destination_ipv4_address') && ctx?.netflow?.destination_ipv4_address =~ /^(192.168.0.(1|2|3|4|5)|127.22.3.(1|2|3|4|5))$/
OR
ctx['netflow'].containsKey('destination_ipv6_address') && ctx?.netflow?.destination_ipv6_address =~ /^(2a02.68.0.(1|2|3|4|5)|2a08.2.3.(1|2|3|4|5))$/

That means, that I could make one Set processor for each customer instead of making two Set processors for each customer (one for ipv4 and one for ipv6)

I managed to get it done via script proessor and the following code:

if( ctx?.netflow?.destination_ipv4_address =~ /^(8.8.8.8|9.9.9.9)$/ ) {
    ctx.customer = [ "account" : "customer1" ] ;
} else if ( ctx?.netflow?.destination_ipv6_address =~ /^(2002:37a:1bc::13|2001:37b:50d8::9)$/ ) {
    ctx.customer = [ "account" : "customer1" ] ;
}

1 Like

Beat me to it!

The processors only have a single if / conditional statement. I was about to say you should do a script but you figured it out. Awesome and thanks for posting your result. It helps other people

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.