in elkserver/docker/redelk-base/redelkinstalldata/scripts/modules/enrich_synciplists/module.py [0:0]
def get_cfg_ips(self, iplist):
"""Gets the list of IPs present in the config file"""
cfg_iplist = []
fname = f"/etc/redelk/iplist_{iplist}.conf"
# Check first if the local config file exists; if not, skip the sync
if not os.path.isfile(fname):
self.logger.warning(
"File %s doesn't exist, skipping IP list sync for this one.", fname
)
return None
with open(fname, "r", encoding="utf-8") as config_file:
content = config_file.readlines()
for line in content:
ip_match = re.match(IP_CIDR_RE, line)
if ip_match:
cfg_iplist.append(
(ip_match.group(1), ip_match.group(len(ip_match.groups())))
)
else:
ip_match = re.match(IP_RE, line)
if ip_match:
cfg_iplist.append(
(
f"{ip_match.group(1)}/32",
ip_match.group(len(ip_match.groups())),
)
)
return cfg_iplist