in DataConnectors/Syslog/Forwarder_AMA_installer.py [0:0]
def set_syslog_ng_configuration():
'''
syslog-ng has a default configuration, which enables the incoming ports and defines that
the source pipe to the daemon will verify it is configured correctly.
'''
comment_line = False
snet_found = False
with open(syslog_ng_conf_path, "rt") as fin:
with open(temp_file_path, "wt") as fout:
for line in fin:
# fount snet
if "s_net" in line and not "#":
snet_found = True
# found source that is not s_net - should remove it
elif "source" in line and "#" not in line and "s_net" not in line and "log" not in line:
comment_line = True
# if starting a new definition stop commenting
elif comment_line is True and "#" not in line and (
"source" in line or "destination" in line or "filter" in line or "log" in line):
# stop commenting out
comment_line = False
# write line correctly
fout.write(line if not comment_line else ("#" + line))
command_tokens = ["sudo", "cp", temp_file_path, syslog_ng_conf_path]
write_new_content = subprocess.Popen(command_tokens, stdout=subprocess.PIPE)
time.sleep(3)
o, e = write_new_content.communicate()
if e is not None:
handle_error(e,
error_response_str="Error: could not change syslog-ng.conf configuration in -" + syslog_ng_conf_path)
return False
if not snet_found:
append_content_to_file(line=syslog_ng_source_content, file_path=syslog_ng_conf_path)
print_ok("syslog-ng.conf configuration was changed to fit required protocol - " + syslog_ng_conf_path)
return True