Skip to content

Instantly share code, notes, and snippets.

@hardillb
Created January 23, 2015 21:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hardillb/bf705cbcd7cbf47f17b1 to your computer and use it in GitHub Desktop.
Save hardillb/bf705cbcd7cbf47f17b1 to your computer and use it in GitHub Desktop.
Generate /var/log/secure from systemd journald data. This is to try and get denyhosts working on Fedora 20
#!/usr/bin/env python
# {
# '_BOOT_ID': UUID('50a800f6-f77b-4110-a0bc-e5f16609d257'),
# '_SELINUX_CONTEXT': u'system_u:system_r:chkpwd_t:s0-s0:c0.c1023',
# '__REALTIME_TIMESTAMP': datetime.datetime(2015, 1, 18, 22, 42, 51, 62301),
# '__MONOTONIC_TIMESTAMP': (datetime.timedelta(0, 8300, 665432), UUID('50a800f6-f77b-4110-a0bc-e5f16609d257')),
# '_MACHINE_ID': UUID('6ffa4760-01ea-4a4d-96c3-560e48051718'),
# '_PID': 8774,
# 'SYSLOG_FACILITY': 10,
# '_SOURCE_REALTIME_TIMESTAMP': datetime.datetime(2015, 1, 18, 22, 42, 51, 61166),
# 'PRIORITY': 5,
# '_UID': 0,
# '_TRANSPORT': u'syslog',
# 'SYSLOG_IDENTIFIER': u'unix_chkpwd',
# '_GID': 0,
# 'SYSLOG_PID': 8774,
# '__CURSOR': 's=e11ab0dffad549e1911945d5c1f5fb4a;i=2f4407;b=50a800f6f77b4110a0bce5f16609d257;m=1eec21a58;t=50cf4ecfc441d;x=1949eadc8b29df50',
# 'MESSAGE': u'password check failed for user (root)',
# '_HOSTNAME': u'deathstar'
#}
#Jan 17 19:40:26 deathstar unix_chkpwd[30182]: password check failed for user (root)
from systemd import journal
j = journal.Reader()
j.this_boot()
j.log_level(journal.LOG_INFO)
j.add_match(SYSLOG_FACILITY="10")
for entry in j:
print("{0:%b} {0:%d} {0:%H:%M:%S} {1} {2}[0]: {3}".format( entry['__REALTIME_TIMESTAMP'], entry['_HOSTNAME'], entry['SYSLOG_IDENTIFIER'] ,entry['MESSAGE']))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment