regex for hostgroup
Posted: Fri Jun 17, 2016 1:07 pm
I have hosts with names like 'aaaaa-foo-01', 'bbbbb-foo-02' and so on. I also have a hostgroup with members defined as follows:
members ^(aaaaa|bbbbb|ccccc|ddddd|eeeee|fffff)\-foo\-[0-9]{2}$
This will match hosts aaaaa-foo-01, bbbbb-foo-02, etc. It works fine. Now we have some new hosts which we want in the same hostgroup. They have names like 'ccccc-bar-foo-01' and 'ddddd-bazz-foo-01' -- there is an additional 'field' before foo with either three or four characters. I adjusted the regex to:
members ^(aaaaa|bbbbb|ccccc|ddddd|eeeee|fffff)(\-\w{3,4}){0,1}\-foo\-[0-9]{2}$
which I believe should match both types of names, however the preflight check fails with "Error: Could not expand members specified in hostgroup (config file '/usr/local/nagios/etc/hostgroups-device.cfg', starting on line 273)"
I also tried using '.' instead of \w and got the same results.
There are ways I can work around this but I'm wondering if someone better versed with regex in Nagios can spot any red flags or if I am perhaps barking up the wrong tree.
Any insights appreciated!
k. plankton
members ^(aaaaa|bbbbb|ccccc|ddddd|eeeee|fffff)\-foo\-[0-9]{2}$
This will match hosts aaaaa-foo-01, bbbbb-foo-02, etc. It works fine. Now we have some new hosts which we want in the same hostgroup. They have names like 'ccccc-bar-foo-01' and 'ddddd-bazz-foo-01' -- there is an additional 'field' before foo with either three or four characters. I adjusted the regex to:
members ^(aaaaa|bbbbb|ccccc|ddddd|eeeee|fffff)(\-\w{3,4}){0,1}\-foo\-[0-9]{2}$
which I believe should match both types of names, however the preflight check fails with "Error: Could not expand members specified in hostgroup (config file '/usr/local/nagios/etc/hostgroups-device.cfg', starting on line 273)"
I also tried using '.' instead of \w and got the same results.
There are ways I can work around this but I'm wondering if someone better versed with regex in Nagios can spot any red flags or if I am perhaps barking up the wrong tree.
Any insights appreciated!
k. plankton