I am using Notepad ++ and I would like to ask for help to achieve the following.
I have several (several 1000 lines) Nagios / Icinga configurations that look like this:
define host {
use generic-host
host_name FakeNameA-748-SomeNameA
alias FakeNameA-748-SomeNameA
address 10.1.1.97
}
define host {
use generic-host
host_name H548-AP02
alias H548-AP02
address 172.19.115.190
}
define host {
use generic-host
host_name FakeNameB-302-SomeNameB
alias FakeNameB-302-SomeNameB
address 192.168.149.1
}
define host {
use generic-host
host_name FakeNameC-902-Acronym
alias FakeNameC-902-Acronym
address 192.168.48.1
}
define host {
use generic-host
host_name H902-AP01
alias H902-AP01
address 192.168.48.190
}
I need to create some host groups containing all host names, but in two groups.
Like this:
define hostgroup {
hostgroup_name GroupA
alias GroupA
members FakeNameA-748-SomeNameA,FakeNameB-302-SomeNameB,FakeNameC-902-Acronym
}
define hostgroup {
hostgroup_name GroupB
alias GroupB
members H548-AP02,H902-AP01
}
As you can see, if "host_name" contains "AP", it should go to GroupB and everything else in GroupA (note that they must be separated by commas).
Does anyone have any idea how I can automate this?
Thank you for your time:)
source
share