---
apiVersion: v1
kind: ConfigMap
metadata:
  name: mitm-configmap
data:
  addons.py: |
    import socket
    import json
    import sys

    class LogRequests:
        def __init__(self):
            self.host = 'logstash-http'
            self.port = 32698


        def request(self, flow):
            headers = {
              name: value
              for name, value in flow.request.headers.items()
            }
            msg = { '@host': flow.request.pretty_host, '@path': flow.request.path, '@url': flow.request.pretty_url, '@headers': headers }

            try:
                sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
            except socket.error:
                sys.exit(1)

            sock.sendto(bytes(json.dumps(msg), "utf-8"), (self.host, self.port))

            sock.close()

    addons = [
        LogRequests()
    ]
