From efdf80cd8a316f28c8ab6d40646254875bb724a4 Mon Sep 17 00:00:00 2001 From: vitrinekast Date: Tue, 26 Mar 2024 23:12:47 +0100 Subject: [PATCH] do groupadd_today_log --- script.py | 19 +++++++++++++------ templates/book.jinja | 17 ++++++++--------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/script.py b/script.py index e670d63..ce67851 100644 --- a/script.py +++ b/script.py @@ -58,7 +58,14 @@ ip_address = run_command(['awk', '$1 == "inet" {gsub(/\/.*$/, "", $2); print $2} print("start running the service commands, this sometimes takes longer"); logins_today_log = subprocess.run(["sudo", "journalctl","_COMM=systemd-logind", "-S", "today", "-g", "New session" ], check=True, capture_output=True) -logins_today = run_command(['grep', '-v', "Boot"], based=logins_today_log.stdout).splitlines() + + +# TODO: merge into one command and then grep the various _COMM\s, wrap in a function +groupadd_today_log = subprocess.run(["sudo", "journalctl", "-S","today","_COMM=groupadd","-r"], check=True, capture_output=True) +groupremove_today_log = subprocess.run(["sudo", "journalctl", "-S","today","_COMM=groupremove","-r"], check=True, capture_output=True) +usermod_today_log = subprocess.run(["sudo", "journalctl", "-S","today","_COMM=usermod","-r"], check=True, capture_output=True) +userdel_today_log = subprocess.run(["sudo", "journalctl", "-S","today","_COMM=userdel","-r"], check=True, capture_output=True) + kitchen_services = run_command(["sudo", "journalctl", "-S", "today", "-u", "kitchen-stove.service", "-u", "kitchen-bin.service", "-u", "kitchen-fridge.service", "-r", "-n"]).splitlines() # loading the jinja template environment @@ -85,17 +92,17 @@ output = template.render( days_since_last_boot = time_since_last_boot.days, kitchen_services = kitchen_services, ip_address = ip_address, - logins_today = logins_today, + logins_today = run_command(['grep', '-v', "Boot"], based=logins_today_log.stdout).splitlines(), list_groups = run_command(["getent","group"]).splitlines(), list_active_services = run_command(["sudo", "service", "--status-all"]).splitlines(), debian_version = run_command(["cat", "/etc/debian_version"]), kernel_version = run_command(["uname","-a"]), hostname = run_command(["hostname","-i"]), - groups_created = run_command(["sudo", "journalctl", "-S","today","_COMM=groupadd","-r"]).splitlines(), - groups_removed = run_command(["sudo", "journalctl", "-S","today","_COMM=groupremove","-r"]).splitlines(), - user_modified = run_command(["sudo", "journalctl", "-S","today","_COMM=usermod","-r"]).splitlines(), - user_deleted = run_command(["sudo", "journalctl", "-S","today","_COMM=userdel","-r"]).splitlines(), + groups_created = run_command(['grep', '-v', "Boot"], based=groupadd_today_log.stdout).splitlines(), + groups_removed = run_command(['grep', '-v', "Boot"], based=groupremove_today_log.stdout).splitlines(), + user_modified = run_command(['grep', '-v', "Boot"], based=usermod_today_log.stdout).splitlines(), + user_deleted = run_command(['grep', '-v', "Boot"], based=userdel_today_log.stdout).splitlines() ) diff --git a/templates/book.jinja b/templates/book.jinja index 2409c21..eaa81ac 100644 --- a/templates/book.jinja +++ b/templates/book.jinja @@ -208,15 +208,14 @@ user_deleted : {{ user_deleted }} {% if logins_today is defined %} - - does not show the users of logins_today - - These users have logged into our shared server chopchop, during the course of this day. - + {{ log_output(logins_today) }} + {% if logins_today|length > 0 %} + + These users have logged into our shared server chopchop, during the course of this day. + + {% else %} + it was quiet today. + {% endif %} {% endif %} {% if groups_created|length > 0 %}