From bcf376ab82405c7c78027b06029c588209520ba3 Mon Sep 17 00:00:00 2001 From: Vadim Troshchinskiy Date: Mon, 16 Dec 2024 13:07:28 +0100 Subject: [PATCH] Make log filename machine-dependent Move kernel args parsing --- gitlib/gitlib.py | 32 ++++++++++---------------------- gitlib/kernel.py | 22 ++++++++++++++++++++++ 2 files changed, 32 insertions(+), 22 deletions(-) create mode 100644 gitlib/kernel.py diff --git a/gitlib/gitlib.py b/gitlib/gitlib.py index d182a90..ce91fd0 100755 --- a/gitlib/gitlib.py +++ b/gitlib/gitlib.py @@ -291,28 +291,7 @@ class OpengnsysGitLibrary: f.write("\n".join(self.default_ignore_list)) f.write("\n") - def _parse_kernel_cmdline(self): - """Parse the kernel arguments to obtain configuration parameters in Oglive - OpenGnsys passes data in the kernel arguments, for example: - [...] group=Aula_virtual ogrepo=192.168.2.1 oglive=192.168.2.1 [...] - - Returns: - dict: Dict of configuration parameters and their values. - """ - params = {} - self.logger.debug("Parsing kernel parameters") - - with open("/proc/cmdline", encoding='utf-8') as cmdline: - line = cmdline.readline() - parts = line.split() - for part in parts: - if "=" in part: - key, value = part.split("=") - params[key] = value - - self.logger.debug("%i parameters found", len(params)) - return params @@ -1544,6 +1523,9 @@ if __name__ == '__main__': # esto arregla las tildes y las eñes sys.stdout.reconfigure(encoding='utf-8') + kernel_args = parse_kernel_cmdline() + + opengnsys_log_dir = "/opt/opengnsys/log" logger = logging.getLogger(__package__) @@ -1555,7 +1537,13 @@ if __name__ == '__main__': if not os.path.exists(opengnsys_log_dir): os.mkdir(opengnsys_log_dir) - logFilePath = f"{opengnsys_log_dir}/gitlib.log" + ip_address = "unknown" + if "ip" in kernel_args: + ip_address = kernel_args["ip"].split(":")[0] + + + logFilePath = f"{opengnsys_log_dir}/{ip_address}.gitlib.log" + fileLog = logging.FileHandler(logFilePath) fileLog.setLevel(logging.DEBUG) diff --git a/gitlib/kernel.py b/gitlib/kernel.py new file mode 100644 index 0000000..f0a7eb2 --- /dev/null +++ b/gitlib/kernel.py @@ -0,0 +1,22 @@ + + +def parse_kernel_cmdline(): + """Parse the kernel arguments to obtain configuration parameters in Oglive + + OpenGnsys passes data in the kernel arguments, for example: + [...] group=Aula_virtual ogrepo=192.168.2.1 oglive=192.168.2.1 [...] + + Returns: + dict: Dict of configuration parameters and their values. + """ + params = {} + + with open("/proc/cmdline", encoding='utf-8') as cmdline: + line = cmdline.readline() + parts = line.split() + for part in parts: + if "=" in part: + key, value = part.split("=") + params[key] = value + + return params \ No newline at end of file