Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
ef3e32071d | ||
|
fa21e7a2ac | ||
|
648e5f038a | ||
|
661a5b597a | ||
|
3df4e83711 | ||
|
b8172d5f96 | ||
|
ce57a34fe2 | ||
|
784895c416 | ||
|
d95b95e56c |
2
maintenance_server_monitoring/.gitignore
vendored
Normal file
2
maintenance_server_monitoring/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
*.*~
|
||||||
|
*pyc
|
44
maintenance_server_monitoring/README.rst
Normal file
44
maintenance_server_monitoring/README.rst
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
======================================
|
||||||
|
maintenance_server_monitoring
|
||||||
|
======================================
|
||||||
|
|
||||||
|
Monitor some data on remote hosts
|
||||||
|
|
||||||
|
Installation
|
||||||
|
============
|
||||||
|
|
||||||
|
Use Odoo normal module installation procedure to install
|
||||||
|
``maintenance_server_monitoring``.
|
||||||
|
|
||||||
|
Known issues / Roadmap
|
||||||
|
======================
|
||||||
|
|
||||||
|
None yet.
|
||||||
|
|
||||||
|
Bug Tracker
|
||||||
|
===========
|
||||||
|
|
||||||
|
Bugs are tracked on `our issues website <https://github.com/elabore-coop/maintenance-tools/issues>`_. In case of
|
||||||
|
trouble, please check there if your issue has already been
|
||||||
|
reported. If you spotted it first, help us smashing it by providing a
|
||||||
|
detailed and welcomed feedback.
|
||||||
|
|
||||||
|
Credits
|
||||||
|
=======
|
||||||
|
|
||||||
|
Contributors
|
||||||
|
------------
|
||||||
|
|
||||||
|
* Clément Thomas
|
||||||
|
|
||||||
|
Funders
|
||||||
|
-------
|
||||||
|
|
||||||
|
The development of this module has been financially supported by:
|
||||||
|
* Elabore (https://elabore.coop)
|
||||||
|
|
||||||
|
|
||||||
|
Maintainer
|
||||||
|
----------
|
||||||
|
|
||||||
|
This module is maintained by Elabore.
|
3
maintenance_server_monitoring/__init__.py
Normal file
3
maintenance_server_monitoring/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from . import models
|
39
maintenance_server_monitoring/__manifest__.py
Normal file
39
maintenance_server_monitoring/__manifest__.py
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
# Copyright 2023 Stéphan Sainléger (Elabore)
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
|
{
|
||||||
|
"name": "maintenance_server_monitoring",
|
||||||
|
"version": "14.0.1.0.0",
|
||||||
|
"author": "Elabore",
|
||||||
|
"website": "https://elabore.coop",
|
||||||
|
"maintainer": "Clément Thomas",
|
||||||
|
"license": "AGPL-3",
|
||||||
|
"category": "Tools",
|
||||||
|
"summary": "Monitor some data on remote hosts",
|
||||||
|
# any module necessary for this one to work correctly
|
||||||
|
"depends": [
|
||||||
|
"base",
|
||||||
|
"maintenance",
|
||||||
|
"maintenance_server_ssh"
|
||||||
|
],
|
||||||
|
"qweb": [
|
||||||
|
# "static/src/xml/*.xml",
|
||||||
|
],
|
||||||
|
"external_dependencies": {
|
||||||
|
"python": [],
|
||||||
|
},
|
||||||
|
# always loaded
|
||||||
|
"data": [
|
||||||
|
"views/maintenance_equipment_views.xml",
|
||||||
|
"data/cron.xml",
|
||||||
|
],
|
||||||
|
# only loaded in demonstration mode
|
||||||
|
"demo": [],
|
||||||
|
"js": [],
|
||||||
|
"css": [],
|
||||||
|
"installable": True,
|
||||||
|
# Install this module automatically if all dependency have been previously
|
||||||
|
# and independently installed. Used for synergetic or glue modules.
|
||||||
|
"auto_install": False,
|
||||||
|
"application": False,
|
||||||
|
}
|
12
maintenance_server_monitoring/data/cron.xml
Normal file
12
maintenance_server_monitoring/data/cron.xml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<odoo>
|
||||||
|
<record id="ir_cron_server_monitoring" model="ir.cron">
|
||||||
|
<field name="name">Server Monitoring : check all equipments</field>
|
||||||
|
<field name="model_id" ref="model_maintenance_equipment"/>
|
||||||
|
<field name="state">code</field>
|
||||||
|
<field name="code">model.cron_monitoring_test()</field>
|
||||||
|
<field name="interval_number">1</field>
|
||||||
|
<field name="interval_type">minutes</field>
|
||||||
|
<field name="numbercall">-1</field>
|
||||||
|
<field eval="False" name="doall"/>
|
||||||
|
</record>
|
||||||
|
</odoo>
|
1
maintenance_server_monitoring/models/__init__.py
Normal file
1
maintenance_server_monitoring/models/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
from . import maintenance_equipment
|
221
maintenance_server_monitoring/models/maintenance_equipment.py
Normal file
221
maintenance_server_monitoring/models/maintenance_equipment.py
Normal file
@@ -0,0 +1,221 @@
|
|||||||
|
from odoo import fields, models, api
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
import psutil
|
||||||
|
from io import StringIO
|
||||||
|
|
||||||
|
LOG_LIMIT = 100000
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
if you want to add a new test :
|
||||||
|
* create new module named maintenance_server_monitoring_{your_test}
|
||||||
|
* add new field to MaintenanceEquipment (named {fieldname} below)
|
||||||
|
* add a new function named test_{fieldname} which return a filled MonitoringTest class with :
|
||||||
|
-> log = logs you want to appear in logs
|
||||||
|
-> result = value which will be set to {fieldname}
|
||||||
|
-> error = MonitoringTest.ERROR or MonitoringTest.WARNING to generate maintenance request
|
||||||
|
** Note you can use test_ok, test_warning, and test_error functions to simplify code **
|
||||||
|
* inherit get_tests() to reference your field {fieldname}
|
||||||
|
|
||||||
|
be inspired by maintenance_server_monitoring_ping for exemple
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
class MaintenanceEquipment(models.Model):
|
||||||
|
_inherit = 'maintenance.equipment'
|
||||||
|
|
||||||
|
last_monitoring_test_date = fields.Datetime('Date of last monitoring test', readonly=True)
|
||||||
|
|
||||||
|
enable_monitoring = fields.Boolean('Monitoring enabled', help="If enabled, cron will test this equipment")
|
||||||
|
|
||||||
|
#log
|
||||||
|
log = fields.Html("Log", readonly=True)
|
||||||
|
|
||||||
|
#maintenance requests
|
||||||
|
error_maintenance_request = fields.Many2one('maintenance.request', "Error maintenance request")
|
||||||
|
warning_maintenance_request = fields.Many2one('maintenance.request', "Warning maintenance request")
|
||||||
|
|
||||||
|
|
||||||
|
class MonitoringTest:
|
||||||
|
"""Class to make the tests
|
||||||
|
"""
|
||||||
|
WARNING = "warning"
|
||||||
|
ERROR = "error"
|
||||||
|
|
||||||
|
def __init__(self, name):
|
||||||
|
self.name = name # name of the test
|
||||||
|
self.result = 0 # result of the test
|
||||||
|
self.log = "" # logs of the test
|
||||||
|
self.date = fields.Datetime.now() # date of the test
|
||||||
|
self.error = "" # errors of the test
|
||||||
|
|
||||||
|
def add_to_log(self, text):
|
||||||
|
"""
|
||||||
|
add a new line to logs composed with DATE > TEST NAME > WHAT TO LOG
|
||||||
|
"""
|
||||||
|
self.log += f"{self.date} > {self.name} > {text}\n"
|
||||||
|
|
||||||
|
def test_ok(self, result, log):
|
||||||
|
"""to call when the test is ok.
|
||||||
|
It just fill the test with result and embellished log
|
||||||
|
|
||||||
|
Args:
|
||||||
|
result: result of test
|
||||||
|
log (string): what to log
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
MonitoringTest: filled test
|
||||||
|
"""
|
||||||
|
self.add_to_log(log)
|
||||||
|
self.result = result
|
||||||
|
return self
|
||||||
|
|
||||||
|
def test_error(self, result, log):
|
||||||
|
"""to call when test error.
|
||||||
|
It just fill the test with result, embellished log and set error value to ERROR
|
||||||
|
|
||||||
|
Args:
|
||||||
|
result: result of test
|
||||||
|
log (string): what to log
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
MonitoringTest: filled test
|
||||||
|
"""
|
||||||
|
self.add_to_log(f"🚨 ERROR : {log}")
|
||||||
|
self.result = result
|
||||||
|
self.error = self.ERROR
|
||||||
|
return self
|
||||||
|
|
||||||
|
def test_warning(self, result, log):
|
||||||
|
"""to call when test warning.
|
||||||
|
It just fill the test with result, embellished log and set error value to WARNING
|
||||||
|
|
||||||
|
Args:
|
||||||
|
result: result of test
|
||||||
|
log (string): what to log
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
MonitoringTest: filled test
|
||||||
|
"""
|
||||||
|
self.add_to_log(f"🔥 WARNING : {log}")
|
||||||
|
self.result = result
|
||||||
|
self.error = self.WARNING
|
||||||
|
return self
|
||||||
|
|
||||||
|
@api.model
|
||||||
|
def cron_monitoring_test(self):
|
||||||
|
"""cron launch test on all equipments
|
||||||
|
"""
|
||||||
|
self.search([("enable_monitoring","=",True)]).monitoring_test()
|
||||||
|
|
||||||
|
def launch_test(self, field_name, *test_function_args):
|
||||||
|
"""run test function with name = test_[attribute]
|
||||||
|
associate result of test to equipment
|
||||||
|
write logs of test
|
||||||
|
|
||||||
|
|
||||||
|
Args:
|
||||||
|
attribute_name (string): attribute of MaintenanceEquipment we want to test
|
||||||
|
*test_function_args = optionnal args to pass to function (unused for the moment)
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
MonitoringTest: returned by test function
|
||||||
|
"""
|
||||||
|
test_function = getattr(self,"test_"+field_name)
|
||||||
|
test = test_function(*test_function_args)
|
||||||
|
setattr(self, field_name, test.result)
|
||||||
|
return test
|
||||||
|
|
||||||
|
def get_tests(self):
|
||||||
|
"""function to inherit in sub-modules
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
array[string]: names of fields to test
|
||||||
|
"""
|
||||||
|
return []
|
||||||
|
|
||||||
|
def monitoring_test(self):
|
||||||
|
|
||||||
|
for equipment in self:
|
||||||
|
# array of all tests
|
||||||
|
tests_results = []
|
||||||
|
|
||||||
|
# run all tests referenced in get_tests and save result
|
||||||
|
for test in self.get_tests():
|
||||||
|
tests_results.append(equipment.launch_test(test))
|
||||||
|
|
||||||
|
# set test date
|
||||||
|
equipment.last_monitoring_test_date = fields.Datetime.now()
|
||||||
|
|
||||||
|
# write logs
|
||||||
|
#new logs are current datetime + join of test results logs
|
||||||
|
new_log = f'📣 {fields.Datetime.now()}\n{"".join([tests_result.log for tests_result in tests_results])}\n'.replace("\n","<br />")
|
||||||
|
#add new logs to the beginning of equipment log
|
||||||
|
equipment.log = f'{new_log}<br />{equipment.log}'[:LOG_LIMIT] #limit logs
|
||||||
|
|
||||||
|
#Create maintenance request only if monitoring is enabled
|
||||||
|
if not equipment.enable_monitoring:
|
||||||
|
return
|
||||||
|
|
||||||
|
# if error create maintenance request
|
||||||
|
error = warning =False
|
||||||
|
if any(test.error == test.ERROR for test in tests_results):
|
||||||
|
error = True # if any arror in tests
|
||||||
|
elif any(test.error == test.WARNING for test in tests_results):
|
||||||
|
warning = True # if any warning in tests
|
||||||
|
|
||||||
|
if error or warning:
|
||||||
|
# check if error or warning request (not done) already exists before creating a new one
|
||||||
|
# if only a warning request exists, error request will be created anyway
|
||||||
|
existing_not_done_error_request = None
|
||||||
|
existing_not_done_warning_request = None
|
||||||
|
if equipment.error_maintenance_request and not equipment.error_maintenance_request.stage_id.done:
|
||||||
|
existing_not_done_error_request = equipment.error_maintenance_request
|
||||||
|
if equipment.warning_maintenance_request and not equipment.warning_maintenance_request.stage_id.done:
|
||||||
|
existing_not_done_warning_request = equipment.warning_maintenance_request
|
||||||
|
if (error and not existing_not_done_error_request) \
|
||||||
|
or (warning and not existing_not_done_warning_request and not existing_not_done_error_request):
|
||||||
|
equipment.create_maintenance_request(self.MonitoringTest.ERROR if error else self.MonitoringTest.WARNING, new_log)
|
||||||
|
else:
|
||||||
|
equipment.no_error()
|
||||||
|
|
||||||
|
|
||||||
|
def create_maintenance_request(self, error_level, description):
|
||||||
|
"""create a maintenance request for equipment (self)
|
||||||
|
|
||||||
|
Args:
|
||||||
|
error_level (string): MonitoringTest.ERROR or MonitoringTest.WARNING
|
||||||
|
description (string): description of maintenance request
|
||||||
|
"""
|
||||||
|
maintenance_request = self.env['maintenance.request'].create({
|
||||||
|
"name":f'[{error_level.upper()}] {self.name}',
|
||||||
|
"equipment_id":self.id,
|
||||||
|
"user_id":self.technician_user_id.id,
|
||||||
|
"maintenance_team_id":self.maintenance_team_id.id or self.env["maintenance.team"].search([], limit=1),
|
||||||
|
"priority":'2' if error_level == self.MonitoringTest.ERROR else '3',
|
||||||
|
"maintenance_type":"corrective" if error_level == self.MonitoringTest.ERROR else "preventive",
|
||||||
|
"description":description
|
||||||
|
})
|
||||||
|
if error_level == self.MonitoringTest.ERROR:
|
||||||
|
self.error_maintenance_request = maintenance_request
|
||||||
|
self.warning_maintenance_request = None
|
||||||
|
else:
|
||||||
|
self.warning_maintenance_request = maintenance_request
|
||||||
|
self.error_maintenance_request = None
|
||||||
|
|
||||||
|
def no_error(self):
|
||||||
|
"""set error and warning maintenance request to None
|
||||||
|
"""
|
||||||
|
self.error_maintenance_request = None
|
||||||
|
self.warning_maintenance_request = None
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@@ -0,0 +1,35 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<odoo>
|
||||||
|
<record id="equipment_view_form_server_inherit" model="ir.ui.view">
|
||||||
|
<field name="name">equipment.form.server.inherit</field>
|
||||||
|
<field name="model">maintenance.equipment</field>
|
||||||
|
<field name="inherit_id" ref="maintenance.hr_equipment_view_form" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<xpath expr="//notebook" position="inside">
|
||||||
|
<page name="monitoring" string="Monitoring">
|
||||||
|
<group name="monitoring_test" string="Test">
|
||||||
|
<field name="enable_monitoring" />
|
||||||
|
<field name="last_monitoring_test_date" />
|
||||||
|
<button name="monitoring_test" type="object" string="Test" />
|
||||||
|
</group>
|
||||||
|
<group name="monitoring_test_result" />
|
||||||
|
<group name="monitoring_log" string="Log">
|
||||||
|
<field name="log" />
|
||||||
|
</group>
|
||||||
|
</page>
|
||||||
|
</xpath>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
|
||||||
|
<record id="equipment_view_tree_server_inherit" model="ir.ui.view">
|
||||||
|
<field name="name">equipment.tree.server.inherit</field>
|
||||||
|
<field name="model">maintenance.equipment</field>
|
||||||
|
<field name="inherit_id" ref="maintenance.hr_equipment_view_tree" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<xpath expr="//field[@name='category_id']" position="after">
|
||||||
|
<field name="enable_monitoring" />
|
||||||
|
</xpath>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
</odoo>
|
2
maintenance_server_monitoring_disk/.gitignore
vendored
Normal file
2
maintenance_server_monitoring_disk/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
*.*~
|
||||||
|
*pyc
|
44
maintenance_server_monitoring_disk/README.rst
Normal file
44
maintenance_server_monitoring_disk/README.rst
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
======================================
|
||||||
|
maintenance_server_monitoring_memory
|
||||||
|
======================================
|
||||||
|
|
||||||
|
Improve monitoring with ping test
|
||||||
|
|
||||||
|
Installation
|
||||||
|
============
|
||||||
|
|
||||||
|
Use Odoo normal module installation procedure to install
|
||||||
|
``maintenance_server_monitoring_memory``.
|
||||||
|
|
||||||
|
Known issues / Roadmap
|
||||||
|
======================
|
||||||
|
|
||||||
|
None yet.
|
||||||
|
|
||||||
|
Bug Tracker
|
||||||
|
===========
|
||||||
|
|
||||||
|
Bugs are tracked on `our issues website <https://github.com/elabore-coop/maintenance-tools/issues>`_. In case of
|
||||||
|
trouble, please check there if your issue has already been
|
||||||
|
reported. If you spotted it first, help us smashing it by providing a
|
||||||
|
detailed and welcomed feedback.
|
||||||
|
|
||||||
|
Credits
|
||||||
|
=======
|
||||||
|
|
||||||
|
Contributors
|
||||||
|
------------
|
||||||
|
|
||||||
|
* Clément Thomas
|
||||||
|
|
||||||
|
Funders
|
||||||
|
-------
|
||||||
|
|
||||||
|
The development of this module has been financially supported by:
|
||||||
|
* Elabore (https://elabore.coop)
|
||||||
|
|
||||||
|
|
||||||
|
Maintainer
|
||||||
|
----------
|
||||||
|
|
||||||
|
This module is maintained by Elabore.
|
3
maintenance_server_monitoring_disk/__init__.py
Normal file
3
maintenance_server_monitoring_disk/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from . import models
|
37
maintenance_server_monitoring_disk/__manifest__.py
Normal file
37
maintenance_server_monitoring_disk/__manifest__.py
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
# Copyright 2023 Stéphan Sainléger (Elabore)
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
|
{
|
||||||
|
"name": "maintenance_server_monitoring_memory",
|
||||||
|
"version": "14.0.1.0.0",
|
||||||
|
"author": "Elabore",
|
||||||
|
"website": "https://elabore.coop",
|
||||||
|
"maintainer": "Clément Thomas",
|
||||||
|
"license": "AGPL-3",
|
||||||
|
"category": "Tools",
|
||||||
|
"summary": "Monitor memory on remote hosts",
|
||||||
|
# any module necessary for this one to work correctly
|
||||||
|
"depends": [
|
||||||
|
"maintenance_server_monitoring",
|
||||||
|
"maintenance_server_ssh"
|
||||||
|
],
|
||||||
|
"qweb": [
|
||||||
|
# "static/src/xml/*.xml",
|
||||||
|
],
|
||||||
|
"external_dependencies": {
|
||||||
|
"python": [],
|
||||||
|
},
|
||||||
|
# always loaded
|
||||||
|
"data": [
|
||||||
|
"views/maintenance_equipment_views.xml",
|
||||||
|
],
|
||||||
|
# only loaded in demonstration mode
|
||||||
|
"demo": [],
|
||||||
|
"js": [],
|
||||||
|
"css": [],
|
||||||
|
"installable": True,
|
||||||
|
# Install this module automatically if all dependency have been previously
|
||||||
|
# and independently installed. Used for synergetic or glue modules.
|
||||||
|
"auto_install": False,
|
||||||
|
"application": False,
|
||||||
|
}
|
1
maintenance_server_monitoring_disk/models/__init__.py
Normal file
1
maintenance_server_monitoring_disk/models/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
from . import maintenance_equipment
|
@@ -0,0 +1,52 @@
|
|||||||
|
from odoo import fields, models, api
|
||||||
|
|
||||||
|
USED_DISK_SPACE_COMMAND = "df /srv -h | tail -n +2 | sed -r 's/ +/ /g' | cut -f 5 -d ' ' | cut -f 1 -d %"
|
||||||
|
MAX_USED_DISK_SPACE_WARNING = 70
|
||||||
|
MAX_USED_DISK_SPACE_ERROR = 90
|
||||||
|
|
||||||
|
|
||||||
|
class MaintenanceEquipment(models.Model):
|
||||||
|
_inherit = 'maintenance.equipment'
|
||||||
|
|
||||||
|
used_disk_space = fields.Float('Percent of used disk space', readonly=True)
|
||||||
|
|
||||||
|
def get_tests(self):
|
||||||
|
res = super(MaintenanceEquipment, self).get_tests()
|
||||||
|
res.append("used_disk_space")
|
||||||
|
return res
|
||||||
|
|
||||||
|
def test_used_disk_space(self):
|
||||||
|
"""
|
||||||
|
test Used disk space with a bash command called by ssh
|
||||||
|
|
||||||
|
Args:
|
||||||
|
ssh (paramiko.SSHClient): ssh client
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
MonitoringTest: representing current test with :
|
||||||
|
* result = -2 if error
|
||||||
|
* result = percent of Used disk space if no error
|
||||||
|
* error defined with MonitoringTest.ERROR or MonitoringTest.WARNING depending on result comparaison
|
||||||
|
with MAX_USED_DISK_SPACE_WARNING and MAX_USED_DISK_SPACE_ERROR
|
||||||
|
* log file
|
||||||
|
"""
|
||||||
|
test = self.MonitoringTest("Used disk space")
|
||||||
|
try:
|
||||||
|
ssh = self.get_ssh_connection()
|
||||||
|
if not ssh:
|
||||||
|
return test.test_error(-2, "No ssh connection")
|
||||||
|
_stdin, stdout, _stderr = ssh.exec_command(USED_DISK_SPACE_COMMAND)
|
||||||
|
used_disk_space = float(stdout.read().decode())
|
||||||
|
if used_disk_space < MAX_USED_DISK_SPACE_WARNING:
|
||||||
|
return test.test_ok(used_disk_space, f"{used_disk_space}% used")
|
||||||
|
elif used_disk_space < MAX_USED_DISK_SPACE_ERROR:
|
||||||
|
# disk usage between WARNING and ERROR steps
|
||||||
|
return test.test_warning(used_disk_space, f"{used_disk_space}% used (>{MAX_USED_DISK_SPACE_WARNING})")
|
||||||
|
else:
|
||||||
|
# disk usage higher than ERROR steps
|
||||||
|
return test.test_error(used_disk_space, f"{used_disk_space}% used (>{MAX_USED_DISK_SPACE_ERROR})")
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
return test.test_error(-2, f"{e}")
|
||||||
|
|
||||||
|
|
@@ -0,0 +1,24 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<odoo>
|
||||||
|
<record id="equipment_view_form_server_inherit" model="ir.ui.view">
|
||||||
|
<field name="name">equipment.form.server.inherit</field>
|
||||||
|
<field name="model">maintenance.equipment</field>
|
||||||
|
<field name="inherit_id" ref="maintenance.hr_equipment_view_form" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<group name="monitoring_test_result" position="inside">
|
||||||
|
<field name="used_disk_space" />
|
||||||
|
</group>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<record id="equipment_view_tree_server_inherit" model="ir.ui.view">
|
||||||
|
<field name="name">equipment.tree.server.inherit</field>
|
||||||
|
<field name="model">maintenance.equipment</field>
|
||||||
|
<field name="inherit_id" ref="maintenance.hr_equipment_view_tree" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<xpath expr="//field[@name='enable_monitoring']" position="after">
|
||||||
|
<field name="used_disk_space" optional="hide" />
|
||||||
|
</xpath>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
</odoo>
|
2
maintenance_server_monitoring_maintenance_equipment_status/.gitignore
vendored
Normal file
2
maintenance_server_monitoring_maintenance_equipment_status/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
*.*~
|
||||||
|
*pyc
|
@@ -0,0 +1,44 @@
|
|||||||
|
======================================
|
||||||
|
maintenance_server_monitoring
|
||||||
|
======================================
|
||||||
|
|
||||||
|
Monitor some data on remote hosts
|
||||||
|
|
||||||
|
Installation
|
||||||
|
============
|
||||||
|
|
||||||
|
Use Odoo normal module installation procedure to install
|
||||||
|
``maintenance_server_monitoring``.
|
||||||
|
|
||||||
|
Known issues / Roadmap
|
||||||
|
======================
|
||||||
|
|
||||||
|
None yet.
|
||||||
|
|
||||||
|
Bug Tracker
|
||||||
|
===========
|
||||||
|
|
||||||
|
Bugs are tracked on `our issues website <https://github.com/elabore-coop/maintenance-tools/issues>`_. In case of
|
||||||
|
trouble, please check there if your issue has already been
|
||||||
|
reported. If you spotted it first, help us smashing it by providing a
|
||||||
|
detailed and welcomed feedback.
|
||||||
|
|
||||||
|
Credits
|
||||||
|
=======
|
||||||
|
|
||||||
|
Contributors
|
||||||
|
------------
|
||||||
|
|
||||||
|
* Clément Thomas
|
||||||
|
|
||||||
|
Funders
|
||||||
|
-------
|
||||||
|
|
||||||
|
The development of this module has been financially supported by:
|
||||||
|
* Elabore (https://elabore.coop)
|
||||||
|
|
||||||
|
|
||||||
|
Maintainer
|
||||||
|
----------
|
||||||
|
|
||||||
|
This module is maintained by Elabore.
|
@@ -0,0 +1,3 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from . import models
|
@@ -0,0 +1,38 @@
|
|||||||
|
# Copyright 2023 Stéphan Sainléger (Elabore)
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
|
{
|
||||||
|
"name": "maintenance_server_monitoring_maintenance_equipment_status",
|
||||||
|
"version": "14.0.1.0.0",
|
||||||
|
"author": "Elabore",
|
||||||
|
"website": "https://elabore.coop",
|
||||||
|
"maintainer": "Clément Thomas",
|
||||||
|
"license": "AGPL-3",
|
||||||
|
"category": "Tools",
|
||||||
|
"summary": "Monitor some data on remote hosts",
|
||||||
|
# any module necessary for this one to work correctly
|
||||||
|
"depends": [
|
||||||
|
"base",
|
||||||
|
"maintenance_server_monitoring",
|
||||||
|
"maintenance_equipment_status"
|
||||||
|
],
|
||||||
|
"qweb": [
|
||||||
|
# "static/src/xml/*.xml",
|
||||||
|
],
|
||||||
|
"external_dependencies": {
|
||||||
|
"python": [],
|
||||||
|
},
|
||||||
|
# always loaded
|
||||||
|
"data": [
|
||||||
|
"views/maintenance_equipment_status_views.xml",
|
||||||
|
],
|
||||||
|
# only loaded in demonstration mode
|
||||||
|
"demo": [],
|
||||||
|
"js": [],
|
||||||
|
"css": [],
|
||||||
|
"installable": True,
|
||||||
|
# Install this module automatically if all dependency have been previously
|
||||||
|
# and independently installed. Used for synergetic or glue modules.
|
||||||
|
"auto_install": True,
|
||||||
|
"application": False,
|
||||||
|
}
|
@@ -0,0 +1,2 @@
|
|||||||
|
from . import maintenance_equipment
|
||||||
|
from . import maintenance_equipment_status
|
@@ -0,0 +1,23 @@
|
|||||||
|
from odoo import fields, models, api
|
||||||
|
|
||||||
|
|
||||||
|
class MaintenanceEquipment(models.Model):
|
||||||
|
_inherit = 'maintenance.equipment'
|
||||||
|
|
||||||
|
def create_maintenance_request(self, error_level, description):
|
||||||
|
res = super(MaintenanceEquipment, self).create_maintenance_request(error_level, description)
|
||||||
|
if self.error_maintenance_request:
|
||||||
|
error_status = self.env["maintenance.equipment.status"].search([("is_error_status",'=',True),'|', ('category_ids', 'in', [self.category_id.id]), ('category_ids', '=', False)], limit=1)
|
||||||
|
if error_status:
|
||||||
|
self.status_id = error_status
|
||||||
|
else:
|
||||||
|
warning_status = self.env["maintenance.equipment.status"].search([("is_warning_status",'=',True),'|', ('category_ids', 'in', [self.category_id.id]), ('category_ids', '=', False)], limit=1)
|
||||||
|
if warning_status:
|
||||||
|
self.status_id = warning_status
|
||||||
|
return res
|
||||||
|
|
||||||
|
def no_error(self):
|
||||||
|
res = super(MaintenanceEquipment, self).no_error()
|
||||||
|
ok_status = self.env["maintenance.equipment.status"].search([("is_error_status",'=',False),("is_warning_status",'=',False),'|', ('category_ids', 'in', [self.category_id.id]), ('category_ids', '=', False)], limit=1)
|
||||||
|
self.status_id = ok_status
|
||||||
|
return res
|
@@ -0,0 +1,11 @@
|
|||||||
|
from odoo import fields, models, api
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
import psutil
|
||||||
|
from io import StringIO
|
||||||
|
|
||||||
|
class MaintenanceEquipmentStatus(models.Model):
|
||||||
|
_inherit = "maintenance.equipment.status"
|
||||||
|
|
||||||
|
is_warning_status = fields.Boolean('Is warning status')
|
||||||
|
is_error_status = fields.Boolean('Is error status')
|
@@ -0,0 +1,29 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<odoo>
|
||||||
|
<record id="maintenance_equipment_status_view_form_inherit" model="ir.ui.view">
|
||||||
|
<field name="name">maintenance.equipment.status.form.inherit</field>
|
||||||
|
<field name="model">maintenance.equipment.status</field>
|
||||||
|
<field name="inherit_id" ref="maintenance_equipment_status.maintenance_equipment_status_view_form" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<group name="notes" position="after">
|
||||||
|
<group name="monitoring">
|
||||||
|
<field name="is_warning_status" />
|
||||||
|
<field name="is_error_status" />
|
||||||
|
</group>
|
||||||
|
</group>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<record id="maintenance_equipment_status_view_tree_inherit" model="ir.ui.view">
|
||||||
|
<field name="name">maintenance.equipment.status.tree.inherit</field>
|
||||||
|
<field name="model">maintenance.equipment.status</field>
|
||||||
|
<field name="inherit_id" ref="maintenance_equipment_status.maintenance_equipment_status_view_tree" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<field name="category_ids" position="after">
|
||||||
|
<field name="is_warning_status" />
|
||||||
|
<field name="is_error_status" />
|
||||||
|
</field>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
</odoo>
|
2
maintenance_server_monitoring_memory/.gitignore
vendored
Normal file
2
maintenance_server_monitoring_memory/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
*.*~
|
||||||
|
*pyc
|
44
maintenance_server_monitoring_memory/README.rst
Normal file
44
maintenance_server_monitoring_memory/README.rst
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
======================================
|
||||||
|
maintenance_server_monitoring_memory
|
||||||
|
======================================
|
||||||
|
|
||||||
|
Improve monitoring with ping test
|
||||||
|
|
||||||
|
Installation
|
||||||
|
============
|
||||||
|
|
||||||
|
Use Odoo normal module installation procedure to install
|
||||||
|
``maintenance_server_monitoring_memory``.
|
||||||
|
|
||||||
|
Known issues / Roadmap
|
||||||
|
======================
|
||||||
|
|
||||||
|
None yet.
|
||||||
|
|
||||||
|
Bug Tracker
|
||||||
|
===========
|
||||||
|
|
||||||
|
Bugs are tracked on `our issues website <https://github.com/elabore-coop/maintenance-tools/issues>`_. In case of
|
||||||
|
trouble, please check there if your issue has already been
|
||||||
|
reported. If you spotted it first, help us smashing it by providing a
|
||||||
|
detailed and welcomed feedback.
|
||||||
|
|
||||||
|
Credits
|
||||||
|
=======
|
||||||
|
|
||||||
|
Contributors
|
||||||
|
------------
|
||||||
|
|
||||||
|
* Clément Thomas
|
||||||
|
|
||||||
|
Funders
|
||||||
|
-------
|
||||||
|
|
||||||
|
The development of this module has been financially supported by:
|
||||||
|
* Elabore (https://elabore.coop)
|
||||||
|
|
||||||
|
|
||||||
|
Maintainer
|
||||||
|
----------
|
||||||
|
|
||||||
|
This module is maintained by Elabore.
|
3
maintenance_server_monitoring_memory/__init__.py
Normal file
3
maintenance_server_monitoring_memory/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from . import models
|
37
maintenance_server_monitoring_memory/__manifest__.py
Normal file
37
maintenance_server_monitoring_memory/__manifest__.py
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
# Copyright 2023 Stéphan Sainléger (Elabore)
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
|
{
|
||||||
|
"name": "maintenance_server_monitoring_memory",
|
||||||
|
"version": "14.0.1.0.0",
|
||||||
|
"author": "Elabore",
|
||||||
|
"website": "https://elabore.coop",
|
||||||
|
"maintainer": "Clément Thomas",
|
||||||
|
"license": "AGPL-3",
|
||||||
|
"category": "Tools",
|
||||||
|
"summary": "Monitor memory on remote hosts",
|
||||||
|
# any module necessary for this one to work correctly
|
||||||
|
"depends": [
|
||||||
|
"maintenance_server_monitoring",
|
||||||
|
"maintenance_server_ssh"
|
||||||
|
],
|
||||||
|
"qweb": [
|
||||||
|
# "static/src/xml/*.xml",
|
||||||
|
],
|
||||||
|
"external_dependencies": {
|
||||||
|
"python": [],
|
||||||
|
},
|
||||||
|
# always loaded
|
||||||
|
"data": [
|
||||||
|
"views/maintenance_equipment_views.xml",
|
||||||
|
],
|
||||||
|
# only loaded in demonstration mode
|
||||||
|
"demo": [],
|
||||||
|
"js": [],
|
||||||
|
"css": [],
|
||||||
|
"installable": True,
|
||||||
|
# Install this module automatically if all dependency have been previously
|
||||||
|
# and independently installed. Used for synergetic or glue modules.
|
||||||
|
"auto_install": False,
|
||||||
|
"application": False,
|
||||||
|
}
|
1
maintenance_server_monitoring_memory/models/__init__.py
Normal file
1
maintenance_server_monitoring_memory/models/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
from . import maintenance_equipment
|
@@ -0,0 +1,51 @@
|
|||||||
|
from odoo import fields, models, api
|
||||||
|
|
||||||
|
|
||||||
|
AVAILABLE_MEMORY_PERCENT_COMMAND = "free | grep Mem | awk '{print $3/$2 * 100.0}'"
|
||||||
|
MIN_AVAILABLE_MEMORY_PERCENT_WARNING = 20
|
||||||
|
MIN_AVAILABLE_MEMORY_PERCENT_ERROR = 5
|
||||||
|
|
||||||
|
class MaintenanceEquipment(models.Model):
|
||||||
|
_inherit = 'maintenance.equipment'
|
||||||
|
|
||||||
|
available_memory_percent = fields.Float('Percent of available memory', readonly=True)
|
||||||
|
|
||||||
|
def get_tests(self):
|
||||||
|
res = super(MaintenanceEquipment, self).get_tests()
|
||||||
|
res.append("available_memory_percent")
|
||||||
|
return res
|
||||||
|
|
||||||
|
def test_available_memory_percent(self):
|
||||||
|
"""
|
||||||
|
test available memory with a bash command called by ssh
|
||||||
|
|
||||||
|
Args:
|
||||||
|
ssh (paramiko.SSHClient): ssh client
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
MonitoringTest: representing current test with :
|
||||||
|
* result = -2 if error
|
||||||
|
* result = percent of available memory if no error
|
||||||
|
* error defined with MonitoringTest.ERROR or MonitoringTest.WARNING depending on result comparaison
|
||||||
|
with MIN_AVAILABLE_MEMORY_PERCENT_WARNING and MIN_AVAILABLE_MEMORY_PERCENT_ERROR
|
||||||
|
* log file
|
||||||
|
"""
|
||||||
|
test = self.MonitoringTest("Available memory percent")
|
||||||
|
try:
|
||||||
|
ssh = self.get_ssh_connection()
|
||||||
|
if not ssh:
|
||||||
|
return test.test_error(-2, "No ssh connection")
|
||||||
|
_stdin, stdout, _stderr = ssh.exec_command(AVAILABLE_MEMORY_PERCENT_COMMAND)
|
||||||
|
available_memory_percent = float(stdout.read().decode())
|
||||||
|
if available_memory_percent > MIN_AVAILABLE_MEMORY_PERCENT_WARNING:
|
||||||
|
return test.test_ok(available_memory_percent, f"{available_memory_percent}% available")
|
||||||
|
elif available_memory_percent > MIN_AVAILABLE_MEMORY_PERCENT_ERROR:
|
||||||
|
# memory between warning and error step
|
||||||
|
return test.test_warning(available_memory_percent, f"{available_memory_percent}% available (<{MIN_AVAILABLE_MEMORY_PERCENT_WARNING})")
|
||||||
|
else:
|
||||||
|
# memory available lower than error step
|
||||||
|
return test.test_error(available_memory_percent, f"{available_memory_percent}% available (<{MIN_AVAILABLE_MEMORY_PERCENT_ERROR})")
|
||||||
|
except Exception as e:
|
||||||
|
return test.test_error(-2, f"{e}")
|
||||||
|
|
||||||
|
|
@@ -0,0 +1,25 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<odoo>
|
||||||
|
<record id="equipment_view_form_server_inherit" model="ir.ui.view">
|
||||||
|
<field name="name">equipment.form.server.inherit</field>
|
||||||
|
<field name="model">maintenance.equipment</field>
|
||||||
|
<field name="inherit_id" ref="maintenance.hr_equipment_view_form" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<group name="monitoring_test_result" position="inside">
|
||||||
|
<field name="available_memory_percent" />
|
||||||
|
</group>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
|
||||||
|
<record id="equipment_view_tree_server_inherit" model="ir.ui.view">
|
||||||
|
<field name="name">equipment.tree.server.inherit</field>
|
||||||
|
<field name="model">maintenance.equipment</field>
|
||||||
|
<field name="inherit_id" ref="maintenance.hr_equipment_view_tree" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<xpath expr="//field[@name='enable_monitoring']" position="after">
|
||||||
|
<field name="available_memory_percent" optional="hide" />
|
||||||
|
</xpath>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
</odoo>
|
2
maintenance_server_monitoring_ping/.gitignore
vendored
Normal file
2
maintenance_server_monitoring_ping/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
*.*~
|
||||||
|
*pyc
|
44
maintenance_server_monitoring_ping/README.rst
Normal file
44
maintenance_server_monitoring_ping/README.rst
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
======================================
|
||||||
|
maintenance_server_monitoring_ping
|
||||||
|
======================================
|
||||||
|
|
||||||
|
Improve monitoring with ping test
|
||||||
|
|
||||||
|
Installation
|
||||||
|
============
|
||||||
|
|
||||||
|
Use Odoo normal module installation procedure to install
|
||||||
|
``maintenance_server_monitoring_ping``.
|
||||||
|
|
||||||
|
Known issues / Roadmap
|
||||||
|
======================
|
||||||
|
|
||||||
|
None yet.
|
||||||
|
|
||||||
|
Bug Tracker
|
||||||
|
===========
|
||||||
|
|
||||||
|
Bugs are tracked on `our issues website <https://github.com/elabore-coop/maintenance-tools/issues>`_. In case of
|
||||||
|
trouble, please check there if your issue has already been
|
||||||
|
reported. If you spotted it first, help us smashing it by providing a
|
||||||
|
detailed and welcomed feedback.
|
||||||
|
|
||||||
|
Credits
|
||||||
|
=======
|
||||||
|
|
||||||
|
Contributors
|
||||||
|
------------
|
||||||
|
|
||||||
|
* Clément Thomas
|
||||||
|
|
||||||
|
Funders
|
||||||
|
-------
|
||||||
|
|
||||||
|
The development of this module has been financially supported by:
|
||||||
|
* Elabore (https://elabore.coop)
|
||||||
|
|
||||||
|
|
||||||
|
Maintainer
|
||||||
|
----------
|
||||||
|
|
||||||
|
This module is maintained by Elabore.
|
3
maintenance_server_monitoring_ping/__init__.py
Normal file
3
maintenance_server_monitoring_ping/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from . import models
|
36
maintenance_server_monitoring_ping/__manifest__.py
Normal file
36
maintenance_server_monitoring_ping/__manifest__.py
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
# Copyright 2023 Stéphan Sainléger (Elabore)
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
|
{
|
||||||
|
"name": "maintenance_server_monitoring_ping",
|
||||||
|
"version": "14.0.1.0.0",
|
||||||
|
"author": "Elabore",
|
||||||
|
"website": "https://elabore.coop",
|
||||||
|
"maintainer": "Clément Thomas",
|
||||||
|
"license": "AGPL-3",
|
||||||
|
"category": "Tools",
|
||||||
|
"summary": "Monitor ping on remote hosts",
|
||||||
|
# any module necessary for this one to work correctly
|
||||||
|
"depends": [
|
||||||
|
"maintenance_server_monitoring"
|
||||||
|
],
|
||||||
|
"qweb": [
|
||||||
|
# "static/src/xml/*.xml",
|
||||||
|
],
|
||||||
|
"external_dependencies": {
|
||||||
|
"python": [],
|
||||||
|
},
|
||||||
|
# always loaded
|
||||||
|
"data": [
|
||||||
|
"views/maintenance_equipment_views.xml",
|
||||||
|
],
|
||||||
|
# only loaded in demonstration mode
|
||||||
|
"demo": [],
|
||||||
|
"js": [],
|
||||||
|
"css": [],
|
||||||
|
"installable": True,
|
||||||
|
# Install this module automatically if all dependency have been previously
|
||||||
|
# and independently installed. Used for synergetic or glue modules.
|
||||||
|
"auto_install": False,
|
||||||
|
"application": False,
|
||||||
|
}
|
1
maintenance_server_monitoring_ping/models/__init__.py
Normal file
1
maintenance_server_monitoring_ping/models/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
from . import maintenance_equipment
|
@@ -0,0 +1,71 @@
|
|||||||
|
from odoo import fields, models, api
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
MAX_PING_MS_WARNING = 1000
|
||||||
|
MAX_PING_MS_ERROR = 5000
|
||||||
|
|
||||||
|
class MaintenanceEquipment(models.Model):
|
||||||
|
_inherit = 'maintenance.equipment'
|
||||||
|
|
||||||
|
ping_ok = fields.Boolean("Ping ok", readonly=True)
|
||||||
|
|
||||||
|
def get_tests(self):
|
||||||
|
res = super(MaintenanceEquipment, self).get_tests()
|
||||||
|
res.append("ping_ok")
|
||||||
|
return res
|
||||||
|
|
||||||
|
def test_ping_ok(self):
|
||||||
|
"""
|
||||||
|
test PING with ping3 library
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
MonitoringTest: representing current test with :
|
||||||
|
* result = False if error
|
||||||
|
* result = True if no error
|
||||||
|
* error defined with MonitoringTest.ERROR or MonitoringTest.WARNING depending on ping time comparaison
|
||||||
|
with MAX_PING_MS_WARNING and MAX_PING_MS_ERROR
|
||||||
|
* log file
|
||||||
|
"""
|
||||||
|
test = self.MonitoringTest("Ping")
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ping3 import ping
|
||||||
|
except ImportError as e:
|
||||||
|
# unable to import ping3
|
||||||
|
try:
|
||||||
|
command = ['pip3','install',"ping3==4.0.5"]
|
||||||
|
response = subprocess.call(command) # run "pip install ping3" command
|
||||||
|
if response != 0:
|
||||||
|
return test.test_error(False, f"ping3 : unable to install : response = {response}")
|
||||||
|
else:
|
||||||
|
from ping3 import ping
|
||||||
|
except Exception as e:
|
||||||
|
return test.test_error(False, f"ping3 : unable to install : {e}")
|
||||||
|
|
||||||
|
hostname = self.server_domain
|
||||||
|
if not hostname:
|
||||||
|
# equipment host name not filled
|
||||||
|
return test.test_error(False, f"host name seems empty !")
|
||||||
|
|
||||||
|
try:
|
||||||
|
r = ping(hostname)
|
||||||
|
except Exception as e:
|
||||||
|
# Any problem when call ping
|
||||||
|
return test.test_error(False, f"unable to call ping ! > {e}")
|
||||||
|
|
||||||
|
if r:
|
||||||
|
test.result = True
|
||||||
|
ping_ms = int(r*1000)
|
||||||
|
if ping_ms < MAX_PING_MS_WARNING:
|
||||||
|
# ping OK
|
||||||
|
return test.test_ok(True, f"PING OK in {ping_ms} ms")
|
||||||
|
elif ping_ms < MAX_PING_MS_ERROR:
|
||||||
|
# ping result between WARNING and ERROR => WARNING
|
||||||
|
return test.test_warning(True, f"PING OK in {ping_ms}ms (> {MAX_PING_MS_WARNING})")
|
||||||
|
else:
|
||||||
|
# ping result higher than ERROR => ERROR
|
||||||
|
return test.test_error(True, f"PING OK in {ping_ms}ms (> {MAX_PING_MS_ERROR})")
|
||||||
|
else:
|
||||||
|
return test.test_error(False, "PING FAILED")
|
||||||
|
|
||||||
|
|
@@ -0,0 +1,25 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<odoo>
|
||||||
|
<record id="equipment_view_form_server_inherit" model="ir.ui.view">
|
||||||
|
<field name="name">equipment.form.server.inherit</field>
|
||||||
|
<field name="model">maintenance.equipment</field>
|
||||||
|
<field name="inherit_id" ref="maintenance.hr_equipment_view_form" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<group name="monitoring_test_result" position="inside">
|
||||||
|
<field name="ping_ok" />
|
||||||
|
</group>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
|
||||||
|
<record id="equipment_view_tree_server_inherit" model="ir.ui.view">
|
||||||
|
<field name="name">equipment.tree.server.inherit</field>
|
||||||
|
<field name="model">maintenance.equipment</field>
|
||||||
|
<field name="inherit_id" ref="maintenance.hr_equipment_view_tree" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<xpath expr="//field[@name='enable_monitoring']" position="after">
|
||||||
|
<field name="ping_ok" optional="hide" />
|
||||||
|
</xpath>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
</odoo>
|
2
maintenance_server_monitoring_ssh/.gitignore
vendored
Normal file
2
maintenance_server_monitoring_ssh/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
*.*~
|
||||||
|
*pyc
|
44
maintenance_server_monitoring_ssh/README.rst
Normal file
44
maintenance_server_monitoring_ssh/README.rst
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
======================================
|
||||||
|
maintenance_server_monitoring_ssh
|
||||||
|
======================================
|
||||||
|
|
||||||
|
Improve monitoring with ping test
|
||||||
|
|
||||||
|
Installation
|
||||||
|
============
|
||||||
|
|
||||||
|
Use Odoo normal module installation procedure to install
|
||||||
|
``maintenance_server_monitoring_ssh``.
|
||||||
|
|
||||||
|
Known issues / Roadmap
|
||||||
|
======================
|
||||||
|
|
||||||
|
None yet.
|
||||||
|
|
||||||
|
Bug Tracker
|
||||||
|
===========
|
||||||
|
|
||||||
|
Bugs are tracked on `our issues website <https://github.com/elabore-coop/maintenance-tools/issues>`_. In case of
|
||||||
|
trouble, please check there if your issue has already been
|
||||||
|
reported. If you spotted it first, help us smashing it by providing a
|
||||||
|
detailed and welcomed feedback.
|
||||||
|
|
||||||
|
Credits
|
||||||
|
=======
|
||||||
|
|
||||||
|
Contributors
|
||||||
|
------------
|
||||||
|
|
||||||
|
* Clément Thomas
|
||||||
|
|
||||||
|
Funders
|
||||||
|
-------
|
||||||
|
|
||||||
|
The development of this module has been financially supported by:
|
||||||
|
* Elabore (https://elabore.coop)
|
||||||
|
|
||||||
|
|
||||||
|
Maintainer
|
||||||
|
----------
|
||||||
|
|
||||||
|
This module is maintained by Elabore.
|
3
maintenance_server_monitoring_ssh/__init__.py
Normal file
3
maintenance_server_monitoring_ssh/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from . import models
|
37
maintenance_server_monitoring_ssh/__manifest__.py
Normal file
37
maintenance_server_monitoring_ssh/__manifest__.py
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
# Copyright 2023 Stéphan Sainléger (Elabore)
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
|
{
|
||||||
|
"name": "maintenance_server_monitoring_ssh",
|
||||||
|
"version": "14.0.1.0.0",
|
||||||
|
"author": "Elabore",
|
||||||
|
"website": "https://elabore.coop",
|
||||||
|
"maintainer": "Clément Thomas",
|
||||||
|
"license": "AGPL-3",
|
||||||
|
"category": "Tools",
|
||||||
|
"summary": "Monitor ssh response on remote hosts",
|
||||||
|
# any module necessary for this one to work correctly
|
||||||
|
"depends": [
|
||||||
|
"maintenance_server_monitoring",
|
||||||
|
"maintenance_server_ssh"
|
||||||
|
],
|
||||||
|
"qweb": [
|
||||||
|
# "static/src/xml/*.xml",
|
||||||
|
],
|
||||||
|
"external_dependencies": {
|
||||||
|
"python": [],
|
||||||
|
},
|
||||||
|
# always loaded
|
||||||
|
"data": [
|
||||||
|
"views/maintenance_equipment_views.xml",
|
||||||
|
],
|
||||||
|
# only loaded in demonstration mode
|
||||||
|
"demo": [],
|
||||||
|
"js": [],
|
||||||
|
"css": [],
|
||||||
|
"installable": True,
|
||||||
|
# Install this module automatically if all dependency have been previously
|
||||||
|
# and independently installed. Used for synergetic or glue modules.
|
||||||
|
"auto_install": False,
|
||||||
|
"application": False,
|
||||||
|
}
|
1
maintenance_server_monitoring_ssh/models/__init__.py
Normal file
1
maintenance_server_monitoring_ssh/models/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
from . import maintenance_equipment
|
@@ -0,0 +1,30 @@
|
|||||||
|
from odoo import fields, models, api
|
||||||
|
|
||||||
|
class MaintenanceEquipment(models.Model):
|
||||||
|
_inherit = 'maintenance.equipment'
|
||||||
|
|
||||||
|
ssh_ok = fields.Boolean("SSH ok", readonly=True)
|
||||||
|
|
||||||
|
def get_tests(self):
|
||||||
|
res = super(MaintenanceEquipment, self).get_tests()
|
||||||
|
res.append("ssh_ok")
|
||||||
|
return res
|
||||||
|
|
||||||
|
def test_ssh_ok(self):
|
||||||
|
"""
|
||||||
|
test ssh with maintenance_server_ssh module
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
MonitoringTest: representing current test with :
|
||||||
|
* result = False if error
|
||||||
|
* result = ssh connection if no error
|
||||||
|
* error = MonitoringTest.ERROR if connection failed
|
||||||
|
* log file
|
||||||
|
"""
|
||||||
|
test = self.MonitoringTest("SSH OK")
|
||||||
|
try:
|
||||||
|
# SSH connection ok : set ssh connection in result, converted in boolean (True) when set in ssh_ok field
|
||||||
|
return test.test_ok(self.get_ssh_connection(), "SSH Connection OK") #ssh connection given by maintenance_server_ssh module
|
||||||
|
except Exception as e:
|
||||||
|
# SSH connection failed
|
||||||
|
return test.test_error(False, "connection failed {e}")
|
@@ -0,0 +1,25 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<odoo>
|
||||||
|
<record id="equipment_view_form_server_inherit" model="ir.ui.view">
|
||||||
|
<field name="name">equipment.form.server.inherit</field>
|
||||||
|
<field name="model">maintenance.equipment</field>
|
||||||
|
<field name="inherit_id" ref="maintenance.hr_equipment_view_form" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<group name="monitoring_test_result" position="inside">
|
||||||
|
<field name="ssh_ok" />
|
||||||
|
</group>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
|
||||||
|
<record id="equipment_view_tree_server_inherit" model="ir.ui.view">
|
||||||
|
<field name="name">equipment.tree.server.inherit</field>
|
||||||
|
<field name="model">maintenance.equipment</field>
|
||||||
|
<field name="inherit_id" ref="maintenance.hr_equipment_view_tree" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<xpath expr="//field[@name='enable_monitoring']" position="after">
|
||||||
|
<field name="ssh_ok" />
|
||||||
|
</xpath>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
</odoo>
|
2
maintenance_server_ssh/.gitignore
vendored
Normal file
2
maintenance_server_ssh/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
*.*~
|
||||||
|
*pyc
|
44
maintenance_server_ssh/README.rst
Normal file
44
maintenance_server_ssh/README.rst
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
======================================
|
||||||
|
maintenance_server_ssh
|
||||||
|
======================================
|
||||||
|
|
||||||
|
Create an SSH remote connection for maintenance equipment, usable for other modules
|
||||||
|
|
||||||
|
Installation
|
||||||
|
============
|
||||||
|
|
||||||
|
Use Odoo normal module installation procedure to install
|
||||||
|
``maintenance_server_ssh``.
|
||||||
|
|
||||||
|
Known issues / Roadmap
|
||||||
|
======================
|
||||||
|
|
||||||
|
None yet.
|
||||||
|
|
||||||
|
Bug Tracker
|
||||||
|
===========
|
||||||
|
|
||||||
|
Bugs are tracked on `our issues website <https://github.com/elabore-coop/maintenance-tools/issues>`_. In case of
|
||||||
|
trouble, please check there if your issue has already been
|
||||||
|
reported. If you spotted it first, help us smashing it by providing a
|
||||||
|
detailed and welcomed feedback.
|
||||||
|
|
||||||
|
Credits
|
||||||
|
=======
|
||||||
|
|
||||||
|
Contributors
|
||||||
|
------------
|
||||||
|
|
||||||
|
* Clément Thomas
|
||||||
|
|
||||||
|
Funders
|
||||||
|
-------
|
||||||
|
|
||||||
|
The development of this module has been financially supported by:
|
||||||
|
* Elabore (https://elabore.coop)
|
||||||
|
|
||||||
|
|
||||||
|
Maintainer
|
||||||
|
----------
|
||||||
|
|
||||||
|
This module is maintained by Elabore.
|
3
maintenance_server_ssh/__init__.py
Normal file
3
maintenance_server_ssh/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from . import models
|
37
maintenance_server_ssh/__manifest__.py
Normal file
37
maintenance_server_ssh/__manifest__.py
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
# Copyright 2023 Stéphan Sainléger (Elabore)
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
|
{
|
||||||
|
"name": "maintenance_server_ssh",
|
||||||
|
"version": "14.0.1.0.0",
|
||||||
|
"author": "Elabore",
|
||||||
|
"website": "https://elabore.coop",
|
||||||
|
"maintainer": "Clément Thomas",
|
||||||
|
"license": "AGPL-3",
|
||||||
|
"category": "Tools",
|
||||||
|
"summary": "Monitor some data on remote hosts",
|
||||||
|
# any module necessary for this one to work correctly
|
||||||
|
"depends": [
|
||||||
|
"base",
|
||||||
|
"maintenance",
|
||||||
|
],
|
||||||
|
"qweb": [
|
||||||
|
# "static/src/xml/*.xml",
|
||||||
|
],
|
||||||
|
"external_dependencies": {
|
||||||
|
"python": [],
|
||||||
|
},
|
||||||
|
# always loaded
|
||||||
|
"data": [
|
||||||
|
"views/maintenance_equipment_views.xml",
|
||||||
|
],
|
||||||
|
# only loaded in demonstration mode
|
||||||
|
"demo": [],
|
||||||
|
"js": [],
|
||||||
|
"css": [],
|
||||||
|
"installable": True,
|
||||||
|
# Install this module automatically if all dependency have been previously
|
||||||
|
# and independently installed. Used for synergetic or glue modules.
|
||||||
|
"auto_install": False,
|
||||||
|
"application": False,
|
||||||
|
}
|
1
maintenance_server_ssh/models/__init__.py
Normal file
1
maintenance_server_ssh/models/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
from . import maintenance_equipment
|
27
maintenance_server_ssh/models/maintenance_equipment.py
Normal file
27
maintenance_server_ssh/models/maintenance_equipment.py
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
from odoo import fields, models
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
import psutil
|
||||||
|
|
||||||
|
|
||||||
|
class MaintenanceEquipment(models.Model):
|
||||||
|
_inherit = 'maintenance.equipment'
|
||||||
|
|
||||||
|
server_domain = fields.Char('Server Domain')
|
||||||
|
ssh_private_key_path = fields.Char("SSH private key path", default="/opt/odoo/auto/dev/ssh_keys/id_rsa")
|
||||||
|
|
||||||
|
def get_ssh_connection(self):
|
||||||
|
ssh_connections = self.env.context.get('ssh_connections',{})
|
||||||
|
if self.id in ssh_connections:
|
||||||
|
return ssh_connections[self.id]
|
||||||
|
|
||||||
|
import paramiko
|
||||||
|
ssh = paramiko.SSHClient()
|
||||||
|
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||||
|
ssh.connect(self.server_domain, username="root", key_filename=self.ssh_private_key_path)
|
||||||
|
|
||||||
|
ssh_connections[self.id] = ssh
|
||||||
|
self = self.with_context(ssh_connections=ssh_connections)
|
||||||
|
return ssh
|
||||||
|
|
||||||
|
|
30
maintenance_server_ssh/views/maintenance_equipment_views.xml
Normal file
30
maintenance_server_ssh/views/maintenance_equipment_views.xml
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<odoo>
|
||||||
|
<record id="equipment_view_form_server_inherit" model="ir.ui.view">
|
||||||
|
<field name="name">equipment.form.server.inherit</field>
|
||||||
|
<field name="model">maintenance.equipment</field>
|
||||||
|
<field name="inherit_id" ref="maintenance.hr_equipment_view_form" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<xpath expr="//notebook" position="inside">
|
||||||
|
<page name="ssh" string="SSH">
|
||||||
|
<group name="ssh_connection" string="SSH Connection">
|
||||||
|
<field name="server_domain" />
|
||||||
|
<field name="ssh_private_key_path" />
|
||||||
|
</group>
|
||||||
|
</page>
|
||||||
|
</xpath>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<record id="equipment_view_tree_server_inherit" model="ir.ui.view">
|
||||||
|
<field name="name">equipment.tree.server.inherit</field>
|
||||||
|
<field name="model">maintenance.equipment</field>
|
||||||
|
<field name="inherit_id" ref="maintenance.hr_equipment_view_tree" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<xpath expr="//field[@name='category_id']" position="after">
|
||||||
|
<field name="server_domain" optional="hide" />
|
||||||
|
</xpath>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
</odoo>
|
Reference in New Issue
Block a user