[NEW] maintenance_server_monitoring

This commit is contained in:
clementthomas
2024-04-02 13:26:45 +02:00
parent 2e9f01cb0d
commit e4d6071e65
7 changed files with 170 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
*.*~
*pyc

View File

@@ -0,0 +1,44 @@
======================================
maintenance_server_data
======================================
Gather several identification data about the servers to maintain.
Installation
============
Use Odoo normal module installation procedure to install
``maintenance_server_data``.
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
------------
* Stéphan Sainléger
Funders
-------
The development of this module has been financially supported by:
* Elabore (https://elabore.coop)
Maintainer
----------
This module is maintained by Elabore.

View File

@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
from . import models

View 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",
"version": "16.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,
}

View File

@@ -0,0 +1 @@
from . import maintenance_equipment

View File

@@ -0,0 +1,46 @@
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")
last_monitoring_test_date = fields.Datetime('Date of last monitoring test', readonly=True)
ping_ok = fields.Boolean("Ping ok", readonly=True)
available_memory_percent = fields.Float('Percent of available memory', readonly=True)
def install_dependencies(self):
if "ping3" not in sys.modules:
command = ['pip','install',"ping3"]
response = subprocess.call(command)
return response
def monitoring_test(self):
self.install_dependencies()
self.test_ping()
self.test_available_memory_percent()
self.last_monitoring_test_date = fields.Datetime.now()
return
def test_available_memory_percent(self):
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)
_stdin, stdout, _stderr = ssh.exec_command("free | grep Mem | awk '{print $3/$2 * 100.0}'")
self.available_memory_percent = float(stdout.read().decode())
def test_ping(self):
from ping3 import ping
hostname = self.server_domain
r = ping(hostname)
if r:
self.ping_ok = True
else:
self.ping_ok = False
return

View File

@@ -0,0 +1,37 @@
<?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" string="Configuration">
<field name="server_domain" />
<field name="ssh_private_key_path" />
</group>
<group name="monitoring_test" string="Test">
<field name="last_monitoring_test_date" />
<field name="ping_ok" />
<field name="available_memory_percent" />
<button name="monitoring_test" type="object" string="Test" />
</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" />
<field name="ping_ok" optional="hide" />
</xpath>
</field>
</record>
</odoo>