prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  csirtg plugin no longer working
  I'm not sure exactly when this happened, but just happend to check the logs today, and noticed the csirtg plugin has some errors.
  
  ```
  2017-11-02T17:05:41-0400 [cowrie.telnet.transport.HoneyPotTelnetFactory] New connection: 45.32.221.61:59776 (x.x.x.x:23) [session: TT0]
  2017-11-02T17:05:41-0400 [twisted.logger._observer#critical] Temporarily disabling observer LegacyLogObserverWrapper(<bound method Output.emit of <cowrie.output.csirtg.Output object at 0x7f3a5ce9bb50>>) due to exception: [Failure instance: Traceback: <type 'exceptions.TypeError'>: string indices must be integers
  	/home/cowrie/cowrie/cowrie/telnet/transport.py:218:connectionMade
  	/usr/local/lib/python2.7/dist-packages/twisted/python/threadable.py:53:sync
  	/usr/local/lib/python2.7/dist-packages/twisted/python/log.py:286:msg
  	/usr/local/lib/python2.7/dist-packages/twisted/logger/_legacy.py:154:publishToNewObserver
  	--- <exception caught here> ---
  	/usr/local/lib/python2.7/dist-packages/twisted/logger/_observer.py:131:__call__
  	/usr/local/lib/python2.7/dist-packages/twisted/logger/_legacy.py:93:__call__
  	/home/cowrie/cowrie/cowrie/core/output.py:190:emit
  	/home/cowrie/cowrie/cowrie/output/csirtg.py:82:write
  	]
  	Traceback (most recent call last):
  	  File "/home/cowrie/cowrie/cowrie/telnet/transport.py", line 218, in connectionMade
  	    session=self.transportId, sessionno='T'+str(sessionno))
  	  File "/usr/local/lib/python2.7/dist-packages/twisted/python/threadable.py", line 53, in sync
  	    return function(self, *args, **kwargs)
  	  File "/usr/local/lib/python2.7/dist-packages/twisted/python/log.py", line 286, in msg
  	    _publishNew(self._publishPublisher, actualEventDict, textFromEventDict)
  	  File "/usr/local/lib/python2.7/dist-packages/twisted/logger/_legacy.py", line 154, in publishToNewObserver
  	    observer(eventDict)
  	--- <exception caught here> ---
  	  File "/usr/local/lib/python2.7/dist-packages/twisted/logger/_observer.py", line 131, in __call__
  	    observer(event)
  	  File "/usr/local/lib/python2.7/dist-packages/twisted/logger/_legacy.py", line 93, in __call__
  	    self.legacyObserver(event)
  	  File "/home/cowrie/cowrie/cowrie/core/output.py", line 190, in emit
  	    self.write(ev)
  	  File "/home/cowrie/cowrie/cowrie/output/csirtg.py", line 82, in write
  	    logger.info('logged to csirtg %s ' % ret['indicator']['location'])
  	exceptions.TypeError: string indices must be integers
  ```
  
  </issue>
  <code>
  [start of cowrie/output/csirtg.py]
  1 from __future__ import division, absolute_import
  2 
  3 import cowrie.core.output
  4 
  5 from csirtgsdk.indicator import Indicator
  6 from csirtgsdk.client import Client
  7 from datetime import datetime
  8 import logging
  9 import os
  10 
  11 logger = logging.getLogger(__name__)
  12 
  13 USERNAME = os.environ.get('CSIRTG_USER')
  14 FEED = os.environ.get('CSIRTG_FEED')
  15 TOKEN = os.environ.get('CSIRG_TOKEN')
  16 DESCRIPTION = os.environ.get('CSIRTG_DESCRIPTION', 'random scanning activity')
  17 
  18 
  19 class Output(cowrie.core.output.Output):
  20     def __init__(self, cfg):
  21         cowrie.core.output.Output.__init__(self, cfg)
  22         self.user = cfg.get('output_csirtg', 'username') or USERNAME
  23         self.feed = cfg.get('output_csirtg', 'feed') or FEED
  24         self.token = cfg.get('output_csirtg', 'token') or TOKEN
  25         try:
  26             self.description = cfg.get('output_csirtg', 'description')
  27         except Exception:
  28             self.description = DESCRIPTION
  29         self.context = {}
  30         self.client = Client(token=self.token)
  31 
  32     def start(self,):
  33         pass
  34 
  35     def stop(self):
  36         pass
  37 
  38     def write(self, e):
  39         sid = e['session']
  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             logger.debug('skipping {}'.format(system))
  46             return
  47 
  48         today = str(datetime.now().date())
  49 
  50         if not self.context.get(today):
  51             logger.debug('resetting context for %s' % today)
  52             self.context = {}
  53             self.context[today] = set()
  54 
  55         key = ','.join([peerIP, system])
  56 
  57         if key in self.context[today]:
  58             logger.debug('skipping {}'.format(key))
  59             return
  60 
  61         self.context[today].add(key)
  62 
  63         tags = 'scanner,ssh'
  64         port = 22
  65         if e['system'] == 'cowrie.telnet.transport.HoneyPotTelnetFactory':
  66             tags = 'scanner,telnet'
  67             port = 23
  68 
  69         i = {
  70             'user': self.user,
  71             'feed': self.feed,
  72             'indicator': peerIP,
  73             'portlist': port,
  74             'protocol': 'tcp',
  75             'tags': tags,
  76             'firsttime': ts,
  77             'lasttime': ts,
  78             'description': self.description
  79         }
  80 
  81         ret = Indicator(self.client, i).submit()
  82         logger.info('logged to csirtg %s ' % ret['indicator']['location'])
  83 
  84
  [end of 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/cowrie/output/csirtg.py b/cowrie/output/csirtg.py
  --- a/cowrie/output/csirtg.py
  +++ b/cowrie/output/csirtg.py
  @@ -7,8 +7,7 @@
   from datetime import datetime
   import logging
   import os
  -
  -logger = logging.getLogger(__name__)
  +from twisted.python import log
   
   USERNAME = os.environ.get('CSIRTG_USER')
   FEED = os.environ.get('CSIRTG_FEED')
  @@ -42,20 +41,17 @@
           system = e['system']
   
           if system not in ['cowrie.ssh.factory.CowrieSSHFactory', 'cowrie.telnet.transport.HoneyPotTelnetFactory']:
  -            logger.debug('skipping {}'.format(system))
               return
   
           today = str(datetime.now().date())
   
           if not self.context.get(today):
  -            logger.debug('resetting context for %s' % today)
               self.context = {}
               self.context[today] = set()
   
           key = ','.join([peerIP, system])
   
           if key in self.context[today]:
  -            logger.debug('skipping {}'.format(key))
               return
   
           self.context[today].add(key)
  @@ -79,5 +75,5 @@
           }
   
           ret = Indicator(self.client, i).submit()
  -        logger.info('logged to csirtg %s ' % ret['indicator']['location'])
  +        log.msg('logged to csirtg %s ' % ret['location'])
  
