Browse Source

[ADD] dead_mans_switch_client

pull/303/head
Holger Brunn 9 years ago
parent
commit
6c83748d4e
  1. 4
      dead_mans_switch_client/__init__.py
  2. 39
      dead_mans_switch_client/__openerp__.py
  3. 13
      dead_mans_switch_client/data/ir_actions.xml
  4. 13
      dead_mans_switch_client/data/ir_cron.xml
  5. 4
      dead_mans_switch_client/models/__init__.py
  6. 67
      dead_mans_switch_client/models/dead_mans_switch_client.py
  7. BIN
      dead_mans_switch_client/static/src/img/icon.png

4
dead_mans_switch_client/__init__.py

@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# © 2015 Therp BV <http://therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import models

39
dead_mans_switch_client/__openerp__.py

@ -0,0 +1,39 @@
# -*- coding: utf-8 -*-
# © 2015 Therp BV <http://therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "Dead man's switch (client)",
"version": "1.0.0",
"author": "Therp BV,Odoo Community Association (OCA)",
"license": "AGPL-3",
"category": "Monitoring",
"description": """
==========================
Dead man's switch (client)
==========================
This module is the client part of `dead_mans_switch_server`. It is responsible
of sending the server status updates, which in turn takes action if those
updates don't come in time.
Configuration
=============
After installing this module, you need to fill in the system parameter
`dead_mans_switch_client.url`. This must be the full URL to the server's
controller, usually of the form https://your.server/dead_mans_switch/alive
This module attempts to send CPU and RAM statistics to the server. While this
is not mandatory, it's helpful for assessing a server's health. If you want
this, you need to install `psutil`.
You can also have the currently online users logged, but this only works if
the `im_chat` module is installed.""",
"depends": [
'base',
],
"data": [
"data/ir_actions.xml",
"data/ir_cron.xml",
],
}

13
dead_mans_switch_client/data/ir_actions.xml

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<act_window id="action_setup" res_model="ir.config_parameter"
name="Configure the dead man's switch server" view_mode="form"
context="{'default_key': 'dead_mans_switch_client.url'}"/>
<record id="todo_setup" model="ir.actions.todo">
<field name="name">Configure the dead man's switch server</field>
<field name="type">automatic</field>
<field name="action_id" ref="action_setup" />
</record>
</data>
</openerp>

13
dead_mans_switch_client/data/ir_cron.xml

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data noupdate="1">
<record id="cron_client" model="ir.cron">
<field name="name">Dead man&apos;s switch client</field>
<field name="interval_number">5</field>
<field name="interval_type">minutes</field>
<field name="numbercall">-1</field>
<field name="model">dead.mans.switch.client</field>
<field name="function">alive</field>
</record>
</data>
</openerp>

4
dead_mans_switch_client/models/__init__.py

@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# © 2015 Therp BV <http://therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import dead_mans_switch_client

67
dead_mans_switch_client/models/dead_mans_switch_client.py

@ -0,0 +1,67 @@
# -*- coding: utf-8 -*-
# © 2015 Therp BV <http://therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import json
import logging
import os
try:
import psutil
except ImportError:
psutil = None
import urllib2
from openerp.osv import orm
class DeadMansSwitchClient(orm.AbstractModel):
_name = 'dead.mans.switch.client'
_register = True
def _get_data(self, cr, uid, context=None):
ram = 0
cpu = 0
if psutil:
process = psutil.Process(os.getpid())
# psutil changed its api through versions
processes = [process]
if process.parent:
if hasattr(process.parent, '__call__'):
process = process.parent()
else:
process = process.parent
if hasattr(process, 'children'):
processes += process.children(True)
elif hasattr(process, 'get_children'):
processes += process.get_children(True)
for process in processes:
if hasattr(process, 'memory_percent'):
ram += process.memory_percent()
if hasattr(process, 'cpu_percent'):
cpu += process.cpu_percent()
return {
'database_uuid': self.pool['ir.config_parameter'].get_param(
cr, uid, 'database.uuid', context=context),
'cpu': cpu,
'ram': ram,
'user_count': 0,
}
def alive(self, cr, uid, context=None):
url = self.pool['ir.config_parameter'].get_param(
cr, uid, 'dead_mans_switch_client.url')
logger = logging.getLogger(__name__)
if not url:
logger.error('No server configured!')
return
data = self._get_data(cr, uid, context=context)
logger.debug('sending %s', data)
urllib2.urlopen(
urllib2.Request(
url,
json.dumps({
'jsonrpc': '2.0',
'method': 'call',
'params': data,
}),
{
'Content-Type': 'application/json',
}))

BIN
dead_mans_switch_client/static/src/img/icon.png

After

Width: 128  |  Height: 128  |  Size: 9.2 KiB

Loading…
Cancel
Save