prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Bug in csirtg plugin
  @wesyoung Not sure when this bug started, but just looked today at my honeypots and saw this happening all over the place in the logs.
  
  ```
  2018-02-11T16:53:14-0500 [twisted.internet.defer#critical] Unhandled error in Deferred:
  2018-02-11T16:53:14-0500 [twisted.internet.defer#critical]
  	Traceback (most recent call last):
  	  File "/usr/local/lib/python2.7/dist-packages/twisted/internet/tcp.py", line 289, in connectionLost
  	    protocol.connectionLost(reason)
  	  File "/usr/local/lib/python2.7/dist-packages/twisted/web/client.py", line 223, in connectionLost
  	    self.factory._disconnectedDeferred.callback(None)
  	  File "/usr/local/lib/python2.7/dist-packages/twisted/internet/defer.py", line 459, in callback
  	    self._startRunCallbacks(result)
  	  File "/usr/local/lib/python2.7/dist-packages/twisted/internet/defer.py", line 567, in _startRunCallbacks
  	    self._runCallbacks()
  	--- <exception caught here> ---
  	  File "/usr/local/lib/python2.7/dist-packages/twisted/internet/defer.py", line 653, in _runCallbacks
  	    current.result = callback(current.result, *args, **kw)
  	  File "/home/cowrie/cowrie/cowrie/commands/wget.py", line 241, in error
  	    url=self.url)
  	  File "/home/cowrie/cowrie/cowrie/shell/protocol.py", line 80, in logDispatch
  	    pt.factory.logDispatch(*msg, **args)
  	  File "/home/cowrie/cowrie/cowrie/telnet/transport.py", line 43, in logDispatch
  	    output.logDispatch(*msg, **args)
  	  File "/home/cowrie/cowrie/cowrie/core/output.py", line 117, in logDispatch
  	    self.emit(ev)
  	  File "/home/cowrie/cowrie/cowrie/core/output.py", line 206, in emit
  	    self.write(ev)
  	  File "/home/cowrie/cowrie/cowrie/output/csirtg.py", line 43, in write
  	    system = e['system']
  	exceptions.KeyError: 'system'
  ```
  
  </issue>
  <code>
  [start of src/cowrie/output/csirtg.py]
  1 from __future__ import absolute_import, division
  2 
  3 import os
  4 from datetime import datetime
  5 
  6 from csirtgsdk.client import Client
  7 from csirtgsdk.indicator import Indicator
  8 
  9 from twisted.python import log
  10 
  11 import cowrie.core.output
  12 from cowrie.core.config import CONFIG
  13 
  14 USERNAME = os.environ.get('CSIRTG_USER')
  15 FEED = os.environ.get('CSIRTG_FEED')
  16 TOKEN = os.environ.get('CSIRG_TOKEN')
  17 DESCRIPTION = os.environ.get('CSIRTG_DESCRIPTION', 'random scanning activity')
  18 
  19 
  20 class Output(cowrie.core.output.Output):
  21     def __init__(self):
  22         self.user = CONFIG.get('output_csirtg', 'username') or USERNAME
  23         self.feed = CONFIG.get('output_csirtg', 'feed') or FEED
  24         self.token = CONFIG.get('output_csirtg', 'token') or TOKEN
  25         try:
  26             self.description = CONFIG.get('output_csirtg', 'description')
  27         except Exception:
  28             self.description = DESCRIPTION
  29         self.context = {}
  30         self.client = Client(token=self.token)
  31         cowrie.core.output.Output.__init__(self)
  32 
  33     def start(self, ):
  34         pass
  35 
  36     def stop(self):
  37         pass
  38 
  39     def write(self, e):
  40         peerIP = e['src_ip']
  41         ts = e['timestamp']
  42         system = e['system']
  43 
  44         if system not in ['cowrie.ssh.factory.CowrieSSHFactory', 'cowrie.telnet.transport.HoneyPotTelnetFactory']:
  45             return
  46 
  47         today = str(datetime.now().date())
  48 
  49         if not self.context.get(today):
  50             self.context = {}
  51             self.context[today] = set()
  52 
  53         key = ','.join([peerIP, system])
  54 
  55         if key in self.context[today]:
  56             return
  57 
  58         self.context[today].add(key)
  59 
  60         tags = 'scanner,ssh'
  61         port = 22
  62         if e['system'] == 'cowrie.telnet.transport.HoneyPotTelnetFactory':
  63             tags = 'scanner,telnet'
  64             port = 23
  65 
  66         i = {
  67             'user': self.user,
  68             'feed': self.feed,
  69             'indicator': peerIP,
  70             'portlist': port,
  71             'protocol': 'tcp',
  72             'tags': tags,
  73             'firsttime': ts,
  74             'lasttime': ts,
  75             'description': self.description
  76         }
  77 
  78         ret = Indicator(self.client, i).submit()
  79         log.msg('logged to csirtg %s ' % ret['location'])
  80
  [end of src/cowrie/output/csirtg.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/src/cowrie/output/csirtg.py b/src/cowrie/output/csirtg.py
  --- a/src/cowrie/output/csirtg.py
  +++ b/src/cowrie/output/csirtg.py
  @@ -39,9 +39,10 @@
       def write(self, e):
           peerIP = e['src_ip']
           ts = e['timestamp']
  -        system = e['system']
  +        system = e.get('system', None)
   
  -        if system not in ['cowrie.ssh.factory.CowrieSSHFactory', 'cowrie.telnet.transport.HoneyPotTelnetFactory']:
  +        if system not in ['cowrie.ssh.factory.CowrieSSHFactory',
  +                          'cowrie.telnet.transport.HoneyPotTelnetFactory']:
               return
   
           today = str(datetime.now().date())
  
verification_info: {"golden_diff": "diff --git a/src/cowrie/output/csirtg.py b/src/cowrie/output/csirtg.py\n--- a/src/cowrie/output/csirtg.py\n+++ b/src/cowrie/output/csirtg.py\n@@ -39,9 +39,10 @@\n     def write(self, e):\n         peerIP = e['src_ip']\n         ts = e['timestamp']\n-        system = e['system']\n+        system = e.get('system', None)\n \n-        if system not in ['cowrie.ssh.factory.CowrieSSHFactory', 'cowrie.telnet.transport.HoneyPotTelnetFactory']:\n+        if system not in ['cowrie.ssh.factory.CowrieSSHFactory',\n+                          'cowrie.telnet.transport.HoneyPotTelnetFactory']:\n             return\n \n         today = str(datetime.now().date())\n", "issue": "Bug in csirtg plugin\n@wesyoung Not sure when this bug started, but just looked today at my honeypots and saw this happening all over the place in the logs.\r\n\r\n```\r\n2018-02-11T16:53:14-0500 [twisted.internet.defer#critical] Unhandled error in Deferred:\r\n2018-02-11T16:53:14-0500 [twisted.internet.defer#critical]\r\n\tTraceback (most recent call last):\r\n\t  File \"/usr/local/lib/python2.7/dist-packages/twisted/internet/tcp.py\", line 289, in connectionLost\r\n\t    protocol.connectionLost(reason)\r\n\t  File \"/usr/local/lib/python2.7/dist-packages/twisted/web/client.py\", line 223, in connectionLost\r\n\t    self.factory._disconnectedDeferred.callback(None)\r\n\t  File \"/usr/local/lib/python2.7/dist-packages/twisted/internet/defer.py\", line 459, in callback\r\n\t    self._startRunCallbacks(result)\r\n\t  File \"/usr/local/lib/python2.7/dist-packages/twisted/internet/defer.py\", line 567, in _startRunCallbacks\r\n\t    self._runCallbacks()\r\n\t--- <exception caught here> ---\r\n\t  File \"/usr/local/lib/python2.7/dist-packages/twisted/internet/defer.py\", line 653, in _runCallbacks\r\n\t    current.result = callback(current.result, *args, **kw)\r\n\t  File \"/home/cowrie/cowrie/cowrie/commands/wget.py\", line 241, in error\r\n\t    url=self.url)\r\n\t  File \"/home/cowrie/cowrie/cowrie/shell/protocol.py\", line 80, in logDispatch\r\n\t    pt.factory.logDispatch(*msg, **args)\r\n\t  File \"/home/cowrie/cowrie/cowrie/telnet/transport.py\", line 43, in logDispatch\r\n\t    output.logDispatch(*msg, **args)\r\n\t  File \"/home/cowrie/cowrie/cowrie/core/output.py\", line 117, in logDispatch\r\n\t    self.emit(ev)\r\n\t  File \"/home/cowrie/cowrie/cowrie/core/output.py\", line 206, in emit\r\n\t    self.write(ev)\r\n\t  File \"/home/cowrie/cowrie/cowrie/output/csirtg.py\", line 43, in write\r\n\t    system = e['system']\r\n\texceptions.KeyError: 'system'\r\n```\n", "before_files": [{"content": "from __future__ import absolute_import, division\n\nimport os\nfrom datetime import datetime\n\nfrom csirtgsdk.client import Client\nfrom csirtgsdk.indicator import Indicator\n\nfrom twisted.python import log\n\nimport cowrie.core.output\nfrom cowrie.core.config import CONFIG\n\nUSERNAME = os.environ.get('CSIRTG_USER')\nFEED = os.environ.get('CSIRTG_FEED')\nTOKEN = os.environ.get('CSIRG_TOKEN')\nDESCRIPTION = os.environ.get('CSIRTG_DESCRIPTION', 'random scanning activity')\n\n\nclass Output(cowrie.core.output.Output):\n    def __init__(self):\n        self.user = CONFIG.get('output_csirtg', 'username') or USERNAME\n        self.feed = CONFIG.get('output_csirtg', 'feed') or FEED\n        self.token = CONFIG.get('output_csirtg', 'token') or TOKEN\n        try:\n            self.description = CONFIG.get('output_csirtg', 'description')\n        except Exception:\n            self.description = DESCRIPTION\n        self.context = {}\n        self.client = Client(token=self.token)\n        cowrie.core.output.Output.__init__(self)\n\n    def start(self, ):\n        pass\n\n    def stop(self):\n        pass\n\n    def write(self, e):\n        peerIP = e['src_ip']\n        ts = e['timestamp']\n        system = e['system']\n\n        if system not in ['cowrie.ssh.factory.CowrieSSHFactory', 'cowrie.telnet.transport.HoneyPotTelnetFactory']:\n            return\n\n        today = str(datetime.now().date())\n\n        if not self.context.get(today):\n            self.context = {}\n            self.context[today] = set()\n\n        key = ','.join([peerIP, system])\n\n        if key in self.context[today]:\n            return\n\n        self.context[today].add(key)\n\n        tags = 'scanner,ssh'\n        port = 22\n        if e['system'] == 'cowrie.telnet.transport.HoneyPotTelnetFactory':\n            tags = 'scanner,telnet'\n            port = 23\n\n        i = {\n            'user': self.user,\n            'feed': self.feed,\n            'indicator': peerIP,\n            'portlist': port,\n            'protocol': 'tcp',\n            'tags': tags,\n            'firsttime': ts,\n            'lasttime': ts,\n            'description': self.description\n        }\n\n        ret = Indicator(self.client, i).submit()\n        log.msg('logged to csirtg %s ' % ret['location'])\n", "path": "src/cowrie/output/csirtg.py"}]}