verification_info: {"golden_diff": "diff --git a/cowrie/output/csirtg.py b/cowrie/output/csirtg.py\n--- a/cowrie/output/csirtg.py\n+++ b/cowrie/output/csirtg.py\n@@ -7,8 +7,7 @@\n from datetime import datetime\n import logging\n import os\n-\n-logger = logging.getLogger(__name__)\n+from twisted.python import log\n \n USERNAME = os.environ.get('CSIRTG_USER')\n FEED = os.environ.get('CSIRTG_FEED')\n@@ -42,20 +41,17 @@\n         system = e['system']\n \n         if system not in ['cowrie.ssh.factory.CowrieSSHFactory', 'cowrie.telnet.transport.HoneyPotTelnetFactory']:\n-            logger.debug('skipping {}'.format(system))\n             return\n \n         today = str(datetime.now().date())\n \n         if not self.context.get(today):\n-            logger.debug('resetting context for %s' % today)\n             self.context = {}\n             self.context[today] = set()\n \n         key = ','.join([peerIP, system])\n \n         if key in self.context[today]:\n-            logger.debug('skipping {}'.format(key))\n             return\n \n         self.context[today].add(key)\n@@ -79,5 +75,5 @@\n         }\n \n         ret = Indicator(self.client, i).submit()\n-        logger.info('logged to csirtg %s ' % ret['indicator']['location'])\n+        log.msg('logged to csirtg %s ' % ret['location'])\n", "issue": "csirtg plugin no longer working\nI'm not sure exactly when this happened, but just happend to check the logs today, and noticed the csirtg plugin has some errors.\r\n\r\n```\r\n2017-11-02T17:05:41-0400 [cowrie.telnet.transport.HoneyPotTelnetFactory] New connection: 45.32.221.61:59776 (x.x.x.x:23) [session: TT0]\r\n2017-11-02T17:05:41-0400 [twisted.logger._observer#critical] Temporarily disabling observer LegacyLogObserverWrapper(<bound method Output.emit of <cowrie.output.csirtg.Output object at 0x7f3a5ce9bb50>>) due to exception: [Failure instance: Traceback: <type 'exceptions.TypeError'>: string indices must be integers\r\n\t/home/cowrie/cowrie/cowrie/telnet/transport.py:218:connectionMade\r\n\t/usr/local/lib/python2.7/dist-packages/twisted/python/threadable.py:53:sync\r\n\t/usr/local/lib/python2.7/dist-packages/twisted/python/log.py:286:msg\r\n\t/usr/local/lib/python2.7/dist-packages/twisted/logger/_legacy.py:154:publishToNewObserver\r\n\t--- <exception caught here> ---\r\n\t/usr/local/lib/python2.7/dist-packages/twisted/logger/_observer.py:131:__call__\r\n\t/usr/local/lib/python2.7/dist-packages/twisted/logger/_legacy.py:93:__call__\r\n\t/home/cowrie/cowrie/cowrie/core/output.py:190:emit\r\n\t/home/cowrie/cowrie/cowrie/output/csirtg.py:82:write\r\n\t]\r\n\tTraceback (most recent call last):\r\n\t  File \"/home/cowrie/cowrie/cowrie/telnet/transport.py\", line 218, in connectionMade\r\n\t    session=self.transportId, sessionno='T'+str(sessionno))\r\n\t  File \"/usr/local/lib/python2.7/dist-packages/twisted/python/threadable.py\", line 53, in sync\r\n\t    return function(self, *args, **kwargs)\r\n\t  File \"/usr/local/lib/python2.7/dist-packages/twisted/python/log.py\", line 286, in msg\r\n\t    _publishNew(self._publishPublisher, actualEventDict, textFromEventDict)\r\n\t  File \"/usr/local/lib/python2.7/dist-packages/twisted/logger/_legacy.py\", line 154, in publishToNewObserver\r\n\t    observer(eventDict)\r\n\t--- <exception caught here> ---\r\n\t  File \"/usr/local/lib/python2.7/dist-packages/twisted/logger/_observer.py\", line 131, in __call__\r\n\t    observer(event)\r\n\t  File \"/usr/local/lib/python2.7/dist-packages/twisted/logger/_legacy.py\", line 93, in __call__\r\n\t    self.legacyObserver(event)\r\n\t  File \"/home/cowrie/cowrie/cowrie/core/output.py\", line 190, in emit\r\n\t    self.write(ev)\r\n\t  File \"/home/cowrie/cowrie/cowrie/output/csirtg.py\", line 82, in write\r\n\t    logger.info('logged to csirtg %s ' % ret['indicator']['location'])\r\n\texceptions.TypeError: string indices must be integers\r\n```\n", "before_files": [{"content": "from __future__ import division, absolute_import\n\nimport cowrie.core.output\n\nfrom csirtgsdk.indicator import Indicator\nfrom csirtgsdk.client import Client\nfrom datetime import datetime\nimport logging\nimport os\n\nlogger = logging.getLogger(__name__)\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, cfg):\n        cowrie.core.output.Output.__init__(self, cfg)\n        self.user = cfg.get('output_csirtg', 'username') or USERNAME\n        self.feed = cfg.get('output_csirtg', 'feed') or FEED\n        self.token = cfg.get('output_csirtg', 'token') or TOKEN\n        try:\n            self.description = cfg.get('output_csirtg', 'description')\n        except Exception:\n            self.description = DESCRIPTION\n        self.context = {}\n        self.client = Client(token=self.token)\n\n    def start(self,):\n        pass\n\n    def stop(self):\n        pass\n\n    def write(self, e):\n        sid = e['session']\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            logger.debug('skipping {}'.format(system))\n            return\n\n        today = str(datetime.now().date())\n\n        if not self.context.get(today):\n            logger.debug('resetting context for %s' % today)\n            self.context = {}\n            self.context[today] = set()\n\n        key = ','.join([peerIP, system])\n\n        if key in self.context[today]:\n            logger.debug('skipping {}'.format(key))\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        logger.info('logged to csirtg %s ' % ret['indicator']['location'])\n\n", "path": "cowrie/output/csirtg.py"}]}