further bugfixing in parsers & clean up formatting.py
[logparse.git] / logparse / parsers / sudo.py
index ef74ec29ffe526f72de91258c9c69907f19644e4..87d4be71d783906d5980f540d75ccad859410539 100644 (file)
@@ -14,9 +14,8 @@ import logging
 logger = logging.getLogger(__name__)
 
 def parse_log():
-    output = ''
     logger.debug("Starting sudo section")
-    output += opentag('div', 1, 'sudo', 'section')
+    section = Section("sudo")
     logger.debug("Searching for matches in {0}".format(config.prefs['logs']['auth']))
     umatches = re.findall('.*sudo:session\): session opened.*', readlog(config.prefs['logs']['auth']))
     num = sum(1 for line in umatches)    # total number of sessions
@@ -35,22 +34,25 @@ def parse_log():
         commands.append(cmd)
     logger.debug("Finished parsing sudo sessions")
 
-    output += writetitle("sudo")
-    subtitle = plural("sudo session", num) + " for"
+    auth_data = Data(subtitle=plural("sudo session", num) + " for")
+
     if (len(users) == 1):
         logger.debug("found " + str(num) + " sudo session(s) for user " + str(users[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]) + ')')
+            auth_data.items.append(user[0] + ' (' + str(user[1]) + ')')
         logger.debug("found " + str(num) + " sudo sessions for users " + str(data))
-        output += writedata(subtitle, data)
+    section.append_data(auth_data)
+
     if (len(commands) > 0):
-        commands = addtag(commands, 'code')
-        commands = orderbyfreq(commands)
-        commands = truncl(commands, config.prefs['maxcmd'])
-        output += writedata("top sudo commands", [c for c in commands])
-    output += closetag('div', 1)
-    return output
+        command_data = Data(subtitle="top sudo commands")
+        commands = backticks(commands)
+        command_data.items = commands
+        command_data.orderbyfreq()
+        command_data.truncl(config.prefs['maxcmd'])
+        section.append_data(command_data)
+
     logger.info("Finished sudo section")
+
+    return section