Page MenuHomeDevCentral

D3290.id8471.diff
No OneTemporary

D3290.id8471.diff

diff --git a/roles/dbserver-pgsql/init.sls b/roles/dbserver-pgsql/init.sls
--- a/roles/dbserver-pgsql/init.sls
+++ b/roles/dbserver-pgsql/init.sls
@@ -7,3 +7,4 @@
include:
- .server
+ - .monitoring
diff --git a/roles/dbserver-pgsql/monitoring/files/check-postgresql-dependencies.py b/roles/dbserver-pgsql/monitoring/files/check-postgresql-dependencies.py
new file mode 100755
--- /dev/null
+++ b/roles/dbserver-pgsql/monitoring/files/check-postgresql-dependencies.py
@@ -0,0 +1,68 @@
+#!/usr/bin/env python3
+
+# -------------------------------------------------------------
+# Monitoring :: PostgreSQL :: Dynamic dependencies
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+# Project: Nasqueron
+# Description: Checks if the PostgreSQL port needs to be rebuild
+# if dependencies have been upgraded.
+# License: BSD-2-Clause
+# -------------------------------------------------------------
+
+
+import distutils.spawn
+import lddcollect
+import sys
+
+
+# -------------------------------------------------------------
+# Dependencies
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+
+def get_libs_real_paths(process):
+ dependencies = lddcollect.lddtree(process)
+
+ return {lib: lib_info["realpath"] for lib, lib_info in dependencies["libs"].items()}
+
+
+def get_missing_libs(process):
+ libs = get_libs_real_paths(process)
+
+ return [lib for lib, path in libs.items() if path is None]
+
+
+# -------------------------------------------------------------
+# PostgreSQL locator
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+
+def find_postgres():
+ return distutils.spawn.find_executable("postgres")
+
+
+# -------------------------------------------------------------
+# Application entry point
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+
+def run():
+ process = find_postgres()
+ if process is None:
+ print("UNKNOWN: can't find expected postgres process")
+ sys.exit(3)
+
+ missing_libs = get_missing_libs(process)
+ if not missing_libs:
+ print("OK")
+ sys.exit(0)
+
+ libs = " / ".join(missing_libs)
+ print(
+ f"ERROR: {libs} are missing, PostgreSQL port MUST be rebuilt as soon as possible."
+ )
+ sys.exit(2)
+
+
+if __name__ == "__main__":
+ run()
diff --git a/roles/dbserver-pgsql/monitoring/files/check-postgresql-xml-support.py b/roles/dbserver-pgsql/monitoring/files/check-postgresql-xml-support.py
new file mode 100755
--- /dev/null
+++ b/roles/dbserver-pgsql/monitoring/files/check-postgresql-xml-support.py
@@ -0,0 +1,60 @@
+#!/usr/bin/env python3
+
+# -------------------------------------------------------------
+# Monitoring :: PostgreSQL :: XML support
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+# Project: Nasqueron
+# Description: Checks if the PostgreSQL process has XML support
+# License: BSD-2-Clause
+# -------------------------------------------------------------
+
+
+import distutils.spawn
+import lddcollect
+import sys
+
+
+# -------------------------------------------------------------
+# Dependencies
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+
+def has_lib(process, needed_lib):
+ dependencies = lddcollect.lddtree(process)
+
+ return any(lib.startswith(needed_lib) for lib in dependencies["needed"])
+
+
+# -------------------------------------------------------------
+# PostgreSQL locator
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+
+def find_postgres():
+ return distutils.spawn.find_executable("postgres")
+
+
+# -------------------------------------------------------------
+# Application entry point
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+
+def run():
+ process = find_postgres()
+ if process is None:
+ print("UNKNOWN: can't find expected postgres process")
+ sys.exit(3)
+
+ is_built_against_libxml = has_lib(process, "libxml2.so")
+ if is_built_against_libxml:
+ print("OK")
+ sys.exit(0)
+
+ print(
+ "ERROR: PostgreSQL has no XML support through libxml2, PostgreSQL port MUST be rebuilt as soon as possible."
+ )
+ sys.exit(2)
+
+
+if __name__ == "__main__":
+ run()
diff --git a/roles/dbserver-pgsql/monitoring/init.sls b/roles/dbserver-pgsql/monitoring/init.sls
new file mode 100644
--- /dev/null
+++ b/roles/dbserver-pgsql/monitoring/init.sls
@@ -0,0 +1,37 @@
+# -------------------------------------------------------------
+# Salt — Database server — PostgreSQL
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+# Project: Nasqueron
+# License: Trivial work, not eligible to copyright
+# -------------------------------------------------------------
+
+{% if grains["os"] == "FreeBSD" %}
+
+# -------------------------------------------------------------
+# Python dependencies for checks
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+postgresql_monitoring_dependencies:
+ pkg.installed:
+ - pkgs:
+ - {{ packages_prefixes.python3 }}pip
+ pip.installed:
+ - name: lddcollect
+ - require:
+ - pkg: postgresql_monitoring_dependencies
+
+# -------------------------------------------------------------
+# PostgreSQL checks
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+/usr/local/bin/check-postgresql-dependencies:
+ file.managed:
+ - source: salt://roles/dbserver-pgsql/monitoring/files/check-postgresql-dependencies.py
+ - mode: 755
+
+/usr/local/bin/check-postgresql-xml-support:
+ file.managed:
+ - source: salt://roles/dbserver-pgsql/monitoring/files/check-postgresql-xml-support.py
+ - mode: 755
+
+{% endif %}

File Metadata

Mime Type
text/plain
Expires
Mon, Nov 25, 03:41 (20 h, 46 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2261700
Default Alt Text
D3290.id8471.diff (5 KB)

Event Timeline