Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F3772802
D3290.id8475.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
5 KB
Referenced Files
None
Subscribers
None
D3290.id8475.diff
View Options
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,39 @@
+# -------------------------------------------------------------
+# Salt — Database server — PostgreSQL
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+# Project: Nasqueron
+# License: Trivial work, not eligible to copyright
+# -------------------------------------------------------------
+
+{% from "map.jinja" import packages_prefixes with context %}
+
+{% 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
Details
Attached
Mime Type
text/plain
Expires
Mon, Nov 25, 04:57 (21 h, 18 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2261880
Default Alt Text
D3290.id8475.diff (5 KB)
Attached To
Mode
D3290: Ensure PostgreSQL port is still up-to-date on FreeBSD
Attached
Detach File
Event Timeline
Log In to Comment