create reusable function for the command getting

main
vitrinekast 8 months ago
parent bce6f5609c
commit 1e9dd4ba9a

@ -26,7 +26,7 @@
<header> <header>
<h1>TL;DR</h1> <h1>TL;DR</h1>
<h2>too log didn't read</h2> <h2>too log didn't read</h2>
<small>Some temp debug info: This log was generated on 2024-03-18 20:31:58.328818, the next will be available after 2024-03-18 23:31:58.328818. I now have 18 logs generated! </small> <small>Some temp debug info: This log was generated on 2024-03-18 20:48:33.398733, the next will be available after 2024-03-18 23:48:33.398733. I now have 25 logs generated! </small>
</header> </header>
<nav class="slider slider--top"> <nav class="slider slider--top">
<label for="time">time</label> <label for="time">time</label>
@ -49,13 +49,7 @@
Mar 18 17:39:07 chopchop python3[10827]: lp: No file in print request. Mar 18 17:39:07 chopchop python3[10827]: lp: No file in print request.
Mar 18 17:39:07 chopchop python3[10812]: request id is hp-color-laserjet-cp5225-16 (1 file(s)) Mar 18 17:39:07 chopchop python3[10812]: request id is hp-color-laserjet-cp5225-16 (1 file(s))
Mar 18 17:39:06 chopchop systemd[1]: Started kitchen-stove.service - Kitchen Stove Service. Mar 18 17:39:06 chopchop systemd[1]: Started kitchen-stove.service - Kitchen Stove Service.
Mar 18 17:38:33 chopchop systemd[1]: Started kitchen-bin.service - Kitchen Bin Service. Mar 18 17:38:33 chopchop systemd[1]: Started kitchen-bin.service - Kitchen Bin Service.</p>
</p>
end0:
-s
addressq
ip addr show eth0 | awk '$1 == "inet" {gsub(/\/.*$/, "", $2); print $2}'
<pre>uptime -s</pre> <pre>uptime -s</pre>
<p>2024-03-18 07:51:34</p> <p>2024-03-18 07:51:34</p>
@ -81,14 +75,13 @@ Mar 18 17:38:33 chopchop systemd[1]: Started kitchen-bin.service - Kitchen Bin S
<hr /> <hr />
<pre>users_created_today</pre> <pre>users_created_today</pre>
<p>-- No entries -- <p>-- No entries --
<span class="annotation fn-annotatation" level="1"> <span class="annotation fn-annotatation" level="1">
A level 1 annotation for users_created_today A level 1 annotation for users_created_today
</span> </span>
<pre>list_active_services</pre> <pre>list_active_services</pre>
<p> [ - ] alsa-utils <p>[ - ] alsa-utils
[ - ] apparmor [ - ] apparmor
[ + ] atop [ + ] atop
[ + ] atopacct [ + ] atopacct
@ -125,7 +118,6 @@ Mar 18 17:38:33 chopchop systemd[1]: Started kitchen-bin.service - Kitchen Bin S
[ + ] udev [ + ] udev
[ - ] uuidd [ - ] uuidd
[ - ] x11-common [ - ] x11-common
<span class="annotation fn-annotatation" level="1"> <span class="annotation fn-annotatation" level="1">
A level 1 annotation for list_active_services A level 1 annotation for list_active_services
@ -229,7 +221,6 @@ ssl-cert:x:127:
scanner:x:128:saned scanner:x:128:saned
saned:x:129: saned:x:129:
colord:x:130: colord:x:130:
<span class="annotation fn-annotatation" level="1"> <span class="annotation fn-annotatation" level="1">
A level 1 annotation for list_groups A level 1 annotation for list_groups
@ -305,7 +296,6 @@ colord:x:130:
<pre>debian_version</pre> <pre>debian_version</pre>
<p>12.1 <p>12.1
<span class="annotation fn-annotatation" level="1"> <span class="annotation fn-annotatation" level="1">
A level 1 annotation for debian_version A level 1 annotation for debian_version
@ -313,7 +303,6 @@ colord:x:130:
<pre>kernel_version</pre> <pre>kernel_version</pre>
<p>Linux chopchop 6.1.65-v8+ #1703 SMP PREEMPT Tue Dec 5 16:25:41 GMT 2023 aarch64 GNU/Linux <p>Linux chopchop 6.1.65-v8+ #1703 SMP PREEMPT Tue Dec 5 16:25:41 GMT 2023 aarch64 GNU/Linux
<span class="annotation fn-annotatation" level="1"> <span class="annotation fn-annotatation" level="1">
A level 1 annotation for kernel_version A level 1 annotation for kernel_version
@ -331,7 +320,7 @@ colord:x:130:
<script type="text/javascript" src="script.js"></script> <script type="text/javascript" src="script.js"></script>
<script type="text/javascript"> <script type="text/javascript">
window.addEventListener("DOMContentLoaded", function () { window.addEventListener("DOMContentLoaded", function () {
var nextDate = new Date("2024-03-18 23:31:58.328818"); var nextDate = new Date("2024-03-18 23:48:33.398733");
var now = new Date(); var now = new Date();
var ms = nextDate - now; var ms = nextDate - now;
console.log("start a timeout in , ", ms); console.log("start a timeout in , ", ms);

@ -9,29 +9,31 @@ amount_of_logs = len(fnmatch.filter(os.listdir("./logs"), '*.html'))
now = datetime.today() now = datetime.today()
next_report = now + timedelta(hours=3) next_report = now + timedelta(hours=3)
def run_command(command, based = False):
result = subprocess.run(command, capture_output=True, input=based)
result.check_returncode()
return result.stdout.decode('UTF-8').strip()
last_user_added = subprocess.run(["sudo", "journalctl","_COMM=useradd","-r","-n", "1" , "--output-fields=MESSAGE"], capture_output=True) last_user_added = subprocess.run(["sudo", "journalctl","_COMM=useradd","-r","-n", "1" , "--output-fields=MESSAGE"], capture_output=True)
last_user_added_name = subprocess.run(['grep', '-Po', "(?<=name)\W*\K[^ ]*"], input=last_user_added.stdout, capture_output=True).stdout.decode('UTF-8').strip() last_user_added_name = run_command(['grep', '-Po', "(?<=name)\W*\K[^ ]*"], based=last_user_added.stdout)
users_created_today = subprocess.run(["sudo", "journalctl", "-S","today","_COMM=useradd","-r","-n","1","--output-fields=MESSAGE"], capture_output=True).stdout.decode('UTF-8') users_created_today = run_command(["sudo", "journalctl", "-S","today","_COMM=useradd","-r","-n","1","--output-fields=MESSAGE"])
list_active_services = subprocess.run(["sudo", "service", "--status-all"], capture_output=True).stdout.decode('UTF-8')
list_groups = subprocess.run(["getent","group"], capture_output=True).stdout.decode('UTF-8')
since_last_boot = subprocess.run(["uptime","-s"], capture_output=True).stdout.decode('UTF-8').strip() since_last_boot = run_command(["uptime","-s"])
slb_date = datetime.strptime(since_last_boot, "%Y-%m-%d %H:%M:%S") slb_date = datetime.strptime(since_last_boot, "%Y-%m-%d %H:%M:%S")
time_since_last_boot = now - slb_date time_since_last_boot = now - slb_date
list_package_installs = subprocess.run(["grep", 'install', "/var/log/dpkg.log"], capture_output=True).stdout.decode('UTF-8') list_package_installs = subprocess.run(["grep", 'install', "/var/log/dpkg.log"], capture_output=True).stdout.decode('UTF-8')
list_package_upgrade = subprocess.run(["grep", 'upgrade', "/var/log/dpkg.log"], capture_output=True).stdout.decode('UTF-8') list_package_upgrade = subprocess.run(["grep", 'upgrade', "/var/log/dpkg.log"], capture_output=True).stdout.decode('UTF-8')
list_package_remove = subprocess.run(["grep", 'remove', "/var/log/dpkg.log"], capture_output=True).stdout.decode('UTF-8') list_package_remove = subprocess.run(["grep", 'remove', "/var/log/dpkg.log"], capture_output=True).stdout.decode('UTF-8')
device_info_grab = subprocess.run(["grep", 'Model' , "/proc/cpuinfo"], check=True, capture_output=True) device_info_grab = subprocess.run(["grep", 'Model' , "/proc/cpuinfo"], check=True, capture_output=True)
device_info = subprocess.run(['awk', '-F:', '{ print $2}'], input=device_info_grab.stdout, capture_output=True).stdout.decode('utf-8').strip() device_info = run_command(['awk', '-F:', '{ print $2}'], based=device_info_grab.stdout)
ip_address_show = subprocess.run(["ip", "addr", "show", "end0"], check=True, capture_output=True) ip_address_show = subprocess.run(["ip", "addr", "show", "end0"], check=True, capture_output=True)
ip_address = subprocess.run(['awk', '$1 == "inet" {gsub(/\/.*$/, "", $2); print $2}' ], input=ip_address_show.stdout, capture_output=True).stdout.decode('utf-8').strip() ip_address = run_command(['awk', '$1 == "inet" {gsub(/\/.*$/, "", $2); print $2}' ], based=ip_address_show.stdout)
kitchen_services = run_command(["sudo", "journalctl", "-S", "today", "-u", "kitchen-stove.service", "-u", "kitchen-bin.service", "-u", "kitchen-fridge.service", "-r", "-n"])
debian_version = subprocess.run(["cat", "/etc/debian_version"], capture_output=True).stdout.decode('UTF-8')
kernel_version = subprocess.run(["uname","-a"], capture_output=True).stdout.decode('UTF-8')
hostname = subprocess.run(["hostname","-i"], capture_output=True).stdout.decode('UTF-8')
kitchen_services = subprocess.run(["sudo", "journalctl", "-S", "today", "-u", "kitchen-stove.service", "-u", "kitchen-bin.service", "-u", "kitchen-fridge.service", "-r", "-n"], capture_output=True).stdout.decode('UTF-8')
# loading the environment # loading the environment
env = Environment(loader=FileSystemLoader("templates")) env = Environment(loader=FileSystemLoader("templates"))
@ -47,19 +49,19 @@ output = template.render(
last_user_added=last_user_added.stdout.decode('UTF-8'), last_user_added=last_user_added.stdout.decode('UTF-8'),
last_user_added_name=last_user_added_name, last_user_added_name=last_user_added_name,
users_created_today=users_created_today, users_created_today=users_created_today,
list_active_services=list_active_services,
list_groups=list_groups,
since_last_boot=since_last_boot, since_last_boot=since_last_boot,
list_package_installs=list_package_installs, list_package_installs=list_package_installs,
list_package_upgrade=list_package_upgrade, list_package_upgrade=list_package_upgrade,
list_package_remove=list_package_remove, list_package_remove=list_package_remove,
device_info=device_info, device_info=device_info,
debian_version=debian_version,
kernel_version=kernel_version,
hostname=hostname,
days_since_last_boot = time_since_last_boot.days, days_since_last_boot = time_since_last_boot.days,
kitchen_services = kitchen_services, kitchen_services = kitchen_services,
ip_address = ip_address ip_address = ip_address,
list_groups = run_command(["getent","group"]),
list_active_services = run_command(["sudo", "service", "--status-all"]),
debian_version = run_command(["cat", "/etc/debian_version"]),
kernel_version = run_command(["uname","-a"]),
hostname = run_command(["hostname","-i"])
) )
log_file_name = "logs/log_" + now.strftime("%Y-%m-%d_%H:%M:%S") + ".html" log_file_name = "logs/log_" + now.strftime("%Y-%m-%d_%H:%M:%S") + ".html"

Loading…
Cancel
Save