prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  [8.0][dead_mans_switch_client] Module crashes runbots
  I'm seeing more and more runbots with :x: because of this module. [This seems the offending line](https://github.com/OCA/server-tools/blob/8.0/dead_mans_switch_client/models/dead_mans_switch_client.py#L54). Any clue on how to fix it?
  
  Example runbot: https://runbot.odoo-community.org/runbot/build/3137787
  
  CC @hbrunn.
  
  
  </issue>
  <code>
  [start of dead_mans_switch_client/__openerp__.py]
  1 # -*- coding: utf-8 -*-
  2 # © 2015 Therp BV <http://therp.nl>
  3 # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4 {
  5     "name": "Dead man's switch (client)",
  6     "version": "8.0.1.0.0",
  7     "author": "Therp BV,Odoo Community Association (OCA)",
  8     "license": "AGPL-3",
  9     "category": "Monitoring",
  10     "summary": "Be notified when customers' odoo instances go down",
  11     "depends": [
  12         'base',
  13     ],
  14     "data": [
  15         "data/ir_actions.xml",
  16         "data/ir_cron.xml",
  17     ],
  18 }
  19
  [end of dead_mans_switch_client/__openerp__.py]
  [start of dead_mans_switch_client/models/dead_mans_switch_client.py]
  1 # -*- coding: utf-8 -*-
  2 # © 2015 Therp BV <http://therp.nl>
  3 # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4 import json
  5 import logging
  6 import os
  7 try:
  8     import psutil
  9 except ImportError:
  10     psutil = None
  11 import urllib2
  12 from openerp import api, models
  13 
  14 
  15 class DeadMansSwitchClient(models.AbstractModel):
  16     _name = 'dead.mans.switch.client'
  17     _register = True
  18 
  19     @api.model
  20     def _get_data(self):
  21         ram = 0
  22         cpu = 0
  23         if psutil:
  24             process = psutil.Process(os.getpid())
  25             # psutil changed its api through versions
  26             if process.parent:
  27                 if hasattr(process.parent, '__call__'):
  28                     process = process.parent()
  29                 else:
  30                     process = process.parent
  31             if hasattr(process, 'memory_percent'):
  32                 ram = process.memory_percent()
  33             if hasattr(process, 'cpu_percent'):
  34                 cpu = process.cpu_percent()
  35         user_count = 0
  36         if 'im_chat.presence' in self.env.registry:
  37             user_count = len(self.env['im_chat.presence'].search([
  38                 ('status', '!=', 'offline'),
  39             ]))
  40         return {
  41             'database_uuid': self.env['ir.config_parameter'].get_param(
  42                 'database.uuid'),
  43             'cpu': cpu,
  44             'ram': ram,
  45             'user_count': user_count,
  46         }
  47 
  48     @api.model
  49     def alive(self):
  50         url = self.env['ir.config_parameter'].get_param(
  51             'dead_mans_switch_client.url')
  52         logger = logging.getLogger(__name__)
  53         if not url:
  54             logger.error('No server configured!')
  55             return
  56         data = self._get_data()
  57         logger.debug('sending %s', data)
  58         urllib2.urlopen(
  59             urllib2.Request(
  60                 url,
  61                 json.dumps({
  62                     'jsonrpc': '2.0',
  63                     'method': 'call',
  64                     'params': data,
  65                 }),
  66                 {
  67                     'Content-Type': 'application/json',
  68                 }))
  69
  [end of dead_mans_switch_client/models/dead_mans_switch_client.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/dead_mans_switch_client/__openerp__.py b/dead_mans_switch_client/__openerp__.py
  --- a/dead_mans_switch_client/__openerp__.py
  +++ b/dead_mans_switch_client/__openerp__.py
  @@ -3,7 +3,7 @@
   # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
   {
       "name": "Dead man's switch (client)",
  -    "version": "8.0.1.0.0",
  +    "version": "8.0.1.0.1",
       "author": "Therp BV,Odoo Community Association (OCA)",
       "license": "AGPL-3",
       "category": "Monitoring",
  @@ -15,4 +15,7 @@
           "data/ir_actions.xml",
           "data/ir_cron.xml",
       ],
  +    "demo": [
  +        "demo/dead_mans_switch_client_demo.yml",
  +    ],
   }
  diff --git a/dead_mans_switch_client/models/dead_mans_switch_client.py b/dead_mans_switch_client/models/dead_mans_switch_client.py
  --- a/dead_mans_switch_client/models/dead_mans_switch_client.py
  +++ b/dead_mans_switch_client/models/dead_mans_switch_client.py
  @@ -1,5 +1,6 @@
   # -*- coding: utf-8 -*-
   # © 2015 Therp BV <http://therp.nl>
  +# © 2015 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis
   # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
   import json
   import logging
  @@ -66,3 +67,19 @@
                   {
                       'Content-Type': 'application/json',
                   }))
  +
  +    @api.model
  +    def _install_default_url(self):
  +        """Set up a default URL."""
  +        conf = self.env["ir.config_parameter"]
  +        name = "dead_mans_switch_client.url"
  +        param = conf.get_param(name)
  +
  +        if not param:
  +            url = "{}/dead_mans_switch/alive".format(
  +                conf.get_param(
  +                    "report.url",
  +                    conf.get_param(
  +                        "web.base.url",
  +                        "http://localhost")))
  +            conf.set_param(name, url)
  
