]> gitweb.michael.orlitzky.com - djbdns-logparse.git/commitdiff
bin/djbdns-logparse.py: add docstring for handle_dnscache_log().
authorMichael Orlitzky <michael@orlitzky.com>
Thu, 15 Sep 2022 23:02:22 +0000 (19:02 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Thu, 15 Sep 2022 23:02:22 +0000 (19:02 -0400)
bin/djbdns-logparse.py

index d97a812867ae83ec48fbc0b4f5364083f6457480..97182b677c6fe2ff40f854159d7e25b73495a06a 100755 (executable)
@@ -129,6 +129,54 @@ def decode_type(words, i):
     words[i] = query_type.get(int(qt), qt)
 
 def handle_dnscache_log(line) -> bool:
+    """
+    Handle a single log line if it matches the ``dnscache_log_re`` regex.
+
+    Parameters
+    ----------
+
+    line : string
+        The log line that might match ``dnscache_log_re``.
+
+    Returns
+    -------
+
+    ``True`` if the log line was handled (that is, if it was really a
+    dnscache log line), and ``False`` otherwise.
+
+    Examples
+    --------
+
+        >>> line = "2022-09-15 18:37:33.863805500 query 1 7f000001:a3db:4fb9 1 www.example.com."
+        >>> handle_dnscache_log(line)
+        2022-09-15 18:37:33.863805500 query #1 127.0.0.1:41947 (id 20409) a www.example.com.
+        True
+
+        >>> line = "2022-09-15 18:37:33.863874500 tx 0 1 www.example.com. . c0a80101"
+        >>> handle_dnscache_log(line)
+        2022-09-15 18:37:33.863874500 tx g=0 a www.example.com. . 192.168.1.1
+        True
+
+        >>> line = "2022-09-15 18:37:33.878529500 rr c0a80101 20865 1 www.example.com. 5db8d822"
+        >>> handle_dnscache_log(line)
+        2022-09-15 18:37:33.878529500 rr 192.168.1.1 TTL=20865 a www.example.com. 93.184.216.34
+        True
+
+        >>> line = "2022-09-15 18:37:33.878532500 stats 1 43 1 0"
+        >>> handle_dnscache_log(line)
+        2022-09-15 18:37:33.878532500 stats count=1 motion=43 udp-active=1 tcp-active=0
+        True
+
+        >>> line = "2022-09-15 18:37:33.878602500 sent 1 49"
+        >>> handle_dnscache_log(line)
+        2022-09-15 18:37:33.878602500 sent #1 49
+        True
+
+        >>> line = "this line is nonsense"
+        >>> handle_dnscache_log(line)
+        False
+
+    """
     match = dnscache_log_re.match(line)
     if not match:
         return False