update parsers to new output model
[logparse.git] / logparse / parsers / httpd.py
index 221f98224a85c5e70e82414478e9ac251507bd0a..7175ea8326fd582fd06b544478bb37950ac13a9e 100644 (file)
@@ -18,9 +18,8 @@ import logging
 logger = logging.getLogger(__name__)
 
 def parse_log():
-    output = ''
     logger.debug("Starting httpd section")
-    output += opentag('div', 1, 'httpd', 'section')
+    section = Section("httpd")
     accesslog = readlog(config.prefs['logs']['httpd'] + '/access.log')
     a = len(accesslog.split('\n'))
     errorlog = readlog(config.prefs['logs']['httpd'] + '/error.log')
@@ -48,33 +47,34 @@ def parse_log():
                 logger.warning("Error processing httpd access log: " + str(error))
                 traceback.print_exc()
     data_h = parsesize(data_b)
-    output += writetitle("apache")
 
     logger.info("httpd has transferred " + str(data_b) + " bytes in response to " + str(a) + " requests with " + str(e) + " errors")
     if (a > 0):
         logger.debug("Parsing request statistics (this might take a while)")
-        files = addtag(files, 'code')
-        files = orderbyfreq(files)
-        files = truncl(files, config.prefs['maxlist'])
-        output += writedata(plural(" request", a), files)
+        request_data = Data()
+        request_data.items = backticks(files)
+        request_data.orderbyfreq()
+        request_data.truncl(config.prefs['maxlist'])
+        request_data.subtitle = plural(" request", a)
+        section.append_data(request_data)
     if (ips != None):
         logger.debug("Parsing client statistics")
-        ips = addtag(ips, 'code')
-        ips = orderbyfreq(ips)
-        n_ip = str(len(ips))
-        ips = truncl(ips, config.prefs['maxlist'])
-        output += writedata(plural(" client", n_ip), ips)
+        client_data = Data()
+        client_data.items = orderbyfreq(ips)
+        client_data.subtitlte = plural(" client", str(len(ips)))
+        client_data.truncl(config.prefs['maxlist'])
+        section.append_data(client_data)
     if (useragents != None):
         logger.debug("Parsing user agent statistics")
-        useragents = addtag(useragents, 'code')
-        useragents = orderbyfreq(useragents)
-        n_ua = str(len(useragents))
-        useragents = truncl(useragents, config.prefs['maxlist'])
-        output += writedata(plural(" device", n_ua), useragents)
+        ua_data = Data()
+        ua_data.items = orderbyfreq(useragents)
+        n_ua = str(len(ua_data.items))
+        ua_data.truncl(config.prefs['maxlist'])
+        ua_data.subtitle = plural(" user agent", n_ua)
+        section.append_data(client_data)
 
-    output += writedata(data_h + " transferred")
-    output += writedata(plural(" error", e))
+    section.append_data(Data(data_h + " transferred"))
+    section.append_data(Data(plural(" error", e)))
 
-    output += closetag('div', 1)
     logger.info("Finished httpd section")
-    return output
+    return section