We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Mysql output has incorrect sql query in line 121
line 120-121 of src/cowrie/output/mysql.py show:
```
elif entry["eventid"] == 'cowrie.login.failed':
    self.simpleQuery('INSERT INTO `auth` (`session`, `success` `username`, `password`, `timestamp`) '
```
There is a missing comma between `success` & `username`. This results in failure to log failed login attempts to mysql.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `src/cowrie/output/mysql.py`
Content:
```
1 """
2 MySQL output connector. Writes audit logs to MySQL database
3 """
4 
5 from __future__ import absolute_import, division
6 
7 import MySQLdb
8 
9 from twisted.enterprise import adbapi
10 from twisted.internet import defer
11 from twisted.python import log
12 
13 import cowrie.core.output
14 from cowrie.core.config import CONFIG
15 
16 
17 class ReconnectingConnectionPool(adbapi.ConnectionPool):
18     """
19     Reconnecting adbapi connection pool for MySQL.
20 
21     This class improves on the solution posted at
22     http://www.gelens.org/2008/09/12/reinitializing-twisted-connectionpool/
23     by checking exceptions by error code and only disconnecting the current
24     connection instead of all of them.
25 
26     Also see:
27     http://twistedmatrix.com/pipermail/twisted-python/2009-July/020007.html
28     """
29 
30     def _runInteraction(self, interaction, *args, **kw):
31         try:
32             return adbapi.ConnectionPool._runInteraction(
33                 self, interaction, *args, **kw)
34         except MySQLdb.OperationalError as e:
35             if e[0] not in (2003, 2006, 2013):
36                 log.msg("RCP: got error {0}, retrying operation".format(e))
37                 raise e
38             conn = self.connections.get(self.threadID())
39             self.disconnect(conn)
40             # Try the interaction again
41             return adbapi.ConnectionPool._runInteraction(
42                 self, interaction, *args, **kw)
43 
44 
45 class Output(cowrie.core.output.Output):
46     db = None
47 
48     def __init__(self):
49         try:
50             self.debug = CONFIG.getboolean('output_mysql', 'debug')
51         except Exception:
52             self.debug = False
53 
54         cowrie.core.output.Output.__init__(self)
55 
56     def start(self):
57         try:
58             port = CONFIG.getint('output_mysql', 'port')
59         except Exception:
60             port = 3306
61 
62         try:
63             self.db = ReconnectingConnectionPool(
64                 'MySQLdb',
65                 host=CONFIG.get('output_mysql', 'host'),
66                 db=CONFIG.get('output_mysql', 'database'),
67                 user=CONFIG.get('output_mysql', 'username'),
68                 passwd=CONFIG.get('output_mysql', 'password', raw=True),
69                 port=port,
70                 cp_min=1,
71                 cp_max=1
72             )
73         except MySQLdb.Error as e:
74             log.msg("output_mysql: Error %d: %s" % (e.args[0], e.args[1]))
75 
76     def stop(self):
77         self.db.close()
78 
79     def sqlerror(self, error):
80         log.err('output_mysql: MySQL Error: {}'.format(error.value))
81 
82     def simpleQuery(self, sql, args):
83         """
84         Just run a deferred sql query, only care about errors
85         """
86         if self.debug:
87             log.msg("output_mysql: MySQL query: {} {}".format(sql, repr(args)))
88         d = self.db.runQuery(sql, args)
89         d.addErrback(self.sqlerror)
90 
91     @defer.inlineCallbacks
92     def write(self, entry):
93         if entry["eventid"] == 'cowrie.session.connect':
94             r = yield self.db.runQuery(
95                 "SELECT `id`"
96                 "FROM `sensors`"
97                 "WHERE `ip` = %s",
98                 (self.sensor,))
99 
100             if r:
101                 sensorid = r[0][0]
102             else:
103                 yield self.db.runQuery(
104                     'INSERT INTO `sensors` (`ip`) '
105                     'VALUES (%s)',
106                     (self.sensor,))
107 
108                 r = yield self.db.runQuery('SELECT LAST_INSERT_ID()')
109                 sensorid = int(r[0][0])
110             self.simpleQuery(
111                 "INSERT INTO `sessions` (`id`, `starttime`, `sensor`, `ip`) "
112                 "VALUES (%s, FROM_UNIXTIME(%s), %s, %s)",
113                 (entry["session"], entry["time"], sensorid, entry["src_ip"]))
114 
115         elif entry["eventid"] == 'cowrie.login.success':
116             self.simpleQuery('INSERT INTO `auth` (`session`, `success`, `username`, `password`, `timestamp`) '
117                              'VALUES (%s, %s, %s, %s, FROM_UNIXTIME(%s))',
118                              (entry["session"], 1, entry['username'], entry['password'], entry["time"]))
119 
120         elif entry["eventid"] == 'cowrie.login.failed':
121             self.simpleQuery('INSERT INTO `auth` (`session`, `success` `username`, `password`, `timestamp`) '
122                              'VALUES (%s, %s, %s, %s, FROM_UNIXTIME(%s))',
123                              (entry["session"], 0, entry['username'], entry['password'], entry["time"]))
124 
125         elif entry["eventid"] == 'cowrie.session.params':
126             self.simpleQuery('INSERT INTO `params` (`session`, `arch`) '
127                              'VALUES (%s, %s)',
128                              (entry["session"], entry["arch"]))
129 
130         elif entry["eventid"] == 'cowrie.command.input':
131             self.simpleQuery('INSERT INTO `input` (`session`, `timestamp`, `success`, `input`) '
132                              'VALUES (%s, FROM_UNIXTIME(%s), %s , %s)',
133                              (entry["session"], entry["time"], 1, entry["input"]))
134 
135         elif entry["eventid"] == 'cowrie.command.failed':
136             self.simpleQuery('INSERT INTO `input` (`session`, `timestamp`, `success`, `input`) '
137                              'VALUES (%s, FROM_UNIXTIME(%s), %s , %s)',
138                              (entry["session"], entry["time"], 0, entry["input"]))
139 
140         elif entry["eventid"] == 'cowrie.session.file_download':
141             self.simpleQuery('INSERT INTO `downloads` (`session`, `timestamp`, `url`, `outfile`, `shasum`) '
142                              'VALUES (%s, FROM_UNIXTIME(%s), %s, %s, %s)',
143                              (entry["session"], entry["time"], entry['url'], entry['outfile'], entry['shasum']))
144 
145         elif entry["eventid"] == 'cowrie.session.file_download.failed':
146             self.simpleQuery('INSERT INTO `downloads` (`session`, `timestamp`, `url`, `outfile`, `shasum`) '
147                              'VALUES (%s, FROM_UNIXTIME(%s), %s, %s, %s)',
148                              (entry["session"], entry["time"], entry['url'], 'NULL', 'NULL'))
149 
150         elif entry["eventid"] == 'cowrie.session.file_upload':
151             self.simpleQuery('INSERT INTO `downloads` (`session`, `timestamp`, `url`, `outfile`, `shasum`) '
152                              'VALUES (%s, FROM_UNIXTIME(%s), %s, %s, %s)',
153                              (entry["session"], entry["time"], '', entry['outfile'], entry['shasum']))
154 
155         elif entry["eventid"] == 'cowrie.session.input':
156             self.simpleQuery('INSERT INTO `input` (`session`, `timestamp`, `realm`, `input`) '
157                              'VALUES (%s, FROM_UNIXTIME(%s), %s , %s)',
158                              (entry["session"], entry["time"], entry["realm"], entry["input"]))
159 
160         elif entry["eventid"] == 'cowrie.client.version':
161             r = yield self.db.runQuery(
162                 'SELECT `id` FROM `clients` '
163                 'WHERE `version` = %s',
164                 (entry['version'],))
165 
166             if r:
167                 id = int(r[0][0])
168             else:
169                 yield self.db.runQuery(
170                     'INSERT INTO `clients` (`version`) '
171                     'VALUES (%s)',
172                     (entry['version'],))
173 
174                 r = yield self.db.runQuery('SELECT LAST_INSERT_ID()')
175                 id = int(r[0][0])
176             self.simpleQuery(
177                 'UPDATE `sessions` '
178                 'SET `client` = %s '
179                 'WHERE `id` = %s',
180                 (id, entry["session"]))
181 
182         elif entry["eventid"] == 'cowrie.client.size':
183             self.simpleQuery(
184                 'UPDATE `sessions` '
185                 'SET `termsize` = %s '
186                 'WHERE `id` = %s',
187                 ('%sx%s' % (entry['width'], entry['height']), entry["session"]))
188 
189         elif entry["eventid"] == 'cowrie.session.closed':
190             self.simpleQuery(
191                 'UPDATE `sessions` '
192                 'SET `endtime` = FROM_UNIXTIME(%s) '
193                 'WHERE `id` = %s',
194                 (entry["time"], entry["session"]))
195 
196         elif entry["eventid"] == 'cowrie.log.closed':
197             self.simpleQuery(
198                 'INSERT INTO `ttylog` (`session`, `ttylog`, `size`) '
199                 'VALUES (%s, %s, %s)',
200                 (entry["session"], entry["ttylog"], entry["size"]))
201 
202         elif entry["eventid"] == 'cowrie.client.fingerprint':
203             self.simpleQuery(
204                 'INSERT INTO `keyfingerprints` (`session`, `username`, `fingerprint`) '
205                 'VALUES (%s, %s, %s)',
206                 (entry["session"], entry["username"], entry["fingerprint"]))
207
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/src/cowrie/output/mysql.py b/src/cowrie/output/mysql.py
--- a/src/cowrie/output/mysql.py
+++ b/src/cowrie/output/mysql.py
@@ -118,7 +118,7 @@
                              (entry["session"], 1, entry['username'], entry['password'], entry["time"]))
 
         elif entry["eventid"] == 'cowrie.login.failed':
-            self.simpleQuery('INSERT INTO `auth` (`session`, `success` `username`, `password`, `timestamp`) '
+            self.simpleQuery('INSERT INTO `auth` (`session`, `success`, `username`, `password`, `timestamp`) '
                              'VALUES (%s, %s, %s, %s, FROM_UNIXTIME(%s))',
                              (entry["session"], 0, entry['username'], entry['password'], entry["time"]))

{"golden_diff": "diff --git a/src/cowrie/output/mysql.py b/src/cowrie/output/mysql.py\n--- a/src/cowrie/output/mysql.py\n+++ b/src/cowrie/output/mysql.py\n@@ -118,7 +118,7 @@\n                              (entry[\"session\"], 1, entry['username'], entry['password'], entry[\"time\"]))\n \n         elif entry[\"eventid\"] == 'cowrie.login.failed':\n-            self.simpleQuery('INSERT INTO `auth` (`session`, `success` `username`, `password`, `timestamp`) '\n+            self.simpleQuery('INSERT INTO `auth` (`session`, `success`, `username`, `password`, `timestamp`) '\n                              'VALUES (%s, %s, %s, %s, FROM_UNIXTIME(%s))',\n                              (entry[\"session\"], 0, entry['username'], entry['password'], entry[\"time\"]))\n", "issue": "Mysql output has incorrect sql query in line 121\nline 120-121 of src/cowrie/output/mysql.py show:\r\n```\r\nelif entry[\"eventid\"] == 'cowrie.login.failed':\r\n    self.simpleQuery('INSERT INTO `auth` (`session`, `success` `username`, `password`, `timestamp`) '\r\n```\r\nThere is a missing comma between `success` & `username`. This results in failure to log failed login attempts to mysql.\n", "before_files": [{"content": "\"\"\"\nMySQL output connector. Writes audit logs to MySQL database\n\"\"\"\n\nfrom __future__ import absolute_import, division\n\nimport MySQLdb\n\nfrom twisted.enterprise import adbapi\nfrom twisted.internet import defer\nfrom twisted.python import log\n\nimport cowrie.core.output\nfrom cowrie.core.config import CONFIG\n\n\nclass ReconnectingConnectionPool(adbapi.ConnectionPool):\n    \"\"\"\n    Reconnecting adbapi connection pool for MySQL.\n\n    This class improves on the solution posted at\n    http://www.gelens.org/2008/09/12/reinitializing-twisted-connectionpool/\n    by checking exceptions by error code and only disconnecting the current\n    connection instead of all of them.\n\n    Also see:\n    http://twistedmatrix.com/pipermail/twisted-python/2009-July/020007.html\n    \"\"\"\n\n    def _runInteraction(self, interaction, *args, **kw):\n        try:\n            return adbapi.ConnectionPool._runInteraction(\n                self, interaction, *args, **kw)\n        except MySQLdb.OperationalError as e:\n            if e[0] not in (2003, 2006, 2013):\n                log.msg(\"RCP: got error {0}, retrying operation\".format(e))\n                raise e\n            conn = self.connections.get(self.threadID())\n            self.disconnect(conn)\n            # Try the interaction again\n            return adbapi.ConnectionPool._runInteraction(\n                self, interaction, *args, **kw)\n\n\nclass Output(cowrie.core.output.Output):\n    db = None\n\n    def __init__(self):\n        try:\n            self.debug = CONFIG.getboolean('output_mysql', 'debug')\n        except Exception:\n            self.debug = False\n\n        cowrie.core.output.Output.__init__(self)\n\n    def start(self):\n        try:\n            port = CONFIG.getint('output_mysql', 'port')\n        except Exception:\n            port = 3306\n\n        try:\n            self.db = ReconnectingConnectionPool(\n                'MySQLdb',\n                host=CONFIG.get('output_mysql', 'host'),\n                db=CONFIG.get('output_mysql', 'database'),\n                user=CONFIG.get('output_mysql', 'username'),\n                passwd=CONFIG.get('output_mysql', 'password', raw=True),\n                port=port,\n                cp_min=1,\n                cp_max=1\n            )\n        except MySQLdb.Error as e:\n            log.msg(\"output_mysql: Error %d: %s\" % (e.args[0], e.args[1]))\n\n    def stop(self):\n        self.db.close()\n\n    def sqlerror(self, error):\n        log.err('output_mysql: MySQL Error: {}'.format(error.value))\n\n    def simpleQuery(self, sql, args):\n        \"\"\"\n        Just run a deferred sql query, only care about errors\n        \"\"\"\n        if self.debug:\n            log.msg(\"output_mysql: MySQL query: {} {}\".format(sql, repr(args)))\n        d = self.db.runQuery(sql, args)\n        d.addErrback(self.sqlerror)\n\n    @defer.inlineCallbacks\n    def write(self, entry):\n        if entry[\"eventid\"] == 'cowrie.session.connect':\n            r = yield self.db.runQuery(\n                \"SELECT `id`\"\n                \"FROM `sensors`\"\n                \"WHERE `ip` = %s\",\n                (self.sensor,))\n\n            if r:\n                sensorid = r[0][0]\n            else:\n                yield self.db.runQuery(\n                    'INSERT INTO `sensors` (`ip`) '\n                    'VALUES (%s)',\n                    (self.sensor,))\n\n                r = yield self.db.runQuery('SELECT LAST_INSERT_ID()')\n                sensorid = int(r[0][0])\n            self.simpleQuery(\n                \"INSERT INTO `sessions` (`id`, `starttime`, `sensor`, `ip`) \"\n                \"VALUES (%s, FROM_UNIXTIME(%s), %s, %s)\",\n                (entry[\"session\"], entry[\"time\"], sensorid, entry[\"src_ip\"]))\n\n        elif entry[\"eventid\"] == 'cowrie.login.success':\n            self.simpleQuery('INSERT INTO `auth` (`session`, `success`, `username`, `password`, `timestamp`) '\n                             'VALUES (%s, %s, %s, %s, FROM_UNIXTIME(%s))',\n                             (entry[\"session\"], 1, entry['username'], entry['password'], entry[\"time\"]))\n\n        elif entry[\"eventid\"] == 'cowrie.login.failed':\n            self.simpleQuery('INSERT INTO `auth` (`session`, `success` `username`, `password`, `timestamp`) '\n                             'VALUES (%s, %s, %s, %s, FROM_UNIXTIME(%s))',\n                             (entry[\"session\"], 0, entry['username'], entry['password'], entry[\"time\"]))\n\n        elif entry[\"eventid\"] == 'cowrie.session.params':\n            self.simpleQuery('INSERT INTO `params` (`session`, `arch`) '\n                             'VALUES (%s, %s)',\n                             (entry[\"session\"], entry[\"arch\"]))\n\n        elif entry[\"eventid\"] == 'cowrie.command.input':\n            self.simpleQuery('INSERT INTO `input` (`session`, `timestamp`, `success`, `input`) '\n                             'VALUES (%s, FROM_UNIXTIME(%s), %s , %s)',\n                             (entry[\"session\"], entry[\"time\"], 1, entry[\"input\"]))\n\n        elif entry[\"eventid\"] == 'cowrie.command.failed':\n            self.simpleQuery('INSERT INTO `input` (`session`, `timestamp`, `success`, `input`) '\n                             'VALUES (%s, FROM_UNIXTIME(%s), %s , %s)',\n                             (entry[\"session\"], entry[\"time\"], 0, entry[\"input\"]))\n\n        elif entry[\"eventid\"] == 'cowrie.session.file_download':\n            self.simpleQuery('INSERT INTO `downloads` (`session`, `timestamp`, `url`, `outfile`, `shasum`) '\n                             'VALUES (%s, FROM_UNIXTIME(%s), %s, %s, %s)',\n                             (entry[\"session\"], entry[\"time\"], entry['url'], entry['outfile'], entry['shasum']))\n\n        elif entry[\"eventid\"] == 'cowrie.session.file_download.failed':\n            self.simpleQuery('INSERT INTO `downloads` (`session`, `timestamp`, `url`, `outfile`, `shasum`) '\n                             'VALUES (%s, FROM_UNIXTIME(%s), %s, %s, %s)',\n                             (entry[\"session\"], entry[\"time\"], entry['url'], 'NULL', 'NULL'))\n\n        elif entry[\"eventid\"] == 'cowrie.session.file_upload':\n            self.simpleQuery('INSERT INTO `downloads` (`session`, `timestamp`, `url`, `outfile`, `shasum`) '\n                             'VALUES (%s, FROM_UNIXTIME(%s), %s, %s, %s)',\n                             (entry[\"session\"], entry[\"time\"], '', entry['outfile'], entry['shasum']))\n\n        elif entry[\"eventid\"] == 'cowrie.session.input':\n            self.simpleQuery('INSERT INTO `input` (`session`, `timestamp`, `realm`, `input`) '\n                             'VALUES (%s, FROM_UNIXTIME(%s), %s , %s)',\n                             (entry[\"session\"], entry[\"time\"], entry[\"realm\"], entry[\"input\"]))\n\n        elif entry[\"eventid\"] == 'cowrie.client.version':\n            r = yield self.db.runQuery(\n                'SELECT `id` FROM `clients` '\n                'WHERE `version` = %s',\n                (entry['version'],))\n\n            if r:\n                id = int(r[0][0])\n            else:\n                yield self.db.runQuery(\n                    'INSERT INTO `clients` (`version`) '\n                    'VALUES (%s)',\n                    (entry['version'],))\n\n                r = yield self.db.runQuery('SELECT LAST_INSERT_ID()')\n                id = int(r[0][0])\n            self.simpleQuery(\n                'UPDATE `sessions` '\n                'SET `client` = %s '\n                'WHERE `id` = %s',\n                (id, entry[\"session\"]))\n\n        elif entry[\"eventid\"] == 'cowrie.client.size':\n            self.simpleQuery(\n                'UPDATE `sessions` '\n                'SET `termsize` = %s '\n                'WHERE `id` = %s',\n                ('%sx%s' % (entry['width'], entry['height']), entry[\"session\"]))\n\n        elif entry[\"eventid\"] == 'cowrie.session.closed':\n            self.simpleQuery(\n                'UPDATE `sessions` '\n                'SET `endtime` = FROM_UNIXTIME(%s) '\n                'WHERE `id` = %s',\n                (entry[\"time\"], entry[\"session\"]))\n\n        elif entry[\"eventid\"] == 'cowrie.log.closed':\n            self.simpleQuery(\n                'INSERT INTO `ttylog` (`session`, `ttylog`, `size`) '\n                'VALUES (%s, %s, %s)',\n                (entry[\"session\"], entry[\"ttylog\"], entry[\"size\"]))\n\n        elif entry[\"eventid\"] == 'cowrie.client.fingerprint':\n            self.simpleQuery(\n                'INSERT INTO `keyfingerprints` (`session`, `username`, `fingerprint`) '\n                'VALUES (%s, %s, %s)',\n                (entry[\"session\"], entry[\"username\"], entry[\"fingerprint\"]))\n", "path": "src/cowrie/output/mysql.py"}], "after_files": [{"content": "\"\"\"\nMySQL output connector. Writes audit logs to MySQL database\n\"\"\"\n\nfrom __future__ import absolute_import, division\n\nimport MySQLdb\n\nfrom twisted.enterprise import adbapi\nfrom twisted.internet import defer\nfrom twisted.python import log\n\nimport cowrie.core.output\nfrom cowrie.core.config import CONFIG\n\n\nclass ReconnectingConnectionPool(adbapi.ConnectionPool):\n    \"\"\"\n    Reconnecting adbapi connection pool for MySQL.\n\n    This class improves on the solution posted at\n    http://www.gelens.org/2008/09/12/reinitializing-twisted-connectionpool/\n    by checking exceptions by error code and only disconnecting the current\n    connection instead of all of them.\n\n    Also see:\n    http://twistedmatrix.com/pipermail/twisted-python/2009-July/020007.html\n    \"\"\"\n\n    def _runInteraction(self, interaction, *args, **kw):\n        try:\n            return adbapi.ConnectionPool._runInteraction(\n                self, interaction, *args, **kw)\n        except MySQLdb.OperationalError as e:\n            if e[0] not in (2003, 2006, 2013):\n                log.msg(\"RCP: got error {0}, retrying operation\".format(e))\n                raise e\n            conn = self.connections.get(self.threadID())\n            self.disconnect(conn)\n            # Try the interaction again\n            return adbapi.ConnectionPool._runInteraction(\n                self, interaction, *args, **kw)\n\n\nclass Output(cowrie.core.output.Output):\n    db = None\n\n    def __init__(self):\n        try:\n            self.debug = CONFIG.getboolean('output_mysql', 'debug')\n        except Exception:\n            self.debug = False\n\n        cowrie.core.output.Output.__init__(self)\n\n    def start(self):\n        try:\n            port = CONFIG.getint('output_mysql', 'port')\n        except Exception:\n            port = 3306\n\n        try:\n            self.db = ReconnectingConnectionPool(\n                'MySQLdb',\n                host=CONFIG.get('output_mysql', 'host'),\n                db=CONFIG.get('output_mysql', 'database'),\n                user=CONFIG.get('output_mysql', 'username'),\n                passwd=CONFIG.get('output_mysql', 'password', raw=True),\n                port=port,\n                cp_min=1,\n                cp_max=1\n            )\n        except MySQLdb.Error as e:\n            log.msg(\"output_mysql: Error %d: %s\" % (e.args[0], e.args[1]))\n\n    def stop(self):\n        self.db.close()\n\n    def sqlerror(self, error):\n        log.err('output_mysql: MySQL Error: {}'.format(error.value))\n\n    def simpleQuery(self, sql, args):\n        \"\"\"\n        Just run a deferred sql query, only care about errors\n        \"\"\"\n        if self.debug:\n            log.msg(\"output_mysql: MySQL query: {} {}\".format(sql, repr(args)))\n        d = self.db.runQuery(sql, args)\n        d.addErrback(self.sqlerror)\n\n    @defer.inlineCallbacks\n    def write(self, entry):\n        if entry[\"eventid\"] == 'cowrie.session.connect':\n            r = yield self.db.runQuery(\n                \"SELECT `id`\"\n                \"FROM `sensors`\"\n                \"WHERE `ip` = %s\",\n                (self.sensor,))\n\n            if r:\n                sensorid = r[0][0]\n            else:\n                yield self.db.runQuery(\n                    'INSERT INTO `sensors` (`ip`) '\n                    'VALUES (%s)',\n                    (self.sensor,))\n\n                r = yield self.db.runQuery('SELECT LAST_INSERT_ID()')\n                sensorid = int(r[0][0])\n            self.simpleQuery(\n                \"INSERT INTO `sessions` (`id`, `starttime`, `sensor`, `ip`) \"\n                \"VALUES (%s, FROM_UNIXTIME(%s), %s, %s)\",\n                (entry[\"session\"], entry[\"time\"], sensorid, entry[\"src_ip\"]))\n\n        elif entry[\"eventid\"] == 'cowrie.login.success':\n            self.simpleQuery('INSERT INTO `auth` (`session`, `success`, `username`, `password`, `timestamp`) '\n                             'VALUES (%s, %s, %s, %s, FROM_UNIXTIME(%s))',\n                             (entry[\"session\"], 1, entry['username'], entry['password'], entry[\"time\"]))\n\n        elif entry[\"eventid\"] == 'cowrie.login.failed':\n            self.simpleQuery('INSERT INTO `auth` (`session`, `success`, `username`, `password`, `timestamp`) '\n                             'VALUES (%s, %s, %s, %s, FROM_UNIXTIME(%s))',\n                             (entry[\"session\"], 0, entry['username'], entry['password'], entry[\"time\"]))\n\n        elif entry[\"eventid\"] == 'cowrie.session.params':\n            self.simpleQuery('INSERT INTO `params` (`session`, `arch`) '\n                             'VALUES (%s, %s)',\n                             (entry[\"session\"], entry[\"arch\"]))\n\n        elif entry[\"eventid\"] == 'cowrie.command.input':\n            self.simpleQuery('INSERT INTO `input` (`session`, `timestamp`, `success`, `input`) '\n                             'VALUES (%s, FROM_UNIXTIME(%s), %s , %s)',\n                             (entry[\"session\"], entry[\"time\"], 1, entry[\"input\"]))\n\n        elif entry[\"eventid\"] == 'cowrie.command.failed':\n            self.simpleQuery('INSERT INTO `input` (`session`, `timestamp`, `success`, `input`) '\n                             'VALUES (%s, FROM_UNIXTIME(%s), %s , %s)',\n                             (entry[\"session\"], entry[\"time\"], 0, entry[\"input\"]))\n\n        elif entry[\"eventid\"] == 'cowrie.session.file_download':\n            self.simpleQuery('INSERT INTO `downloads` (`session`, `timestamp`, `url`, `outfile`, `shasum`) '\n                             'VALUES (%s, FROM_UNIXTIME(%s), %s, %s, %s)',\n                             (entry[\"session\"], entry[\"time\"], entry['url'], entry['outfile'], entry['shasum']))\n\n        elif entry[\"eventid\"] == 'cowrie.session.file_download.failed':\n            self.simpleQuery('INSERT INTO `downloads` (`session`, `timestamp`, `url`, `outfile`, `shasum`) '\n                             'VALUES (%s, FROM_UNIXTIME(%s), %s, %s, %s)',\n                             (entry[\"session\"], entry[\"time\"], entry['url'], 'NULL', 'NULL'))\n\n        elif entry[\"eventid\"] == 'cowrie.session.file_upload':\n            self.simpleQuery('INSERT INTO `downloads` (`session`, `timestamp`, `url`, `outfile`, `shasum`) '\n                             'VALUES (%s, FROM_UNIXTIME(%s), %s, %s, %s)',\n                             (entry[\"session\"], entry[\"time\"], '', entry['outfile'], entry['shasum']))\n\n        elif entry[\"eventid\"] == 'cowrie.session.input':\n            self.simpleQuery('INSERT INTO `input` (`session`, `timestamp`, `realm`, `input`) '\n                             'VALUES (%s, FROM_UNIXTIME(%s), %s , %s)',\n                             (entry[\"session\"], entry[\"time\"], entry[\"realm\"], entry[\"input\"]))\n\n        elif entry[\"eventid\"] == 'cowrie.client.version':\n            r = yield self.db.runQuery(\n                'SELECT `id` FROM `clients` '\n                'WHERE `version` = %s',\n                (entry['version'],))\n\n            if r:\n                id = int(r[0][0])\n            else:\n                yield self.db.runQuery(\n                    'INSERT INTO `clients` (`version`) '\n                    'VALUES (%s)',\n                    (entry['version'],))\n\n                r = yield self.db.runQuery('SELECT LAST_INSERT_ID()')\n                id = int(r[0][0])\n            self.simpleQuery(\n                'UPDATE `sessions` '\n                'SET `client` = %s '\n                'WHERE `id` = %s',\n                (id, entry[\"session\"]))\n\n        elif entry[\"eventid\"] == 'cowrie.client.size':\n            self.simpleQuery(\n                'UPDATE `sessions` '\n                'SET `termsize` = %s '\n                'WHERE `id` = %s',\n                ('%sx%s' % (entry['width'], entry['height']), entry[\"session\"]))\n\n        elif entry[\"eventid\"] == 'cowrie.session.closed':\n            self.simpleQuery(\n                'UPDATE `sessions` '\n                'SET `endtime` = FROM_UNIXTIME(%s) '\n                'WHERE `id` = %s',\n                (entry[\"time\"], entry[\"session\"]))\n\n        elif entry[\"eventid\"] == 'cowrie.log.closed':\n            self.simpleQuery(\n                'INSERT INTO `ttylog` (`session`, `ttylog`, `size`) '\n                'VALUES (%s, %s, %s)',\n                (entry[\"session\"], entry[\"ttylog\"], entry[\"size\"]))\n\n        elif entry[\"eventid\"] == 'cowrie.client.fingerprint':\n            self.simpleQuery(\n                'INSERT INTO `keyfingerprints` (`session`, `username`, `fingerprint`) '\n                'VALUES (%s, %s, %s)',\n                (entry[\"session\"], entry[\"username\"], entry[\"fingerprint\"]))\n", "path": "src/cowrie/output/mysql.py"}]}