misc: display unit name

This commit is contained in:
Christophe Siraut 2020-09-10 14:25:16 +02:00
parent 95960d3b6c
commit b202828360
3 changed files with 8 additions and 1 deletions

View File

@ -20,9 +20,10 @@ class Command(BaseCommand):
def handle(self, *args, **options):
_, columns = os.popen("stty size", "r").read().split()
for entry in Entry.objects.dump(lines=options['lines']):
line = "%s %s %s" % (
line = "%s %s %s %s" % (
entry.timestamp.astimezone().strftime("%b %d %X"),
entry.host,
entry.unit,
entry.data.get("MESSAGE"),
)
priority = entry.data.get("PRIORITY")

View File

@ -26,3 +26,7 @@ class Entry(models.Model):
def __str__(self):
return '%s %s %s' % (self.timestamp, self.host, self.data)
@property
def unit(self):
return self.data.get('_SYSTEMD_UNIT', '').replace('.service', '')

View File

@ -9,6 +9,7 @@
<tr>
<td>Time</td>
<td>Host</td>
<td>Unit</td>
<td>Message</td>
</tr>
</thead>
@ -17,6 +18,7 @@
<tr>
<td>{{ line.timestamp|date:'b d H:i:s' }}</td>
<td>{{ line.host }}</td>
<td>{{ line.unit }}</td>
<td>{{ line.data.MESSAGE }}</td>
</tr>
{% empty %}