Add daemon PostgreSQL notify action

This commit is contained in:
Lyncoln
2026-09-17 16:19:26 -04:00
parent 6e00e80c5e
commit 972232332f
3 changed files with 145 additions and 1 deletions
+4 -1
View File
@@ -2,7 +2,10 @@
"name": "postgresql",
"version": 3,
"module": "plugin.py",
"actions": ["monitor"],
"actions": [
"monitor",
"notify"
],
"required_config": [
"PGHOST",
"PGPORT",
+55
View File
@@ -380,3 +380,58 @@ def monitor(config, runtime_state):
finally:
conn.close()
NOTIFY_FIELDS = (
"type",
"operation",
"promote_uname",
"demote_uname",
"promoted_uname",
"unpromoted_uname",
)
def _notify_value(parameters, field):
value = parameters.get(field, "")
if not isinstance(value, str):
raise ValueError(
f"notify field {field} must be a string"
)
if any(char in value for char in ("\n", "\r", "\x00")):
raise ValueError(
f"notify field {field} contains invalid characters"
)
return value.strip()
def notify(config, runtime_state, request_parameters):
"""
Record Pacemaker notification metadata in daemon runtime state.
The daemon remains the local authority for this resource instance.
Node-target interpretation is deliberately deferred until the state
persistence and demotion action are migrated together.
"""
if not isinstance(request_parameters, dict):
raise ValueError(
"notify parameters must be a JSON object"
)
state = {
field: _notify_value(request_parameters, field)
for field in NOTIFY_FIELDS
}
state["received_at"] = time.time()
postgresql_state = _postgres_runtime_state(runtime_state)
postgresql_state["notification"] = state
return {
"ocf_rc": OCF_SUCCESS,
"state": dict(state),
}