From 6f4d8059941bc591ed2b36e0fbd84fa08bb15c1b Mon Sep 17 00:00:00 2001 From: dmius Date: Wed, 9 Oct 2019 16:27:49 +0300 Subject: [PATCH 1/3] Create new nodes.json for new epoch --- checkup | 84 ++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 56 insertions(+), 28 deletions(-) diff --git a/checkup b/checkup index 294782d..7799a9f 100755 --- a/checkup +++ b/checkup @@ -979,6 +979,29 @@ host_pre_start_checks() { dbg "_PSQL_NO_TIMEOUT: '${_PSQL_NO_TIMEOUT}'" } +####################################### +# Prepare to create new 'nodes.json' in the project dir +# Fill/update hostname, role, internal alias +# Start/update 'epoch' of the check +# Globals: +# PROJECT_DIR, +# ALIAS_NAME, ALIAS_INDEX, ROLE, JSON_REPORTS_DIR +# TIMESTAMP_DIR, SHORT_DIR_NAME, +# MD_REPORTS_DIR +# Arguments: +# None +# Returns: +# None +####################################### +init_nodes_json() { + ALIAS_NAME="node1" + ALIAS_INDEX="1" + prev_role="${ROLE}" + JSON_REPORTS_DIR="${PROJECT_DIR}/json_reports/${EPOCH}_${TIMESTAMP_DIR}" + MD_REPORTS_DIR="${PROJECT_DIR}/md_reports/${EPOCH}_${TIMESTAMP_DIR}" + SHORT_DIR_NAME="${EPOCH}_${TIMESTAMP_DIR}" +} + ####################################### # Update/create 'nodes.json' in the project dir # Fill/update hostname, role, internal alias @@ -1012,12 +1035,7 @@ update_nodes_json() { # if file 'nodes.json' does not exist generate alias for a first host if [[ ! -f "${PROJECT_DIR}/nodes.json" ]]; then - ALIAS_NAME="node1" - ALIAS_INDEX="1" - prev_role="${ROLE}" - JSON_REPORTS_DIR="${PROJECT_DIR}/json_reports/${EPOCH}_${TIMESTAMP_DIR}" - MD_REPORTS_DIR="${PROJECT_DIR}/md_reports/${EPOCH}_${TIMESTAMP_DIR}" - SHORT_DIR_NAME="${EPOCH}_${TIMESTAMP_DIR}" + init_nodes_json; local input_json_fname="${SCRIPT_DIR}/resources/templates/nodes.json" @@ -1032,34 +1050,44 @@ update_nodes_json() { exit 1 fi - # read current nodes.json - ALIAS_NAME=$(jq -r '.hosts.'\"${HOST}\"'.internal_alias' "${PROJECT_DIR}/nodes.json") + prev_epoch=$(jq -r '.last_check.epoch' "${PROJECT_DIR}/nodes.json") + prev_timestamp_dirname=$(jq -r '.last_check.dir' "${PROJECT_DIR}/nodes.json") + if [[ "${prev_epoch}" != "${EPOCH}" ]]; then + # New epoch + # Backup nodes.json and remove + mv "${PROJECT_DIR}/nodes.json" "${PROJECT_DIR}/${prev_timestamp_dirname}_nodes.json" + init_nodes_json; + + local input_json_fname="${SCRIPT_DIR}/resources/templates/nodes.json" + else + # read current nodes.json + ALIAS_NAME=$(jq -r '.hosts.'\"${HOST}\"'.internal_alias' "${PROJECT_DIR}/nodes.json") - # mark host as new if we can't find alias by path with HOST - if [[ "${ALIAS_NAME}" = "null" ]]; then - host_is_new="true" - dbg "host '${HOST}' is a new host" - fi + # mark host as new if we can't find alias by path with HOST + if [[ "${ALIAS_NAME}" = "null" ]]; then + host_is_new="true" + dbg "host '${HOST}' is a new host" + fi - ALIAS_INDEX=$(jq -r '.hosts.'\"${HOST}\"'.index' "${PROJECT_DIR}/nodes.json") - prev_role=$(jq -r '.hosts.'\"${HOST}\"'.role' "${PROJECT_DIR}/nodes.json") - prev_epoch=$(jq -r '.last_check.epoch' "${PROJECT_DIR}/nodes.json") + ALIAS_INDEX=$(jq -r '.hosts.'\"${HOST}\"'.index' "${PROJECT_DIR}/nodes.json") + prev_role=$(jq -r '.hosts.'\"${HOST}\"'.role' "${PROJECT_DIR}/nodes.json") - # create a new epoch dirs or use existing - if test -d "${PROJECT_DIR}/json_reports/${EPOCH}"_*/../; then - SHORT_DIR_NAME=$(find "${PROJECT_DIR}/json_reports/" -type d -name ${EPOCH}_*) - SHORT_DIR_NAME=$(basename "${SHORT_DIR_NAME}") - JSON_REPORTS_DIR="${PROJECT_DIR}/json_reports/${SHORT_DIR_NAME}" + # create a new epoch dirs or use existing + if test -d "${PROJECT_DIR}/json_reports/${EPOCH}"_*/../; then + SHORT_DIR_NAME=$(find "${PROJECT_DIR}/json_reports/" -type d -name ${EPOCH}_*) + SHORT_DIR_NAME=$(basename "${SHORT_DIR_NAME}") + JSON_REPORTS_DIR="${PROJECT_DIR}/json_reports/${SHORT_DIR_NAME}" - MD_REPORTS_DIR="${PROJECT_DIR}/md_reports/${SHORT_DIR_NAME}" - else - SHORT_DIR_NAME="${EPOCH}_${TIMESTAMP_DIR}" - JSON_REPORTS_DIR="${PROJECT_DIR}/json_reports/${SHORT_DIR_NAME}" + MD_REPORTS_DIR="${PROJECT_DIR}/md_reports/${SHORT_DIR_NAME}" + else + SHORT_DIR_NAME="${EPOCH}_${TIMESTAMP_DIR}" + JSON_REPORTS_DIR="${PROJECT_DIR}/json_reports/${SHORT_DIR_NAME}" - MD_REPORTS_DIR="${PROJECT_DIR}/md_reports/${SHORT_DIR_NAME}" - fi + MD_REPORTS_DIR="${PROJECT_DIR}/md_reports/${SHORT_DIR_NAME}" + fi - local input_json_fname="${PROJECT_DIR}/nodes.json" + local input_json_fname="${PROJECT_DIR}/nodes.json" + fi fi export JSON_REPORTS_DIR MD_REPORTS_DIR SHORT_DIR_NAME -- GitLab From f55aed962e14dffa4ed2499c46950d6390540875 Mon Sep 17 00:00:00 2001 From: dmius Date: Wed, 9 Oct 2019 21:29:45 +0300 Subject: [PATCH 2/3] Fix database name and epoch in title of full report --- checkup | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/checkup b/checkup index 7799a9f..5620f8b 100755 --- a/checkup +++ b/checkup @@ -875,14 +875,19 @@ check_bin_deps() { glue_md_reports() { # final report path and name local out_fname="${MD_REPORTS_DIR}/${FULL_REPORT_FNAME}" + local epoch=$(jq '.last_check.epoch' ${PROJECT_DIR}/nodes.json) local database=$(jq '.last_check.database' ${PROJECT_DIR}/nodes.json) + database="${database/\"/}" + database="${database/\"/}" + epoch="${epoch/\"/}" + epoch="${epoch/\"/}" # do not re-generate full report if '--file' is given [[ "${FILE}" != "None" ]] && return 0 # make header echo "# PostgreSQL Checkup. Project: '${PROJECT}'. Database: '${database}'" > "${out_fname}" - echo "## Epoch number: '${EPOCH}'" >> "${out_fname}" + echo "## Epoch number: '${epoch}'" >> "${out_fname}" echo "NOTICE: while most reports describe the “current database”, some of them may contain cluster-wide information describing all databases in the cluster." >> "${out_fname}" echo >> "${out_fname}" echo "Last modified at: " $(date +'%Y-%m-%d %H:%M:%S %z') >> "${out_fname}" -- GitLab From 0c6be75ff1a3c41f4e687761adc4695fcf549d7c Mon Sep 17 00:00:00 2001 From: dmius Date: Wed, 9 Oct 2019 21:41:18 +0300 Subject: [PATCH 3/3] Fix database name and epoch in title of full report --- checkup | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/checkup b/checkup index 5620f8b..5e64f03 100755 --- a/checkup +++ b/checkup @@ -875,12 +875,8 @@ check_bin_deps() { glue_md_reports() { # final report path and name local out_fname="${MD_REPORTS_DIR}/${FULL_REPORT_FNAME}" - local epoch=$(jq '.last_check.epoch' ${PROJECT_DIR}/nodes.json) - local database=$(jq '.last_check.database' ${PROJECT_DIR}/nodes.json) - database="${database/\"/}" - database="${database/\"/}" - epoch="${epoch/\"/}" - epoch="${epoch/\"/}" + local epoch=$(jq -r '.last_check.epoch' ${PROJECT_DIR}/nodes.json) + local database=$(jq -r '.last_check.database' ${PROJECT_DIR}/nodes.json) # do not re-generate full report if '--file' is given [[ "${FILE}" != "None" ]] && return 0 -- GitLab