Migrate to version 3.8

(grafted from eec3a3932591273a0465b141921b62c21f399a00)
This commit is contained in:
Sergi Almacellas Abellana 2015-12-16 00:12:51 +01:00
parent cbc12252b7
commit e411b94109
11 changed files with 56 additions and 51 deletions

View File

@ -1,2 +1,3 @@
Version 3.8.0 - 2015-12-09
Version 3.4.0 - 2014-11-03
* Initial release

View File

@ -3,12 +3,13 @@
import sys
import ssl
import sql
from sql import Column
import xmlrpclib
from datetime import datetime
import random
import string
import hashlib
from itertools import izip, chain, groupby
from itertools import izip, chain
from decimal import Decimal
import logging
@ -17,13 +18,13 @@ try:
except ImportError:
bcrypt = None
from trytond.tools import safe_eval
from trytond.model import ModelSQL, ModelView, fields
from trytond.pool import Pool, PoolMeta
from trytond.pyson import Eval
from trytond.config import config
from trytond.rpc import RPC
from trytond.transaction import Transaction
from trytond import backend
__all__ = ['CheckType', 'ResultType', 'StateType', 'StateIndicator',
@ -61,7 +62,6 @@ class StateType(ModelSQL, ModelView):
'Monitoring State Value'
__name__ = 'monitoring.state.type'
name = fields.Char('Name', translate=True, required=True)
color = fields.Char('Color')
class StateIndicator(ModelSQL, ModelView):
@ -104,9 +104,30 @@ class Scheduler(ModelSQL, ModelView):
# It might make sense to create a parent and inherit values from the
# parent similar to Nagios behaviour.
name = fields.Char('Name', required=True, translate=True)
normal_check_interval = fields.Float('Normal Check Interval', required=True)
normal_check = fields.TimeDelta('Normal Check Interval', required=True)
retries = fields.Integer('Retries', required=True)
retry_check_interval = fields.Float('Retry Check Interval', required=True)
retry_check = fields.TimeDelta('Retry Check Interval', required=True)
@classmethod
def __register__(cls, module_name):
TableHandler = backend.get('TableHandler')
cursor = Transaction().cursor
table = TableHandler(cursor, cls, module_name)
sql_table = cls.__table__()
super(Scheduler, cls).__register__(module_name)
for field in ('normal_check', 'retry_check'):
old_field = '%s_interval'
if table.column_exist(old_field):
cursor.execute(*sql_table.select(
sql_table.id, Column(sql_table, old_field)))
for id_, hours in cursor.fetchall():
new_value = datetime.timedelta(hours=hours)
cursor.execute(*sql_table.update(
[Column(sql_table, field)],
[new_value],
where=sql_table.id == id_))
table.drop_column(old_field)
# TODO: We should probably create a scheduler queue
@ -164,7 +185,7 @@ class CheckPlan(ModelSQL, ModelView):
state_type = None
for line in indicator.lines:
#ast.literal_eval(indicator.expression)
if safe_eval(line.expression, {
if eval(line.expression, {
'value': value,
'label': label,
'payload': payload,
@ -288,7 +309,7 @@ class CheckPlan(ModelSQL, ModelView):
last_check = checks[0]
delta = datetime.now() - last_check.timestamp
if (delta.seconds / 3600.0) >= plan.scheduler.normal_check_interval:
if delta >= plan.scheduler.normal_check:
to_check.append(plan)
cls.check(cls.browse([x.id for x in to_check]))
@ -328,13 +349,12 @@ class StateIndicatorCheckPlan(ModelSQL, ModelView):
'Monitoring Asset'), 'get_asset', searcher='search_asset')
monitored_asset = fields.Function(fields.Many2One('asset',
'Monitored Asset'), 'get_asset', searcher='search_asset')
color = fields.Function(fields.Char('Color'), 'get_lasts')
@classmethod
def get_lasts(cls, records, names):
res = {}
for name in ('last_state', 'last_check', 'last_state_type',
'last_state_value', 'color'):
'last_state_value'):
res[name] = dict([(x.id, None) for x in records])
@ -368,8 +388,6 @@ class StateIndicatorCheckPlan(ModelSQL, ModelView):
res['last_check'][mapping[state.id]] = state.check.id
res['last_state_type'][mapping[state.id]] = state.state.id
res['last_state_value'][mapping[state.id]] = state.value
res['color'][mapping[state.id]] = (state.state.color if state.state
else 'black')
return res
def get_asset(self, name):
@ -419,7 +437,6 @@ class State(ModelSQL, ModelView):
monitored_asset = fields.Function(fields.Many2One('asset',
'Monitored Asset'), 'get_asset', searcher='search_asset')
state = fields.Many2One('monitoring.state.type', 'State', required=True)
color = fields.Function(fields.Char('Color'), 'get_color')
value = fields.Char('Value')
label = fields.Char('Label')
payload = fields.Text('Payload')
@ -436,9 +453,6 @@ class State(ModelSQL, ModelView):
def search_asset(cls, name, clause):
return [('check.%s' % name,) + tuple(clause[1:])]
def get_color(self, name):
return self.state.color if self.state else 'black'
class ResultInteger(ModelSQL, ModelView):
'Monitoring Result Integer'

View File

@ -233,7 +233,7 @@
<!-- monitoring.state.type-party.party -->
<record model="ir.model.access" id="access_monitoring_state_type_party_party">
<field name="model" search="[('model', '=', 'monitoring.state.type-party.party')]"/>
<field name="perm_read" eval="True"/> monitoring.state.type-party.party
<field name="perm_read" eval="True"/>
<field name="perm_write" eval="False"/>
<field name="perm_create" eval="False"/>
<field name="perm_delete" eval="False"/>
@ -559,6 +559,13 @@
<field name="perm_create" eval="True"/>
<field name="perm_delete" eval="True"/>
</record>
<record model="ir.model.access" id="access_asset_party_notification_default">
<field name="model" search="[('model', '=', 'asset-party.party-notification')]"/>
<field name="perm_read" eval="False"/>
<field name="perm_write" eval="False"/>
<field name="perm_create" eval="False"/>
<field name="perm_delete" eval="False"/>
</record>
<record model="ir.model.access" id="access_asset_party_notification">
<field name="model" search="[('model', '=', 'asset-party.party-notification')]"/>
@ -600,7 +607,8 @@
<record model="ir.action.act_window" id="act_asset_states">
<field name="name">States</field>
<field name="res_model">monitoring.state</field>
<field name="domain">[('monitoring_asset', 'in', Eval('active_ids'))]</field>
<field name="domain" pyson="1"
eval="[('monitoring_asset', 'in', Eval('active_ids'))]"/>
</record>
<record model="ir.action.keyword" id="act_asset_states_keyword1">
<field name="keyword">form_relate</field>
@ -611,7 +619,8 @@
<record model="ir.action.act_window" id="act_plan_checks">
<field name="name">Checks</field>
<field name="res_model">monitoring.check</field>
<field name="domain">[('plan', 'in', Eval('active_ids'))]</field>
<field name="domain" domain="[('plan', 'in', Eval('active_ids'))]"
pyson="1"/>
</record>
<record model="ir.action.keyword" id="act_plan_checks_keyword1">
<field name="keyword">form_relate</field>
@ -622,7 +631,8 @@
<record model="ir.action.act_window" id="act_asset_checks">
<field name="name">Checks</field>
<field name="res_model">monitoring.check</field>
<field name="domain">[('monitoring_asset', 'in', Eval('active_ids'))]</field>
<field name="domain" pyson="1"
eval="[('monitoring_asset', 'in', Eval('active_ids'))]" />
</record>
<record model="ir.action.keyword" id="act_asset_checks_keyword1">
<field name="keyword">form_relate</field>
@ -807,19 +817,15 @@
<!-- State Types -->
<record model="monitoring.state.type" id="state_type_ok">
<field name="name">Ok</field>
<field name="color">green</field>
</record>
<record model="monitoring.state.type" id="state_type_error">
<field name="name">Error</field>
<field name="color">red</field>
</record>
<record model="monitoring.state.type" id="state_type_warning">
<field name="name">Warning</field>
<field name="color">orange</field>
</record>
<record model="monitoring.state.type" id="state_type_exception">
<field name="name">Exception</field>
<field name="color">purple</field>
</record>
</data>
</tryton>

View File

@ -1,24 +1,13 @@
#!/usr/bin/env python
# The COPYRIGHT file at the top level of this repository contains the full
# copyright notices and license terms.
import unittest
import trytond.tests.test_tryton
from trytond.tests.test_tryton import test_view, test_depends
from trytond.tests.test_tryton import ModuleTestCase
class TestCase(unittest.TestCase):
class TestCase(ModuleTestCase):
'Test module'
def setUp(self):
trytond.tests.test_tryton.install_module('monitoring')
def test0005views(self):
'Test views'
test_view('monitoring')
def test0006depends(self):
'Test depends'
test_depends()
module = 'monitoring'
def suite():

View File

@ -1,5 +1,5 @@
[tryton]
version=3.4.0
version=3.8.0
depends:
ir
res

View File

@ -4,10 +4,10 @@
<form string="Monitoring Scheduler">
<label name="name"/>
<field name="name"/>
<label name="normal_check_interval"/>
<field name="normal_check_interval" widget="float_time"/>
<label name="normal_check"/>
<field name="normal_check"/>
<label name="retries"/>
<field name="retries"/>
<label name="retry_check_interval"/>
<field name="retry_check_interval" widget="float_time"/>
<label name="retry_check"/>
<field name="retry_check"/>
</form>

View File

@ -3,7 +3,7 @@
copyright notices and license terms. -->
<tree string="Monitoring Scheduler">
<field name="name"/>
<field name="normal_check_interval" widget="float_time"/>
<field name="normal_check"/>
<field name="retries"/>
<field name="retry_check_interval" widget="float_time"/>
<field name="retry_check"/>
</tree>

View File

@ -1,7 +1,7 @@
<?xml version="1.0"?>
<!-- The COPYRIGHT file at the top level of this repository contains the full
copyright notices and license terms. -->
<tree string="Current State" colors="Eval('color')">
<tree string="Current State">
<field name="plan"/>
<field name="monitoring_asset"/>
<field name="monitored_asset"/>
@ -9,5 +9,4 @@
<field name="last_check"/>
<field name="last_state_type"/>
<field name="last_state_value"/>
<field name="color" tree_invisible="1"/>
</tree>

View File

@ -1,12 +1,11 @@
<?xml version="1.0"?>
<!-- The COPYRIGHT file at the top level of this repository contains the full
copyright notices and license terms. -->
<tree string="Monitoring State" colors="Eval('color')">
<tree string="Monitoring State">
<field name="check"/>
<field name="indicator"/>
<field name="state"/>
<field name="value"/>
<field name="label"/>
<field name="payload"/>
<field name="color" tree_invisible="1"/>
</tree>

View File

@ -4,6 +4,4 @@
<form string="Monitoring State Type">
<label name="name"/>
<field name="name"/>
<label name="color"/>
<field name="color"/>
</form>

View File

@ -3,5 +3,4 @@
copyright notices and license terms. -->
<tree string="Monitoring State Type">
<field name="name"/>
<field name="color"/>
</tree>