From a0c23306be55216fc6fa4dc761dbf3151672a855 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Thu, 4 Mar 2021 12:05:05 +0300 Subject: add journalctl output --- app.py | 42 ++++++++++++++++++++++++++++-------------- index.html | 16 ++++++++++++++++ 2 files changed, 44 insertions(+), 14 deletions(-) diff --git a/app.py b/app.py index a224b0b..8d76170 100755 --- a/app.py +++ b/app.py @@ -164,22 +164,32 @@ class Systemd(Command): return env -class Systemctl(Systemd): +class Ctl(Systemd): + def __init__(self, executable, *args): + super().__init__(executable, *args, '--full') + + @classmethod + def system(cls, *args): + return cls('--system', *args) + + @classmethod + def user(cls, *args): + return cls('--user', *args) + + +class Systemctl(Ctl): def __init__(self, *args): - super().__init__('systemctl', *args, '--full') + super().__init__('systemctl', *args) - @staticmethod - def system(*args): - return Systemctl('--system', *args) - @staticmethod - def user(*args): - return Systemctl('--user', *args) +class Journalctl(Ctl): + def __init__(self, *args): + super().__init__('journalctl', *args) class Loginctl(Systemd): def __init__(self, *args): - super().__init__('loginctl', *args) + super().__init__('loginctl', *args, '--full') class Task(abc.ABC): @@ -230,37 +240,41 @@ class PoweroffTask(Task): class InstanceStatusTask(Task): - def __init__(self, systemctl): + def __init__(self, systemctl, journalctl): self.overview_cmd = systemctl('status') self.failed_cmd = systemctl('list-units', '--failed') self.timers_cmd = systemctl('list-timers', '--all') + self.journal_cmd = journalctl('-b', '--lines=20') def run(self): self.overview_task = self.overview_cmd.run() self.failed_task = self.failed_cmd.run() self.timers_task = self.timers_cmd.run() + self.journal_task = self.journal_cmd.run() def result(self): return { 'overview': self.overview_task.result(), 'failed': self.failed_task.result(), 'timers': self.timers_task.result(), + 'journal': self.journal_task.result(), } class SystemInstanceStatusTask(InstanceStatusTask): def __init__(self): - super().__init__(Systemctl.system) + super().__init__(Systemctl.system, Journalctl.system) class UserInstanceStatusTask(InstanceStatusTask): - def __init__(self, systemctl=Systemctl.user): - super().__init__(systemctl) + def __init__(self, systemctl=Systemctl.user, journalctl=Journalctl.user): + super().__init__(systemctl, journalctl) @staticmethod def su(user): systemctl = lambda *args: Systemd.su(user, Systemctl.user(*args)) - return UserInstanceStatusTask(systemctl) + journalctl = lambda *args: Systemd.su(user, Journalctl.user(*args)) + return UserInstanceStatusTask(systemctl, journalctl) class UserInstanceStatusTaskList(Task): diff --git a/index.html b/index.html index 3cbf6cc..d1adc14 100644 --- a/index.html +++ b/index.html @@ -50,6 +50,11 @@ h1, .h1 {

           
           
+

journalctl --system -b --lines=20

+
+

+          
+
@@ -98,6 +103,9 @@ function set_system(data) { if ('timers' in data) { $('#timers_system').text(data['timers']); } + if ('journal' in data) { + $('#journal_system').text(data['journal']); + } } var users = []; @@ -126,6 +134,11 @@ function add_user(name) {

     

+

journalctl --user -b --lines=20

+
+

+    
+
`; @@ -144,6 +157,9 @@ function set_user(name, data) { if ('timers' in data) { $('#timers_user_' + name).text(data['timers']); } + if ('journal' in data) { + $('#journal_user_' + name).text(data['journal']); + } } function set_users(data) { -- cgit v1.2.3