verification_info: {"golden_diff": "diff --git a/dead_mans_switch_client/__openerp__.py b/dead_mans_switch_client/__openerp__.py\n--- a/dead_mans_switch_client/__openerp__.py\n+++ b/dead_mans_switch_client/__openerp__.py\n@@ -3,7 +3,7 @@\n # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).\n {\n     \"name\": \"Dead man's switch (client)\",\n-    \"version\": \"8.0.1.0.0\",\n+    \"version\": \"8.0.1.0.1\",\n     \"author\": \"Therp BV,Odoo Community Association (OCA)\",\n     \"license\": \"AGPL-3\",\n     \"category\": \"Monitoring\",\n@@ -15,4 +15,7 @@\n         \"data/ir_actions.xml\",\n         \"data/ir_cron.xml\",\n     ],\n+    \"demo\": [\n+        \"demo/dead_mans_switch_client_demo.yml\",\n+    ],\n }\ndiff --git a/dead_mans_switch_client/models/dead_mans_switch_client.py b/dead_mans_switch_client/models/dead_mans_switch_client.py\n--- a/dead_mans_switch_client/models/dead_mans_switch_client.py\n+++ b/dead_mans_switch_client/models/dead_mans_switch_client.py\n@@ -1,5 +1,6 @@\n # -*- coding: utf-8 -*-\n # \u00a9 2015 Therp BV <http://therp.nl>\n+# \u00a9 2015 Grupo ESOC Ingenier\u00eda de Servicios, S.L.U. - Jairo Llopis\n # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).\n import json\n import logging\n@@ -66,3 +67,19 @@\n                 {\n                     'Content-Type': 'application/json',\n                 }))\n+\n+    @api.model\n+    def _install_default_url(self):\n+        \"\"\"Set up a default URL.\"\"\"\n+        conf = self.env[\"ir.config_parameter\"]\n+        name = \"dead_mans_switch_client.url\"\n+        param = conf.get_param(name)\n+\n+        if not param:\n+            url = \"{}/dead_mans_switch/alive\".format(\n+                conf.get_param(\n+                    \"report.url\",\n+                    conf.get_param(\n+                        \"web.base.url\",\n+                        \"http://localhost\")))\n+            conf.set_param(name, url)\n", "issue": "[8.0][dead_mans_switch_client] Module crashes runbots\nI'm seeing more and more runbots with :x: because of this module. [This seems the offending line](https://github.com/OCA/server-tools/blob/8.0/dead_mans_switch_client/models/dead_mans_switch_client.py#L54). Any clue on how to fix it?\n\nExample runbot: https://runbot.odoo-community.org/runbot/build/3137787\n\nCC @hbrunn.\n\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n# \u00a9 2015 Therp BV <http://therp.nl>\n# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).\n{\n    \"name\": \"Dead man's switch (client)\",\n    \"version\": \"8.0.1.0.0\",\n    \"author\": \"Therp BV,Odoo Community Association (OCA)\",\n    \"license\": \"AGPL-3\",\n    \"category\": \"Monitoring\",\n    \"summary\": \"Be notified when customers' odoo instances go down\",\n    \"depends\": [\n        'base',\n    ],\n    \"data\": [\n        \"data/ir_actions.xml\",\n        \"data/ir_cron.xml\",\n    ],\n}\n", "path": "dead_mans_switch_client/__openerp__.py"}, {"content": "# -*- coding: utf-8 -*-\n# \u00a9 2015 Therp BV <http://therp.nl>\n# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).\nimport json\nimport logging\nimport os\ntry:\n    import psutil\nexcept ImportError:\n    psutil = None\nimport urllib2\nfrom openerp import api, models\n\n\nclass DeadMansSwitchClient(models.AbstractModel):\n    _name = 'dead.mans.switch.client'\n    _register = True\n\n    @api.model\n    def _get_data(self):\n        ram = 0\n        cpu = 0\n        if psutil:\n            process = psutil.Process(os.getpid())\n            # psutil changed its api through versions\n            if process.parent:\n                if hasattr(process.parent, '__call__'):\n                    process = process.parent()\n                else:\n                    process = process.parent\n            if hasattr(process, 'memory_percent'):\n                ram = process.memory_percent()\n            if hasattr(process, 'cpu_percent'):\n                cpu = process.cpu_percent()\n        user_count = 0\n        if 'im_chat.presence' in self.env.registry:\n            user_count = len(self.env['im_chat.presence'].search([\n                ('status', '!=', 'offline'),\n            ]))\n        return {\n            'database_uuid': self.env['ir.config_parameter'].get_param(\n                'database.uuid'),\n            'cpu': cpu,\n            'ram': ram,\n            'user_count': user_count,\n        }\n\n    @api.model\n    def alive(self):\n        url = self.env['ir.config_parameter'].get_param(\n            'dead_mans_switch_client.url')\n        logger = logging.getLogger(__name__)\n        if not url:\n            logger.error('No server configured!')\n            return\n        data = self._get_data()\n        logger.debug('sending %s', data)\n        urllib2.urlopen(\n            urllib2.Request(\n                url,\n                json.dumps({\n                    'jsonrpc': '2.0',\n                    'method': 'call',\n                    'params': data,\n                }),\n                {\n                    'Content-Type': 'application/json',\n                }))\n", "path": "dead_mans_switch_client/models/dead_mans_switch_client.py"}]}