From 2756d6fd9450ed076bd6772925a1bb790eda58d7 Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Wed, 20 Apr 2022 17:45:00 +0900 Subject: [PATCH] node check: prevent WARNING in --downstream --nagios output --- dbutils.c | 34 +++++++++++++++++++++++++++------- dbutils.h | 1 + repmgr-action-node.c | 2 +- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/dbutils.c b/dbutils.c index 22ab1b85..4806c497 100644 --- a/dbutils.c +++ b/dbutils.c @@ -61,6 +61,8 @@ static ReplSlotStatus _verify_replication_slot(PGconn *conn, char *slot_name, PQ static bool _create_event(PGconn *conn, t_configuration_options *options, int node_id, char *event, bool successful, char *details, t_event_info *event_info, bool send_notification); +static NodeAttached _is_downstream_node_attached(PGconn *conn, char *node_name, char **node_state, bool quiet); + /* * This provides a standardized way of logging database errors. Note * that the provided PGconn can be a normal or a replication connection; @@ -5792,6 +5794,19 @@ get_node_replication_stats(PGconn *conn, t_node_info *node_info) NodeAttached is_downstream_node_attached(PGconn *conn, char *node_name, char **node_state) { + return _is_downstream_node_attached(conn, node_name, node_state, false); +} + +NodeAttached +is_downstream_node_attached_quiet(PGconn *conn, char *node_name, char **node_state) +{ + return _is_downstream_node_attached(conn, node_name, node_state, true); +} + +NodeAttached +_is_downstream_node_attached(PGconn *conn, char *node_name, char **node_state, bool quiet) +{ + PQExpBufferData query; PGresult *res = NULL; @@ -5826,9 +5841,12 @@ is_downstream_node_attached(PGconn *conn, char *node_name, char **node_state) */ if (PQntuples(res) > 1) { - log_error(_("multiple entries with \"application_name\" set to \"%s\" found in \"pg_stat_replication\""), - node_name); - log_hint(_("verify that a unique node name is configured for each node")); + if (quiet == false) + { + log_error(_("multiple entries with \"application_name\" set to \"%s\" found in \"pg_stat_replication\""), + node_name); + log_hint(_("verify that a unique node name is configured for each node")); + } PQclear(res); @@ -5837,7 +5855,8 @@ is_downstream_node_attached(PGconn *conn, char *node_name, char **node_state) if (PQntuples(res) == 0) { - log_warning(_("node \"%s\" not found in \"pg_stat_replication\""), node_name); + if (quiet == false) + log_warning(_("node \"%s\" not found in \"pg_stat_replication\""), node_name); PQclear(res); @@ -5863,9 +5882,10 @@ is_downstream_node_attached(PGconn *conn, char *node_name, char **node_state) if (strcmp(state, "streaming") != 0) { - log_warning(_("node \"%s\" attached in state \"%s\""), - node_name, - state); + if (quiet == false) + log_warning(_("node \"%s\" attached in state \"%s\""), + node_name, + state); PQclear(res); diff --git a/dbutils.h b/dbutils.h index e2783cea..f5ee6ab1 100644 --- a/dbutils.h +++ b/dbutils.h @@ -597,6 +597,7 @@ int get_replication_lag_seconds(PGconn *conn); TimeLineID get_node_timeline(PGconn *conn, char *timeline_id_str); void get_node_replication_stats(PGconn *conn, t_node_info *node_info); NodeAttached is_downstream_node_attached(PGconn *conn, char *node_name, char **node_state); +NodeAttached is_downstream_node_attached_quiet(PGconn *conn, char *node_name, char **node_state); void set_upstream_last_seen(PGconn *conn, int upstream_node_id); int get_upstream_last_seen(PGconn *conn, t_server_type node_type); diff --git a/repmgr-action-node.c b/repmgr-action-node.c index fcbab0b3..ac476172 100644 --- a/repmgr-action-node.c +++ b/repmgr-action-node.c @@ -1327,7 +1327,7 @@ do_node_check_downstream(PGconn *conn, OutputMode mode, t_node_info *node_info, continue; } - if (is_downstream_node_attached(conn, cell->node_info->node_name, NULL) != NODE_ATTACHED) + if (is_downstream_node_attached_quiet(conn, cell->node_info->node_name, NULL) != NODE_ATTACHED) { missing_nodes_count++; item_list_append_format(&missing_nodes,