Your regex seems incorrect to me. You escaped the dot, but then you used *
to repeat zero or more times. Try an extra dot in your regex, un-escaped?
Better yet, don't use regular expressions to match on IP addresses if you can avoid it. Maybe iprange()
, or isipinsubnet()
would be a good fit for you.
Here I hacked at your example:
bundle agent my_test { vars: "ipregex" string => "172\.16\.1\.*"
; "ipregex2" string => "172\.16\.1\..*";
classes: "found" expression => regcmp("$(ipregex)","172.16.1.10")
; "found2" expression => regcmp("$(ipregex2)","172.16.1.10");
reports: found:: "Found the ip "
; found2:: "Found the ip2 ";
!found:: " Don't found the ip"
; !found2:: " Don't found the ip2";
} bundle agent __main__ { methods: "my_test"; }
R: Found the ip2 R: Don't found the ip
-
Dear Nick.
Thank's for your answer. I was wrong in this Regex... I forgot the ultimate point caracter that is important in a anchored regex!
And i will use the iprange, that's help me a lot in other stuff
with cfengine..
Regards!
-- Jérôme Pourquoi les établissements ouverts 24 heures sur 24 ont-ils des serrures ? (Anonyme)