diff --git a/script.py b/script.py index a16c164..1a64edc 100644 --- a/script.py +++ b/script.py @@ -74,21 +74,22 @@ list_package_upgrade = subprocess.run(["grep","-E", dpkg_date + '.*upgrade|upgra list_package_remove = subprocess.run(["grep","-E", dpkg_date + '.*remove|remove.*' + dpkg_date, "/var/log/dpkg.log"], capture_output=True).stdout.decode('UTF-8').splitlines() 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_log = subprocess.run(["sudo", "journalctl","_COMM=systemd-logind", "-g", "New session" ] + get_journalctl_on(), check=True, capture_output=True) # journalctl --utc +# TODO this is not working with the time ago. name should be grepped from user_created_today last_user_added = subprocess.run(["sudo", "journalctl","_COMM=useradd","-r","-n", "1" , "--output-fields=MESSAGE"], capture_output=True) last_user_added_name = run_command(['grep', '-Po', "(?<=name)\W*\K[^ ]*"], based=last_user_added.stdout) users_created_today = run_command(["sudo", "journalctl","_COMM=useradd","-r"] + get_journalctl_on()).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) +groupadd_today_log = subprocess.run(["sudo", "journalctl","_COMM=groupadd","-r"] + get_journalctl_on(), check=True, capture_output=True) +groupremove_today_log = subprocess.run(["sudo", "journalctl","_COMM=groupremove","-r"] + get_journalctl_on(), check=True, capture_output=True) +usermod_today_log = subprocess.run(["sudo", "journalctl","_COMM=usermod","-r"] + get_journalctl_on(), check=True, capture_output=True) +userdel_today_log = subprocess.run(["sudo", "journalctl","_COMM=userdel","-r"] + get_journalctl_on(), 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() +kitchen_services = run_command(["sudo", "journalctl", "-u", "kitchen-stove.service", "-u", "kitchen-bin.service", "-u", "kitchen-fridge.service", "-r", "-n"] + get_journalctl_on()).splitlines() # loading the jinja template environment print("Filling the template"); @@ -111,10 +112,10 @@ output = template.render( days_since_last_boot = time_since_last_boot, kitchen_services = kitchen_services, ip_address = ip_address, - logins_today = run_command(['grep', '-v', "Boot"], based=logins_today_log.stdout).splitlines(), list_active_services = run_command(["sudo", "service", "--status-all"]).splitlines() if not time_ago_arg else False, debian_version = run_command(["cat", "/etc/debian_version"]) if not time_ago_arg else False, hostname = run_command(["hostname","-i"]) if not time_ago_arg else False, + logins_today = run_command(['grep', '-v', "Boot"], based=logins_today_log.stdout).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(),