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.

Commit61fa42c

Browse files
committed
feat: SSHSUDOPASSWORD to specify the password for sudo on remote hosts
1 parent2deff34 commit61fa42c

File tree

5 files changed

+109
-32
lines changed

5 files changed

+109
-32
lines changed

‎README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,9 @@ you cannot use `localhost` in `-h` parameter. You have to use a bridge between
292292
host OS and Docker Engine. By default, host IP is`172.17.0.1` in`docker0`
293293
network, but it vary depending on configuration. More information[here](https://nickjanetakis.com/blog/docker-tip-65-get-your-docker-hosts-ip-address-from-in-a-container).
294294

295+
If you use SSH connection and`sudo` on the remote server requires a password,
296+
you can provide this password using the`SSHSUDOPASSWORD` environment variable.
297+
295298
##Credits
296299

297300
Some reports are based on or inspired by useful queries created and improved by

‎checkup

Lines changed: 21 additions & 2 deletions
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,7 +1475,11 @@ ssh() {
14601475
ssh_options="$ssh_options -S$ssh_master_socket$ssh_master_options"
14611476
fi
14621477

1463-
command ssh$ssh_options"$@"
1478+
if [["$@"==*" sudo"* ]]&& [[!-z${SSHSUDOPASSWORD+x} ]];then
1479+
commandecho"$SSHSUDOPASSWORD"|command ssh -q -tt$ssh_options"$@"
1480+
else
1481+
command ssh$ssh_options"$@"
1482+
fi
14641483
}
14651484

14661485
#######################################

‎resources/checks/A008_disk_usage_fstype.sh

Lines changed: 60 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,33 @@ fi
6666
# json
6767
#######################################
6868
df_to_json() {
69-
echo"{
70-
\"fstype\":\"$3\",
71-
\"size\":\"$4\",
72-
\"avail\":\"$6\",
73-
\"used\":\"$5\",
74-
\"use_percent\":\"$7\",
75-
\"mount_point\":\"$8\",
76-
\"path\":\"$1\",
77-
\"device\":\"$2\"
78-
}"
69+
if [[!-z${1+x} ]]&&
70+
[[!-z${2+x} ]]&&
71+
[[!-z${3+x} ]]&&
72+
[[!-z${4+x} ]]&&
73+
[[!-z${5+x} ]]&&
74+
[[!-z${6+x} ]]&&
75+
[[!-z${7+x} ]]&&
76+
[[!-z${8+x} ]];
77+
then
78+
cat -<<JSON
79+
{
80+
"fstype": "$3",
81+
"size": "$4",
82+
"avail": "$6",
83+
"used": "$5",
84+
"use_percent": "$7",
85+
"mount_point": "$8",
86+
"path": "$1",
87+
"device": "$2"
88+
}
89+
JSON
90+
else
91+
errmsg"ERROR: Wrong result of 'sudo df' command"
92+
exit 1
93+
fi
7994

95+
return 0
8096
}
8197

8298
#######################################
@@ -91,7 +107,15 @@ df_to_json() {
91107
#######################################
92108
print_df() {
93109
local path="$1"
94-
df_to_json"${path}"$(${CHECK_HOST_CMD}"sudo df -TPh\"${path}\" | tail -n +2")
110+
local raw_df=$(${CHECK_HOST_CMD}"sudo df -TPh\"${path}\"")
111+
df=$(echo"$raw_df"| grep -v"\[sudo\] password for"| tail -n 1)
112+
113+
if df_to_json"${path}"$df;then
114+
raw_df=""
115+
else
116+
echo"null"
117+
errmsg"Cannot get disk information. 'sudo df' returned: '$raw_df'"
118+
fi
95119
}
96120

97121
# json output starts here
@@ -132,23 +156,32 @@ echo "},"
132156
echo"\"fs_data\":{"
133157

134158
i=0
135-
points=$(${CHECK_HOST_CMD}"sudo df -TPh | tail -n +2")
159+
points=$(${CHECK_HOST_CMD}"sudo df -TPh")
160+
points=$(echo"$points"| grep -v"\[sudo\] password for"| tail -n +2)
161+
136162
whileread -r line;do
137-
if [[$i-gt 0 ]];then
138-
echo",\"$i\":{"
139-
else
140-
echo"\"$i\":{"
141-
fi
142-
let i=$i+1
143163
params=($line)
144-
echo"\"fstype\":\"${params[1]}\",
145-
\"size\":\"${params[2]}\",
146-
\"avail\":\"${params[4]}\",
147-
\"used\":\"${params[3]}\",
148-
\"use_percent\":\"${params[5]}\",
149-
\"mount_point\":\"${params[6]}\",
150-
\"path\":\"${params[6]}\",
151-
\"device\":\"${params[0]}\"
152-
}"
164+
165+
if [[${#params[@]}-ge 1 ]];then
166+
if [[$i-gt 0 ]];then
167+
echo",\"$i\":{"
168+
else
169+
echo"\"$i\":{"
170+
fi
171+
172+
cat -<<JSON
173+
"fstype": "${params[1]}",
174+
"size": "${params[2]}",
175+
"avail": "${params[4]}",
176+
"used": "${params[3]}",
177+
"use_percent": "${params[5]}",
178+
"mount_point": "${params[6]}",
179+
"path": "${params[6]}",
180+
"device": "${params[0]}"
181+
}
182+
JSON
183+
fi;
184+
185+
i=$((i+1))
153186
done<<<"$points"
154187
echo"}}"

‎resources/checks/D002_useful_linux_tools.sh

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ check_list() {
3030
IFS=","
3131
local cnt="0"
3232
local comma=""
33-
forutilin$list;do
33+
forutilin$list;do
3434
[["$cnt"-eq"0" ]]&& comma=""|| comma=","
3535
IFS="$SAVE_IFS"# non-standart IFS ruins ${CHECK_HOST_CMD}
36-
if$(${CHECK_HOST_CMD}"sudo which$util >/dev/null 2>&1");then
36+
local res=$(${CHECK_HOST_CMD}"sudo which$util 2>&1")
37+
res=$(echo"$res"| grep -v"\[sudo\] password for")
38+
if [["$res"!="" ]];then
3739
json="${json}${comma}\"$util\":\"yes\""
3840
else
3941
json="${json}${comma}\"$util\":\"\""
@@ -44,9 +46,17 @@ check_list() {
4446
echo"$json"
4547
}
4648

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: Cannot execute 'which' on the target server."
54+
exit 1
55+
fi
56+
4757
# build json object to stdout
4858
echo"{"
49-
check_list"cpu""$cpu_list"&&echo -n","
59+
check_list"cpu""${cpu_list}"&&echo -n","
5060
check_list"free_space""$disk_usage_list"&&echo -n","
5161
check_list"io""$io_list"&&echo -n","
5262
check_list"memory""$memory_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