Hi Everyone,
I need your help with this one please.
I have a config file that is written/updated with a Python based web front
end tool. I would like to add/remove hosts to/from this config file using
Perl.
The idea I have is for Perl to read this config file, and instead of
adding/replcing values to the original config file, to re-write the config
file with the
latest hostname that was added or removed to a new config file in the same
format so that the Python based web tool can read it.
This exceeds my knowledge of Perl at the moment and hope I can learn the
ways from the Perl Masters :-)
The basic explanation of the different sections for each that exist in the
config file:
*Every hostname belongs to their own contact groups with a section:
host_contactgroups*
host_contactgroups += [ ('group1', ['hostname1']), ]
*Every host must belong to the section with other hosts: all_hosts*
all_hosts += [ "hostname1|cmk-agent|prod|lan|tcp|wato|/" + FOLDER_PATH
+ "/", ]
*Every host must belong to the section shared with other hosts:
ipaddresses.update*
ipaddresses.update({'hostname1': u'hostname1.domain.com'})
*Every host must belong to the section shared with other hosts:
extra_host_conf.setdefault*
extra_host_conf.setdefault('alias', []).extend( (u'hostname1.domain.com',
['hostname1'])])
*Finally every host must have it's own section: host_attributes.update*
host_attributes.update(
{'hostname1': {'alias': u'hostname1.domain.com',
'contactgroups': (True, ['group1', 'group2', 'group3',
'group4']),
'ipaddress': u'hostname1.domain.com',
'tag_agent': 'cmk-agent',
'tag_criticality': 'prod',
'tag_networking': 'lan'},
*The actual config file looks like this:*
host_contactgroups += [
( 'group1', ['hostname1'] ),
( 'group2', ['hostname1'] ),
( 'group3', ['hostname1'] ),
( 'group4', ['hostname1'] ),
]
host_contactgroups += [
( 'group3', ['hostname2'] ),
( 'group4', ['hostname2'] ),
]
host_contactgroups += [
( 'group3', ['hostname3'] ),
]
all_hosts += [
"hostname1|cmk-agent|prod|lan|tcp|wato|/" + FOLDER_PATH + "/",
"hostname2|test|cmk-agent|lan|tcp|wato|/" + FOLDER_PATH + "/",
"hostname3|cmk-agent|prod|lan|tcp|wato|/" + FOLDER_PATH + "/",
]
# Explicit IP addresses
ipaddresses.update({'hostname1': u'hostname1.domain.com',
'hostname2': u'hostname2.domain.com',
'hostname3': u'hostname3.domain.com'})
# Settings for alias
extra_host_conf.setdefault('alias', []).extend(
[(u'hostname3.domain.com', ['hostname3']),
(u'hostname2.domain.com', ['hostname2']),
(u'hostname1.domain.com', ['hostname1'])])
# Host attributes
host_attributes.update(
{'hostname1': {'alias': u'hostname1.domain.com',
'contactgroups': (True, ['group1', 'group2', 'group3',
'group4']),
'ipaddress': u'hostname1.domain.com',
'tag_agent': 'cmk-agent',
'tag_criticality': 'prod',
'tag_networking': 'lan'},
'hostname2': {'alias': u'hostname2.domain.com',
'contactgroups': (True, ['group3', 'group4']),
'ipaddress': u'hostname2.domain.com',
'tag_agent': 'cmk-agent',
'tag_criticality': 'test',
'tag_networking': 'lan'},
'hostname3': {'alias': u'hostname3.domain.com',
'contactgroups': (True, ['group3']),
'ipaddress': u'hostname3.domain.com',
'tag_agent': 'cmk-agent',
'tag_criticality': 'prod',
'tag_networking': 'lan'}})
Many thanks,
Wernher