Skip to content
This repository was archived by the owner on Jul 6, 2021. It is now read-only.

Commit ea2da66

Browse files
committed
Merge branch 'master' into dmius-keep-rows-order
2 parents 98dc65a + 7d2b624 commit ea2da66

File tree

3 files changed

+45
-6
lines changed

3 files changed

+45
-6
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ Requirements
4242
* bash
4343
* psql
4444
* coreutils
45-
* jq >= 1.5,
45+
* jq >= 1.5
4646
* golang >= 1.8
4747
* awk
48+
* sed
4849

4950

check

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
CMD_TIMEOUT="10" # timeout for command (ssh, psql, etc.)
1212
# TODO(vyagofarov): think about timing
1313
# out commands in macOS
14+
FULL_REPORT_FNAME="full_report.md"
1415

1516
# GLOBALS (autoload, do not change)
1617
: ${DEBUG:=false} # print debug output
@@ -690,10 +691,31 @@ check_bin_deps() {
690691
fi
691692
}
692693

694+
#######################################
695+
# Add the newly generated report to a fileф
696+
# (makes final report)
697+
# Globals:
698+
# PROJECT_DIR, FULL_REPORT_FNAME
699+
# Arguments:
700+
# md_reports_dir, report_fname
701+
# Returns:
702+
# Integer
703+
#######################################
704+
append_to_final_report() {
705+
local md_reports_dir="$1"
706+
local report_fname="$2"
707+
708+
local out_fname="${PROJECT_DIR}/${FULL_REPORT_FNAME}"
709+
710+
# glue
711+
cat "${md_reports_dir}/${report_fname}" >> "${out_fname}"
712+
}
713+
693714
#######################################
694715
# Check rights, set global variables, etc.
695716
# Globals:
696717
# HOST, CHECK_HOST_CMD, NATIVE_HOSTNAME
718+
# SSH_SUPPORT
697719
# Arguments:
698720
# None
699721
# Returns:
@@ -706,6 +728,7 @@ host_pre_start_checks() {
706728
if NATIVE_HOSTNAME=$(ssh $HOST "hostname" 2>/dev/null); then
707729
# ssh to remote host and use local psql (default)
708730
export CHECK_HOST_CMD="ssh ${HOST}"
731+
export SSH_SUPPORT="true"
709732
else
710733
NATIVE_HOSTNAME="${HOST}"
711734
# swap ssh with bash
@@ -720,6 +743,8 @@ host_pre_start_checks() {
720743
# use TCP for psql
721744
export _PSQL="${_PSQL} -h ${HOST}"
722745
fi
746+
747+
export SSH_SUPPORT="false"
723748
fi
724749

725750
export NATIVE_HOSTNAME
@@ -868,6 +893,15 @@ run_checks() {
868893

869894
local pghrep_failed_jsons_stack=""
870895

896+
export PROJECT_DIR="${SCRIPT_DIR}/artifacts/${PROJECT}"
897+
test -d "${PROJECT_DIR}" || mkdir -p "${PROJECT_DIR}"
898+
899+
# make a header for a FULL_REPORT_FNAME
900+
echo "# '${PROJECT}' PostgreSQL health-check" > "${PROJECT_DIR}/${FULL_REPORT_FNAME}"
901+
echo >> "${PROJECT_DIR}/${FULL_REPORT_FNAME}"
902+
echo $(date +'%Y-%m-%d %H:%M:%S %z') >> "${PROJECT_DIR}/${FULL_REPORT_FNAME}"
903+
echo >> "${PROJECT_DIR}/${FULL_REPORT_FNAME}"
904+
871905
# perform all checks from './resources/checks/' directory
872906
msg
873907
msg "########## Perform checks for host '${NATIVE_HOSTNAME}':"
@@ -913,9 +947,6 @@ run_checks() {
913947
msg "check '$check_id' is finished"
914948
fi
915949

916-
export PROJECT_DIR="${SCRIPT_DIR}/artifacts/${PROJECT}"
917-
test -d "${PROJECT_DIR}" || mkdir -p "${PROJECT_DIR}"
918-
919950
# alot of magic is here
920951
update_nodes_json
921952

@@ -929,6 +960,8 @@ run_checks() {
929960
--outdir="${MD_REPORTS_DIR}" 2>&1) ; then
930961
msg "WARNING: ${pghrep_output}"
931962
pghrep_failed_jsons_stack="${pghrep_failed_jsons_stack} ${check_id}_${check_name}.json"
963+
else
964+
append_to_final_report "${MD_REPORTS_DIR}" "${check_id}_${check_name}.md"
932965
fi
933966

934967
# parse only one file if check is given by CLI
@@ -950,8 +983,8 @@ run_checks() {
950983
fi
951984

952985
msg
953-
msg "All .md reports has been saved at directory:"
954-
echo " '${MD_REPORTS_DIR}'"
986+
msg "Final .md report is ready:"
987+
echo " '${PROJECT_DIR}/${FULL_REPORT_FNAME}'"
955988

956989
msg
957990
msg "ALL DONE!"

resources/checks/A001_system_info.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ OS_INFO=""
66
DISK_INFO=""
77
CTL_INFO=""
88

9+
if [[ "${SSH_SUPPORT}" = "false" ]]; then
10+
echo "SSH is not supported, skipping..." >&2
11+
exit 1
12+
fi
13+
914
function get_cpu_info() {
1015
local res=""
1116
local cpu_info="$(${CHECK_HOST_CMD} "lscpu")"

0 commit comments

Comments
 (0)