Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jul 6, 2021. It is now read-only.

Commitc6408d8

Browse files
committed
Debug output added and error processing improved
1 parent010f3c3 commitc6408d8

File tree

4 files changed

+70
-13
lines changed

4 files changed

+70
-13
lines changed

‎checkup

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function dbg() {
5757
}
5858

5959
#######################################
60-
# Print an error/warning/notice to STDERR with timestamp
60+
# Print an error/warning/notice to STDERR with timestamp and error location
6161
# Please use 'exit' with code after usage
6262
# of this function (if needed)
6363
# Globals:
@@ -71,6 +71,21 @@ function err() {
7171
echo"[$(date +'%Y-%m-%dT%H:%M:%S%z')] ERROR:${FUNCNAME[1]}:$@">&2
7272
}
7373

74+
#######################################
75+
# Print an error/warning/notice to STDERR with timestamp only
76+
# Please use 'exit' with code after usage
77+
# of this function (if needed)
78+
# Globals:
79+
# None
80+
# Arguments:
81+
# (text) Error message
82+
# Returns:
83+
# (text) STDERR
84+
#######################################
85+
functionerrmsg() {
86+
echo"[$(date +'%Y-%m-%dT%H:%M:%S%z')]$@">&2
87+
}
88+
7489
#######################################
7590
# Error trapping function, prints line number
7691
# Globals:
@@ -1460,6 +1475,16 @@ ssh() {
14601475
ssh_options="$ssh_options -S$ssh_master_socket$ssh_master_options"
14611476
fi
14621477

1478+
errmsg"SSH CMD:$@"
1479+
if [["$@"==*"sudo"* ]];then
1480+
errmsg"DEBUG: SSH CMD: sudo found in command"
1481+
fi
1482+
if [[!-z${SSHSUDOPASSWORD+x} ]];then
1483+
errmsg"DEBUG: SSH CMD: SSHSUDOPASSWORD is set"
1484+
else
1485+
errmsg"DEBUG: SSH CMD: SSHSUDOPASSWORD is NOT set"
1486+
fi
1487+
14631488
if [["$@"==*"sudo"* ]]&& [[!-z${SSHSUDOPASSWORD+x} ]];then
14641489
commandecho"$SSHSUDOPASSWORD"|command ssh -q -tt$ssh_options"$@"
14651490
else

‎resources/checks/A008_disk_usage_fstype.sh

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ fi
6666
# json
6767
#######################################
6868
df_to_json() {
69-
echo"{
69+
if [[!-z${1+x} ]]&& [[!-z${2+x} ]]&& [[!-z${3+x} ]]&& [[!-z${4+x} ]]&&
70+
[[!-z${5+x} ]]&& [[!-z${6+x} ]]&& [[!-z${7+x} ]]&& [[!-z${8+x} ]];then
71+
echo"{
7072
\"fstype\":\"$3\",
7173
\"size\":\"$4\",
7274
\"avail\":\"$6\",
@@ -76,7 +78,11 @@ df_to_json() {
7678
\"path\":\"$1\",
7779
\"device\":\"$2\"
7880
}"
79-
81+
else
82+
errmsg"ERROR: Wrong result of 'sudo df' command"
83+
return 1
84+
fi
85+
return 0
8086
}
8187

8288
#######################################
@@ -91,9 +97,14 @@ df_to_json() {
9197
#######################################
9298
print_df() {
9399
local path="$1"
94-
local df=$(${CHECK_HOST_CMD}"sudo df -TPh\"${path}\"")
95-
df=$(echo"$df"| grep -v"\[sudo\] password for"| tail -n +2)
96-
df_to_json"${path}"$df
100+
local rawDf=$(${CHECK_HOST_CMD}"sudo df -TPh\"${path}\"")
101+
df=$(echo"$rawDf"| grep -v"\[sudo\] password for"| tail -n +2)
102+
if df_to_json"${path}"$df;then
103+
rawDf=""
104+
else
105+
echo"null"
106+
errmsg"'sudo df' returns: '$rawDf'"
107+
fi
97108
}
98109

99110
# json output starts here
@@ -137,14 +148,14 @@ i=0
137148
points=$(${CHECK_HOST_CMD}"sudo df -TPh")
138149
points=$(echo"$points"| grep -v"\[sudo\] password for"| tail -n +2)
139150
whileread -r line;do
140-
if [[$i-gt 0 ]];then
141-
echo",\"$i\":{"
142-
else
143-
echo"\"$i\":{"
144-
fi
145-
let i=$i+1
146151
params=($line)
147-
echo"\"fstype\":\"${params[1]}\",
152+
if [[${#params[@]}-ge 1 ]];then
153+
if [[$i-gt 0 ]];then
154+
echo",\"$i\":{"
155+
else
156+
echo"\"$i\":{"
157+
fi
158+
echo"\"fstype\":\"${params[1]}\",
148159
\"size\":\"${params[2]}\",
149160
\"avail\":\"${params[4]}\",
150161
\"used\":\"${params[3]}\",
@@ -153,5 +164,7 @@ while read -r line; do
153164
\"path\":\"${params[6]}\",
154165
\"device\":\"${params[0]}\"
155166
}"
167+
fi;
168+
let i=$i+1
156169
done<<<"$points"
157170
echo"}}"

‎resources/checks/D002_useful_linux_tools.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ check_list() {
4646
echo"$json"
4747
}
4848

49+
res1=$(${CHECK_HOST_CMD}"which sudo")
50+
res2=$(${CHECK_HOST_CMD}"sudo which sudo")
51+
res2=$(echo"$res2"| grep -v"\[sudo\] password for")
52+
if [["$res1"!="$res2" ]];then
53+
errmsg"ERROR: Can not execute 'which' on target server."
54+
fi
55+
4956
# build json object to stdout
5057
echo"{"
5158
check_list"cpu""$cpu_list"&&echo -n","

‎resources/checks/K000_query_analysis.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@ else
2727
change_db_cmd=""
2828
fi
2929

30+
# check pg_stat_statements availability
31+
err_code="0"
32+
res=$(${CHECK_HOST_CMD}"${_PSQL} >/dev/null 2>&1 -f -"<<SQL
33+
${change_db_cmd}
34+
select from pg_stat_statements limit 1 -- the fastest way
35+
SQL
36+
)|| err_code="$?"
37+
38+
if [["${err_code}"-ne"0" ]];then
39+
errmsg"ERROR: Cannot find extension\"pg_stat_stat_statements\". Install extension\"pg_stat_stat_statements\" using\"CREATE EXTENSION pg_stat_statements;\" or run postgres-checkup with CLI option\"--ss-dbname\" pointing to a database where this extension is already installed."
40+
exit 1
41+
fi
3042

3143
tmp_dir="${JSON_REPORTS_DIR}/tmp_K000"
3244
mkdir -p"${tmp_dir}"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp