node check: prevent WARNING in --downstream --nagios output

This commit is contained in:
Ian Barwick
2022-04-20 17:45:00 +09:00
parent bb63fb08d0
commit 2756d6fd94
3 changed files with 29 additions and 8 deletions

View File

@@ -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 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 * This provides a standardized way of logging database errors. Note
* that the provided PGconn can be a normal or a replication connection; * 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 NodeAttached
is_downstream_node_attached(PGconn *conn, char *node_name, char **node_state) 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; PQExpBufferData query;
PGresult *res = NULL; PGresult *res = NULL;
@@ -5826,9 +5841,12 @@ is_downstream_node_attached(PGconn *conn, char *node_name, char **node_state)
*/ */
if (PQntuples(res) > 1) if (PQntuples(res) > 1)
{ {
log_error(_("multiple entries with \"application_name\" set to \"%s\" found in \"pg_stat_replication\""), if (quiet == false)
node_name); {
log_hint(_("verify that a unique node name is configured for each node")); 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); PQclear(res);
@@ -5837,7 +5855,8 @@ is_downstream_node_attached(PGconn *conn, char *node_name, char **node_state)
if (PQntuples(res) == 0) 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); PQclear(res);
@@ -5863,9 +5882,10 @@ is_downstream_node_attached(PGconn *conn, char *node_name, char **node_state)
if (strcmp(state, "streaming") != 0) if (strcmp(state, "streaming") != 0)
{ {
log_warning(_("node \"%s\" attached in state \"%s\""), if (quiet == false)
node_name, log_warning(_("node \"%s\" attached in state \"%s\""),
state); node_name,
state);
PQclear(res); PQclear(res);

View File

@@ -597,6 +597,7 @@ int get_replication_lag_seconds(PGconn *conn);
TimeLineID get_node_timeline(PGconn *conn, char *timeline_id_str); TimeLineID get_node_timeline(PGconn *conn, char *timeline_id_str);
void get_node_replication_stats(PGconn *conn, t_node_info *node_info); 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(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); void set_upstream_last_seen(PGconn *conn, int upstream_node_id);
int get_upstream_last_seen(PGconn *conn, t_server_type node_type); int get_upstream_last_seen(PGconn *conn, t_server_type node_type);

View File

@@ -1327,7 +1327,7 @@ do_node_check_downstream(PGconn *conn, OutputMode mode, t_node_info *node_info,
continue; 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++; missing_nodes_count++;
item_list_append_format(&missing_nodes, item_list_append_format(&missing_nodes,