Compare commits
3 Commits
18.0
...
c4d12f4a73
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c4d12f4a73 | ||
|
|
053927aba3 | ||
|
|
c3ed1fbdc0 |
@@ -1,42 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
#
|
|
||||||
# Run the Python tests of the given Odoo modules.
|
|
||||||
#
|
|
||||||
# This script is meant to be executed *inside* an Elabore doodba image
|
|
||||||
# (docker.0k.io/mirror/odoo:rc_<version>-ELABORE-LIGHT), with a
|
|
||||||
# PostgreSQL service reachable at $PGHOST. The modules under test are
|
|
||||||
# read from the current working directory (the checked-out repository),
|
|
||||||
# which is prepended to the addons path so that the PR's code takes
|
|
||||||
# precedence over the modules already baked in the image.
|
|
||||||
#
|
|
||||||
# Usage: odoo-tests.sh <module1,module2,...>
|
|
||||||
|
|
||||||
set -euo pipefail
|
|
||||||
|
|
||||||
modules="${1:?usage: odoo-tests.sh <module1,module2,...>}"
|
|
||||||
|
|
||||||
export PGHOST=postgres
|
|
||||||
export PGUSER=odoo
|
|
||||||
export PGPASSWORD=odoopassword
|
|
||||||
export PGDATABASE="test_$(basename "$PWD" | tr '.-' '__')"
|
|
||||||
export WITHOUT_DEMO=all
|
|
||||||
export DB_FILTER='.*'
|
|
||||||
|
|
||||||
# Generate /opt/odoo/auto/odoo.conf from the environment and wait for
|
|
||||||
# the database to accept connections.
|
|
||||||
/opt/odoo/common/entrypoint
|
|
||||||
|
|
||||||
# Odoo test-tags format: "/module1,/module2" (one leading slash).
|
|
||||||
tags="/$(echo "$modules" | tr ',' ',/')"
|
|
||||||
|
|
||||||
exec odoo \
|
|
||||||
--config=/opt/odoo/auto/odoo.conf \
|
|
||||||
--max-cron-threads=0 \
|
|
||||||
--limit-time-real=10000 \
|
|
||||||
--workers=0 \
|
|
||||||
--test-enable \
|
|
||||||
--stop-after-init \
|
|
||||||
--addons-path="$PWD,/opt/odoo/auto/addons" \
|
|
||||||
-d "$PGDATABASE" \
|
|
||||||
-i "$modules" \
|
|
||||||
--test-tags "$tags"
|
|
||||||
@@ -2,6 +2,8 @@ name: pre-commit
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- "16.0*"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
pre-commit:
|
pre-commit:
|
||||||
@@ -13,10 +15,10 @@ jobs:
|
|||||||
python-version: "3.11"
|
python-version: "3.11"
|
||||||
- name: Get python version
|
- name: Get python version
|
||||||
run: echo "PY=$(python -VV | sha256sum | cut -d' ' -f1)" >> $GITHUB_ENV
|
run: echo "PY=$(python -VV | sha256sum | cut -d' ' -f1)" >> $GITHUB_ENV
|
||||||
- uses: https://gitea.com/actions/cache@v3
|
# - uses: actions/cache@v4
|
||||||
with:
|
# with:
|
||||||
path: ~/.cache/pre-commit
|
# path: ~/.cache/pre-commit
|
||||||
key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}
|
# key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}
|
||||||
- name: Install pre-commit
|
- name: Install pre-commit
|
||||||
run: pip install pre-commit
|
run: pip install pre-commit
|
||||||
- name: Run pre-commit
|
- name: Run pre-commit
|
||||||
|
|||||||
@@ -1,79 +0,0 @@
|
|||||||
name: tests
|
|
||||||
|
|
||||||
on:
|
|
||||||
pull_request:
|
|
||||||
branches:
|
|
||||||
- "18.0*"
|
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
test:
|
|
||||||
runs-on: odoo-ci
|
|
||||||
container:
|
|
||||||
image: docker.0k.io/mirror/odoo:rc_18.0-ELABORE-LIGHT
|
|
||||||
services:
|
|
||||||
postgres:
|
|
||||||
image: docker.0k.io/postgres:17.2.0-myc
|
|
||||||
env:
|
|
||||||
POSTGRES_USER: odoo
|
|
||||||
POSTGRES_PASSWORD: odoopassword
|
|
||||||
POSTGRES_DB: postgres
|
|
||||||
steps:
|
|
||||||
# The doodba image ships no Node.js, so actions/checkout@v4 cannot
|
|
||||||
# run here. The repository is private, so the job token is required.
|
|
||||||
- name: Checkout
|
|
||||||
env:
|
|
||||||
SECRET_GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
|
||||||
SECRET_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
run: |
|
|
||||||
set -eu
|
|
||||||
token="${GITEA_TOKEN:-${GITHUB_TOKEN:-${SECRET_GITEA_TOKEN:-${SECRET_GITHUB_TOKEN:-}}}}"
|
|
||||||
if [ -z "$token" ]; then
|
|
||||||
echo "::error::No job token available to clone the repository"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
server="${GITHUB_SERVER_URL:-https://git.elabore.coop}"
|
|
||||||
repo="${GITHUB_REPOSITORY:?GITHUB_REPOSITORY is not set}"
|
|
||||||
ref="${GITHUB_REF:-${GITHUB_SHA:?neither GITHUB_REF nor GITHUB_SHA is set}}"
|
|
||||||
auth_url="$(printf '%s' "${server%/}/${repo}.git" |
|
|
||||||
sed -E "s#^https://#https://${token}@#")"
|
|
||||||
git init -q .
|
|
||||||
git config --global --add safe.directory "$PWD"
|
|
||||||
git remote add origin "$auth_url"
|
|
||||||
git fetch -q --depth=1 origin "$ref"
|
|
||||||
git checkout -q FETCH_HEAD
|
|
||||||
|
|
||||||
- name: Detect changed modules
|
|
||||||
id: changed
|
|
||||||
run: |
|
|
||||||
set -eu
|
|
||||||
if [ -n "${GITHUB_BASE_REF:-}" ]; then
|
|
||||||
git fetch -q --depth=1 origin "refs/heads/$GITHUB_BASE_REF"
|
|
||||||
base_rev="FETCH_HEAD"
|
|
||||||
scope="diff against $GITHUB_BASE_REF"
|
|
||||||
else
|
|
||||||
base_rev=""
|
|
||||||
scope="all installable modules (manual run)"
|
|
||||||
fi
|
|
||||||
if [ -n "$base_rev" ]; then
|
|
||||||
modules="$(
|
|
||||||
git diff --name-only "$base_rev" HEAD |
|
|
||||||
awk -F/ '{print $1}' | sort -u |
|
|
||||||
while read -r dir; do
|
|
||||||
[ -f "$dir/__manifest__.py" ] && echo "$dir"
|
|
||||||
done | paste -sd, -
|
|
||||||
)"
|
|
||||||
else
|
|
||||||
modules="$(
|
|
||||||
for dir in */; do
|
|
||||||
dir="${dir%/}"
|
|
||||||
[ -f "$dir/__manifest__.py" ] && echo "$dir"
|
|
||||||
done | paste -sd, -
|
|
||||||
)"
|
|
||||||
fi
|
|
||||||
echo "modules=$modules" >> "$GITHUB_OUTPUT"
|
|
||||||
echo "Modules to test ($scope): ${modules:-<none>}"
|
|
||||||
|
|
||||||
- name: Run Odoo tests
|
|
||||||
if: steps.changed.outputs.modules != ''
|
|
||||||
run: bash .gitea/scripts/odoo-tests.sh "${{ steps.changed.outputs.modules }}"
|
|
||||||
88
.gitignore
vendored
88
.gitignore
vendored
@@ -1,88 +0,0 @@
|
|||||||
# Byte-compiled / optimized / DLL files
|
|
||||||
__pycache__/
|
|
||||||
*.py[cod]
|
|
||||||
/.venv
|
|
||||||
/.pytest_cache
|
|
||||||
/.ruff_cache
|
|
||||||
|
|
||||||
# C extensions
|
|
||||||
*.so
|
|
||||||
|
|
||||||
# Distribution / packaging
|
|
||||||
.Python
|
|
||||||
env/
|
|
||||||
bin/
|
|
||||||
build/
|
|
||||||
develop-eggs/
|
|
||||||
dist/
|
|
||||||
eggs/
|
|
||||||
lib64/
|
|
||||||
parts/
|
|
||||||
sdist/
|
|
||||||
var/
|
|
||||||
*.egg-info/
|
|
||||||
.installed.cfg
|
|
||||||
*.egg
|
|
||||||
*.eggs
|
|
||||||
|
|
||||||
# Windows installers
|
|
||||||
*.msi
|
|
||||||
|
|
||||||
# Debian packages
|
|
||||||
*.deb
|
|
||||||
|
|
||||||
# Redhat packages
|
|
||||||
*.rpm
|
|
||||||
|
|
||||||
# MacOS packages
|
|
||||||
*.dmg
|
|
||||||
*.pkg
|
|
||||||
|
|
||||||
# Installer logs
|
|
||||||
pip-log.txt
|
|
||||||
pip-delete-this-directory.txt
|
|
||||||
|
|
||||||
# Unit test / coverage reports
|
|
||||||
htmlcov/
|
|
||||||
.tox/
|
|
||||||
.coverage
|
|
||||||
.cache
|
|
||||||
nosetests.xml
|
|
||||||
coverage.xml
|
|
||||||
|
|
||||||
# Translations
|
|
||||||
*.mo
|
|
||||||
|
|
||||||
# Pycharm
|
|
||||||
.idea
|
|
||||||
|
|
||||||
# Eclipse
|
|
||||||
.settings
|
|
||||||
|
|
||||||
# Visual Studio cache/options directory
|
|
||||||
.vs/
|
|
||||||
.vscode
|
|
||||||
|
|
||||||
# OSX Files
|
|
||||||
.DS_Store
|
|
||||||
|
|
||||||
# Django stuff:
|
|
||||||
*.log
|
|
||||||
|
|
||||||
# Mr Developer
|
|
||||||
.mr.developer.cfg
|
|
||||||
.project
|
|
||||||
.pydevproject
|
|
||||||
|
|
||||||
# Rope
|
|
||||||
.ropeproject
|
|
||||||
|
|
||||||
# Sphinx documentation
|
|
||||||
docs/_build/
|
|
||||||
|
|
||||||
# Backup files
|
|
||||||
*~
|
|
||||||
*.swp
|
|
||||||
|
|
||||||
# OCA rules
|
|
||||||
!static/lib/
|
|
||||||
@@ -22,7 +22,7 @@ exclude: |
|
|||||||
(LICENSE.*|COPYING.*)
|
(LICENSE.*|COPYING.*)
|
||||||
default_language_version:
|
default_language_version:
|
||||||
python: python3
|
python: python3
|
||||||
node: "22.9.0"
|
node: "16.17.0"
|
||||||
repos:
|
repos:
|
||||||
- repo: local
|
- repo: local
|
||||||
hooks:
|
hooks:
|
||||||
@@ -38,12 +38,8 @@ repos:
|
|||||||
entry: found a en.po file
|
entry: found a en.po file
|
||||||
language: fail
|
language: fail
|
||||||
files: '[a-zA-Z0-9_]*/i18n/en\.po$'
|
files: '[a-zA-Z0-9_]*/i18n/en\.po$'
|
||||||
- repo: https://github.com/sbidoul/whool
|
|
||||||
rev: v1.3
|
|
||||||
hooks:
|
|
||||||
- id: whool-init
|
|
||||||
- repo: https://github.com/oca/maintainer-tools
|
- repo: https://github.com/oca/maintainer-tools
|
||||||
rev: b89f767503be6ab2b11e4f50a7557cb20066e667
|
rev: f9b919b9868143135a9c9cb03021089cabba8223
|
||||||
hooks:
|
hooks:
|
||||||
# update the NOT INSTALLABLE ADDONS section above
|
# update the NOT INSTALLABLE ADDONS section above
|
||||||
- id: oca-update-pre-commit-excluded-addons
|
- id: oca-update-pre-commit-excluded-addons
|
||||||
@@ -53,13 +49,16 @@ repos:
|
|||||||
$(git rev-parse --show-toplevel))"'
|
$(git rev-parse --show-toplevel))"'
|
||||||
- id: oca-gen-addon-readme
|
- id: oca-gen-addon-readme
|
||||||
entry:
|
entry:
|
||||||
bash -c 'oca-gen-addon-readme --addons-dir=. --branch=$(git symbolic-ref
|
bash -c 'oca-gen-addon-readme
|
||||||
|
--addons-dir=.
|
||||||
|
--branch=$(git symbolic-ref
|
||||||
refs/remotes/origin/HEAD | sed "s@^refs/remotes/origin/@@")
|
refs/remotes/origin/HEAD | sed "s@^refs/remotes/origin/@@")
|
||||||
--repo-name=$(basename $(git rev-parse --show-toplevel)) --org-name="Elabore"
|
--repo-name=$(basename $(git rev-parse --show-toplevel))
|
||||||
--if-source-changed --keep-source-digest --convert-fragments-to-markdown'
|
--org-name="Elabore"
|
||||||
- id: oca-gen-external-dependencies
|
--if-source-changed --keep-source-digest'
|
||||||
|
|
||||||
- repo: https://github.com/OCA/odoo-pre-commit-hooks
|
- repo: https://github.com/OCA/odoo-pre-commit-hooks
|
||||||
rev: v0.0.33
|
rev: v0.1.4
|
||||||
hooks:
|
hooks:
|
||||||
- id: oca-checks-odoo-module
|
- id: oca-checks-odoo-module
|
||||||
- id: oca-checks-po
|
- id: oca-checks-po
|
||||||
@@ -78,8 +77,8 @@ repos:
|
|||||||
files: \.(css|htm|html|js|json|jsx|less|md|scss|toml|ts|xml|yaml|yml)$
|
files: \.(css|htm|html|js|json|jsx|less|md|scss|toml|ts|xml|yaml|yml)$
|
||||||
language: node
|
language: node
|
||||||
additional_dependencies:
|
additional_dependencies:
|
||||||
- "prettier@3.3.3"
|
- "prettier@2.7.1"
|
||||||
- "@prettier/plugin-xml@3.4.1"
|
- "@prettier/plugin-xml@2.2.0"
|
||||||
- repo: local
|
- repo: local
|
||||||
hooks:
|
hooks:
|
||||||
- id: eslint
|
- id: eslint
|
||||||
@@ -92,11 +91,10 @@ repos:
|
|||||||
types: [javascript]
|
types: [javascript]
|
||||||
language: node
|
language: node
|
||||||
additional_dependencies:
|
additional_dependencies:
|
||||||
- "eslint@9.12.0"
|
- "eslint@8.24.0"
|
||||||
- "eslint-plugin-jsdoc@50.3.1"
|
- "eslint-plugin-jsdoc@"
|
||||||
- "globals@16.0.0"
|
|
||||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||||
rev: v4.6.0
|
rev: v5.0.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: trailing-whitespace
|
- id: trailing-whitespace
|
||||||
# exclude autogenerated files
|
# exclude autogenerated files
|
||||||
@@ -117,8 +115,23 @@ repos:
|
|||||||
- id: check-xml
|
- id: check-xml
|
||||||
- id: mixed-line-ending
|
- id: mixed-line-ending
|
||||||
args: ["--fix=lf"]
|
args: ["--fix=lf"]
|
||||||
|
- repo: https://github.com/PyCQA/docformatter
|
||||||
|
rev: v1.7.7
|
||||||
|
hooks:
|
||||||
|
- id: docformatter
|
||||||
|
args: [
|
||||||
|
"--in-place", # modify the files
|
||||||
|
"--recursive", # run on all the files
|
||||||
|
"--wrap-summaries",
|
||||||
|
"88", # max length of 1st line
|
||||||
|
"--wrap-descriptions",
|
||||||
|
"88", # max length of other lines
|
||||||
|
"--pre-summary-newline", # new line before a long summary
|
||||||
|
"--make-summary-multi-line", # force summary on multilines
|
||||||
|
]
|
||||||
|
additional_dependencies: ["tomli"] # if Python <3.11
|
||||||
- repo: https://github.com/astral-sh/ruff-pre-commit
|
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||||
rev: v0.6.8
|
rev: v0.12.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: ruff
|
- id: ruff
|
||||||
args: [--fix, --exit-non-zero-on-fix]
|
args: [--fix, --exit-non-zero-on-fix]
|
||||||
|
|||||||
73
.pylintrc
73
.pylintrc
@@ -10,7 +10,7 @@ manifest-required-authors=Elabore
|
|||||||
manifest-required-keys=license
|
manifest-required-keys=license
|
||||||
manifest-deprecated-keys=description,active
|
manifest-deprecated-keys=description,active
|
||||||
license-allowed=AGPL-3,GPL-2,GPL-2 or any later version,GPL-3,GPL-3 or any later version,LGPL-3
|
license-allowed=AGPL-3,GPL-2,GPL-2 or any later version,GPL-3,GPL-3 or any later version,LGPL-3
|
||||||
valid-odoo-versions=18.0
|
valid-odoo-versions=16.0
|
||||||
|
|
||||||
[MESSAGES CONTROL]
|
[MESSAGES CONTROL]
|
||||||
disable=all
|
disable=all
|
||||||
@@ -25,25 +25,19 @@ disable=all
|
|||||||
enable=anomalous-backslash-in-string,
|
enable=anomalous-backslash-in-string,
|
||||||
api-one-deprecated,
|
api-one-deprecated,
|
||||||
api-one-multi-together,
|
api-one-multi-together,
|
||||||
|
assignment-from-none,
|
||||||
|
attribute-deprecated,
|
||||||
class-camelcase,
|
class-camelcase,
|
||||||
|
dangerous-default-value,
|
||||||
dangerous-view-replace-wo-priority,
|
dangerous-view-replace-wo-priority,
|
||||||
|
development-status-allowed,
|
||||||
duplicate-id-csv,
|
duplicate-id-csv,
|
||||||
|
duplicate-key,
|
||||||
duplicate-xml-fields,
|
duplicate-xml-fields,
|
||||||
duplicate-xml-record-id,
|
duplicate-xml-record-id,
|
||||||
eval-referenced,
|
eval-referenced,
|
||||||
incoherent-interpreter-exec-perm,
|
|
||||||
openerp-exception-warning,
|
|
||||||
redundant-modulename-xml,
|
|
||||||
relative-import,
|
|
||||||
rst-syntax-error,
|
|
||||||
wrong-tabs-instead-of-spaces,
|
|
||||||
xml-syntax-error,
|
|
||||||
assignment-from-none,
|
|
||||||
attribute-deprecated,
|
|
||||||
dangerous-default-value,
|
|
||||||
development-status-allowed,
|
|
||||||
duplicate-key,
|
|
||||||
eval-used,
|
eval-used,
|
||||||
|
incoherent-interpreter-exec-perm,
|
||||||
license-allowed,
|
license-allowed,
|
||||||
manifest-author-string,
|
manifest-author-string,
|
||||||
manifest-deprecated-key,
|
manifest-deprecated-key,
|
||||||
@@ -54,68 +48,73 @@ enable=anomalous-backslash-in-string,
|
|||||||
method-inverse,
|
method-inverse,
|
||||||
method-required-super,
|
method-required-super,
|
||||||
method-search,
|
method-search,
|
||||||
|
openerp-exception-warning,
|
||||||
pointless-statement,
|
pointless-statement,
|
||||||
pointless-string-statement,
|
pointless-string-statement,
|
||||||
print-used,
|
print-used,
|
||||||
redundant-keyword-arg,
|
redundant-keyword-arg,
|
||||||
|
redundant-modulename-xml,
|
||||||
reimported,
|
reimported,
|
||||||
|
relative-import,
|
||||||
return-in-init,
|
return-in-init,
|
||||||
|
rst-syntax-error,
|
||||||
sql-injection,
|
sql-injection,
|
||||||
too-few-format-args,
|
too-few-format-args,
|
||||||
translation-field,
|
translation-field,
|
||||||
translation-required,
|
translation-required,
|
||||||
unreachable,
|
unreachable,
|
||||||
use-vim-comment,
|
use-vim-comment,
|
||||||
|
wrong-tabs-instead-of-spaces,
|
||||||
|
xml-syntax-error,
|
||||||
|
attribute-string-redundant,
|
||||||
character-not-valid-in-resource-link,
|
character-not-valid-in-resource-link,
|
||||||
|
consider-merging-classes-inherited,
|
||||||
|
context-overridden,
|
||||||
create-user-wo-reset-password,
|
create-user-wo-reset-password,
|
||||||
dangerous-filter-wo-user,
|
dangerous-filter-wo-user,
|
||||||
dangerous-qweb-replace-wo-priority,
|
dangerous-qweb-replace-wo-priority,
|
||||||
deprecated-data-xml-node,
|
deprecated-data-xml-node,
|
||||||
deprecated-openerp-xml-node,
|
deprecated-openerp-xml-node,
|
||||||
duplicate-po-message-definition,
|
duplicate-po-message-definition,
|
||||||
file-not-used,
|
|
||||||
missing-newline-extrafiles,
|
|
||||||
old-api7-method-defined,
|
|
||||||
po-msgstr-variables,
|
|
||||||
po-syntax-error,
|
|
||||||
str-format-used,
|
|
||||||
unnecessary-utf8-coding-comment,
|
|
||||||
xml-attribute-translatable,
|
|
||||||
xml-deprecated-qweb-directive,
|
|
||||||
xml-deprecated-tree-attribute,
|
|
||||||
attribute-string-redundant,
|
|
||||||
consider-merging-classes-inherited,
|
|
||||||
context-overridden,
|
|
||||||
except-pass,
|
except-pass,
|
||||||
|
file-not-used,
|
||||||
invalid-commit,
|
invalid-commit,
|
||||||
manifest-maintainers-list,
|
manifest-maintainers-list,
|
||||||
|
missing-newline-extrafiles,
|
||||||
missing-readme,
|
missing-readme,
|
||||||
missing-return,
|
missing-return,
|
||||||
odoo-addons-relative-import,
|
odoo-addons-relative-import,
|
||||||
|
old-api7-method-defined,
|
||||||
|
po-msgstr-variables,
|
||||||
|
po-syntax-error,
|
||||||
renamed-field-parameter,
|
renamed-field-parameter,
|
||||||
resource-not-exist,
|
resource-not-exist,
|
||||||
|
str-format-used,
|
||||||
test-folder-imported,
|
test-folder-imported,
|
||||||
translation-contains-variable,
|
translation-contains-variable,
|
||||||
translation-positional-used,
|
translation-positional-used,
|
||||||
website-manifest-key-not-valid-uri,
|
|
||||||
external-request-timeout,
|
|
||||||
missing-manifest-dependency,
|
|
||||||
too-complex,,
|
|
||||||
create-user-wo-reset-password,
|
|
||||||
dangerous-filter-wo-user,
|
|
||||||
file-not-used,
|
|
||||||
missing-newline-extrafiles,
|
|
||||||
no-utf8-coding-comment,
|
|
||||||
old-api7-method-defined,
|
|
||||||
unnecessary-utf8-coding-comment,
|
unnecessary-utf8-coding-comment,
|
||||||
|
website-manifest-key-not-valid-uri,
|
||||||
|
xml-attribute-translatable,
|
||||||
|
xml-deprecated-qweb-directive,
|
||||||
|
xml-deprecated-tree-attribute,
|
||||||
|
external-request-timeout,
|
||||||
# messages that do not cause the lint step to fail
|
# messages that do not cause the lint step to fail
|
||||||
consider-merging-classes-inherited,
|
consider-merging-classes-inherited,
|
||||||
|
create-user-wo-reset-password,
|
||||||
|
dangerous-filter-wo-user,
|
||||||
deprecated-module,
|
deprecated-module,
|
||||||
|
file-not-used,
|
||||||
invalid-commit,
|
invalid-commit,
|
||||||
|
missing-manifest-dependency,
|
||||||
|
missing-newline-extrafiles,
|
||||||
missing-readme,
|
missing-readme,
|
||||||
|
no-utf8-coding-comment,
|
||||||
odoo-addons-relative-import,
|
odoo-addons-relative-import,
|
||||||
|
old-api7-method-defined,
|
||||||
redefined-builtin,
|
redefined-builtin,
|
||||||
manifest-external-assets
|
too-complex,
|
||||||
|
unnecessary-utf8-coding-comment
|
||||||
|
|
||||||
|
|
||||||
[REPORTS]
|
[REPORTS]
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ manifest-required-authors=Elabore
|
|||||||
manifest-required-keys=license
|
manifest-required-keys=license
|
||||||
manifest-deprecated-keys=description,active
|
manifest-deprecated-keys=description,active
|
||||||
license-allowed=AGPL-3,GPL-2,GPL-2 or any later version,GPL-3,GPL-3 or any later version,LGPL-3
|
license-allowed=AGPL-3,GPL-2,GPL-2 or any later version,GPL-3,GPL-3 or any later version,LGPL-3
|
||||||
valid-odoo-versions=18.0
|
valid-odoo-versions=16.0
|
||||||
|
|
||||||
[MESSAGES CONTROL]
|
[MESSAGES CONTROL]
|
||||||
disable=all
|
disable=all
|
||||||
@@ -17,25 +17,19 @@ disable=all
|
|||||||
enable=anomalous-backslash-in-string,
|
enable=anomalous-backslash-in-string,
|
||||||
api-one-deprecated,
|
api-one-deprecated,
|
||||||
api-one-multi-together,
|
api-one-multi-together,
|
||||||
|
assignment-from-none,
|
||||||
|
attribute-deprecated,
|
||||||
class-camelcase,
|
class-camelcase,
|
||||||
|
dangerous-default-value,
|
||||||
dangerous-view-replace-wo-priority,
|
dangerous-view-replace-wo-priority,
|
||||||
|
development-status-allowed,
|
||||||
duplicate-id-csv,
|
duplicate-id-csv,
|
||||||
|
duplicate-key,
|
||||||
duplicate-xml-fields,
|
duplicate-xml-fields,
|
||||||
duplicate-xml-record-id,
|
duplicate-xml-record-id,
|
||||||
eval-referenced,
|
eval-referenced,
|
||||||
incoherent-interpreter-exec-perm,
|
|
||||||
openerp-exception-warning,
|
|
||||||
redundant-modulename-xml,
|
|
||||||
relative-import,
|
|
||||||
rst-syntax-error,
|
|
||||||
wrong-tabs-instead-of-spaces,
|
|
||||||
xml-syntax-error,
|
|
||||||
assignment-from-none,
|
|
||||||
attribute-deprecated,
|
|
||||||
dangerous-default-value,
|
|
||||||
development-status-allowed,
|
|
||||||
duplicate-key,
|
|
||||||
eval-used,
|
eval-used,
|
||||||
|
incoherent-interpreter-exec-perm,
|
||||||
license-allowed,
|
license-allowed,
|
||||||
manifest-author-string,
|
manifest-author-string,
|
||||||
manifest-deprecated-key,
|
manifest-deprecated-key,
|
||||||
@@ -46,50 +40,56 @@ enable=anomalous-backslash-in-string,
|
|||||||
method-inverse,
|
method-inverse,
|
||||||
method-required-super,
|
method-required-super,
|
||||||
method-search,
|
method-search,
|
||||||
|
openerp-exception-warning,
|
||||||
pointless-statement,
|
pointless-statement,
|
||||||
pointless-string-statement,
|
pointless-string-statement,
|
||||||
print-used,
|
print-used,
|
||||||
redundant-keyword-arg,
|
redundant-keyword-arg,
|
||||||
|
redundant-modulename-xml,
|
||||||
reimported,
|
reimported,
|
||||||
|
relative-import,
|
||||||
return-in-init,
|
return-in-init,
|
||||||
|
rst-syntax-error,
|
||||||
sql-injection,
|
sql-injection,
|
||||||
too-few-format-args,
|
too-few-format-args,
|
||||||
translation-field,
|
translation-field,
|
||||||
translation-required,
|
translation-required,
|
||||||
unreachable,
|
unreachable,
|
||||||
use-vim-comment,
|
use-vim-comment,
|
||||||
|
wrong-tabs-instead-of-spaces,
|
||||||
|
xml-syntax-error,
|
||||||
|
attribute-string-redundant,
|
||||||
character-not-valid-in-resource-link,
|
character-not-valid-in-resource-link,
|
||||||
|
consider-merging-classes-inherited,
|
||||||
|
context-overridden,
|
||||||
create-user-wo-reset-password,
|
create-user-wo-reset-password,
|
||||||
dangerous-filter-wo-user,
|
dangerous-filter-wo-user,
|
||||||
dangerous-qweb-replace-wo-priority,
|
dangerous-qweb-replace-wo-priority,
|
||||||
deprecated-data-xml-node,
|
deprecated-data-xml-node,
|
||||||
deprecated-openerp-xml-node,
|
deprecated-openerp-xml-node,
|
||||||
duplicate-po-message-definition,
|
duplicate-po-message-definition,
|
||||||
file-not-used,
|
|
||||||
missing-newline-extrafiles,
|
|
||||||
old-api7-method-defined,
|
|
||||||
po-msgstr-variables,
|
|
||||||
po-syntax-error,
|
|
||||||
str-format-used,
|
|
||||||
unnecessary-utf8-coding-comment,
|
|
||||||
xml-attribute-translatable,
|
|
||||||
xml-deprecated-qweb-directive,
|
|
||||||
xml-deprecated-tree-attribute,
|
|
||||||
attribute-string-redundant,
|
|
||||||
consider-merging-classes-inherited,
|
|
||||||
context-overridden,
|
|
||||||
except-pass,
|
except-pass,
|
||||||
|
file-not-used,
|
||||||
invalid-commit,
|
invalid-commit,
|
||||||
manifest-maintainers-list,
|
manifest-maintainers-list,
|
||||||
|
missing-newline-extrafiles,
|
||||||
missing-readme,
|
missing-readme,
|
||||||
missing-return,
|
missing-return,
|
||||||
odoo-addons-relative-import,
|
odoo-addons-relative-import,
|
||||||
|
old-api7-method-defined,
|
||||||
|
po-msgstr-variables,
|
||||||
|
po-syntax-error,
|
||||||
renamed-field-parameter,
|
renamed-field-parameter,
|
||||||
resource-not-exist,
|
resource-not-exist,
|
||||||
|
str-format-used,
|
||||||
test-folder-imported,
|
test-folder-imported,
|
||||||
translation-contains-variable,
|
translation-contains-variable,
|
||||||
translation-positional-used,
|
translation-positional-used,
|
||||||
|
unnecessary-utf8-coding-comment,
|
||||||
website-manifest-key-not-valid-uri,
|
website-manifest-key-not-valid-uri,
|
||||||
|
xml-attribute-translatable,
|
||||||
|
xml-deprecated-qweb-directive,
|
||||||
|
xml-deprecated-tree-attribute,
|
||||||
external-request-timeout
|
external-request-timeout
|
||||||
|
|
||||||
[REPORTS]
|
[REPORTS]
|
||||||
|
|||||||
@@ -1,205 +0,0 @@
|
|||||||
var globals = require('globals');
|
|
||||||
jsdoc = require("eslint-plugin-jsdoc");
|
|
||||||
|
|
||||||
const config = [{
|
|
||||||
plugins: {
|
|
||||||
jsdoc,
|
|
||||||
},
|
|
||||||
|
|
||||||
languageOptions: {
|
|
||||||
globals: {
|
|
||||||
_: "readonly",
|
|
||||||
$: "readonly",
|
|
||||||
fuzzy: "readonly",
|
|
||||||
jQuery: "readonly",
|
|
||||||
moment: "readonly",
|
|
||||||
odoo: "readonly",
|
|
||||||
openerp: "readonly",
|
|
||||||
owl: "readonly",
|
|
||||||
luxon: "readonly",
|
|
||||||
QUnit: "readonly",
|
|
||||||
...globals.browser,
|
|
||||||
},
|
|
||||||
|
|
||||||
ecmaVersion: 2024,
|
|
||||||
sourceType: "script",
|
|
||||||
},
|
|
||||||
|
|
||||||
rules: {
|
|
||||||
"accessor-pairs": "warn",
|
|
||||||
"array-callback-return": "warn",
|
|
||||||
"callback-return": "warn",
|
|
||||||
"capitalized-comments": ["warn", "always", {
|
|
||||||
ignoreConsecutiveComments: true,
|
|
||||||
ignoreInlineComments: true,
|
|
||||||
}],
|
|
||||||
complexity: ["warn", 15],
|
|
||||||
"constructor-super": "warn",
|
|
||||||
"dot-notation": "warn",
|
|
||||||
eqeqeq: "warn",
|
|
||||||
"global-require": "warn",
|
|
||||||
"handle-callback-err": "warn",
|
|
||||||
"id-blacklist": "warn",
|
|
||||||
"id-match": "warn",
|
|
||||||
"init-declarations": "error",
|
|
||||||
"max-depth": "warn",
|
|
||||||
"max-nested-callbacks": "warn",
|
|
||||||
"max-statements-per-line": "warn",
|
|
||||||
"no-alert": "warn",
|
|
||||||
"no-array-constructor": "warn",
|
|
||||||
"no-caller": "warn",
|
|
||||||
"no-case-declarations": "warn",
|
|
||||||
"no-class-assign": "warn",
|
|
||||||
"no-cond-assign": "error",
|
|
||||||
"no-const-assign": "error",
|
|
||||||
"no-constant-condition": "warn",
|
|
||||||
"no-control-regex": "warn",
|
|
||||||
"no-debugger": "error",
|
|
||||||
"no-delete-var": "warn",
|
|
||||||
"no-div-regex": "warn",
|
|
||||||
"no-dupe-args": "error",
|
|
||||||
"no-dupe-class-members": "error",
|
|
||||||
"no-dupe-keys": "error",
|
|
||||||
"no-duplicate-case": "error",
|
|
||||||
"no-duplicate-imports": "error",
|
|
||||||
"no-else-return": "warn",
|
|
||||||
"no-empty-character-class": "warn",
|
|
||||||
"no-empty-function": "error",
|
|
||||||
"no-empty-pattern": "error",
|
|
||||||
"no-empty": "warn",
|
|
||||||
"no-eq-null": "error",
|
|
||||||
"no-eval": "error",
|
|
||||||
"no-ex-assign": "error",
|
|
||||||
"no-extend-native": "warn",
|
|
||||||
"no-extra-bind": "warn",
|
|
||||||
"no-extra-boolean-cast": "warn",
|
|
||||||
"no-extra-label": "warn",
|
|
||||||
"no-fallthrough": "warn",
|
|
||||||
"no-func-assign": "error",
|
|
||||||
"no-global-assign": "error",
|
|
||||||
"no-implicit-coercion": ["warn", {
|
|
||||||
allow: ["~"],
|
|
||||||
}],
|
|
||||||
"no-implicit-globals": "warn",
|
|
||||||
"no-implied-eval": "warn",
|
|
||||||
"no-inline-comments": "warn",
|
|
||||||
"no-inner-declarations": "warn",
|
|
||||||
"no-invalid-regexp": "warn",
|
|
||||||
"no-irregular-whitespace": "warn",
|
|
||||||
"no-iterator": "warn",
|
|
||||||
"no-label-var": "warn",
|
|
||||||
"no-labels": "warn",
|
|
||||||
"no-lone-blocks": "warn",
|
|
||||||
"no-lonely-if": "error",
|
|
||||||
"no-mixed-requires": "error",
|
|
||||||
"no-multi-str": "warn",
|
|
||||||
"no-native-reassign": "error",
|
|
||||||
"no-negated-condition": "warn",
|
|
||||||
"no-negated-in-lhs": "error",
|
|
||||||
"no-new-func": "warn",
|
|
||||||
"no-new-object": "warn",
|
|
||||||
"no-new-require": "warn",
|
|
||||||
"no-new-symbol": "warn",
|
|
||||||
"no-new-wrappers": "warn",
|
|
||||||
"no-new": "warn",
|
|
||||||
"no-obj-calls": "warn",
|
|
||||||
"no-octal-escape": "warn",
|
|
||||||
"no-octal": "warn",
|
|
||||||
"no-param-reassign": "warn",
|
|
||||||
"no-path-concat": "warn",
|
|
||||||
"no-process-env": "warn",
|
|
||||||
"no-process-exit": "warn",
|
|
||||||
"no-proto": "warn",
|
|
||||||
"no-prototype-builtins": "warn",
|
|
||||||
"no-redeclare": "warn",
|
|
||||||
"no-regex-spaces": "warn",
|
|
||||||
"no-restricted-globals": "warn",
|
|
||||||
"no-restricted-imports": "warn",
|
|
||||||
"no-restricted-modules": "warn",
|
|
||||||
"no-restricted-syntax": "warn",
|
|
||||||
"no-return-assign": "error",
|
|
||||||
"no-script-url": "warn",
|
|
||||||
"no-self-assign": "warn",
|
|
||||||
"no-self-compare": "warn",
|
|
||||||
"no-sequences": "warn",
|
|
||||||
"no-shadow-restricted-names": "warn",
|
|
||||||
"no-shadow": "warn",
|
|
||||||
"no-sparse-arrays": "warn",
|
|
||||||
"no-sync": "warn",
|
|
||||||
"no-this-before-super": "warn",
|
|
||||||
"no-throw-literal": "warn",
|
|
||||||
"no-undef-init": "warn",
|
|
||||||
"no-undef": "error",
|
|
||||||
"no-unmodified-loop-condition": "warn",
|
|
||||||
"no-unneeded-ternary": "error",
|
|
||||||
"no-unreachable": "error",
|
|
||||||
"no-unsafe-finally": "error",
|
|
||||||
"no-unused-expressions": "error",
|
|
||||||
"no-unused-labels": "error",
|
|
||||||
"no-unused-vars": "error",
|
|
||||||
"no-use-before-define": "error",
|
|
||||||
"no-useless-call": "warn",
|
|
||||||
"no-useless-computed-key": "warn",
|
|
||||||
"no-useless-concat": "warn",
|
|
||||||
"no-useless-constructor": "warn",
|
|
||||||
"no-useless-escape": "warn",
|
|
||||||
"no-useless-rename": "warn",
|
|
||||||
"no-void": "warn",
|
|
||||||
"no-with": "warn",
|
|
||||||
"operator-assignment": ["error", "always"],
|
|
||||||
"prefer-const": "warn",
|
|
||||||
radix: "warn",
|
|
||||||
"require-yield": "warn",
|
|
||||||
"sort-imports": "warn",
|
|
||||||
"spaced-comment": ["error", "always"],
|
|
||||||
strict: ["error", "function"],
|
|
||||||
"use-isnan": "error",
|
|
||||||
|
|
||||||
"jsdoc/check-tag-names": "warn",
|
|
||||||
"jsdoc/check-types": "warn",
|
|
||||||
"jsdoc/require-param-description": "off",
|
|
||||||
"jsdoc/require-return": "off",
|
|
||||||
"jsdoc/require-return-description": "off",
|
|
||||||
"jsdoc/require-return-type": "off",
|
|
||||||
|
|
||||||
"valid-typeof": "warn",
|
|
||||||
yoda: "warn",
|
|
||||||
},
|
|
||||||
|
|
||||||
settings: {
|
|
||||||
jsdoc: {
|
|
||||||
tagNamePreference: {
|
|
||||||
arg: "param",
|
|
||||||
argument: "param",
|
|
||||||
augments: "extends",
|
|
||||||
constructor: "class",
|
|
||||||
exception: "throws",
|
|
||||||
func: "function",
|
|
||||||
method: "function",
|
|
||||||
prop: "property",
|
|
||||||
return: "returns",
|
|
||||||
virtual: "abstract",
|
|
||||||
yield: "yields",
|
|
||||||
},
|
|
||||||
preferredTypes: {
|
|
||||||
array: "Array",
|
|
||||||
bool: "Boolean",
|
|
||||||
boolean: "Boolean",
|
|
||||||
number: "Number",
|
|
||||||
object: "Object",
|
|
||||||
str: "String",
|
|
||||||
string: "String",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
}, {
|
|
||||||
files: ["**/*.esm.js", "**/*test.js"],
|
|
||||||
|
|
||||||
languageOptions: {
|
|
||||||
ecmaVersion: 2024,
|
|
||||||
sourceType: "module",
|
|
||||||
},
|
|
||||||
}];
|
|
||||||
|
|
||||||
module.exports = config
|
|
||||||
@@ -1,92 +0,0 @@
|
|||||||
============================================
|
|
||||||
maintenance_create_requests_from_project_task
|
|
||||||
============================================
|
|
||||||
|
|
||||||
This module allows the bulk creation of maintenance requests directly from a
|
|
||||||
project task. It is particularly useful when a task requires maintenance
|
|
||||||
actions on multiple equipment items simultaneously.
|
|
||||||
|
|
||||||
Key features:
|
|
||||||
|
|
||||||
- **Bulk creation**: Create multiple maintenance requests at once from a task
|
|
||||||
- **Equipment filtering**: Use domain filters to select target equipment
|
|
||||||
- **Smart defaults**: Pre-fills equipment from the task's project
|
|
||||||
- **Request tracking**: View all maintenance requests linked to a task
|
|
||||||
|
|
||||||
# Installation
|
|
||||||
|
|
||||||
Use Odoo normal module installation procedure to install
|
|
||||||
`maintenance_create_requests_from_project_task`.
|
|
||||||
|
|
||||||
This module depends on:
|
|
||||||
- `maintenance`
|
|
||||||
- `maintenance_project`
|
|
||||||
- `project`
|
|
||||||
|
|
||||||
# Configuration
|
|
||||||
|
|
||||||
No specific configuration is required.
|
|
||||||
|
|
||||||
# Usage
|
|
||||||
|
|
||||||
## Creating Maintenance Requests from a Task
|
|
||||||
|
|
||||||
1. Go to Project > Tasks
|
|
||||||
2. Open a task
|
|
||||||
3. In the action menu (or via the server action), click "Create maintenance requests"
|
|
||||||
4. A wizard opens with:
|
|
||||||
- **Task**: The source task (read-only)
|
|
||||||
- **Title**: The name for all created maintenance requests
|
|
||||||
- **Equipment Domain**: Filter to select which equipment to target
|
|
||||||
- By default, shows equipment linked to the task's project
|
|
||||||
- Use the domain builder to refine the selection
|
|
||||||
- **Technician**: Assign a technician to all requests
|
|
||||||
- **Maintenance Type**: Corrective or Preventive
|
|
||||||
- **Priority**: From Very Low to High
|
|
||||||
- **Duration**: Estimated duration in hours
|
|
||||||
- **Scheduled Date**: When the maintenance should occur
|
|
||||||
- **Description**: Details about the maintenance work
|
|
||||||
5. Click "Create"
|
|
||||||
6. All matching equipment will have a maintenance request created
|
|
||||||
7. You are redirected to the list of created requests
|
|
||||||
|
|
||||||
## Viewing Linked Maintenance Requests
|
|
||||||
|
|
||||||
On the task form:
|
|
||||||
- A smart button shows the count of open (not done) maintenance requests
|
|
||||||
- Click it to view all maintenance requests linked to this task
|
|
||||||
|
|
||||||
## Equipment Domain Examples
|
|
||||||
|
|
||||||
- All equipment in the project: `[('project_id', '=', project_id)]`
|
|
||||||
- Only servers: `[('category_id.name', '=', 'Server')]`
|
|
||||||
- Equipment needing backup: `[('backup_activated', '=', True)]`
|
|
||||||
- Combine conditions: `[('project_id', '=', project_id), ('category_id.name', '=', 'Server')]`
|
|
||||||
|
|
||||||
# Known issues / Roadmap
|
|
||||||
|
|
||||||
- Add template support for common maintenance scenarios
|
|
||||||
- Add option to create a single request for multiple equipment
|
|
||||||
|
|
||||||
# Bug Tracker
|
|
||||||
|
|
||||||
Bugs are tracked on
|
|
||||||
[our issues website](https://git.elabore.coop/Elabore/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.
|
|
||||||
48
maintenance_create_requests_from_project_task/README.rst
Normal file
48
maintenance_create_requests_from_project_task/README.rst
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
=============================================
|
||||||
|
maintenance_create_requests_from_project_task
|
||||||
|
=============================================
|
||||||
|
|
||||||
|
Allow the creation of multiple maintenance requests from a projet task.
|
||||||
|
|
||||||
|
When user click on the button "Create maintenance requests", a wizard appears.
|
||||||
|
The wizard allows the user to configure the requests and to select the maintenance equipments concerned.
|
||||||
|
At wizard validation, one or several maintenance requests are created, one for each equipement selected.
|
||||||
|
|
||||||
|
Installation
|
||||||
|
============
|
||||||
|
|
||||||
|
Use Odoo normal module installation procedure to install
|
||||||
|
``maintenance_create_requests_from_project_task``.
|
||||||
|
|
||||||
|
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.
|
||||||
@@ -1,2 +1,4 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
from . import models
|
from . import models
|
||||||
from . import wizard
|
from . import wizard
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
{
|
{
|
||||||
"name": "maintenance_create_requests_from_project_task",
|
"name": "maintenance_create_requests_from_project_task",
|
||||||
"version": "18.0.1.0.0",
|
"version": "16.0.1.0.0",
|
||||||
"author": "Elabore",
|
"author": "Elabore",
|
||||||
"website": "https://elabore.coop",
|
"website": "https://elabore.coop",
|
||||||
"maintainer": "Stéphan Sainléger",
|
"maintainer": "Stéphan Sainléger",
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
from odoo import api, fields, models
|
from odoo import fields, models, api
|
||||||
|
|
||||||
|
|
||||||
class ProjectTask(models.Model):
|
class ProjectTask(models.Model):
|
||||||
_inherit = "project.task"
|
_inherit = "project.task"
|
||||||
|
|
||||||
maintenance_request_ids = fields.One2many(
|
maintenance_request_ids = fields.One2many("maintenance.request", "task_id", string="Maintenance Requests")
|
||||||
"maintenance.request", "task_id", string="Maintenance Requests"
|
|
||||||
)
|
|
||||||
maintenance_request_count = fields.Integer(
|
maintenance_request_count = fields.Integer(
|
||||||
compute="_compute_maintenance_request_count"
|
compute="_compute_maintenance_request_count"
|
||||||
)
|
)
|
||||||
@@ -20,7 +18,7 @@ class ProjectTask(models.Model):
|
|||||||
|
|
||||||
def action_view_maintenance_request_ids(self):
|
def action_view_maintenance_request_ids(self):
|
||||||
"""
|
"""
|
||||||
Access to the undone maintenance requests for this task.
|
Access to the undone maintenance requests for this task
|
||||||
"""
|
"""
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
action = self.env["ir.actions.actions"]._for_xml_id(
|
action = self.env["ir.actions.actions"]._for_xml_id(
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink
|
id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink
|
||||||
access_create_maintenance_requests_wizard,maintenance_create_requests_from_portal_tasks.create_maintenance_requests_wizard.access,model_create_maintenance_requests_wizard,base.group_user,1,1,1,0
|
access_create_maintenance_requests_wizard,maintenance_create_requests_from_portal_tasks.create_maintenance_requests_wizard.access,model_create_maintenance_requests_wizard,base.group_user,1,1,1,0
|
||||||
|
@@ -1,27 +1,17 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<odoo>
|
<odoo>
|
||||||
<record id="view_task_form2_maintenance_inherited" model="ir.ui.view">
|
<record id="view_task_form2_maintenance_inherited" model="ir.ui.view">
|
||||||
<field name="model">project.task</field>
|
<field name="model">project.task</field>
|
||||||
<field name="inherit_id" ref="project.view_task_form2" />
|
<field name="inherit_id" ref="project.view_task_form2" />
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<xpath expr="//field[@name='company_id']" position="after">
|
<xpath expr="//field[@name='company_id']" position="after">
|
||||||
<field name="maintenance_request_count" invisible="1" />
|
<field name="maintenance_request_count" invisible="1"/>
|
||||||
</xpath>
|
</xpath>
|
||||||
<xpath expr="//div[@name='button_box']" position="inside">
|
<xpath expr="//div[@name='button_box']" position="inside">
|
||||||
<button
|
<button name="action_view_maintenance_request_ids" type="object" attrs="{'invisible': [('maintenance_request_count', '=', 0)]}" class="oe_stat_button" icon="fa-tasks" >
|
||||||
name="action_view_maintenance_request_ids"
|
|
||||||
type="object"
|
|
||||||
invisible="maintenance_request_count == 0"
|
|
||||||
class="oe_stat_button"
|
|
||||||
icon="fa-tasks"
|
|
||||||
>
|
|
||||||
<div class="o_field_widget o_stat_info">
|
<div class="o_field_widget o_stat_info">
|
||||||
<span class="o_stat_value ">
|
<span class="o_stat_value ">
|
||||||
<field
|
<field name="maintenance_request_count" widget="statinfo" nolabel="1" />
|
||||||
name="maintenance_request_count"
|
|
||||||
widget="statinfo"
|
|
||||||
nolabel="1"
|
|
||||||
/>
|
|
||||||
Maintenance Requests
|
Maintenance Requests
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
from odoo import _, api, fields, models
|
from odoo import api, fields, models, _
|
||||||
from odoo.exceptions import UserError
|
|
||||||
from odoo.tools.safe_eval import safe_eval
|
from odoo.tools.safe_eval import safe_eval
|
||||||
|
|
||||||
|
|
||||||
class CreateMaintenanceRequestsWizard(models.TransientModel):
|
class CreateMaintenanceRequestsWizard(models.TransientModel):
|
||||||
_name = "create.maintenance.requests.wizard"
|
_name= "create.maintenance.requests.wizard"
|
||||||
_description = "Configure the maintenance requests to create from the current task."
|
_description= "Configure the maintenance requests to create from the current task."
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def _default_task_id(self):
|
def _default_task_id(self):
|
||||||
@@ -15,28 +13,19 @@ class CreateMaintenanceRequestsWizard(models.TransientModel):
|
|||||||
def _default_equipment_model(self):
|
def _default_equipment_model(self):
|
||||||
default_domain = []
|
default_domain = []
|
||||||
task_id = self.env["project.task"].browse(self._context.get("active_ids"))
|
task_id = self.env["project.task"].browse(self._context.get("active_ids"))
|
||||||
project_equipements = self.env["maintenance.equipment"].search(
|
project_equipements = self.env["maintenance.equipment"].search([("project_id", "=", task_id.project_id.id)])
|
||||||
[("project_id", "=", task_id.project_id.id)]
|
|
||||||
)
|
|
||||||
if project_equipements:
|
if project_equipements:
|
||||||
equipment_ids_list = [x.id for x in project_equipements]
|
equipment_ids_list = [x.id for x in project_equipements]
|
||||||
default_domain.append(("id", "in", equipment_ids_list))
|
default_domain.append(("id", "in", equipment_ids_list))
|
||||||
return default_domain
|
return default_domain
|
||||||
|
|
||||||
name = fields.Char("Title", required=True)
|
name = fields.Char("Title", required=True)
|
||||||
user_id = fields.Many2one("res.users", string="Technician")
|
user_id = fields.Many2one('res.users', string='Technician')
|
||||||
priority = fields.Selection(
|
priority = fields.Selection([('0', 'Very Low'), ('1', 'Low'), ('2', 'Normal'), ('3', 'High')], string='Priority')
|
||||||
[("0", "Very Low"), ("1", "Low"), ("2", "Normal"), ("3", "High")],
|
maintenance_type = fields.Selection([('corrective', 'Corrective'), ('preventive', 'Preventive')], string='Maintenance Type', default="corrective")
|
||||||
string="Priority",
|
schedule_date = fields.Datetime('Scheduled Date')
|
||||||
)
|
|
||||||
maintenance_type = fields.Selection(
|
|
||||||
[("corrective", "Corrective"), ("preventive", "Preventive")],
|
|
||||||
string="Maintenance Type",
|
|
||||||
default="corrective",
|
|
||||||
)
|
|
||||||
schedule_date = fields.Datetime("Scheduled Date")
|
|
||||||
duration = fields.Float(help="Duration in hours.")
|
duration = fields.Float(help="Duration in hours.")
|
||||||
description = fields.Html("Description")
|
description = fields.Html('Description')
|
||||||
|
|
||||||
equipment_domain = fields.Char("Equipment Domain", default=_default_equipment_model)
|
equipment_domain = fields.Char("Equipment Domain", default=_default_equipment_model)
|
||||||
|
|
||||||
@@ -53,14 +42,15 @@ class CreateMaintenanceRequestsWizard(models.TransientModel):
|
|||||||
Open the form view.
|
Open the form view.
|
||||||
"""
|
"""
|
||||||
return {
|
return {
|
||||||
"name": _("Create maintenance requests"),
|
'name': _('Create maintenance requests'),
|
||||||
"type": "ir.actions.act_window",
|
'type': 'ir.actions.act_window',
|
||||||
"res_model": "create.maintenance.requests.wizard",
|
'res_model': 'create.maintenance.requests.wizard',
|
||||||
"view_type": "form",
|
'view_type': 'form',
|
||||||
"view_mode": "form",
|
'view_mode': 'form',
|
||||||
"target": "new",
|
'target': 'new',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def create_maintenance_requests(self):
|
def create_maintenance_requests(self):
|
||||||
"""
|
"""
|
||||||
Create the maintenance requests with the data filled in the wizard form.
|
Create the maintenance requests with the data filled in the wizard form.
|
||||||
@@ -69,20 +59,14 @@ class CreateMaintenanceRequestsWizard(models.TransientModel):
|
|||||||
maintenance_requests = self.env["maintenance.request"].sudo().create(vals_list)
|
maintenance_requests = self.env["maintenance.request"].sudo().create(vals_list)
|
||||||
return self._get_action(maintenance_requests)
|
return self._get_action(maintenance_requests)
|
||||||
|
|
||||||
|
|
||||||
def _compute_vals_list(self):
|
def _compute_vals_list(self):
|
||||||
"""
|
"""
|
||||||
Compute the list of data to use for all the maintenance requests creation.
|
Compute the list of data to use for all the maintenance requests creation
|
||||||
"""
|
"""
|
||||||
equipment_list = self.env["maintenance.equipment"].search(
|
equipment_list = self.env["maintenance.equipment"].search(safe_eval(self.equipment_domain))
|
||||||
safe_eval(self.equipment_domain)
|
|
||||||
)
|
|
||||||
if len(equipment_list) == 0:
|
if len(equipment_list) == 0:
|
||||||
raise UserError(
|
raise UserError("No equipment is matching the domain. Maintenance request creation is not possible.")
|
||||||
_(
|
|
||||||
"No equipment is matching the domain. "
|
|
||||||
"Maintenance request creation is not possible."
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
vals_list = []
|
vals_list = []
|
||||||
common_vals = {
|
common_vals = {
|
||||||
@@ -94,7 +78,7 @@ class CreateMaintenanceRequestsWizard(models.TransientModel):
|
|||||||
"duration": self.duration,
|
"duration": self.duration,
|
||||||
"description": self.description,
|
"description": self.description,
|
||||||
"task_id": self.task_id.id,
|
"task_id": self.task_id.id,
|
||||||
"project_id": self.task_id.project_id.id,
|
"project_id": self.task_id.project_id.id
|
||||||
}
|
}
|
||||||
|
|
||||||
for equipment in equipment_list:
|
for equipment in equipment_list:
|
||||||
@@ -106,25 +90,20 @@ class CreateMaintenanceRequestsWizard(models.TransientModel):
|
|||||||
|
|
||||||
return vals_list
|
return vals_list
|
||||||
|
|
||||||
|
|
||||||
def _get_action(self, maintenance_requests):
|
def _get_action(self, maintenance_requests):
|
||||||
"""
|
"""
|
||||||
Provide the action to go to the list view of the maintenance requests created.
|
Provide the action to go to the tree view of the maintenance requests created.
|
||||||
"""
|
"""
|
||||||
search_view_ref = self.env.ref(
|
search_view_ref = self.env.ref('maintenance.hr_equipment_request_view_search', False)
|
||||||
"maintenance.hr_equipment_request_view_search", False
|
form_view_ref = self.env.ref('maintenance.hr_equipment_request_view_form', False)
|
||||||
)
|
tree_view_ref = self.env.ref('maintenance.hr_equipment_request_view_tree', False)
|
||||||
form_view_ref = self.env.ref(
|
|
||||||
"maintenance.hr_equipment_request_view_form", False
|
|
||||||
)
|
|
||||||
list_view_ref = self.env.ref(
|
|
||||||
"maintenance.hr_equipment_request_view_tree", False
|
|
||||||
)
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"domain": [("id", "in", maintenance_requests.ids)],
|
'domain': [('id', 'in', maintenance_requests.ids)],
|
||||||
"name": "Maintenance Requests",
|
'name': 'Maintenance Requests',
|
||||||
"res_model": "maintenance.request",
|
'res_model': 'maintenance.request',
|
||||||
"type": "ir.actions.act_window",
|
'type': 'ir.actions.act_window',
|
||||||
"views": [(list_view_ref.id, "list"), (form_view_ref.id, "form")],
|
'views': [(tree_view_ref.id, 'tree'), (form_view_ref.id, 'form')],
|
||||||
"search_view_id": search_view_ref and [search_view_ref.id],
|
'search_view_id': search_view_ref and [search_view_ref.id],
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="utf-8" ?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<odoo>
|
<odoo>
|
||||||
<record id="create_maintenance_requests_wizard_view_form" model="ir.ui.view">
|
<record id="create_maintenance_requests_wizard_view_form" model="ir.ui.view">
|
||||||
<field name="name">create.maintenance.requests.wizard.view.form</field>
|
<field name="name">create.maintenance.requests.wizard.view.form</field>
|
||||||
@@ -12,10 +12,10 @@
|
|||||||
</group>
|
</group>
|
||||||
<group name="domain" string="Equipments targetted">
|
<group name="domain" string="Equipments targetted">
|
||||||
<field
|
<field
|
||||||
name="equipment_domain"
|
name="equipment_domain"
|
||||||
widget="domain"
|
widget="domain"
|
||||||
options='{"model": "maintenance.equipment"}'
|
options='{"model": "maintenance.equipment"}'
|
||||||
/>
|
/>
|
||||||
</group>
|
</group>
|
||||||
<group name="data" string="Requests data">
|
<group name="data" string="Requests data">
|
||||||
<field name="user_id" />
|
<field name="user_id" />
|
||||||
@@ -27,12 +27,8 @@
|
|||||||
</group>
|
</group>
|
||||||
</sheet>
|
</sheet>
|
||||||
<footer>
|
<footer>
|
||||||
<button
|
<button string="Create" name="create_maintenance_requests" type="object"
|
||||||
string="Create"
|
class="btn-primary" />
|
||||||
name="create_maintenance_requests"
|
|
||||||
type="object"
|
|
||||||
class="btn-primary"
|
|
||||||
/>
|
|
||||||
<button string="Cancel" class="btn-secondary" special="cancel" />
|
<button string="Cancel" class="btn-secondary" special="cancel" />
|
||||||
</footer>
|
</footer>
|
||||||
</form>
|
</form>
|
||||||
@@ -40,9 +36,7 @@
|
|||||||
</record>
|
</record>
|
||||||
|
|
||||||
<record
|
<record
|
||||||
id="action_create_maintenance_requests_wizard"
|
id="action_create_maintenance_requests_wizard" model="ir.actions.act_window">
|
||||||
model="ir.actions.act_window"
|
|
||||||
>
|
|
||||||
<field name="name">Create Maintenance Requests</field>
|
<field name="name">Create Maintenance Requests</field>
|
||||||
<field name="res_model">create.maintenance.requests.wizard</field>
|
<field name="res_model">create.maintenance.requests.wizard</field>
|
||||||
<field name="view_mode">form</field>
|
<field name="view_mode">form</field>
|
||||||
@@ -50,16 +44,10 @@
|
|||||||
<field name="target">new</field>
|
<field name="target">new</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
<record
|
<record id="task_wizard_action_create_maintenance_requests" model="ir.actions.server">
|
||||||
id="task_wizard_action_create_maintenance_requests"
|
|
||||||
model="ir.actions.server"
|
|
||||||
>
|
|
||||||
<field name="name">Create maintenance requests</field>
|
<field name="name">Create maintenance requests</field>
|
||||||
<field
|
<field name="model_id" ref="maintenance_create_requests_from_project_task.model_create_maintenance_requests_wizard"/>
|
||||||
name="model_id"
|
<field name="binding_model_id" ref="project.model_project_task"/>
|
||||||
ref="maintenance_create_requests_from_project_task.model_create_maintenance_requests_wizard"
|
|
||||||
/>
|
|
||||||
<field name="binding_model_id" ref="project.model_project_task" />
|
|
||||||
<field name="state">code</field>
|
<field name="state">code</field>
|
||||||
<field name="code">action = model.action_open_wizard()</field>
|
<field name="code">action = model.action_open_wizard()</field>
|
||||||
</record>
|
</record>
|
||||||
|
|||||||
@@ -2,44 +2,22 @@
|
|||||||
maintenance_project_task_domain
|
maintenance_project_task_domain
|
||||||
===============================
|
===============================
|
||||||
|
|
||||||
This module adjusts the domain applied to the task field on maintenance requests
|
This module adjusts the domain applied to task field in order to limit
|
||||||
in order to limit selection to tasks in any of unfolded stages only.
|
selection to tasks in any of unfolded stages.
|
||||||
|
|
||||||
When linking a maintenance request to a project task, the default behavior shows
|
|
||||||
all tasks from the project. This module filters out tasks that are in folded
|
|
||||||
stages (typically completed or cancelled tasks), making it easier to select
|
|
||||||
relevant active tasks.
|
|
||||||
|
|
||||||
# Installation
|
# Installation
|
||||||
|
|
||||||
Use Odoo normal module installation procedure to install
|
Use Odoo normal module installation procedure to install
|
||||||
`maintenance_project_task_domain`.
|
`maintenance_project_task_domain`.
|
||||||
|
|
||||||
This module depends on `maintenance_project` and will be auto-installed when
|
|
||||||
that module is present.
|
|
||||||
|
|
||||||
# Configuration
|
|
||||||
|
|
||||||
No configuration is needed. The module automatically applies the domain filter
|
|
||||||
to the task field on maintenance request forms.
|
|
||||||
|
|
||||||
# Usage
|
|
||||||
|
|
||||||
1. Go to Maintenance > Maintenance Requests
|
|
||||||
2. Create or edit a maintenance request
|
|
||||||
3. When selecting a task in the "Task" field, only tasks from unfolded stages
|
|
||||||
will be displayed
|
|
||||||
|
|
||||||
# Known issues / Roadmap
|
# Known issues / Roadmap
|
||||||
|
|
||||||
- Consider making the stage filter configurable via settings
|
|
||||||
|
|
||||||
# Bug Tracker
|
# Bug Tracker
|
||||||
|
|
||||||
Bugs are tracked on
|
Bugs are tracked on `our issues website <https://github.com/elabore-coop/maintenance-tools/issues>`\_. In case of
|
||||||
[our issues website](https://git.elabore.coop/Elabore/maintenance-tools/issues). In
|
trouble, please check there if your issue has already been
|
||||||
case of trouble, please check there if your issue has already been reported. If you
|
reported. If you spotted it first, help us smashing it by providing a
|
||||||
spotted it first, help us smashing it by providing a detailed and welcomed feedback.
|
detailed and welcomed feedback.
|
||||||
|
|
||||||
# Credits
|
# Credits
|
||||||
|
|
||||||
|
|||||||
@@ -2,16 +2,18 @@
|
|||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
{
|
{
|
||||||
"name": "maintenance_project_task_domain",
|
"name": "maintenance_project_task_domain",
|
||||||
"version": "18.0.1.0.0",
|
"version": "16.0.1.0.0",
|
||||||
"author": "Elabore",
|
"author": "Elabore",
|
||||||
"website": "https://git.elabore.coop/elabore/maintenance-tools",
|
"website": "https://elabore.coop",
|
||||||
"maintainer": "Quentin Mondot",
|
"maintainer": "Quentin Mondot",
|
||||||
"license": "AGPL-3",
|
"license": "AGPL-3",
|
||||||
"category": "Tools",
|
"category": "Tools",
|
||||||
"summary": "This module adjusts the domain applied to task field in order to limit "
|
"summary": "This module adjusts the domain applied to task field in order to limit "
|
||||||
"selection to tasks in any of unfolded stages.",
|
"selection to tasks in any of unfolded stages.",
|
||||||
"depends": ["maintenance_project"],
|
"depends": ["maintenance_project"],
|
||||||
"data": ["views/maintenance_view_form_task_domain.xml"],
|
"data": [
|
||||||
|
"views/maintenance_view_form_task_domain.xml"
|
||||||
|
],
|
||||||
"installable": True,
|
"installable": True,
|
||||||
"auto_install": True,
|
"auto_install": True,
|
||||||
"application": False,
|
"application": False,
|
||||||
|
|||||||
@@ -1,17 +1,14 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<odoo>
|
<odoo>
|
||||||
<record id="maintenance_view_form_task_domain" model="ir.ui.view">
|
<record id="maintenance_view_form_task_domain" model="ir.ui.view">
|
||||||
<field name="name">maintenance.form.task.domain</field>
|
<field name="name">maintenance.form.task.domain</field>
|
||||||
<field name="model">maintenance.request</field>
|
<field name="model">maintenance.request</field>
|
||||||
<field
|
<field name="inherit_id" ref="maintenance_project.hr_equipment_request_view_form" />
|
||||||
name="inherit_id"
|
|
||||||
ref="maintenance_project.hr_equipment_request_view_form"
|
|
||||||
/>
|
|
||||||
<field name="priority" eval="99" />
|
<field name="priority" eval="99" />
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<xpath expr="//field[@name='task_id' and @domain]" position="attributes">
|
<xpath expr="//field[@name='task_id' and @domain]" position="attributes">
|
||||||
<attribute
|
<attribute
|
||||||
name="domain"
|
name="domain"
|
||||||
>[('project_id', '=', project_id),('stage_id.fold', '=', False)]</attribute>
|
>[('project_id', '=', project_id),('stage_id.fold', '=', False)]</attribute>
|
||||||
</xpath>
|
</xpath>
|
||||||
</field>
|
</field>
|
||||||
|
|||||||
@@ -1,89 +0,0 @@
|
|||||||
=======================
|
|
||||||
maintenance_server_data
|
|
||||||
=======================
|
|
||||||
|
|
||||||
This module extends the maintenance equipment model to store detailed server
|
|
||||||
information, enabling comprehensive server infrastructure management within Odoo.
|
|
||||||
|
|
||||||
It adds several new models and fields to track:
|
|
||||||
|
|
||||||
- **Server specifications**: IP address, CPU cores, RAM, disk storage
|
|
||||||
- **Operating system**: Distribution name and version
|
|
||||||
- **Services**: Track services running on each server with their versions and URLs
|
|
||||||
- **Backup information**: Backup server, activation status, and health
|
|
||||||
|
|
||||||
# Installation
|
|
||||||
|
|
||||||
Use Odoo normal module installation procedure to install
|
|
||||||
`maintenance_server_data`.
|
|
||||||
|
|
||||||
This module depends on `maintenance`.
|
|
||||||
|
|
||||||
# Configuration
|
|
||||||
|
|
||||||
No specific configuration is required. After installation, new fields will be
|
|
||||||
available on the maintenance equipment form.
|
|
||||||
|
|
||||||
# Usage
|
|
||||||
|
|
||||||
## Managing Server Equipment
|
|
||||||
|
|
||||||
1. Go to Maintenance > Equipments
|
|
||||||
2. Create or edit an equipment record
|
|
||||||
3. Fill in the server-specific fields:
|
|
||||||
- **Server IP Address**: The server's IP address
|
|
||||||
- **Distribution**: Select or create an OS distribution
|
|
||||||
- **Hosting City**: Physical location of the server
|
|
||||||
- **Nb Cores**: Number of CPU cores
|
|
||||||
- **RAM (Go)**: Amount of RAM in gigabytes
|
|
||||||
- **Disk Storage (Go)**: Disk capacity in gigabytes
|
|
||||||
- **Backup Activated**: Whether backups are enabled
|
|
||||||
- **Backup Server**: The backup destination server
|
|
||||||
- **Backup OK**: Current backup health status
|
|
||||||
|
|
||||||
## Managing OS Distributions
|
|
||||||
|
|
||||||
1. Go to Maintenance > Configuration > OS Distributions
|
|
||||||
2. Create distributions with name and version (e.g., "Ubuntu", "22.04")
|
|
||||||
3. The display name is automatically computed from name + version
|
|
||||||
|
|
||||||
## Managing Services
|
|
||||||
|
|
||||||
1. Go to Maintenance > Configuration > Services
|
|
||||||
2. Create service definitions (e.g., "PostgreSQL", "Nginx", "Odoo")
|
|
||||||
3. Create service versions for each service
|
|
||||||
4. Mark the latest version with "Is Last Version?"
|
|
||||||
|
|
||||||
## Managing Service Instances
|
|
||||||
|
|
||||||
1. Go to Maintenance > Configuration > Service Instances
|
|
||||||
2. Link services to equipment with their specific version and URL
|
|
||||||
3. Service instances are automatically archived when their equipment is archived
|
|
||||||
|
|
||||||
# Known issues / Roadmap
|
|
||||||
|
|
||||||
- Add monitoring integration for automated backup status checks
|
|
||||||
- Add service version upgrade tracking
|
|
||||||
|
|
||||||
# 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.
|
|
||||||
44
maintenance_server_data/README.rst
Normal file
44
maintenance_server_data/README.rst
Normal 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.
|
||||||
@@ -1 +1,3 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
from . import models
|
from . import models
|
||||||
|
|||||||
@@ -3,9 +3,9 @@
|
|||||||
|
|
||||||
{
|
{
|
||||||
"name": "maintenance_server_data",
|
"name": "maintenance_server_data",
|
||||||
"version": "18.0.1.0.0",
|
"version": "16.0.1.0.0",
|
||||||
"author": "Elabore",
|
"author": "Elabore",
|
||||||
"website": "https://git.elabore.coop/elabore/maintenance-tools",
|
"website": "https://elabore.coop",
|
||||||
"maintainer": "Stéphan Sainléger",
|
"maintainer": "Stéphan Sainléger",
|
||||||
"license": "AGPL-3",
|
"license": "AGPL-3",
|
||||||
"category": "Tools",
|
"category": "Tools",
|
||||||
@@ -37,4 +37,4 @@
|
|||||||
# and independently installed. Used for synergetic or glue modules.
|
# and independently installed. Used for synergetic or glue modules.
|
||||||
"auto_install": False,
|
"auto_install": False,
|
||||||
"application": False,
|
"application": False,
|
||||||
}
|
}
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
from . import os_distribution
|
from . import os_distribution
|
||||||
from . import service
|
from . import service
|
||||||
from . import maintenance_equipment
|
from . import maintenance_equipment
|
||||||
@@ -1,17 +1,10 @@
|
|||||||
from odoo import api, fields, models
|
from odoo import fields, models, api
|
||||||
|
|
||||||
|
|
||||||
class MaintenanceEquipment(models.Model):
|
class MaintenanceEquipment(models.Model):
|
||||||
_inherit = "maintenance.equipment"
|
_inherit = "maintenance.equipment"
|
||||||
|
|
||||||
_sql_constraints = [
|
|
||||||
('unique_name', 'UNIQUE(name)', 'Name must be unique.'),
|
|
||||||
('unique_server_ip', 'UNIQUE(server_ip)', 'Server IP must be unique.'),
|
|
||||||
('unique_ssh_target', 'UNIQUE(ssh_target)', 'Main Domain Name must be unique.'),
|
|
||||||
]
|
|
||||||
|
|
||||||
server_ip = fields.Char("Server Ip Address")
|
server_ip = fields.Char("Server Ip Address")
|
||||||
ssh_target = fields.Char("SSH Target", )
|
|
||||||
distribution_id = fields.Many2one("os.distribution", string="Distribution")
|
distribution_id = fields.Many2one("os.distribution", string="Distribution")
|
||||||
service_ids = fields.One2many("service.instance", "equipment_id", string="Services")
|
service_ids = fields.One2many("service.instance", "equipment_id", string="Services")
|
||||||
hosting_city = fields.Char("Hosting City")
|
hosting_city = fields.Char("Hosting City")
|
||||||
@@ -24,24 +17,8 @@ class MaintenanceEquipment(models.Model):
|
|||||||
|
|
||||||
name_fr = fields.Char("Name (FR)", compute="_compute_name_fr", store=True)
|
name_fr = fields.Char("Name (FR)", compute="_compute_name_fr", store=True)
|
||||||
|
|
||||||
def copy_data(self, default=None):
|
|
||||||
default = dict(default or {})
|
|
||||||
if "server_ip" not in default:
|
|
||||||
default["server_ip"] = False
|
|
||||||
if "ssh_target" not in default:
|
|
||||||
default["ssh_target"] = False
|
|
||||||
vals_list = super().copy_data(default=default)
|
|
||||||
if "name" not in default:
|
|
||||||
for equipment, vals in zip(self, vals_list):
|
|
||||||
vals["name"] = self.env._("%s (copy)", equipment.name)
|
|
||||||
return vals_list
|
|
||||||
|
|
||||||
@api.depends("name")
|
@api.depends("name")
|
||||||
def _compute_name_fr(self):
|
def _compute_name_fr(self):
|
||||||
if not self.env["res.lang"]._lang_get("fr_FR"):
|
|
||||||
for record in self:
|
|
||||||
record.name_fr = record.name
|
|
||||||
return
|
|
||||||
for record in self:
|
for record in self:
|
||||||
record.name_fr = record.with_context(lang="fr_FR").name
|
record.name_fr = record.with_context(lang="fr_FR").name
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,17 @@
|
|||||||
from odoo import api, fields, models
|
from odoo import api, fields, models
|
||||||
|
|
||||||
|
|
||||||
class OsDistribution(models.Model):
|
class OsDistribution(models.Model):
|
||||||
_name = "os.distribution"
|
_name = 'os.distribution'
|
||||||
|
|
||||||
name = fields.Char("Name", compute="_compute_name")
|
name = fields.Char('Name', compute="_compute_name")
|
||||||
distrib_name = fields.Char("Distrib Name", required=True)
|
distrib_name = fields.Char('Distrib Name', required=True)
|
||||||
distrib_version = fields.Char("Distrib Version")
|
distrib_version = fields.Char('Distrib Version')
|
||||||
|
|
||||||
@api.depends("distrib_name", "distrib_version")
|
@api.depends("distrib_name","distrib_version")
|
||||||
def _compute_name(self):
|
def _compute_name(self):
|
||||||
for distrib in self:
|
for distrib in self:
|
||||||
distrib.name = ""
|
distrib.name = ""
|
||||||
if distrib.distrib_name != "":
|
if distrib.distrib_name != "":
|
||||||
distrib.name = distrib.distrib_name
|
distrib.name = distrib.distrib_name
|
||||||
if distrib.distrib_version != "":
|
if distrib.distrib_version != "":
|
||||||
distrib.name = distrib.name + " " + distrib.distrib_version
|
distrib.name = distrib.name + ' ' + distrib.distrib_version
|
||||||
@@ -1,31 +1,28 @@
|
|||||||
from odoo import fields, models
|
from odoo import fields, models
|
||||||
|
|
||||||
|
|
||||||
class Service(models.Model):
|
class Service(models.Model):
|
||||||
_name = "service"
|
_name = 'service'
|
||||||
|
|
||||||
name = fields.Char("Name", required=True)
|
|
||||||
|
|
||||||
|
|
||||||
|
name = fields.Char('Name', required=True)
|
||||||
|
|
||||||
class ServiceVersion(models.Model):
|
class ServiceVersion(models.Model):
|
||||||
_name = "service.version"
|
_name = "service.version"
|
||||||
|
|
||||||
service_id = fields.Many2one("service", string="Service", required=True)
|
service_id = fields.Many2one('service', string='Service', required=True)
|
||||||
name = fields.Char("Name")
|
name = fields.Char('Name')
|
||||||
is_last_version = fields.Boolean("Is Last Version?")
|
is_last_version = fields.Boolean('Is Last Version?')
|
||||||
|
|
||||||
|
|
||||||
class ServiceInstance(models.Model):
|
class ServiceInstance(models.Model):
|
||||||
_name = "service.instance"
|
_name = "service.instance"
|
||||||
|
|
||||||
equipment_id = fields.Many2one("maintenance.equipment", string="Equipment")
|
equipment_id = fields.Many2one('maintenance.equipment', string='Equipment')
|
||||||
service_id = fields.Many2one("service", string="Service", required=True)
|
service_id = fields.Many2one('service', string='Service', required=True)
|
||||||
version_id = fields.Many2one("service.version", string="Version")
|
version_id = fields.Many2one('service.version', string='Version')
|
||||||
service_url = fields.Char(string="Service Url")
|
service_url = fields.Char(string='Service Url')
|
||||||
active = fields.Boolean(default=True)
|
active = fields.Boolean(default=True)
|
||||||
|
|
||||||
|
|
||||||
class BackupServer(models.Model):
|
class BackupServer(models.Model):
|
||||||
_name = "backup.server"
|
_name = 'backup.server'
|
||||||
|
|
||||||
name = fields.Char("Name", required=True)
|
name = fields.Char('Name', required=True)
|
||||||
@@ -8,4 +8,4 @@ service_version_manager,service_version_manager,model_service_version,maintenanc
|
|||||||
service_instance_user,service_instance_user,model_service_instance,base.group_user,1,0,0,0
|
service_instance_user,service_instance_user,model_service_instance,base.group_user,1,0,0,0
|
||||||
service_instance_manager,service_instance_manager,model_service_instance,maintenance.group_equipment_manager,1,1,1,1
|
service_instance_manager,service_instance_manager,model_service_instance,maintenance.group_equipment_manager,1,1,1,1
|
||||||
backup_server_user,backup_server_user,model_backup_server,base.group_user,1,0,0,0
|
backup_server_user,backup_server_user,model_backup_server,base.group_user,1,0,0,0
|
||||||
backup_server_manager,backup_server_manager,model_backup_server,maintenance.group_equipment_manager,1,1,1,1
|
backup_server_manager,backup_server_manager,model_backup_server,maintenance.group_equipment_manager,1,1,1,1
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<odoo>
|
<odoo>
|
||||||
<record id="equipment_view_form_server_inherit" model="ir.ui.view">
|
<record id="equipment_view_form_server_inherit" model="ir.ui.view">
|
||||||
<field name="name">equipment.form.server.inherit</field>
|
<field name="name">equipment.form.server.inherit</field>
|
||||||
@@ -8,7 +8,6 @@
|
|||||||
<xpath expr="//field[@name='effective_date']/.." position="after">
|
<xpath expr="//field[@name='effective_date']/.." position="after">
|
||||||
<group name="server_data" string="Server data">
|
<group name="server_data" string="Server data">
|
||||||
<field name="server_ip" />
|
<field name="server_ip" />
|
||||||
<field name="ssh_target" />
|
|
||||||
<field name="hosting_city" />
|
<field name="hosting_city" />
|
||||||
<field name="distribution_id" />
|
<field name="distribution_id" />
|
||||||
<field name="nb_cores" />
|
<field name="nb_cores" />
|
||||||
@@ -24,14 +23,11 @@
|
|||||||
<xpath expr="//notebook" position="inside">
|
<xpath expr="//notebook" position="inside">
|
||||||
<page name="services" string="Services">
|
<page name="services" string="Services">
|
||||||
<field name="service_ids" nolabel="1">
|
<field name="service_ids" nolabel="1">
|
||||||
<list create="true" delete="true" editable="top">
|
<tree create="true" delete="true" editable="top">
|
||||||
<field name="service_id" />
|
<field name="service_id" />
|
||||||
<field
|
<field name="version_id" domain="[('service_id', '=', service_id)]" />
|
||||||
name="version_id"
|
|
||||||
domain="[('service_id', '=', service_id)]"
|
|
||||||
/>
|
|
||||||
<field name="service_url" />
|
<field name="service_url" />
|
||||||
</list>
|
</tree>
|
||||||
</field>
|
</field>
|
||||||
</page>
|
</page>
|
||||||
</xpath>
|
</xpath>
|
||||||
@@ -40,13 +36,12 @@
|
|||||||
|
|
||||||
|
|
||||||
<record id="equipment_view_tree_server_inherit" model="ir.ui.view">
|
<record id="equipment_view_tree_server_inherit" model="ir.ui.view">
|
||||||
<field name="name">equipment.list.server.inherit</field>
|
<field name="name">equipment.tree.server.inherit</field>
|
||||||
<field name="model">maintenance.equipment</field>
|
<field name="model">maintenance.equipment</field>
|
||||||
<field name="inherit_id" ref="maintenance.hr_equipment_view_tree" />
|
<field name="inherit_id" ref="maintenance.hr_equipment_view_tree" />
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<xpath expr="//field[@name='category_id']" position="after">
|
<xpath expr="//field[@name='category_id']" position="after">
|
||||||
<field name="server_ip" optional="hide" />
|
<field name="server_ip" optional="hide" />
|
||||||
<field name="ssh_target" optional="hide" />
|
|
||||||
<field name="hosting_city" optional="hide" />
|
<field name="hosting_city" optional="hide" />
|
||||||
<field name="distribution_id" optional="hide" />
|
<field name="distribution_id" optional="hide" />
|
||||||
<field name="nb_cores" optional="hide" />
|
<field name="nb_cores" optional="hide" />
|
||||||
@@ -58,4 +53,4 @@
|
|||||||
</xpath>
|
</xpath>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
</odoo>
|
</odoo>
|
||||||
@@ -1,20 +1,20 @@
|
|||||||
<?xml version="1.0" encoding="utf-8" ?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<odoo>
|
<odoo>
|
||||||
<record id="os_distribution_view_tree" model="ir.ui.view">
|
<record id="os_distribution_view_tree" model="ir.ui.view">
|
||||||
<field name="name">os.distribution.view.list</field>
|
<field name="name">os.distribution.view.tree</field>
|
||||||
<field name="model">os.distribution</field>
|
<field name="model">os.distribution</field>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<list editable="top">
|
<tree string="OS Distributions" editable="top">
|
||||||
<field name="distrib_name" />
|
<field name="distrib_name" />
|
||||||
<field name="distrib_version" />
|
<field name="distrib_version" />
|
||||||
</list>
|
</tree>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
<record id="os_distribution_action" model="ir.actions.act_window">
|
<record id="os_distribution_action" model="ir.actions.act_window">
|
||||||
<field name="name">OS Distribution</field>
|
<field name="name">OS Distribution</field>
|
||||||
<field name="res_model">os.distribution</field>
|
<field name="res_model">os.distribution</field>
|
||||||
<field name="view_mode">list</field>
|
<field name="view_mode">tree</field>
|
||||||
<field name="view_id" ref="os_distribution_view_tree" />
|
<field name="view_id" ref="os_distribution_view_tree" />
|
||||||
<field name="help" type="html">
|
<field name="help" type="html">
|
||||||
<p class="o_view_nocontent_smiling_face">
|
<p class="o_view_nocontent_smiling_face">
|
||||||
@@ -28,7 +28,6 @@
|
|||||||
name="OS Distributions"
|
name="OS Distributions"
|
||||||
parent="maintenance.menu_maintenance_configuration"
|
parent="maintenance.menu_maintenance_configuration"
|
||||||
action="os_distribution_action"
|
action="os_distribution_action"
|
||||||
sequence="3"
|
sequence="3" />
|
||||||
/>
|
|
||||||
|
|
||||||
</odoo>
|
</odoo>
|
||||||
@@ -1,47 +1,47 @@
|
|||||||
<?xml version="1.0" encoding="utf-8" ?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<odoo>
|
<odoo>
|
||||||
<!-- VIEWS -->
|
<!-- VIEWS -->
|
||||||
<record id="service_view_tree" model="ir.ui.view">
|
<record id="service_view_tree" model="ir.ui.view">
|
||||||
<field name="name">service.view.list</field>
|
<field name="name">service.view.tree</field>
|
||||||
<field name="model">service</field>
|
<field name="model">service</field>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<list editable="top">
|
<tree string="Services" editable="top">
|
||||||
<field name="name" />
|
<field name="name" />
|
||||||
</list>
|
</tree>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
<record id="service_version_view_tree" model="ir.ui.view">
|
<record id="service_version_view_tree" model="ir.ui.view">
|
||||||
<field name="name">service.version.view.list</field>
|
<field name="name">service.version.view.tree</field>
|
||||||
<field name="model">service.version</field>
|
<field name="model">service.version</field>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<list editable="top">
|
<tree string="Service versions" editable="top">
|
||||||
<field name="service_id" />
|
<field name="service_id" />
|
||||||
<field name="name" />
|
<field name="name" />
|
||||||
<field name="is_last_version" />
|
<field name="is_last_version" />
|
||||||
</list>
|
</tree>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
<record id="backup_server_view_tree" model="ir.ui.view">
|
<record id="backup_server_view_tree" model="ir.ui.view">
|
||||||
<field name="name">backup.server.view.list</field>
|
<field name="name">backup.server.view.tree</field>
|
||||||
<field name="model">backup.server</field>
|
<field name="model">backup.server</field>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<list editable="top">
|
<tree string="Backup Servers" editable="top">
|
||||||
<field name="name" />
|
<field name="name" />
|
||||||
</list>
|
</tree>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
<record id="service_instance_view_tree" model="ir.ui.view">
|
<record id="service_instance_view_tree" model="ir.ui.view">
|
||||||
<field name="name">service.instance.view.list</field>
|
<field name="name">service.instance.view.tree</field>
|
||||||
<field name="model">service.instance</field>
|
<field name="model">service.instance</field>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<list>
|
<tree>
|
||||||
<field name="equipment_id" />
|
<field name="equipment_id"/>
|
||||||
<field name="service_id" />
|
<field name="service_id"/>
|
||||||
<field name="version_id" />
|
<field name="version_id"/>
|
||||||
</list>
|
</tree>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
@@ -50,33 +50,17 @@
|
|||||||
<field name="model">service.instance</field>
|
<field name="model">service.instance</field>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<search string="Search Service Instances">
|
<search string="Search Service Instances">
|
||||||
<field name="equipment_id" />
|
<field name="equipment_id"/>
|
||||||
<field name="service_id" />
|
<field name="service_id"/>
|
||||||
<field name="version_id" />
|
<field name="version_id"/>
|
||||||
<field name="service_url" />
|
<field name="service_url"/>
|
||||||
<separator />
|
<separator/>
|
||||||
<filter
|
<filter string="Archived" name="inactive" domain="[('active', '=', False)]"/>
|
||||||
string="Archived"
|
<separator/>
|
||||||
name="inactive"
|
|
||||||
domain="[('active', '=', False)]"
|
|
||||||
/>
|
|
||||||
<separator />
|
|
||||||
<group expand="0" string="Group By">
|
<group expand="0" string="Group By">
|
||||||
<filter
|
<filter string="Equipment" name="group_equipment" context="{'group_by': 'equipment_id'}"/>
|
||||||
string="Equipment"
|
<filter string="Service" name="group_service" context="{'group_by': 'service_id'}"/>
|
||||||
name="group_equipment"
|
<filter string="Version" name="group_version" context="{'group_by': 'version_id'}"/>
|
||||||
context="{'group_by': 'equipment_id'}"
|
|
||||||
/>
|
|
||||||
<filter
|
|
||||||
string="Service"
|
|
||||||
name="group_service"
|
|
||||||
context="{'group_by': 'service_id'}"
|
|
||||||
/>
|
|
||||||
<filter
|
|
||||||
string="Version"
|
|
||||||
name="group_version"
|
|
||||||
context="{'group_by': 'version_id'}"
|
|
||||||
/>
|
|
||||||
</group>
|
</group>
|
||||||
</search>
|
</search>
|
||||||
</field>
|
</field>
|
||||||
@@ -86,7 +70,7 @@
|
|||||||
<record id="service_action" model="ir.actions.act_window">
|
<record id="service_action" model="ir.actions.act_window">
|
||||||
<field name="name">Service</field>
|
<field name="name">Service</field>
|
||||||
<field name="res_model">service</field>
|
<field name="res_model">service</field>
|
||||||
<field name="view_mode">list</field>
|
<field name="view_mode">tree</field>
|
||||||
<field name="view_id" ref="service_view_tree" />
|
<field name="view_id" ref="service_view_tree" />
|
||||||
<field name="help" type="html">
|
<field name="help" type="html">
|
||||||
<p class="o_view_nocontent_smiling_face">
|
<p class="o_view_nocontent_smiling_face">
|
||||||
@@ -98,7 +82,7 @@
|
|||||||
<record id="service_version_action" model="ir.actions.act_window">
|
<record id="service_version_action" model="ir.actions.act_window">
|
||||||
<field name="name">Service Version</field>
|
<field name="name">Service Version</field>
|
||||||
<field name="res_model">service.version</field>
|
<field name="res_model">service.version</field>
|
||||||
<field name="view_mode">list</field>
|
<field name="view_mode">tree</field>
|
||||||
<field name="view_id" ref="service_version_view_tree" />
|
<field name="view_id" ref="service_version_view_tree" />
|
||||||
<field name="help" type="html">
|
<field name="help" type="html">
|
||||||
<p class="o_view_nocontent_smiling_face">
|
<p class="o_view_nocontent_smiling_face">
|
||||||
@@ -110,7 +94,7 @@
|
|||||||
<record id="backup_server_action" model="ir.actions.act_window">
|
<record id="backup_server_action" model="ir.actions.act_window">
|
||||||
<field name="name">Backup server</field>
|
<field name="name">Backup server</field>
|
||||||
<field name="res_model">backup.server</field>
|
<field name="res_model">backup.server</field>
|
||||||
<field name="view_mode">list</field>
|
<field name="view_mode">tree</field>
|
||||||
<field name="view_id" ref="backup_server_view_tree" />
|
<field name="view_id" ref="backup_server_view_tree" />
|
||||||
<field name="help" type="html">
|
<field name="help" type="html">
|
||||||
<p class="o_view_nocontent_smiling_face">
|
<p class="o_view_nocontent_smiling_face">
|
||||||
@@ -122,8 +106,8 @@
|
|||||||
<record id="service_instance_action" model="ir.actions.act_window">
|
<record id="service_instance_action" model="ir.actions.act_window">
|
||||||
<field name="name">Services</field>
|
<field name="name">Services</field>
|
||||||
<field name="res_model">service.instance</field>
|
<field name="res_model">service.instance</field>
|
||||||
<field name="view_mode">list</field>
|
<field name="view_mode">tree</field>
|
||||||
<field name="view_id" ref="service_instance_view_tree" />
|
<field name="view_id" ref="service_instance_view_tree"/>
|
||||||
<field name="help" type="html">
|
<field name="help" type="html">
|
||||||
<p class="o_view_nocontent_smiling_face">
|
<p class="o_view_nocontent_smiling_face">
|
||||||
Add a new Service Instance
|
Add a new Service Instance
|
||||||
@@ -137,31 +121,27 @@
|
|||||||
name="Services"
|
name="Services"
|
||||||
parent="maintenance.menu_maintenance_configuration"
|
parent="maintenance.menu_maintenance_configuration"
|
||||||
action="service_action"
|
action="service_action"
|
||||||
sequence="4"
|
sequence="4" />
|
||||||
/>
|
|
||||||
|
|
||||||
<menuitem
|
<menuitem
|
||||||
id="menu_maintenance_service_version"
|
id="menu_maintenance_service_version"
|
||||||
name="Service Versions"
|
name="Service Versions"
|
||||||
parent="maintenance.menu_maintenance_configuration"
|
parent="maintenance.menu_maintenance_configuration"
|
||||||
action="service_version_action"
|
action="service_version_action"
|
||||||
sequence="5"
|
sequence="5" />
|
||||||
/>
|
|
||||||
|
|
||||||
<menuitem
|
<menuitem
|
||||||
id="menu_maintenance_backup_server"
|
id="menu_maintenance_backup_server"
|
||||||
name="Backup Servers"
|
name="Backup Servers"
|
||||||
parent="maintenance.menu_maintenance_configuration"
|
parent="maintenance.menu_maintenance_configuration"
|
||||||
action="backup_server_action"
|
action="backup_server_action"
|
||||||
sequence="5"
|
sequence="5" />
|
||||||
/>
|
|
||||||
|
|
||||||
<menuitem
|
<menuitem
|
||||||
id="menu_maintenance_service_instance"
|
id="menu_maintenance_service_instance"
|
||||||
name="Services"
|
name="Services"
|
||||||
parent="maintenance.menu_maintenance_title"
|
parent="maintenance.menu_maintenance_title"
|
||||||
action="service_instance_action"
|
action="service_instance_action"
|
||||||
sequence="10"
|
sequence="35"/>
|
||||||
/>
|
|
||||||
|
|
||||||
</odoo>
|
</odoo>
|
||||||
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": "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",
|
||||||
|
"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
|
||||||
372
maintenance_server_monitoring/models/maintenance_equipment.py
Normal file
372
maintenance_server_monitoring/models/maintenance_equipment.py
Normal file
@@ -0,0 +1,372 @@
|
|||||||
|
from odoo import fields, models, api
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
import psutil
|
||||||
|
from io import StringIO
|
||||||
|
|
||||||
|
LOG_LIMIT = 100000
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
MAX_PING_MS_WARNING = 1000
|
||||||
|
MAX_PING_MS_ERROR = 5000
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
if you want to add a new 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 **
|
||||||
|
* add requirements if necessary in install_dependencies function
|
||||||
|
* call your function in monitoring_test() with a simple launch_test({fieldname}, *args)
|
||||||
|
if needed, *args can be passed by parameters to your test function
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
class MaintenanceEquipment(models.Model):
|
||||||
|
_inherit = 'maintenance.equipment'
|
||||||
|
|
||||||
|
last_monitoring_test_date = fields.Datetime('Date of last monitoring test', readonly=True)
|
||||||
|
|
||||||
|
#tests
|
||||||
|
ping_ok = fields.Boolean("Ping ok", readonly=True)
|
||||||
|
available_memory_percent = fields.Float('Percent of available memory', readonly=True)
|
||||||
|
used_disk_space = fields.Float('Percent of used disk space', readonly=True)
|
||||||
|
ssh_ok = fields.Boolean("SSH ok", readonly=True)
|
||||||
|
|
||||||
|
#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([]).monitoring_test()
|
||||||
|
|
||||||
|
def monitoring_test(self):
|
||||||
|
|
||||||
|
def launch_test(attribute, *test_function_args):
|
||||||
|
"""run test function with name = test_[attribute]
|
||||||
|
associate result of test to equipment
|
||||||
|
write logs of test
|
||||||
|
|
||||||
|
|
||||||
|
Args:
|
||||||
|
attribute (string): attribute of MaintenanceEquipment we want to test
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
MonitoringTest: returned by test function
|
||||||
|
"""
|
||||||
|
test_function = getattr(equipment,"test_"+attribute)
|
||||||
|
test = test_function(*test_function_args)
|
||||||
|
setattr(equipment, attribute, test.result)
|
||||||
|
log.write(test.log)
|
||||||
|
tests.append(test)
|
||||||
|
return test
|
||||||
|
|
||||||
|
|
||||||
|
for equipment in self:
|
||||||
|
|
||||||
|
# we use StingIO instead of string to use mutable object
|
||||||
|
log = StringIO()
|
||||||
|
|
||||||
|
# array of all tests
|
||||||
|
tests = []
|
||||||
|
|
||||||
|
# install dependencies and log it
|
||||||
|
log.write(equipment.install_dependencies().log) # launch_test is not used, only logs are necessary
|
||||||
|
|
||||||
|
# run ping test
|
||||||
|
launch_test("ping_ok")
|
||||||
|
|
||||||
|
# SSH dependant test
|
||||||
|
ssh = launch_test("ssh_ok").result
|
||||||
|
|
||||||
|
|
||||||
|
if ssh:
|
||||||
|
# test available memory
|
||||||
|
launch_test("available_memory_percent", ssh)
|
||||||
|
|
||||||
|
# test disk usage
|
||||||
|
launch_test("used_disk_space", ssh)
|
||||||
|
else:
|
||||||
|
equipment.available_memory_percent = -1 #set -1 by convention if error
|
||||||
|
equipment.used_disk_space = -1 #set -1 by convention if error
|
||||||
|
|
||||||
|
# set test date
|
||||||
|
equipment.last_monitoring_test_date = fields.Datetime.now()
|
||||||
|
|
||||||
|
# write logs
|
||||||
|
log.seek(0) #log is a StringIO so seek to beginning before read
|
||||||
|
new_log = f'📣 {fields.Datetime.now()}\n{log.read()}\n'
|
||||||
|
new_log = new_log.replace("\n","<br />") # log field is HTML, so format lines
|
||||||
|
equipment.log = f'{new_log}<br />{equipment.log}'[:LOG_LIMIT] #limit logs
|
||||||
|
|
||||||
|
# if error create maintenance request
|
||||||
|
error = warning =False
|
||||||
|
if any(test.error == test.ERROR for test in tests):
|
||||||
|
error = True # if any arror in tests
|
||||||
|
elif any(test.error == test.WARNING for test in tests):
|
||||||
|
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):
|
||||||
|
maintenance_request = self.env['maintenance.request'].create({
|
||||||
|
"name":f'[{"ERROR" if error else "WARNING"}] {equipment.name}',
|
||||||
|
"equipment_id":equipment.id,
|
||||||
|
"employee_id":equipment.employee_id,
|
||||||
|
"user_id":equipment.technician_user_id,
|
||||||
|
"maintenance_team_id":equipment.maintenance_team_id.id or self.env["maintenance.team"].search([], limit=1),
|
||||||
|
"priority":'2' if error else '3',
|
||||||
|
"maintenance_type":"corrective" if error else "preventive",
|
||||||
|
"description":new_log
|
||||||
|
})
|
||||||
|
if error:
|
||||||
|
equipment.error_maintenance_request = maintenance_request
|
||||||
|
else:
|
||||||
|
equipment.warning_maintenance_request = maintenance_request
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def install_dependencies(self):
|
||||||
|
"""
|
||||||
|
install dependencies needed to do all tests, as python or shell programs
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
MonitoringTest: representing current test with result=0 if not error
|
||||||
|
"""
|
||||||
|
monitoring_test = self.MonitoringTest("install dependencies")
|
||||||
|
if "ping3" in sys.modules:
|
||||||
|
return monitoring_test.test_ok(0, "ping3 already installed")
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
command = ['pip','install',"ping3"]
|
||||||
|
response = subprocess.call(command) # run "pip install ping3" command
|
||||||
|
if response == 0:
|
||||||
|
return monitoring_test.test_ok(0, "ping3 installation successful")
|
||||||
|
else:
|
||||||
|
monitoring_test.test_error(f"ping3 : unable to install : response = {response}")
|
||||||
|
except Exception as e:
|
||||||
|
return monitoring_test.test_error(f"ping3 : unable to install : {e}")
|
||||||
|
|
||||||
|
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, f"{fields.Datetime.now()} > SSH > connection failed {e}\n")
|
||||||
|
|
||||||
|
|
||||||
|
def test_available_memory_percent(self, ssh):
|
||||||
|
"""
|
||||||
|
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
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
test = self.MonitoringTest("Available memory percent")
|
||||||
|
_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}")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def test_used_disk_space(self, ssh):
|
||||||
|
"""
|
||||||
|
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
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
test = self.MonitoringTest("Used disk space")
|
||||||
|
_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}")
|
||||||
|
|
||||||
|
|
||||||
|
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 Exception as e:
|
||||||
|
# unable to import ping3
|
||||||
|
return test.test_error(False, f"ping3 dependencie not satisfied : {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(False, f"PING OK in {ping_ms}ms (> {MAX_PING_MS_ERROR})")
|
||||||
|
else:
|
||||||
|
return test.test_error(False, "PING FAILED")
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
<?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="last_monitoring_test_date" />
|
||||||
|
<field name="ping_ok" />
|
||||||
|
<field name="ssh_ok" />
|
||||||
|
<field name="available_memory_percent" />
|
||||||
|
<field name="used_disk_space" />
|
||||||
|
<button name="monitoring_test" type="object" string="Test" />
|
||||||
|
</group>
|
||||||
|
<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="ping_ok" optional="hide" />
|
||||||
|
<field name="ssh_ok" />
|
||||||
|
<field name="available_memory_percent" optional="hide" />
|
||||||
|
<field name="used_disk_space" optional="hide" />
|
||||||
|
</xpath>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
</odoo>
|
||||||
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": "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,
|
||||||
|
}
|
||||||
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
|
||||||
20
maintenance_server_ssh/models/maintenance_equipment.py
Normal file
20
maintenance_server_ssh/models/maintenance_equipment.py
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
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):
|
||||||
|
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)
|
||||||
|
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>
|
||||||
@@ -3,7 +3,6 @@
|
|||||||
## Contexte codebase
|
## Contexte codebase
|
||||||
|
|
||||||
### Architecture des modules
|
### Architecture des modules
|
||||||
|
|
||||||
```
|
```
|
||||||
maintenance_server_data (base, maintenance)
|
maintenance_server_data (base, maintenance)
|
||||||
├── Définit: service, service.version, service.instance, backup.server
|
├── Définit: service, service.version, service.instance, backup.server
|
||||||
@@ -23,64 +22,51 @@ maintenance_server_monitoring (base, maintenance, maintenance_server_ssh)
|
|||||||
```
|
```
|
||||||
|
|
||||||
### Modèle service.instance actuel (dans maintenance_server_data)
|
### Modèle service.instance actuel (dans maintenance_server_data)
|
||||||
|
|
||||||
- equipment_id (Many2one → maintenance.equipment)
|
- equipment_id (Many2one → maintenance.equipment)
|
||||||
- service_id (Many2one → service, required)
|
- service_id (Many2one → service, required)
|
||||||
- version_id (Many2one → service.version)
|
- version_id (Many2one → service.version)
|
||||||
- service_url (Char) ← URL déjà existante, parfait pour les checks HTTP
|
- service_url (Char) ← URL déjà existante, parfait pour les checks HTTP
|
||||||
|
|
||||||
### Pattern de création maintenance.request existant
|
### Pattern de création maintenance.request existant
|
||||||
|
|
||||||
- Vérifie si une request non-done existe déjà avant d'en créer une nouvelle
|
- Vérifie si une request non-done existe déjà avant d'en créer une nouvelle
|
||||||
- Stocke la référence sur equipment: error_maintenance_request /
|
- Stocke la référence sur equipment: error_maintenance_request / warning_maintenance_request
|
||||||
warning_maintenance_request
|
|
||||||
- Assignation auto: employee_id, technician_user_id, maintenance_team_id
|
- Assignation auto: employee_id, technician_user_id, maintenance_team_id
|
||||||
|
|
||||||
## Requirements confirmés (depuis les specs)
|
## Requirements confirmés (depuis les specs)
|
||||||
|
|
||||||
- [x] Modifier le module `maintenance_server_monitoring` (pas de nouveau module)
|
- [x] Modifier le module `maintenance_server_monitoring` (pas de nouveau module)
|
||||||
- [x] Ajouter `maintenance_server_data` aux dépendances (nécessaire pour accéder à
|
- [x] Ajouter `maintenance_server_data` aux dépendances (nécessaire pour accéder à service.instance)
|
||||||
service.instance)
|
- [x] Étendre `service.instance` avec: last_status_code (Integer), last_check_date (Datetime), status OK/KO (Boolean)
|
||||||
- [x] Étendre `service.instance` avec: last_status_code (Integer), last_check_date
|
- [x] Nouvelle vue liste standalone pour service.instance (nom, version, URL, date check, status code, statut)
|
||||||
(Datetime), status OK/KO (Boolean)
|
|
||||||
- [x] Nouvelle vue liste standalone pour service.instance (nom, version, URL, date
|
|
||||||
check, status code, statut)
|
|
||||||
- [x] Paramètres module: fréquence vérification + durée mode maintenance
|
- [x] Paramètres module: fréquence vérification + durée mode maintenance
|
||||||
- [x] Mode maintenance sur equipment: bool tracked + bandeau
|
- [x] Mode maintenance sur equipment: bool tracked + bandeau
|
||||||
- [x] Si service KO → création maintenance.request (pas de doublon si toujours KO)
|
- [x] Si service KO → création maintenance.request (pas de doublon si toujours KO)
|
||||||
|
|
||||||
## Décision architecturale : NOUVEAU MODULE
|
## Décision architecturale : NOUVEAU MODULE
|
||||||
|
|
||||||
**Nom**: `maintenance_service_http_monitoring` **Raison**: Séparation des préoccupations
|
**Nom**: `maintenance_service_http_monitoring`
|
||||||
— monitoring infra (SSH/ping) vs monitoring applicatif (HTTP) **Dépendances**: `base`,
|
**Raison**: Séparation des préoccupations — monitoring infra (SSH/ping) vs monitoring applicatif (HTTP)
|
||||||
`maintenance`, `maintenance_server_data` **PAS de dépendance** vers
|
**Dépendances**: `base`, `maintenance`, `maintenance_server_data`
|
||||||
`maintenance_server_ssh` ni `maintenance_server_monitoring`
|
**PAS de dépendance** vers `maintenance_server_ssh` ni `maintenance_server_monitoring`
|
||||||
|
|
||||||
## Décisions techniques
|
## Décisions techniques
|
||||||
|
|
||||||
- Paramètres via res.config.settings + ir.config_parameter (pattern standard Odoo)
|
- Paramètres via res.config.settings + ir.config_parameter (pattern standard Odoo)
|
||||||
- \_inherit = 'service.instance' dans le nouveau module pour étendre le modèle
|
- _inherit = 'service.instance' dans le nouveau module pour étendre le modèle
|
||||||
- Cron dédié pour les checks HTTP (fréquence configurable)
|
- Cron dédié pour les checks HTTP (fréquence configurable)
|
||||||
- \_inherit = 'maintenance.equipment' pour ajouter maintenance_mode +
|
- _inherit = 'maintenance.equipment' pour ajouter maintenance_mode + http_maintenance_request
|
||||||
http_maintenance_request
|
|
||||||
- mail.thread déjà hérité par maintenance.equipment dans Odoo base → tracking fonctionne
|
- mail.thread déjà hérité par maintenance.equipment dans Odoo base → tracking fonctionne
|
||||||
|
|
||||||
## Décisions utilisateur (interview)
|
## Décisions utilisateur (interview)
|
||||||
|
|
||||||
1. **Mode maintenance**: HTTP uniquement — le monitoring existant (ping, SSH, mémoire,
|
1. **Mode maintenance**: HTTP uniquement — le monitoring existant (ping, SSH, mémoire, disque) continue normalement
|
||||||
disque) continue normalement
|
2. **Lien maintenance.request**: Sur maintenance.equipment — nouveau champ `http_maintenance_request` (Many2one). Si plusieurs services KO sur un même equipment, UNE seule request qui liste les services KO.
|
||||||
2. **Lien maintenance.request**: Sur maintenance.equipment — nouveau champ
|
3. **Menu service list**: Sous Maintenance > principal, même niveau que Équipements et Demandes
|
||||||
`http_maintenance_request` (Many2one). Si plusieurs services KO sur un même
|
4. **Tests**: OUI — setup pytest-odoo + tests unitaires pour la logique HTTP check et création maintenance requests
|
||||||
equipment, UNE seule request qui liste les services KO.
|
|
||||||
3. **Menu service list**: Sous Maintenance > principal, même niveau que Équipements et
|
|
||||||
Demandes
|
|
||||||
4. **Tests**: OUI — setup pytest-odoo + tests unitaires pour la logique HTTP check et
|
|
||||||
création maintenance requests
|
|
||||||
|
|
||||||
## Scope boundaries
|
## Scope boundaries
|
||||||
|
|
||||||
### IN
|
### IN
|
||||||
|
|
||||||
- NOUVEAU module `maintenance_service_http_monitoring`
|
- NOUVEAU module `maintenance_service_http_monitoring`
|
||||||
- Étendre service.instance avec champs monitoring HTTP
|
- Étendre service.instance avec champs monitoring HTTP
|
||||||
- Cron dédié pour checks HTTP (fréquence configurable)
|
- Cron dédié pour checks HTTP (fréquence configurable)
|
||||||
@@ -91,7 +77,6 @@ maintenance_server_monitoring (base, maintenance, maintenance_server_ssh)
|
|||||||
- Setup pytest-odoo + tests unitaires
|
- Setup pytest-odoo + tests unitaires
|
||||||
|
|
||||||
### OUT
|
### OUT
|
||||||
|
|
||||||
- Aucune modification de `maintenance_server_monitoring` ni de `maintenance_server_ssh`
|
- Aucune modification de `maintenance_server_monitoring` ni de `maintenance_server_ssh`
|
||||||
- Pas de notification email (juste la maintenance.request)
|
- Pas de notification email (juste la maintenance.request)
|
||||||
- Pas de dashboard / reporting
|
- Pas de dashboard / reporting
|
||||||
@@ -99,13 +84,9 @@ maintenance_server_monitoring (base, maintenance, maintenance_server_ssh)
|
|||||||
|
|
||||||
## Décisions Metis (post-gap-analysis)
|
## Décisions Metis (post-gap-analysis)
|
||||||
|
|
||||||
- Services orphelins (sans equipment_id): N'existent pas en pratique, filtrés par
|
- Services orphelins (sans equipment_id): N'existent pas en pratique, filtrés par sécurité
|
||||||
sécurité
|
- Récupération service KO→OK: Rien d'automatique, close manuelle de la maintenance.request
|
||||||
- Récupération service KO→OK: Rien d'automatique, close manuelle de la
|
- Définition KO: Tout échec = KO (timeout, DNS, SSL, connexion refusée, code != 200). Log le détail.
|
||||||
maintenance.request
|
- Timeout HTTP: Hardcodé (constante, comme les seuils existants dans maintenance_server_monitoring)
|
||||||
- Définition KO: Tout échec = KO (timeout, DNS, SSL, connexion refusée, code != 200).
|
|
||||||
Log le détail.
|
|
||||||
- Timeout HTTP: Hardcodé (constante, comme les seuils existants dans
|
|
||||||
maintenance_server_monitoring)
|
|
||||||
- `requests` library: Déclarer dans external_dependencies.python
|
- `requests` library: Déclarer dans external_dependencies.python
|
||||||
- Chaque requests.get() DOIT avoir timeout= (pylintrc enforce external-request-timeout)
|
- Chaque requests.get() DOIT avoir timeout= (pylintrc enforce external-request-timeout)
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,171 +0,0 @@
|
|||||||
===================================
|
|
||||||
maintenance_service_http_monitoring
|
|
||||||
===================================
|
|
||||||
|
|
||||||
This module provides automated HTTP availability monitoring for services
|
|
||||||
defined on maintenance equipment. It periodically checks the HTTP status of
|
|
||||||
service URLs and automatically creates maintenance requests when services
|
|
||||||
are detected as unavailable.
|
|
||||||
|
|
||||||
Key features:
|
|
||||||
|
|
||||||
- **Automated HTTP checks**: Scheduled cron job checks all active services
|
|
||||||
- **Maintenance mode**: Temporarily disable monitoring during planned maintenance
|
|
||||||
- **Automatic maintenance requests**: Creates corrective maintenance requests
|
|
||||||
when services fail HTTP checks
|
|
||||||
- **Status tracking**: Records last HTTP status code and check date per service
|
|
||||||
|
|
||||||
# Installation
|
|
||||||
|
|
||||||
Use Odoo normal module installation procedure to install
|
|
||||||
`maintenance_service_http_monitoring`.
|
|
||||||
|
|
||||||
This module depends on:
|
|
||||||
- `maintenance`
|
|
||||||
- `maintenance_server_data`
|
|
||||||
|
|
||||||
**Python dependencies**: This module requires the `requests` library.
|
|
||||||
|
|
||||||
# Configuration
|
|
||||||
|
|
||||||
## Maintenance Mode Duration
|
|
||||||
|
|
||||||
By default, maintenance mode lasts 4 hours. To change this:
|
|
||||||
|
|
||||||
1. Go to Settings > Technical > System Parameters
|
|
||||||
2. Create or edit the parameter:
|
|
||||||
- Key: `maintenance_service_http_monitoring.maintenance_mode_duration`
|
|
||||||
- Value: Duration in hours (e.g., `8`)
|
|
||||||
|
|
||||||
## Cron Jobs
|
|
||||||
|
|
||||||
Three scheduled actions are installed:
|
|
||||||
|
|
||||||
1. **HTTP Service Monitoring: check all services**
|
|
||||||
- Runs every 10 minutes
|
|
||||||
- Discovery sweep: checks HTTP status of all active service instances with URLs
|
|
||||||
and flags the start of a KO streak
|
|
||||||
|
|
||||||
2. **HTTP Service Monitoring: confirm KO services**
|
|
||||||
- Runs every 2 minutes
|
|
||||||
- Re-checks only the services currently flagged KO (without an open request) and
|
|
||||||
creates a maintenance request once the outage is confirmed
|
|
||||||
|
|
||||||
3. **HTTP Service Monitoring: deactivate expired maintenance mode**
|
|
||||||
- Runs every 15 minutes
|
|
||||||
- Automatically disables maintenance mode when the end time is reached
|
|
||||||
|
|
||||||
## Webhook Notifications
|
|
||||||
|
|
||||||
Go to **Settings > Technical > Parameters > System Parameters** and configure:
|
|
||||||
|
|
||||||
+--------------------------------------------------------+----------------------------------------+
|
|
||||||
| Key | Description |
|
|
||||||
+========================================================+========================================+
|
|
||||||
| ``maintenance_service_http_monitoring.webhook_url`` | Webhook URL (POST endpoint) |
|
|
||||||
+--------------------------------------------------------+----------------------------------------+
|
|
||||||
| ``maintenance_service_http_monitoring.webhook_user`` | Basic Auth username (optional) |
|
|
||||||
+--------------------------------------------------------+----------------------------------------+
|
|
||||||
| ``maintenance_service_http_monitoring.webhook_password``| Basic Auth password (optional) |
|
|
||||||
+--------------------------------------------------------+----------------------------------------+
|
|
||||||
|
|
||||||
|
|
||||||
# Usage
|
|
||||||
|
|
||||||
## Monitoring Services
|
|
||||||
|
|
||||||
Services are automatically monitored if they have:
|
|
||||||
- A service URL defined
|
|
||||||
- An associated equipment
|
|
||||||
- The equipment is not in maintenance mode
|
|
||||||
- The service instance is active
|
|
||||||
|
|
||||||
The monitoring checks HTTPS availability (HTTP URLs are automatically
|
|
||||||
upgraded to HTTPS). A service is considered OK if it returns HTTP 200.
|
|
||||||
|
|
||||||
## Using Maintenance Mode
|
|
||||||
|
|
||||||
When performing planned maintenance on a server:
|
|
||||||
|
|
||||||
1. Go to Maintenance > Equipments
|
|
||||||
2. Open the equipment record
|
|
||||||
3. Click "Activer le mode maintenance" (Activate maintenance mode)
|
|
||||||
4. HTTP monitoring is suspended for this equipment
|
|
||||||
5. The mode automatically expires after the configured duration
|
|
||||||
6. Or click "Désactiver le mode maintenance" to end it manually
|
|
||||||
|
|
||||||
## Viewing HTTP Status
|
|
||||||
|
|
||||||
On service instances, you can see:
|
|
||||||
- **Last HTTP Status Code**: The last received HTTP status (200, 404, 500, etc.)
|
|
||||||
- **Last HTTP Check Date**: When the last check was performed
|
|
||||||
- **HTTP Status OK**: Quick visual indicator of service health
|
|
||||||
|
|
||||||
## Automatic Maintenance Requests
|
|
||||||
|
|
||||||
When a service fails HTTP checks:
|
|
||||||
- The 10-minute discovery sweep flags the outage (``http_first_ko_at``) but does
|
|
||||||
**not** create a request yet
|
|
||||||
- The 2-minute confirmation cron re-checks the flagged services only. A request is
|
|
||||||
created once the service has been continuously KO for at least 2 minutes
|
|
||||||
(``HTTP_KO_CONFIRMATION_DELAY``), so a short transient outage is not flagged
|
|
||||||
- A corrective maintenance request is created per failing service, named
|
|
||||||
``[HTTP KO] {service_url}``
|
|
||||||
- The request description includes the error detail: the HTTP status code,
|
|
||||||
or a network error label (timeout / DNS / SSL) when no HTTP response was received
|
|
||||||
- No duplicate is created as long as an open request already exists for that service
|
|
||||||
- The confirmation cron skips services that already have an open request; those are
|
|
||||||
handled by the discovery sweep
|
|
||||||
|
|
||||||
When a service recovers (returns HTTP 200 after having an open request):
|
|
||||||
- The open maintenance request is automatically moved to the first **done** stage
|
|
||||||
- A chatter note is posted on the request by OdooBot to record the automatic closure
|
|
||||||
- The link between the service and the request is cleared, allowing a new request to
|
|
||||||
be created if the service fails again in the future
|
|
||||||
|
|
||||||
## Webhook notifications
|
|
||||||
|
|
||||||
When a new maintenance request is created (HTTP check failure), the module can
|
|
||||||
send a webhook notification to an external service (e.g., n8n, Rocket.Chat, Slack).
|
|
||||||
|
|
||||||
The webhook sends a JSON POST with the following structure::
|
|
||||||
|
|
||||||
{
|
|
||||||
"id": 42,
|
|
||||||
"name": "[HTTP KO] Server Name",
|
|
||||||
"priority": "2",
|
|
||||||
"description": "Service KO: https://example.com",
|
|
||||||
"equipment": "Server Name",
|
|
||||||
"link": "https://odoo.example.com/web#id=42&model=maintenance.request&view_type=form"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# Known issues / Roadmap
|
|
||||||
|
|
||||||
- Add configurable alert thresholds (e.g., alert after N consecutive failures)
|
|
||||||
- Add email/notification on service failure
|
|
||||||
- Support custom HTTP check endpoints (e.g., /health)
|
|
||||||
- Add support for basic authentication
|
|
||||||
|
|
||||||
# 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.
|
|
||||||
58
maintenance_service_http_monitoring/README.rst
Normal file
58
maintenance_service_http_monitoring/README.rst
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
======================================
|
||||||
|
maintenance_service_http_monitoring
|
||||||
|
======================================
|
||||||
|
|
||||||
|
Module that allows monitoring of different services by checking their HTTP 200 responses:
|
||||||
|
|
||||||
|
- Uses the `maintenance_server_data` service for each device.
|
||||||
|
|
||||||
|
If the service has a URL, a request is made.
|
||||||
|
- Adds maintenance mode for a device:
|
||||||
|
|
||||||
|
- Allows disabling HTTP checks for a specified time (defined in the cron job).
|
||||||
|
|
||||||
|
## Logic:
|
||||||
|
If a request fails and a maintenance task has already been created for the same day,
|
||||||
|
no new task is added.
|
||||||
|
|
||||||
|
The default values for the cron jobs are located in `data/cron.xml`.
|
||||||
|
|
||||||
|
|
||||||
|
Installation
|
||||||
|
============
|
||||||
|
|
||||||
|
Use Odoo normal module installation procedure to install
|
||||||
|
``maintenance_service_http_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
|
||||||
|
------------
|
||||||
|
|
||||||
|
* Boris Gallet
|
||||||
|
|
||||||
|
Funders
|
||||||
|
-------
|
||||||
|
|
||||||
|
The development of this module has been financially supported by:
|
||||||
|
* Elabore (https://elabore.coop)
|
||||||
|
|
||||||
|
|
||||||
|
Maintainer
|
||||||
|
----------
|
||||||
|
|
||||||
|
This module is maintained by Elabore.
|
||||||
@@ -1,17 +1,16 @@
|
|||||||
{
|
{
|
||||||
"name": "maintenance_service_http_monitoring",
|
"name": "maintenance_service_http_monitoring",
|
||||||
"version": "18.0.1.0.0",
|
"version": "16.0.1.0.0",
|
||||||
"author": "Elabore",
|
"author": "Elabore",
|
||||||
"license": "AGPL-3",
|
"license": "AGPL-3",
|
||||||
"category": "Tools",
|
"category": "Tools",
|
||||||
"summary": "Monitor HTTP availability of services",
|
"summary": "Monitor HTTP availability of services",
|
||||||
"depends": ["base", "maintenance", "base_maintenance", "hr_maintenance", "maintenance_server_data"],
|
"depends": ["base", "maintenance", "maintenance_server_data"],
|
||||||
"external_dependencies": {"python": ["requests"]},
|
"external_dependencies": {"python": ["requests"]},
|
||||||
"data": [
|
"data": [
|
||||||
"data/ir_config_parameter.xml",
|
|
||||||
"data/cron.xml",
|
"data/cron.xml",
|
||||||
"views/service_instance_views.xml",
|
"views/service_instance_views.xml",
|
||||||
"views/maintenance_equipment_views.xml",
|
"views/maintenance_equipment_views.xml"
|
||||||
],
|
],
|
||||||
"installable": True,
|
"installable": True
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,32 +1,23 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<odoo>
|
<odoo>
|
||||||
<record id="ir_cron_http_service_monitoring" model="ir.cron">
|
<record id="ir_cron_http_service_monitoring" model="ir.cron">
|
||||||
<field name="name">HTTP Service Monitoring : check all services</field>
|
<field name="name">HTTP Service Monitoring : check all services</field>
|
||||||
<field name="model_id" ref="maintenance_server_data.model_service_instance" />
|
<field name="model_id" ref="maintenance_server_data.model_service_instance"/>
|
||||||
<field name="state">code</field>
|
<field name="state">code</field>
|
||||||
<field name="code">model.cron_check_http_services()</field>
|
<field name="code">model.cron_check_http_services()</field>
|
||||||
<field name="interval_number">10</field>
|
<field name="interval_number">15</field>
|
||||||
<field name="interval_type">minutes</field>
|
|
||||||
</record>
|
|
||||||
<record id="ir_cron_http_service_confirmation" model="ir.cron">
|
|
||||||
<field name="name">HTTP Service Monitoring : confirm KO services</field>
|
|
||||||
<field name="model_id" ref="maintenance_server_data.model_service_instance" />
|
|
||||||
<field name="state">code</field>
|
|
||||||
<field name="code">model.cron_confirm_http_ko_services()</field>
|
|
||||||
<field name="interval_number">2</field>
|
|
||||||
<field name="interval_type">minutes</field>
|
<field name="interval_type">minutes</field>
|
||||||
|
<field name="numbercall">-1</field>
|
||||||
|
<field name="doall">False</field>
|
||||||
</record>
|
</record>
|
||||||
<record id="ir_cron_maintenance_mode_expiry" model="ir.cron">
|
<record id="ir_cron_maintenance_mode_expiry" model="ir.cron">
|
||||||
<field
|
<field name="name">HTTP Service Monitoring : deactivate expired maintenance mode</field>
|
||||||
name="name"
|
<field name="model_id" ref="maintenance_server_data.model_maintenance_equipment"/>
|
||||||
>HTTP Service Monitoring : deactivate expired maintenance mode</field>
|
|
||||||
<field
|
|
||||||
name="model_id"
|
|
||||||
ref="maintenance_server_data.model_maintenance_equipment"
|
|
||||||
/>
|
|
||||||
<field name="state">code</field>
|
<field name="state">code</field>
|
||||||
<field name="code">model.cron_deactivate_expired_maintenance_mode()</field>
|
<field name="code">model.cron_deactivate_expired_maintenance_mode()</field>
|
||||||
<field name="interval_number">15</field>
|
<field name="interval_number">15</field>
|
||||||
<field name="interval_type">minutes</field>
|
<field name="interval_type">minutes</field>
|
||||||
|
<field name="numbercall">-1</field>
|
||||||
|
<field name="doall">False</field>
|
||||||
</record>
|
</record>
|
||||||
</odoo>
|
</odoo>
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<odoo noupdate="1">
|
|
||||||
<record id="config_param_webhook_url" model="ir.config_parameter">
|
|
||||||
<field name="key">maintenance_service_http_monitoring.webhook_url</field>
|
|
||||||
<field name="value"></field>
|
|
||||||
</record>
|
|
||||||
<record id="config_param_webhook_user" model="ir.config_parameter">
|
|
||||||
<field name="key">maintenance_service_http_monitoring.webhook_user</field>
|
|
||||||
<field name="value"></field>
|
|
||||||
</record>
|
|
||||||
<record id="config_param_webhook_password" model="ir.config_parameter">
|
|
||||||
<field name="key">maintenance_service_http_monitoring.webhook_password</field>
|
|
||||||
<field name="value"></field>
|
|
||||||
</record>
|
|
||||||
</odoo>
|
|
||||||
@@ -1,152 +1,97 @@
|
|||||||
import logging
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
from odoo import models, fields, api
|
||||||
from odoo import api, fields, models
|
|
||||||
|
|
||||||
try:
|
|
||||||
import requests as http_requests
|
|
||||||
except ImportError:
|
|
||||||
http_requests = None
|
|
||||||
|
|
||||||
_logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
WEBHOOK_TIMEOUT = 10 # seconds
|
|
||||||
|
|
||||||
|
|
||||||
class MaintenanceEquipment(models.Model):
|
class MaintenanceEquipment(models.Model):
|
||||||
_inherit = "maintenance.equipment"
|
_inherit = 'maintenance.equipment'
|
||||||
|
|
||||||
maintenance_mode = fields.Boolean(
|
maintenance_mode = fields.Boolean(
|
||||||
|
string="Maintenance Mode",
|
||||||
default=False,
|
default=False,
|
||||||
tracking=True,
|
tracking=True,
|
||||||
)
|
)
|
||||||
maintenance_mode_start = fields.Datetime(
|
maintenance_mode_start = fields.Datetime(
|
||||||
|
string="Maintenance Mode Start",
|
||||||
readonly=True,
|
readonly=True,
|
||||||
)
|
)
|
||||||
maintenance_mode_end = fields.Datetime(
|
maintenance_mode_end = fields.Datetime(
|
||||||
|
string="Maintenance Mode End",
|
||||||
readonly=True,
|
readonly=True,
|
||||||
help="Computed from start + configured duration",
|
help="Computed from start + configured duration",
|
||||||
)
|
)
|
||||||
|
http_maintenance_request = fields.Many2one(
|
||||||
|
'maintenance.request',
|
||||||
|
string="HTTP Maintenance Request",
|
||||||
|
readonly=True,
|
||||||
|
)
|
||||||
|
|
||||||
def action_activate_maintenance_mode(self):
|
def action_activate_maintenance_mode(self):
|
||||||
for rec in self:
|
for rec in self:
|
||||||
duration = int(
|
duration = int(self.env['ir.config_parameter'].sudo().get_param(
|
||||||
self.env["ir.config_parameter"]
|
'maintenance_service_http_monitoring.maintenance_mode_duration', 4))
|
||||||
.sudo()
|
|
||||||
.get_param(
|
|
||||||
"maintenance_service_http_monitoring.maintenance_mode_duration", 4
|
|
||||||
)
|
|
||||||
)
|
|
||||||
now = fields.Datetime.now()
|
now = fields.Datetime.now()
|
||||||
rec.write(
|
rec.write({
|
||||||
{
|
'maintenance_mode': True,
|
||||||
"maintenance_mode": True,
|
'maintenance_mode_start': now,
|
||||||
"maintenance_mode_start": now,
|
'maintenance_mode_end': now + timedelta(hours=duration),
|
||||||
"maintenance_mode_end": now + timedelta(hours=duration),
|
})
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
def action_deactivate_maintenance_mode(self):
|
def action_deactivate_maintenance_mode(self):
|
||||||
for rec in self:
|
for rec in self:
|
||||||
rec.write(
|
rec.write({
|
||||||
{
|
'maintenance_mode': False,
|
||||||
"maintenance_mode": False,
|
'maintenance_mode_start': False,
|
||||||
"maintenance_mode_start": False,
|
'maintenance_mode_end': False,
|
||||||
"maintenance_mode_end": False,
|
})
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def cron_deactivate_expired_maintenance_mode(self):
|
def cron_deactivate_expired_maintenance_mode(self):
|
||||||
now = fields.Datetime.now()
|
now = fields.Datetime.now()
|
||||||
expired = self.search(
|
expired = self.search([
|
||||||
[
|
('maintenance_mode', '=', True),
|
||||||
("maintenance_mode", "=", True),
|
('maintenance_mode_end', '<=', now),
|
||||||
("maintenance_mode_end", "<=", now),
|
])
|
||||||
]
|
|
||||||
)
|
|
||||||
expired.action_deactivate_maintenance_mode()
|
expired.action_deactivate_maintenance_mode()
|
||||||
|
|
||||||
def create_http_maintenance_request(self, ko_service):
|
def create_http_maintenance_request(self, ko_services):
|
||||||
"""
|
|
||||||
Create or return the open maintenance.request for a single KO service.
|
|
||||||
|
|
||||||
Deduplication: if ko_service already has an open (non-done) request,
|
|
||||||
return it without creating a new one.
|
|
||||||
"""
|
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
existing = ko_service.http_maintenance_request
|
today = fields.Date.context_today(self)
|
||||||
if existing and not existing.stage_id.done:
|
name = f"[HTTP KO] {self.name}"
|
||||||
|
domain = [
|
||||||
|
('name', '=', name),
|
||||||
|
('equipment_id', '=', self.id),
|
||||||
|
('maintenance_type', '=', 'corrective'),
|
||||||
|
('create_date', '>=', f"{today} 00:00:00"),
|
||||||
|
('create_date', '<=', f"{today} 23:59:59"),
|
||||||
|
]
|
||||||
|
existing = self.env['maintenance.request'].search(domain, limit=1)
|
||||||
|
# Check if a task with same name already exist for the day, if it’s the case : skip
|
||||||
|
if existing:
|
||||||
|
self.http_maintenance_request = existing.id
|
||||||
return existing
|
return existing
|
||||||
status_code = ko_service.last_http_status_code
|
request = self.http_maintenance_request
|
||||||
if status_code == -1:
|
if request and not request.stage_id.done:
|
||||||
error_detail = "Erreur réseau (timeout / DNS / SSL)"
|
return request
|
||||||
else:
|
|
||||||
error_detail = f"HTTP {status_code}"
|
|
||||||
name = f"[HTTP KO] {ko_service.service_url}"
|
|
||||||
description = f"Service KO: {ko_service.service_url}\n{error_detail}"
|
|
||||||
vals = {
|
vals = {
|
||||||
"name": name,
|
'name': name,
|
||||||
"equipment_id": self.id,
|
'equipment_id': self.id,
|
||||||
"priority": "2",
|
'priority': '2',
|
||||||
"maintenance_type": "corrective",
|
'maintenance_type': 'corrective',
|
||||||
"description": description,
|
'description': self._build_ko_services_description(ko_services),
|
||||||
}
|
}
|
||||||
if self.employee_id:
|
if self.employee_id:
|
||||||
vals["employee_id"] = self.employee_id.id
|
vals['employee_id'] = self.employee_id.id
|
||||||
if self.technician_user_id:
|
if self.technician_user_id:
|
||||||
vals["user_id"] = self.technician_user_id.id
|
vals['user_id'] = self.technician_user_id.id
|
||||||
if self.maintenance_team_id:
|
if self.maintenance_team_id:
|
||||||
vals["maintenance_team_id"] = self.maintenance_team_id.id
|
vals['maintenance_team_id'] = self.maintenance_team_id.id
|
||||||
else:
|
else:
|
||||||
team = self.env["maintenance.team"].search([], limit=1)
|
team = self.env['maintenance.team'].search([], limit=1)
|
||||||
if team:
|
if team:
|
||||||
vals["maintenance_team_id"] = team.id
|
vals['maintenance_team_id'] = team.id
|
||||||
request = self.env["maintenance.request"].create(vals)
|
request = self.env['maintenance.request'].create(vals)
|
||||||
ko_service.http_maintenance_request = request.id
|
self.http_maintenance_request = request.id
|
||||||
self._notify_webhook(request, ko_service)
|
|
||||||
return request
|
return request
|
||||||
|
|
||||||
def _notify_webhook(self, request, ko_service):
|
def _build_ko_services_description(self, ko_services):
|
||||||
"""
|
lines = [f"Service KO: {s.service_url or s.name}" for s in ko_services]
|
||||||
Send a webhook notification when a new maintenance request is created.
|
return '\n'.join(lines)
|
||||||
"""
|
|
||||||
ICP = self.env["ir.config_parameter"].sudo()
|
|
||||||
webhook_url = ICP.get_param(
|
|
||||||
"maintenance_service_http_monitoring.webhook_url", ""
|
|
||||||
)
|
|
||||||
if not webhook_url:
|
|
||||||
return
|
|
||||||
webhook_user = ICP.get_param(
|
|
||||||
"maintenance_service_http_monitoring.webhook_user", ""
|
|
||||||
)
|
|
||||||
webhook_password = ICP.get_param(
|
|
||||||
"maintenance_service_http_monitoring.webhook_password", ""
|
|
||||||
)
|
|
||||||
base_url = ICP.get_param("web.base.url", "")
|
|
||||||
link = (
|
|
||||||
f"{base_url}/web#id={request.id}&model=maintenance.request&view_type=form"
|
|
||||||
)
|
|
||||||
payload = {
|
|
||||||
"id": request.id,
|
|
||||||
"name": request.name,
|
|
||||||
"description": request.description or "",
|
|
||||||
"equipment": self.name,
|
|
||||||
"link": link,
|
|
||||||
}
|
|
||||||
auth = None
|
|
||||||
if webhook_user and webhook_password:
|
|
||||||
auth = (webhook_user, webhook_password)
|
|
||||||
try:
|
|
||||||
http_requests.post(
|
|
||||||
webhook_url,
|
|
||||||
json=payload,
|
|
||||||
auth=auth,
|
|
||||||
timeout=WEBHOOK_TIMEOUT,
|
|
||||||
)
|
|
||||||
except Exception as e:
|
|
||||||
_logger.warning(
|
|
||||||
"Webhook notification failed for maintenance request %s: %s",
|
|
||||||
request.id,
|
|
||||||
e,
|
|
||||||
)
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import logging
|
import logging
|
||||||
from datetime import timedelta
|
from datetime import datetime
|
||||||
|
from odoo import models, fields, api
|
||||||
from odoo import api, fields, models
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import requests
|
import requests
|
||||||
@@ -10,12 +9,10 @@ except ImportError:
|
|||||||
|
|
||||||
_logger = logging.getLogger(__name__)
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
HTTP_CHECK_TIMEOUT = 20 # seconds
|
HTTP_CHECK_TIMEOUT = 10 # seconds
|
||||||
HTTP_KO_CONFIRMATION_DELAY = timedelta(minutes=2)
|
|
||||||
|
|
||||||
|
|
||||||
class ServiceInstance(models.Model):
|
class ServiceInstance(models.Model):
|
||||||
_inherit = "service.instance"
|
_inherit = 'service.instance'
|
||||||
|
|
||||||
last_http_status_code = fields.Integer(
|
last_http_status_code = fields.Integer(
|
||||||
string="Last HTTP Status Code",
|
string="Last HTTP Status Code",
|
||||||
@@ -31,150 +28,42 @@ class ServiceInstance(models.Model):
|
|||||||
readonly=True,
|
readonly=True,
|
||||||
default=True,
|
default=True,
|
||||||
)
|
)
|
||||||
http_maintenance_request = fields.Many2one(
|
|
||||||
"maintenance.request",
|
|
||||||
string="HTTP Maintenance Request",
|
|
||||||
readonly=True,
|
|
||||||
)
|
|
||||||
http_first_ko_at = fields.Datetime(
|
|
||||||
string="First HTTP KO Check (current streak)",
|
|
||||||
readonly=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
def check_http_status(self):
|
def check_http_status(self):
|
||||||
"""
|
|
||||||
Perform HTTP check for each record and return the KO recordset.
|
|
||||||
|
|
||||||
Writes last_http_status_code, last_http_check_date and http_status_ok on every
|
|
||||||
checked record, and maintains http_first_ko_at (the start of the current KO
|
|
||||||
streak, reset as soon as the service is OK again). Does NOT create
|
|
||||||
maintenance.request — that decision belongs to cron_confirm_http_ko_services,
|
|
||||||
once the service has been continuously KO for at least
|
|
||||||
HTTP_KO_CONFIRMATION_DELAY, to avoid flagging transient outages (e.g. a short
|
|
||||||
server overload) as real incidents.
|
|
||||||
"""
|
|
||||||
ko_records = self.browse()
|
|
||||||
for rec in self:
|
for rec in self:
|
||||||
if not rec.service_url or not rec.equipment_id:
|
if not rec.service_url or not rec.equipment_id:
|
||||||
continue
|
continue
|
||||||
if rec.equipment_id.maintenance_mode:
|
equipment = rec.equipment_id
|
||||||
|
if getattr(equipment, 'maintenance_mode', False):
|
||||||
continue
|
continue
|
||||||
status_ok = False
|
status_ok = False
|
||||||
status_code = -1
|
status_code = -1
|
||||||
now = fields.Datetime.now()
|
now = fields.Datetime.now()
|
||||||
url = rec.service_url
|
url = rec.service_url
|
||||||
if not url.lower().startswith("https://"):
|
if not url.lower().startswith("https://"):
|
||||||
url = "https://" + url.removeprefix("http://").removeprefix("HTTP://")
|
url = "https://" + url.lstrip("http://")
|
||||||
try:
|
try:
|
||||||
response = requests.get(url, timeout=HTTP_CHECK_TIMEOUT)
|
response = requests.get(url, timeout=HTTP_CHECK_TIMEOUT)
|
||||||
status_code = response.status_code
|
status_code = response.status_code
|
||||||
status_ok = status_code == 200
|
status_ok = (status_code == 200)
|
||||||
except requests.exceptions.RequestException as e:
|
except requests.exceptions.RequestException as e:
|
||||||
_logger.warning("HTTP check failed for %s: %s", rec.service_url, e)
|
_logger.warning(f"HTTP check failed for %s: %s", rec.service_url, e)
|
||||||
vals = {
|
rec.write({
|
||||||
"last_http_status_code": status_code,
|
'last_http_status_code': status_code,
|
||||||
"last_http_check_date": now,
|
'last_http_check_date': now,
|
||||||
"http_status_ok": status_ok,
|
'http_status_ok': status_ok,
|
||||||
}
|
})
|
||||||
if status_ok:
|
|
||||||
vals["http_first_ko_at"] = False
|
|
||||||
elif not rec.http_first_ko_at:
|
|
||||||
vals["http_first_ko_at"] = now
|
|
||||||
rec.write(vals)
|
|
||||||
if not status_ok:
|
if not status_ok:
|
||||||
ko_records |= rec
|
# Delegate maintenance.request creation to equipment
|
||||||
return ko_records
|
if hasattr(equipment, 'create_http_maintenance_request'):
|
||||||
|
equipment.create_http_maintenance_request([rec])
|
||||||
def _close_http_maintenance_request(self):
|
|
||||||
"""
|
|
||||||
Close the open maintenance.request for each recovered service.
|
|
||||||
|
|
||||||
Moves the request to the first done stage, posts a chatter note as OdooBot, and
|
|
||||||
clears http_maintenance_request on the service instance.
|
|
||||||
"""
|
|
||||||
done_stage = self.env["maintenance.stage"].search(
|
|
||||||
[("done", "=", True)], limit=1
|
|
||||||
)
|
|
||||||
if not done_stage:
|
|
||||||
return
|
|
||||||
odoobot = self.env.ref("base.partner_root")
|
|
||||||
for rec in self:
|
|
||||||
request = rec.http_maintenance_request
|
|
||||||
if not request or request.stage_id.done:
|
|
||||||
continue
|
|
||||||
request.sudo().write({"stage_id": done_stage.id})
|
|
||||||
request.sudo().message_post(
|
|
||||||
body=(
|
|
||||||
f"Service {rec.service_url} is back online. "
|
|
||||||
"This request has been automatically closed by the monitoring cron."
|
|
||||||
),
|
|
||||||
author_id=odoobot.id,
|
|
||||||
message_type="comment",
|
|
||||||
subtype_xmlid="mail.mt_note",
|
|
||||||
)
|
|
||||||
rec.http_maintenance_request = False
|
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def cron_check_http_services(self):
|
def cron_check_http_services(self):
|
||||||
"""
|
domain = [('active', '=', True), ('service_url', '!=', False), ('equipment_id', '!=', False)]
|
||||||
Discovery sweep: check all active services with a URL.
|
services = self.search(domain)
|
||||||
|
for service in services:
|
||||||
This cron only detects outages — it flags the start of a KO streak through
|
equipment = service.equipment_id
|
||||||
http_first_ko_at (via check_http_status) and auto-resolves services that
|
if getattr(equipment, 'maintenance_mode', False):
|
||||||
recovered. Maintenance requests are created by the separate, faster
|
continue
|
||||||
cron_confirm_http_ko_services once the outage is confirmed.
|
service.check_http_status()
|
||||||
"""
|
|
||||||
domain = [
|
|
||||||
("active", "=", True),
|
|
||||||
("service_url", "!=", False),
|
|
||||||
("equipment_id", "!=", False),
|
|
||||||
]
|
|
||||||
services = self.search(domain).filtered(
|
|
||||||
lambda s: not s.equipment_id.maintenance_mode
|
|
||||||
)
|
|
||||||
|
|
||||||
# Snapshot services that currently have an open request before the check
|
|
||||||
services_with_open_request = services.filtered(
|
|
||||||
lambda s: s.http_maintenance_request
|
|
||||||
and not s.http_maintenance_request.stage_id.done
|
|
||||||
)
|
|
||||||
|
|
||||||
services.check_http_status()
|
|
||||||
|
|
||||||
# Auto-resolve services that recovered
|
|
||||||
recovered = services_with_open_request.filtered(lambda s: s.http_status_ok)
|
|
||||||
if recovered:
|
|
||||||
recovered._close_http_maintenance_request()
|
|
||||||
|
|
||||||
@api.model
|
|
||||||
def cron_confirm_http_ko_services(self):
|
|
||||||
"""
|
|
||||||
Confirmation pass: re-check services currently flagged KO and create their
|
|
||||||
maintenance.request once the outage is confirmed.
|
|
||||||
|
|
||||||
Only services without an open request are considered (re-checking a service
|
|
||||||
already under an open request is pointless). A service must be continuously
|
|
||||||
KO for at least HTTP_KO_CONFIRMATION_DELAY: a service that recovered in the
|
|
||||||
meantime resets http_first_ko_at via check_http_status and no request is
|
|
||||||
created. Services already under an open request are handled by the slower
|
|
||||||
discovery cron, which also auto-resolves them when they recover.
|
|
||||||
"""
|
|
||||||
domain = [
|
|
||||||
("active", "=", True),
|
|
||||||
("service_url", "!=", False),
|
|
||||||
("equipment_id", "!=", False),
|
|
||||||
("http_first_ko_at", "!=", False),
|
|
||||||
("http_maintenance_request", "=", False),
|
|
||||||
]
|
|
||||||
services = self.search(domain).filtered(
|
|
||||||
lambda s: not s.equipment_id.maintenance_mode
|
|
||||||
)
|
|
||||||
|
|
||||||
ko_services = services.check_http_status()
|
|
||||||
|
|
||||||
confirmed_ko = ko_services.filtered(
|
|
||||||
lambda s: s.last_http_check_date - s.http_first_ko_at
|
|
||||||
>= HTTP_KO_CONFIRMATION_DELAY
|
|
||||||
)
|
|
||||||
for service in confirmed_ko:
|
|
||||||
service.equipment_id.create_http_maintenance_request(service)
|
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
from . import test_http_monitoring
|
|
||||||
@@ -1,468 +0,0 @@
|
|||||||
from datetime import timedelta
|
|
||||||
from unittest.mock import MagicMock, patch
|
|
||||||
|
|
||||||
from odoo import fields
|
|
||||||
from odoo.tests.common import TransactionCase
|
|
||||||
|
|
||||||
SERVICE_INSTANCE_REQUESTS = (
|
|
||||||
"odoo.addons.maintenance_service_http_monitoring.models.service_instance.requests"
|
|
||||||
)
|
|
||||||
EQUIPMENT_HTTP_REQUESTS = (
|
|
||||||
"odoo.addons.maintenance_service_http_monitoring"
|
|
||||||
".models.maintenance_equipment.http_requests"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Comfortably past HTTP_KO_CONFIRMATION_DELAY (currently 2 minutes).
|
|
||||||
PAST_CONFIRMATION_DELAY = timedelta(minutes=10)
|
|
||||||
|
|
||||||
|
|
||||||
def _mock_response(status_code):
|
|
||||||
response = MagicMock()
|
|
||||||
response.status_code = status_code
|
|
||||||
return response
|
|
||||||
|
|
||||||
|
|
||||||
class TestHttpMonitoring(TransactionCase):
|
|
||||||
def setUp(self):
|
|
||||||
super().setUp()
|
|
||||||
team = self.env["maintenance.team"].search([], limit=1)
|
|
||||||
self.equipment = self.env["maintenance.equipment"].create(
|
|
||||||
{
|
|
||||||
"name": "Test Server",
|
|
||||||
"maintenance_team_id": team.id if team else False,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
self.service = self.env["service"].create({"name": "Test Service"})
|
|
||||||
self.service_instance = self.env["service.instance"].create(
|
|
||||||
{
|
|
||||||
"equipment_id": self.equipment.id,
|
|
||||||
"service_id": self.service.id,
|
|
||||||
"service_url": "https://example.com",
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
def _backdate_first_ko(self, *service_instances):
|
|
||||||
"""Simulate a KO streak old enough ago to be confirmed."""
|
|
||||||
for service_instance in service_instances:
|
|
||||||
service_instance.write(
|
|
||||||
{"http_first_ko_at": fields.Datetime.now() - PAST_CONFIRMATION_DELAY}
|
|
||||||
)
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
# Test 1 -- HTTP 200 -> service marked OK
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
def test_http_200_sets_status_ok(self):
|
|
||||||
with patch(SERVICE_INSTANCE_REQUESTS) as mock_requests:
|
|
||||||
mock_requests.get.return_value = _mock_response(200)
|
|
||||||
mock_requests.exceptions.RequestException = Exception
|
|
||||||
self.service_instance.check_http_status()
|
|
||||||
|
|
||||||
self.assertTrue(self.service_instance.http_status_ok)
|
|
||||||
self.assertEqual(self.service_instance.last_http_status_code, 200)
|
|
||||||
self.assertIsNotNone(self.service_instance.last_http_check_date)
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
# Test 2 -- KO confirmed only once continuously KO for HTTP_KO_CONFIRMATION_DELAY,
|
|
||||||
# not on the first observed failure
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
def test_http_500_creates_request_after_confirmation_delay(self):
|
|
||||||
with patch(SERVICE_INSTANCE_REQUESTS) as mock_requests:
|
|
||||||
mock_requests.get.return_value = _mock_response(500)
|
|
||||||
mock_requests.exceptions.RequestException = Exception
|
|
||||||
self.env["service.instance"].cron_check_http_services()
|
|
||||||
|
|
||||||
self.assertFalse(self.service_instance.http_status_ok)
|
|
||||||
self.assertEqual(self.service_instance.last_http_status_code, 500)
|
|
||||||
self.assertTrue(self.service_instance.http_first_ko_at)
|
|
||||||
self.assertFalse(self.service_instance.http_maintenance_request)
|
|
||||||
|
|
||||||
self._backdate_first_ko(self.service_instance)
|
|
||||||
|
|
||||||
with patch(SERVICE_INSTANCE_REQUESTS) as mock_requests:
|
|
||||||
mock_requests.get.return_value = _mock_response(500)
|
|
||||||
mock_requests.exceptions.RequestException = Exception
|
|
||||||
self.env["service.instance"].cron_confirm_http_ko_services()
|
|
||||||
|
|
||||||
request = self.service_instance.http_maintenance_request
|
|
||||||
self.assertTrue(request)
|
|
||||||
self.assertEqual(request.name, f"[HTTP KO] {self.service_instance.service_url}")
|
|
||||||
self.assertEqual(request.priority, "2")
|
|
||||||
self.assertEqual(request.maintenance_type, "corrective")
|
|
||||||
self.assertIn("HTTP 500", request.description)
|
|
||||||
self.assertIn(self.service_instance.service_url, request.description)
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
# Test 3 -- Network error -> KO with code -1
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
def test_network_error_sets_status_ko_and_minus_one(self):
|
|
||||||
with patch(SERVICE_INSTANCE_REQUESTS) as mock_requests:
|
|
||||||
mock_requests.get.side_effect = Exception("connection refused")
|
|
||||||
mock_requests.exceptions.RequestException = Exception
|
|
||||||
self.service_instance.check_http_status()
|
|
||||||
|
|
||||||
self.assertFalse(self.service_instance.http_status_ok)
|
|
||||||
self.assertEqual(self.service_instance.last_http_status_code, -1)
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
# Test 4 -- Repeated failure after confirmation -> a single request, no duplicate
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
def test_no_duplicate_request_on_repeated_failure(self):
|
|
||||||
with patch(SERVICE_INSTANCE_REQUESTS) as mock_requests:
|
|
||||||
mock_requests.get.return_value = _mock_response(500)
|
|
||||||
mock_requests.exceptions.RequestException = Exception
|
|
||||||
self.env["service.instance"].cron_check_http_services() # first_ko_at set
|
|
||||||
|
|
||||||
self.assertFalse(self.service_instance.http_maintenance_request)
|
|
||||||
self._backdate_first_ko(self.service_instance)
|
|
||||||
|
|
||||||
with patch(SERVICE_INSTANCE_REQUESTS) as mock_requests:
|
|
||||||
mock_requests.get.return_value = _mock_response(500)
|
|
||||||
mock_requests.exceptions.RequestException = Exception
|
|
||||||
# confirmed -> request created
|
|
||||||
self.env["service.instance"].cron_confirm_http_ko_services()
|
|
||||||
|
|
||||||
request_1 = self.service_instance.http_maintenance_request
|
|
||||||
self.assertTrue(request_1)
|
|
||||||
|
|
||||||
with patch(SERVICE_INSTANCE_REQUESTS) as mock_requests:
|
|
||||||
mock_requests.exceptions.RequestException = Exception
|
|
||||||
# already handled -> skipped
|
|
||||||
self.env["service.instance"].cron_confirm_http_ko_services()
|
|
||||||
|
|
||||||
# Service already has an open request -> the confirmation cron skips it
|
|
||||||
mock_requests.get.assert_not_called()
|
|
||||||
self.assertEqual(self.service_instance.http_maintenance_request, request_1)
|
|
||||||
self.assertEqual(
|
|
||||||
self.env["maintenance.request"].search_count(
|
|
||||||
[("equipment_id", "=", self.equipment.id)]
|
|
||||||
),
|
|
||||||
1,
|
|
||||||
)
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
# Test 5 -- Equipment in maintenance mode -> cron skips it
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
def test_maintenance_mode_skips_http_check(self):
|
|
||||||
self.equipment.write({"maintenance_mode": True})
|
|
||||||
|
|
||||||
with patch(SERVICE_INSTANCE_REQUESTS) as mock_requests:
|
|
||||||
mock_requests.get.return_value = _mock_response(500)
|
|
||||||
mock_requests.exceptions.RequestException = Exception
|
|
||||||
self.env["service.instance"].cron_check_http_services()
|
|
||||||
|
|
||||||
mock_requests.get.assert_not_called()
|
|
||||||
self.assertFalse(self.service_instance.last_http_check_date)
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
# Test 6 -- Expired maintenance mode -> cron deactivates it
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
def test_maintenance_mode_auto_expiry(self):
|
|
||||||
past = fields.Datetime.now() - timedelta(hours=1)
|
|
||||||
self.equipment.write(
|
|
||||||
{
|
|
||||||
"maintenance_mode": True,
|
|
||||||
"maintenance_mode_start": past - timedelta(hours=4),
|
|
||||||
"maintenance_mode_end": past,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
self.assertTrue(self.equipment.maintenance_mode)
|
|
||||||
|
|
||||||
self.env["maintenance.equipment"].cron_deactivate_expired_maintenance_mode()
|
|
||||||
|
|
||||||
self.assertFalse(self.equipment.maintenance_mode)
|
|
||||||
self.assertFalse(self.equipment.maintenance_mode_start)
|
|
||||||
self.assertFalse(self.equipment.maintenance_mode_end)
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
# Test 7 -- Service without URL -> ignored by cron
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
def test_service_without_url_is_ignored(self):
|
|
||||||
self.service_instance.write({"service_url": False})
|
|
||||||
|
|
||||||
with patch(SERVICE_INSTANCE_REQUESTS) as mock_requests:
|
|
||||||
mock_requests.get.return_value = _mock_response(200)
|
|
||||||
mock_requests.exceptions.RequestException = Exception
|
|
||||||
self.env["service.instance"].cron_check_http_services()
|
|
||||||
|
|
||||||
mock_requests.get.assert_not_called()
|
|
||||||
self.assertFalse(self.service_instance.last_http_check_date)
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
# Test 8 -- HTTP 404 (non-exception) -> KO with correct code
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
def test_http_non_200_non_exception(self):
|
|
||||||
with patch(SERVICE_INSTANCE_REQUESTS) as mock_requests:
|
|
||||||
mock_requests.get.return_value = _mock_response(404)
|
|
||||||
mock_requests.exceptions.RequestException = Exception
|
|
||||||
self.service_instance.check_http_status()
|
|
||||||
|
|
||||||
self.assertFalse(self.service_instance.http_status_ok)
|
|
||||||
self.assertEqual(self.service_instance.last_http_status_code, 404)
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
# Test 9 -- Webhook called only once the request is actually created
|
|
||||||
# (after confirmation delay), not on the first observed failure
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
def test_webhook_called_on_new_request(self):
|
|
||||||
self.env["ir.config_parameter"].sudo().set_param(
|
|
||||||
"maintenance_service_http_monitoring.webhook_url",
|
|
||||||
"https://webhook.example.com/hook",
|
|
||||||
)
|
|
||||||
with (
|
|
||||||
patch(SERVICE_INSTANCE_REQUESTS) as mock_requests,
|
|
||||||
patch(EQUIPMENT_HTTP_REQUESTS) as mock_http,
|
|
||||||
):
|
|
||||||
mock_requests.get.return_value = _mock_response(500)
|
|
||||||
mock_requests.exceptions.RequestException = Exception
|
|
||||||
self.env["service.instance"].cron_check_http_services()
|
|
||||||
|
|
||||||
mock_http.post.assert_not_called()
|
|
||||||
self._backdate_first_ko(self.service_instance)
|
|
||||||
|
|
||||||
with (
|
|
||||||
patch(SERVICE_INSTANCE_REQUESTS) as mock_requests,
|
|
||||||
patch(EQUIPMENT_HTTP_REQUESTS) as mock_http,
|
|
||||||
):
|
|
||||||
mock_requests.get.return_value = _mock_response(500)
|
|
||||||
mock_requests.exceptions.RequestException = Exception
|
|
||||||
self.env["service.instance"].cron_confirm_http_ko_services()
|
|
||||||
|
|
||||||
mock_http.post.assert_called_once()
|
|
||||||
call_kwargs = mock_http.post.call_args
|
|
||||||
payload = call_kwargs.kwargs.get("json") or call_kwargs[1].get("json")
|
|
||||||
self.assertEqual(payload["equipment"], self.equipment.name)
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
# Test 10 -- Webhook skipped when no URL configured
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
def test_webhook_skipped_when_no_url(self):
|
|
||||||
self.env["ir.config_parameter"].sudo().set_param(
|
|
||||||
"maintenance_service_http_monitoring.webhook_url", ""
|
|
||||||
)
|
|
||||||
with patch(SERVICE_INSTANCE_REQUESTS) as mock_requests:
|
|
||||||
mock_requests.get.return_value = _mock_response(500)
|
|
||||||
mock_requests.exceptions.RequestException = Exception
|
|
||||||
self.env["service.instance"].cron_check_http_services()
|
|
||||||
|
|
||||||
self._backdate_first_ko(self.service_instance)
|
|
||||||
|
|
||||||
with (
|
|
||||||
patch(SERVICE_INSTANCE_REQUESTS) as mock_requests,
|
|
||||||
patch(EQUIPMENT_HTTP_REQUESTS) as mock_http,
|
|
||||||
):
|
|
||||||
mock_requests.get.return_value = _mock_response(500)
|
|
||||||
mock_requests.exceptions.RequestException = Exception
|
|
||||||
self.env["service.instance"].cron_confirm_http_ko_services()
|
|
||||||
|
|
||||||
self.assertTrue(self.service_instance.http_maintenance_request)
|
|
||||||
mock_http.post.assert_not_called()
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
# Test 11 -- Service without equipment -> check_http_status skips it
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
def test_service_without_equipment_is_ignored(self):
|
|
||||||
self.service_instance.write({"equipment_id": False})
|
|
||||||
|
|
||||||
with patch(SERVICE_INSTANCE_REQUESTS) as mock_requests:
|
|
||||||
mock_requests.get.return_value = _mock_response(200)
|
|
||||||
mock_requests.exceptions.RequestException = Exception
|
|
||||||
self.service_instance.check_http_status()
|
|
||||||
|
|
||||||
mock_requests.get.assert_not_called()
|
|
||||||
self.assertFalse(self.service_instance.last_http_check_date)
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
# Test 12 -- Transient failure (KO, then back OK before confirmation) ->
|
|
||||||
# no request created, and the KO streak is reset
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
def test_transient_failure_no_request_created(self):
|
|
||||||
with patch(SERVICE_INSTANCE_REQUESTS) as mock_requests:
|
|
||||||
mock_requests.get.return_value = _mock_response(500)
|
|
||||||
mock_requests.exceptions.RequestException = Exception
|
|
||||||
self.env["service.instance"].cron_check_http_services()
|
|
||||||
|
|
||||||
self.assertTrue(self.service_instance.http_first_ko_at)
|
|
||||||
|
|
||||||
with patch(SERVICE_INSTANCE_REQUESTS) as mock_requests:
|
|
||||||
mock_requests.get.return_value = _mock_response(200)
|
|
||||||
mock_requests.exceptions.RequestException = Exception
|
|
||||||
self.env["service.instance"].cron_confirm_http_ko_services()
|
|
||||||
|
|
||||||
self.assertTrue(self.service_instance.http_status_ok)
|
|
||||||
self.assertEqual(self.service_instance.last_http_status_code, 200)
|
|
||||||
self.assertFalse(self.service_instance.http_first_ko_at)
|
|
||||||
self.assertFalse(self.service_instance.http_maintenance_request)
|
|
||||||
self.assertEqual(
|
|
||||||
self.env["maintenance.request"].search_count(
|
|
||||||
[("equipment_id", "=", self.equipment.id)]
|
|
||||||
),
|
|
||||||
0,
|
|
||||||
)
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
# Test 13 -- Confirmed failure (KO continuously past the confirmation delay)
|
|
||||||
# -> request created
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
def test_confirmed_failure_creates_request(self):
|
|
||||||
with patch(SERVICE_INSTANCE_REQUESTS) as mock_requests:
|
|
||||||
mock_requests.get.return_value = _mock_response(503)
|
|
||||||
mock_requests.exceptions.RequestException = Exception
|
|
||||||
self.env["service.instance"].cron_check_http_services()
|
|
||||||
|
|
||||||
self.assertEqual(mock_requests.get.call_count, 1)
|
|
||||||
self.assertFalse(self.service_instance.http_maintenance_request)
|
|
||||||
|
|
||||||
self._backdate_first_ko(self.service_instance)
|
|
||||||
|
|
||||||
with patch(SERVICE_INSTANCE_REQUESTS) as mock_requests:
|
|
||||||
mock_requests.get.return_value = _mock_response(503)
|
|
||||||
mock_requests.exceptions.RequestException = Exception
|
|
||||||
self.env["service.instance"].cron_confirm_http_ko_services()
|
|
||||||
|
|
||||||
self.assertEqual(mock_requests.get.call_count, 1)
|
|
||||||
self.assertFalse(self.service_instance.http_status_ok)
|
|
||||||
self.assertEqual(self.service_instance.last_http_status_code, 503)
|
|
||||||
self.assertTrue(self.service_instance.http_maintenance_request)
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
# Test 14 -- 2 KO services on same equipment -> 2 distinct requests
|
|
||||||
# once both reach the confirmation delay
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
def test_two_ko_services_same_equipment_create_two_requests(self):
|
|
||||||
service2 = self.env["service"].create({"name": "Test Service 2"})
|
|
||||||
service_instance2 = self.env["service.instance"].create(
|
|
||||||
{
|
|
||||||
"equipment_id": self.equipment.id,
|
|
||||||
"service_id": service2.id,
|
|
||||||
"service_url": "https://other.example.com",
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
with patch(SERVICE_INSTANCE_REQUESTS) as mock_requests:
|
|
||||||
mock_requests.get.return_value = _mock_response(500)
|
|
||||||
mock_requests.exceptions.RequestException = Exception
|
|
||||||
self.env["service.instance"].cron_check_http_services()
|
|
||||||
|
|
||||||
self._backdate_first_ko(self.service_instance, service_instance2)
|
|
||||||
|
|
||||||
with patch(SERVICE_INSTANCE_REQUESTS) as mock_requests:
|
|
||||||
mock_requests.get.return_value = _mock_response(500)
|
|
||||||
mock_requests.exceptions.RequestException = Exception
|
|
||||||
self.env["service.instance"].cron_confirm_http_ko_services()
|
|
||||||
|
|
||||||
req1 = self.service_instance.http_maintenance_request
|
|
||||||
req2 = service_instance2.http_maintenance_request
|
|
||||||
|
|
||||||
self.assertTrue(req1)
|
|
||||||
self.assertTrue(req2)
|
|
||||||
self.assertNotEqual(req1, req2)
|
|
||||||
self.assertEqual(req1.name, f"[HTTP KO] {self.service_instance.service_url}")
|
|
||||||
self.assertEqual(req2.name, f"[HTTP KO] {service_instance2.service_url}")
|
|
||||||
self.assertEqual(
|
|
||||||
self.env["maintenance.request"].search_count(
|
|
||||||
[("equipment_id", "=", self.equipment.id)]
|
|
||||||
),
|
|
||||||
2,
|
|
||||||
)
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
# Test 15 -- Service recovery closes the open request and posts a note
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
def test_service_recovery_closes_request(self):
|
|
||||||
# First cron run: service is KO, streak just started -> no request yet
|
|
||||||
with patch(SERVICE_INSTANCE_REQUESTS) as mock_requests:
|
|
||||||
mock_requests.get.return_value = _mock_response(500)
|
|
||||||
mock_requests.exceptions.RequestException = Exception
|
|
||||||
self.env["service.instance"].cron_check_http_services()
|
|
||||||
|
|
||||||
self._backdate_first_ko(self.service_instance)
|
|
||||||
|
|
||||||
# Confirmation cron run: streak confirmed -> request created
|
|
||||||
with patch(SERVICE_INSTANCE_REQUESTS) as mock_requests:
|
|
||||||
mock_requests.get.return_value = _mock_response(500)
|
|
||||||
mock_requests.exceptions.RequestException = Exception
|
|
||||||
self.env["service.instance"].cron_confirm_http_ko_services()
|
|
||||||
|
|
||||||
request = self.service_instance.http_maintenance_request
|
|
||||||
self.assertTrue(request)
|
|
||||||
self.assertFalse(request.stage_id.done)
|
|
||||||
|
|
||||||
# Next cron run: service is back OK -> request auto-closed
|
|
||||||
with patch(SERVICE_INSTANCE_REQUESTS) as mock_requests:
|
|
||||||
mock_requests.get.return_value = _mock_response(200)
|
|
||||||
mock_requests.exceptions.RequestException = Exception
|
|
||||||
self.env["service.instance"].cron_check_http_services()
|
|
||||||
|
|
||||||
# Request must be in a done stage
|
|
||||||
self.assertTrue(request.stage_id.done)
|
|
||||||
# http_maintenance_request must be cleared on the service instance
|
|
||||||
self.assertFalse(self.service_instance.http_maintenance_request)
|
|
||||||
# KO streak must be reset
|
|
||||||
self.assertFalse(self.service_instance.http_first_ko_at)
|
|
||||||
# A chatter note must have been posted mentioning the service URL
|
|
||||||
notes = request.message_ids.filtered(
|
|
||||||
lambda m: self.service_instance.service_url in (m.body or "")
|
|
||||||
)
|
|
||||||
self.assertTrue(notes)
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
# Test 16 -- No open request -> _close_http_maintenance_request is a no-op
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
def test_no_close_when_no_open_request(self):
|
|
||||||
# Service is OK from the start, no request exists
|
|
||||||
self.assertFalse(self.service_instance.http_maintenance_request)
|
|
||||||
# Calling close directly must not raise
|
|
||||||
self.service_instance._close_http_maintenance_request()
|
|
||||||
self.assertFalse(self.service_instance.http_maintenance_request)
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
# Test 17 -- Confirmation cron ignores services without a KO streak
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
def test_confirmation_cron_ignores_unflagged_services(self):
|
|
||||||
with patch(SERVICE_INSTANCE_REQUESTS) as mock_requests:
|
|
||||||
mock_requests.get.return_value = _mock_response(200)
|
|
||||||
mock_requests.exceptions.RequestException = Exception
|
|
||||||
self.env["service.instance"].cron_confirm_http_ko_services()
|
|
||||||
|
|
||||||
mock_requests.get.assert_not_called()
|
|
||||||
self.assertFalse(self.service_instance.http_maintenance_request)
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
# Test 18 -- Confirmation cron does not create a request before
|
|
||||||
# HTTP_KO_CONFIRMATION_DELAY has elapsed
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
def test_confirmation_cron_waits_for_confirmation_delay(self):
|
|
||||||
with patch(SERVICE_INSTANCE_REQUESTS) as mock_requests:
|
|
||||||
mock_requests.get.return_value = _mock_response(500)
|
|
||||||
mock_requests.exceptions.RequestException = Exception
|
|
||||||
self.env["service.instance"].cron_check_http_services()
|
|
||||||
|
|
||||||
self.assertTrue(self.service_instance.http_first_ko_at)
|
|
||||||
|
|
||||||
with patch(SERVICE_INSTANCE_REQUESTS) as mock_requests:
|
|
||||||
mock_requests.get.return_value = _mock_response(500)
|
|
||||||
mock_requests.exceptions.RequestException = Exception
|
|
||||||
self.env["service.instance"].cron_confirm_http_ko_services()
|
|
||||||
|
|
||||||
self.assertFalse(self.service_instance.http_maintenance_request)
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
# Test 19 -- Confirmation cron ignores services whose equipment is in
|
|
||||||
# maintenance mode
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
def test_confirmation_cron_skips_maintenance_mode(self):
|
|
||||||
with patch(SERVICE_INSTANCE_REQUESTS) as mock_requests:
|
|
||||||
mock_requests.get.return_value = _mock_response(500)
|
|
||||||
mock_requests.exceptions.RequestException = Exception
|
|
||||||
self.env["service.instance"].cron_check_http_services()
|
|
||||||
|
|
||||||
self.assertTrue(self.service_instance.http_first_ko_at)
|
|
||||||
self.equipment.write({"maintenance_mode": True})
|
|
||||||
|
|
||||||
with patch(SERVICE_INSTANCE_REQUESTS) as mock_requests:
|
|
||||||
mock_requests.get.return_value = _mock_response(500)
|
|
||||||
mock_requests.exceptions.RequestException = Exception
|
|
||||||
self.env["service.instance"].cron_confirm_http_ko_services()
|
|
||||||
|
|
||||||
mock_requests.get.assert_not_called()
|
|
||||||
self.assertFalse(self.service_instance.http_maintenance_request)
|
|
||||||
@@ -1,53 +1,41 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<odoo>
|
<odoo>
|
||||||
<record id="view_equipment_form_http_monitoring" model="ir.ui.view">
|
<record id="view_equipment_form_http_monitoring" model="ir.ui.view">
|
||||||
<field name="name">maintenance.equipment.form.http.monitoring</field>
|
<field name="name">maintenance.equipment.form.http.monitoring</field>
|
||||||
<field name="model">maintenance.equipment</field>
|
<field name="model">maintenance.equipment</field>
|
||||||
<field name="inherit_id" ref="maintenance.hr_equipment_view_form" />
|
<field name="inherit_id" ref="maintenance.hr_equipment_view_form"/>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<xpath expr="//sheet" position="before">
|
<xpath expr="//sheet" position="before">
|
||||||
<div
|
<div class="alert alert-warning" role="alert" attrs="{'invisible': [('maintenance_mode', '=', False)]}">
|
||||||
class="alert alert-warning"
|
Mode maintenance actif — Vérifications HTTP désactivées.<br/>
|
||||||
role="alert"
|
Fin prévue : <field name="maintenance_mode_end" readonly="1"/>
|
||||||
invisible="not maintenance_mode"
|
|
||||||
>
|
|
||||||
Mode maintenance actif — Vérifications HTTP désactivées.<br />
|
|
||||||
Fin prévue : <field name="maintenance_mode_end" readonly="1" />
|
|
||||||
</div>
|
</div>
|
||||||
</xpath>
|
</xpath>
|
||||||
<xpath expr="//header" position="inside">
|
<xpath expr="//header" position="inside">
|
||||||
<button
|
<button name="action_activate_maintenance_mode" type="object" string="Activer le mode maintenance"
|
||||||
name="action_activate_maintenance_mode"
|
attrs="{'invisible': [('maintenance_mode', '=', True)]}" class="oe_highlight"/>
|
||||||
type="object"
|
<button name="action_deactivate_maintenance_mode" type="object" string="Désactiver le mode maintenance"
|
||||||
string="Activer le mode maintenance"
|
attrs="{'invisible': [('maintenance_mode', '=', False)]}"/>
|
||||||
invisible="maintenance_mode"
|
|
||||||
class="oe_highlight"
|
|
||||||
/>
|
|
||||||
<button
|
|
||||||
name="action_deactivate_maintenance_mode"
|
|
||||||
type="object"
|
|
||||||
string="Désactiver le mode maintenance"
|
|
||||||
invisible="not maintenance_mode"
|
|
||||||
/>
|
|
||||||
</xpath>
|
</xpath>
|
||||||
<xpath expr="//notebook" position="inside">
|
<xpath expr="//notebook" position="inside">
|
||||||
<page string="HTTP Monitoring">
|
<page string="HTTP Monitoring">
|
||||||
<group>
|
<group>
|
||||||
<field name="maintenance_mode" />
|
<field name="maintenance_mode"/>
|
||||||
<field name="maintenance_mode_start" />
|
<field name="maintenance_mode_start"/>
|
||||||
<field name="maintenance_mode_end" />
|
<field name="maintenance_mode_end"/>
|
||||||
|
<field name="http_maintenance_request" readonly="1"/>
|
||||||
</group>
|
</group>
|
||||||
</page>
|
</page>
|
||||||
</xpath>
|
</xpath>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
<record id="view_equipment_tree_http_monitoring" model="ir.ui.view">
|
<record id="view_equipment_tree_http_monitoring" model="ir.ui.view">
|
||||||
<field name="name">maintenance.equipment.list.http.monitoring</field>
|
<field name="name">maintenance.equipment.tree.http.monitoring</field>
|
||||||
<field name="model">maintenance.equipment</field>
|
<field name="model">maintenance.equipment</field>
|
||||||
<field name="inherit_id" ref="maintenance.hr_equipment_view_tree" />
|
<field name="inherit_id" ref="maintenance.hr_equipment_view_tree"/>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<xpath expr="//list" position="inside">
|
<xpath expr="//tree" position="inside">
|
||||||
<field name="maintenance_mode" optional="hide" />
|
<field name="maintenance_mode" optional="hide"/>
|
||||||
</xpath>
|
</xpath>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|||||||
@@ -1,24 +1,19 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<odoo>
|
<odoo>
|
||||||
<!-- Inherit from base list view to add HTTP monitoring fields -->
|
<!-- Inherit from base tree view to add HTTP monitoring fields -->
|
||||||
<record id="service_instance_http_monitoring_tree" model="ir.ui.view">
|
<record id="service_instance_http_monitoring_tree" model="ir.ui.view">
|
||||||
<field name="name">service.instance.http.monitoring.list</field>
|
<field name="name">service.instance.http.monitoring.tree</field>
|
||||||
<field name="model">service.instance</field>
|
<field name="model">service.instance</field>
|
||||||
<field
|
<field name="inherit_id" ref="maintenance_server_data.service_instance_view_tree"/>
|
||||||
name="inherit_id"
|
|
||||||
ref="maintenance_server_data.service_instance_view_tree"
|
|
||||||
/>
|
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<list position="attributes">
|
<tree position="attributes">
|
||||||
<attribute name="decoration-danger">http_status_ok == False</attribute>
|
<attribute name="decoration-danger">http_status_ok == False</attribute>
|
||||||
</list>
|
</tree>
|
||||||
<field name="version_id" position="after">
|
<field name="version_id" position="after">
|
||||||
<field name="service_url" />
|
<field name="service_url"/>
|
||||||
<field name="last_http_check_date" />
|
<field name="last_http_check_date"/>
|
||||||
<field name="last_http_status_code" />
|
<field name="last_http_status_code"/>
|
||||||
<field name="http_status_ok" />
|
<field name="http_status_ok"/>
|
||||||
<field name="http_maintenance_request" optional="hide" />
|
|
||||||
<field name="http_first_ko_at" optional="hide" />
|
|
||||||
</field>
|
</field>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
@@ -27,33 +22,18 @@
|
|||||||
<record id="service_instance_http_monitoring_search" model="ir.ui.view">
|
<record id="service_instance_http_monitoring_search" model="ir.ui.view">
|
||||||
<field name="name">service.instance.http.monitoring.search</field>
|
<field name="name">service.instance.http.monitoring.search</field>
|
||||||
<field name="model">service.instance</field>
|
<field name="model">service.instance</field>
|
||||||
<field
|
<field name="inherit_id" ref="maintenance_server_data.service_instance_view_search"/>
|
||||||
name="inherit_id"
|
|
||||||
ref="maintenance_server_data.service_instance_view_search"
|
|
||||||
/>
|
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<field name="service_url" position="after">
|
<field name="service_url" position="after">
|
||||||
<field name="last_http_status_code" string="Status Code" />
|
<field name="last_http_status_code" string="Status Code"/>
|
||||||
</field>
|
</field>
|
||||||
<filter name="inactive" position="before">
|
<filter name="inactive" position="before">
|
||||||
<filter
|
<filter string="Status OK" name="status_ok" domain="[('http_status_ok', '=', True)]"/>
|
||||||
string="Status OK"
|
<filter string="Status Error" name="status_error" domain="[('http_status_ok', '=', False)]"/>
|
||||||
name="status_ok"
|
<separator/>
|
||||||
domain="[('http_status_ok', '=', True)]"
|
|
||||||
/>
|
|
||||||
<filter
|
|
||||||
string="Status Error"
|
|
||||||
name="status_error"
|
|
||||||
domain="[('http_status_ok', '=', False)]"
|
|
||||||
/>
|
|
||||||
<separator />
|
|
||||||
</filter>
|
</filter>
|
||||||
<filter name="group_version" position="after">
|
<filter name="group_version" position="after">
|
||||||
<filter
|
<filter string="Status Code" name="group_status_code" context="{'group_by': 'last_http_status_code'}"/>
|
||||||
string="Status Code"
|
|
||||||
name="group_status_code"
|
|
||||||
context="{'group_by': 'last_http_status_code'}"
|
|
||||||
/>
|
|
||||||
</filter>
|
</filter>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|||||||
@@ -1,63 +0,0 @@
|
|||||||
==============================
|
|
||||||
maintenance_user_ssh_key
|
|
||||||
==============================
|
|
||||||
|
|
||||||
This module adds SSH key management to Odoo users. It introduces a new
|
|
||||||
``ssh.key`` model and a ``ssh_key_ids`` One2many field on ``res.users``.
|
|
||||||
|
|
||||||
It allows administrators to associate SSH public keys with each user for
|
|
||||||
authentication purposes (e.g., remote server access, deployment).
|
|
||||||
|
|
||||||
Features:
|
|
||||||
|
|
||||||
- **SSH Key model**: Store public keys per user.
|
|
||||||
- **User integration**: SSH keys are displayed and editable directly on the
|
|
||||||
user form view.
|
|
||||||
- **Access control**: All internal users can view SSH keys; only users with
|
|
||||||
``Settings / Administration`` rights can create, edit, or delete them.
|
|
||||||
|
|
||||||
# Installation
|
|
||||||
|
|
||||||
Use Odoo normal module installation procedure to install
|
|
||||||
``maintenance_user_ssh_key``.
|
|
||||||
|
|
||||||
This module depends on ``base`` and requires no external Python dependencies.
|
|
||||||
|
|
||||||
# Configuration
|
|
||||||
|
|
||||||
No specific configuration is required. After installation:
|
|
||||||
|
|
||||||
1. Go to *Settings > Users & Companies > Users*.
|
|
||||||
2. Open any user and navigate to the **SSH Keys** notebook page.
|
|
||||||
3. Add SSH keys with the public key content.
|
|
||||||
|
|
||||||
# Usage
|
|
||||||
|
|
||||||
## Managing SSH Keys
|
|
||||||
|
|
||||||
- Open a user form and go to the *SSH Keys* tab.
|
|
||||||
- Click **Add a line** and paste the public key content.
|
|
||||||
|
|
||||||
# Bug Tracker
|
|
||||||
|
|
||||||
Bugs are tracked on
|
|
||||||
`our issues website <https://git.elabore.coop/Elabore/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.
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
from . import models
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
# Copyright 2026 Stéphan Sainléger (Elabore)
|
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
|
||||||
|
|
||||||
{
|
|
||||||
"name": "maintenance_user_ssh_key",
|
|
||||||
"version": "18.0.1.0.0",
|
|
||||||
"author": "Elabore",
|
|
||||||
"website": "https://git.elabore.coop/elabore/maintenance-tools",
|
|
||||||
"maintainer": "Stéphan Sainléger",
|
|
||||||
"license": "AGPL-3",
|
|
||||||
"category": "Tools",
|
|
||||||
"summary": "Manage SSH keys per user.",
|
|
||||||
"depends": ["base"],
|
|
||||||
"data": [
|
|
||||||
"security/ir.model.access.csv",
|
|
||||||
"views/ssh_key_views.xml",
|
|
||||||
"views/res_users_views.xml",
|
|
||||||
],
|
|
||||||
"installable": True,
|
|
||||||
"auto_install": False,
|
|
||||||
"application": False,
|
|
||||||
}
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
from . import ssh_key
|
|
||||||
from . import res_users
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
# Copyright 2026 Stéphan Sainléger (Elabore)
|
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
|
||||||
|
|
||||||
from odoo import fields, models
|
|
||||||
|
|
||||||
|
|
||||||
class ResUsers(models.Model):
|
|
||||||
_inherit = "res.users"
|
|
||||||
|
|
||||||
ssh_key_ids = fields.One2many(
|
|
||||||
comodel_name="ssh.key",
|
|
||||||
inverse_name="user_id",
|
|
||||||
string="SSH Keys",
|
|
||||||
)
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
# Copyright 2026 Stéphan Sainléger (Elabore)
|
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
|
||||||
|
|
||||||
from odoo import fields, models
|
|
||||||
|
|
||||||
|
|
||||||
class SshKey(models.Model):
|
|
||||||
_name = "ssh.key"
|
|
||||||
_description = "SSH Key"
|
|
||||||
|
|
||||||
key = fields.Text(string="Public Key", required=True)
|
|
||||||
user_id = fields.Many2one(
|
|
||||||
comodel_name="res.users",
|
|
||||||
string="User",
|
|
||||||
required=True,
|
|
||||||
ondelete="cascade",
|
|
||||||
index=True,
|
|
||||||
)
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink
|
|
||||||
access_ssh_key_user,ssh.key.user,model_ssh_key,base.group_user,1,0,0,0
|
|
||||||
access_ssh_key_manager,ssh.key.manager,model_ssh_key,base.group_system,1,1,1,1
|
|
||||||
|
@@ -1,21 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
|
||||||
<odoo>
|
|
||||||
|
|
||||||
<record id="view_users_form_ssh_key_inherit" model="ir.ui.view">
|
|
||||||
<field name="name">res.users.form.ssh.key</field>
|
|
||||||
<field name="model">res.users</field>
|
|
||||||
<field name="inherit_id" ref="base.view_users_form"/>
|
|
||||||
<field name="arch" type="xml">
|
|
||||||
<xpath expr="//notebook" position="inside">
|
|
||||||
<page string="SSH Keys" name="ssh_keys">
|
|
||||||
<field name="ssh_key_ids">
|
|
||||||
<list editable="top">
|
|
||||||
<field name="key"/>
|
|
||||||
</list>
|
|
||||||
</field>
|
|
||||||
</page>
|
|
||||||
</xpath>
|
|
||||||
</field>
|
|
||||||
</record>
|
|
||||||
|
|
||||||
</odoo>
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
|
||||||
<odoo>
|
|
||||||
|
|
||||||
<record id="ssh_key_view_tree" model="ir.ui.view">
|
|
||||||
<field name="name">ssh.key.tree</field>
|
|
||||||
<field name="model">ssh.key</field>
|
|
||||||
<field name="arch" type="xml">
|
|
||||||
<list editable="top">
|
|
||||||
<field name="key"/>
|
|
||||||
<field name="user_id"/>
|
|
||||||
</list>
|
|
||||||
</field>
|
|
||||||
</record>
|
|
||||||
|
|
||||||
<record id="ssh_key_view_form" model="ir.ui.view">
|
|
||||||
<field name="name">ssh.key.form</field>
|
|
||||||
<field name="model">ssh.key</field>
|
|
||||||
<field name="arch" type="xml">
|
|
||||||
<form>
|
|
||||||
<sheet>
|
|
||||||
<group>
|
|
||||||
<field name="user_id"/>
|
|
||||||
</group>
|
|
||||||
<group>
|
|
||||||
<field name="key" nolabel="1"/>
|
|
||||||
</group>
|
|
||||||
</sheet>
|
|
||||||
</form>
|
|
||||||
</field>
|
|
||||||
</record>
|
|
||||||
|
|
||||||
<record id="ssh_key_action" model="ir.actions.act_window">
|
|
||||||
<field name="name">SSH Keys</field>
|
|
||||||
<field name="res_model">ssh.key</field>
|
|
||||||
<field name="view_mode">list,form</field>
|
|
||||||
</record>
|
|
||||||
|
|
||||||
<menuitem
|
|
||||||
id="menu_ssh_key"
|
|
||||||
action="ssh_key_action"
|
|
||||||
parent="base.menu_security"
|
|
||||||
sequence="50"/>
|
|
||||||
|
|
||||||
</odoo>
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
/** @type {import('prettier').Config} */
|
|
||||||
|
|
||||||
const config = {
|
|
||||||
// https://github.com/prettier/prettier/issues/15388#issuecomment-1717746872
|
|
||||||
plugins: [require.resolve("@prettier/plugin-xml")],
|
|
||||||
bracketSpacing: false,
|
|
||||||
printWidth: 88,
|
|
||||||
proseWrap: "always",
|
|
||||||
semi: true,
|
|
||||||
trailingComma: "es5",
|
|
||||||
xmlWhitespaceSensitivity: "preserve",
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = config;
|
|
||||||
Reference in New Issue
Block a user