logger = logging.getLogger(__name__)
def parse_log():
- output = ''
logger.debug("Starting sshd section")
- output += opentag('div', 1, 'sshd', 'section')
+ section = Section("ssh")
logger.debug("Searching for matches in {0}".format(config.prefs['logs']['auth']))
matches = re.findall('.*sshd.*Accepted publickey for .* from .*', readlog(config.prefs['logs']['auth'])) # get all logins
logger.debug("Finished searching for logins")
users[exists[0]][1] += 1
logger.debug("Parsed list of authorised users")
- output += writetitle('sshd')
- subtitle = plural('login', num) + ' from'
+ auth_data = Data(subtitle=plural('login', num) + ' from')
+
if (len(users) == 1): # if only one user, do not display no of logins for this user
logger.debug("found " + str(len(matches)) + " ssh logins for user " + users[0][0])
- subtitle += ' ' + users[0][0]
- output += writedata(subtitle)
+ auth_data.subtitle += ' ' + users[0][0]
else:
for user in users:
- data.append(user[0] + ' (' + str(user[1]) + ')')
- if len(data) > config.prefs['maxlist']: # if there are lots of users, truncate them
- data.append('+ ' + str(len(users) - config.prefs['maxlist'] - 1) + " more")
- break
+ auth_data.items.append(user[0] + ' (' + str(user[1]) + ')')
+ auth_data.orderbyfreq()
+ auth_data.truncl(config.prefs['maxlist'])
logger.debug("found " + str(len(matches)) + " ssh logins for users " + str(data))
- output += writedata(subtitle, data)
- output += closetag('div', 1)
+ section.append_data(auth_data)
logger.info("Finished sshd section")
- return output
+ return section