Skip to content

Commit

Permalink
Make it optional to create logfiles when creating Output obj
Browse files Browse the repository at this point in the history
  • Loading branch information
AlyaGomaa committed Jan 31, 2025
1 parent bbc140b commit 76e4c0d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion managers/process_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def start_output_process(self, stderr, slips_logfile, stdout=""):
verbose=self.main.args.verbose or 0,
debug=self.main.args.debug,
input_type=self.main.input_type,
stop_daemon=self.main.args.stopdaemon,
create_logfiles=False if self.main.args.stopdaemon else True,
)
self.slips_logfile = output_process.slips_logfile
return output_process
Expand Down
10 changes: 7 additions & 3 deletions slips_files/core/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ def get_earliest_line(self):
"""
# Now read lines in order. The line with the earliest timestamp first
files_sorted_by_ts = sorted(self.file_time, key=self.file_time.get)

try:
# get the file that has the earliest flow
file_with_earliest_flow = files_sorted_by_ts[0]
Expand All @@ -344,12 +345,13 @@ def get_earliest_line(self):
self.zeek_files = self.db.get_all_zeek_files()
return False, False

# comes here if we're done with all conn.log flows and it's time to process other files
# comes here if we're done with all conn.log flows and it's time to
# process other files
earliest_line = self.cache_lines[file_with_earliest_flow]
return earliest_line, file_with_earliest_flow

def read_zeek_files(self) -> int:
self.zeek_files = self.db.get_all_zeek_files()

self.open_file_handlers = {}
# stores zeek_log_file_name: timestamp of the last flow read from
# that file
Expand Down Expand Up @@ -386,6 +388,7 @@ def read_zeek_files(self) -> int:
# Delete this line from the cache and the time list
del self.cache_lines[file_with_earliest_flow]
del self.file_time[file_with_earliest_flow]

# Get the new list of files. Since new files may have been created by
# Zeek while we were processing them.
self.zeek_files = self.db.get_all_zeek_files()
Expand Down Expand Up @@ -432,7 +435,8 @@ def read_zeek_folder(self):
self.bro_timeout = 10
growing_zeek_dir: bool = self.db.is_growing_zeek_dir()
if growing_zeek_dir:
# slips is given a dir that is growing i.e zeek dir running on an interface
# slips is given a dir that is growing i.e zeek dir running on an
# interface
# don't stop zeek or slips
self.bro_timeout = float("inf")

Expand Down
14 changes: 7 additions & 7 deletions slips_files/core/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __init__(
stderr="output/errors.log",
slips_logfile="output/slips.log",
input_type=False,
stop_daemon: bool = None,
create_logfiles: bool = True,
stdout="",
):
super().__init__()
Expand All @@ -56,15 +56,17 @@ def __init__(
self.debug = debug
self.stdout = stdout
self.input_type = input_type
self.stop_daemon = stop_daemon
self.errors_logfile = stderr
self.slips_logfile = slips_logfile
# if we're using -S, no need to init all the logfiles

if self.verbose > 2:
print(f"Verbosity: {self.verbose}. Debugging: {self.debug}")

# when we're using -S, no need to init all the logfiles
# we just need an instance of this class to be able
# to start the db from the daemon class
if not stop_daemon:
if create_logfiles:
self._read_configuration()

self.create_logfile(self.errors_logfile)
self.log_branch_info(self.errors_logfile)
self.create_logfile(self.slips_logfile)
Expand All @@ -76,8 +78,6 @@ def __init__(
utils.change_logfiles_ownership(
self.slips_logfile, self.UID, self.GID
)
if self.verbose > 2:
print(f"Verbosity: {self.verbose}. Debugging: {self.debug}")

def _read_configuration(self):
conf = ConfigParser()
Expand Down
1 change: 1 addition & 0 deletions webinterface/database/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def get_db_manager_obj(self, port: int = False) -> Optional[DBManager]:
stdout=os.path.join(output_dir, "slips.log"),
stderr=os.path.join(output_dir, "errors.log"),
slips_logfile=os.path.join(output_dir, "slips.log"),
create_logfiles=False,
)
try:
return DBManager(
Expand Down

0 comments on commit 76e4c0d

Please sign in to comment.