Technical Forum
Ask questions. Discover Answers.
cancel
Showing results for 
Search instead for 
Did you mean: 

Log matched/detected pattern in switch statement.

Akshay_SK
Nimbostratus
Nimbostratus

I have been trying to write a security iRule for my organization that provides a basic security. Here is my code snippet where I am matching the useragent value with the provided patterns.

 

switch -glob $useragent {

"*havij*" -

"*zmeu*" -

"*sqlmap*" {

 

            log local0. "Blocking this request due to detected user agent : "

 

reject

}

}

 

How do I print the detected pattern here? If I try to print the $useragent, I will be logging the entire useragent value instead of only the detected pattern. Any help would be greatly appreciated.

1 REPLY 1

Hello Akshay.

It's no possible to do it that way. You should differentiate each pattern.

switch -glob $useragent {
	"*havij*" {
		log local0. "Blocking this request due to detected user agent : *havij*"
		reject
	}
	"*zmeu*" {
		log local0. "Blocking this request due to detected user agent : *zmeu*"
		reject
	}
	"*sqlmap*" {
		log local0. "Blocking this request due to detected user agent : *sqlmap*"
		reject
	}
}

Regards,

Dario.

Regards,
Dario.