-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathallas-health-check2
169 lines (144 loc) · 5 KB
/
allas-health-check2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/bin/bash
#read static variables
inst_root="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
inst_root="/appl/opt/allas-cli-utils"
source $inst_root/a_env_conf
#allas_conf_path=("/appl/opt/allas-cli-utils/allas_conf")
export OS_USERNAME=$(whoami)
export OS_AUTH_URL=https://pouta.csc.fi:5001/v3
export OS_USER_DOMAIN_NAME="Default"
export OS_REGION_NAME="regionOne"
export OS_INTERFACE=public
export OS_IDENTITY_API_VERSION=3
project="none"
bucket="none"
#store swift autentication if it is done
if [ -n "$OS_AUTH_TOKEN" ]
then
ORIG_OS_AUTH_TOKEN=("$OS_AUTH_TOKEN")
fi
if [ -n "$OS_STORAGE_URL" ]
then
ORIG_OS_STORAGE_UR=("$OS_STORAGE_URL")
fi
buk=(1)
usage="
allas-healt-check checks segment related metadata for all segmented objects in all projects.
With the option -p, you can focus the checking to just one project.
OPTIONS
-p, --project Do testing only for a specific project.
-b, --bucket Do testing only for a specific bucket. Project must be defind too.
"
while [[ $# -ge 1 ]]
do
case "$1" in
'-p' | '--project')
project="$2"
shift
shift
;;
'-b' | '--bucket')
bucket="$2"
shift
shift
;;
*)
echo "$usage"
exit 1
shift # No more switches
;;
esac
done
if [ -z "$OS_PASSWORD" ]; then
echo "Please enter CSC password for account ${OS_USERNAME}: "
read -sr OS_PASSWORD_INPUT
export OS_PASSWORD=$OS_PASSWORD_INPUT
fi
if [[ $project == "none" ]]; then
if [[ $bucket != "none" ]]; then
echo "If you wish to check a spefic bucket, you must define a project too with option --project"
fi
echo "Collecting project list. Please wait."
openstack project list --my-projects -c Name -f value
all_projects=$(openstack project list --my-projects -c Name -f value)
else
all_projects="$project"
fi
fail_tot=0
for pro in $all_projects
do
#Open connection
echo "-----------------------------------------------"
projnum=$( echo $pro | sed -e s/"project_"/""/g | sed -e s/"Project_"/""/g )
saldo -p $projnum 2> /dev/null | grep "^Project"
source $allas_conf_path -f --silent --keeppasswd $pro
echo "-------------------------------------------" >> /tmp/allas-health-tmp-$$
echo "Project: $pro" >> /tmp/allas-health-tmp-$$
#Run the test
fail_pro=0
echo $bucket
if [[ $bucket == "" ]]; then
bucketlist=$(rclone lsd ${storage_server}: | grep _segments$ | awk '{print $NF}' | sed 's/.\{9\}$//')
else
bucketlist=$bucket
fi
#Go through all the buckets that have segments bucket
for bucket in $bucketlist
do
echo "Cheking bucket: $bucket"
num_ok=0
num_fail=0
#List segmented objets
#echo "rclone ls "${storage_server}:${bucket}_segments" | cut -d " " -f 2| sed 's/.\{9\}$//' | uniq"
# fisrt check dynamic large objects
for fobject in $(rclone ls "${storage_server}:${bucket}_segments" | sed s/"^ "// | cut -d " " -f 2 | awk -F "/" '{ if ( $2 != "slo") print $1}' | uniq )
do
check_if_exists=$(rclone ls ${storage_server}:${bucket}/${fobject}| wc -l)
if [[ $check_if_exists -eq 0 ]]; then
echo "Object $fobject has segment objects, but no front object"
echo " Object $bucket/$fobject has segment objects, but no front object." >> /tmp/allas-health-tmp-$$
(( num_fail = num_fail + 1 ))
(( fail_pro = fail_pro + 1 ))
else
bucket_check=$( swift stat ${bucket} ${fobject} | grep Manifest | grep -c "$sobject" )
if [[ $bucket_check -ne 1 ]]; then
echo " Problem with object: ${bucket}/$fobject"
echo " Problem with object: ${bucket}/$fobject" >> /tmp/allas-health-tmp-$$
echo " Segments are either not found or there are several versions available." >> /tmp/allas-health-tmp-$$
(( num_fail = num_fail + 1 ))
(( fail_pro = fail_pro + 1 ))
else
# echo " $fobject OK"
(( num_ok = num_ok + 1 ))
fi
fi
done
if [[ $num_fail -eq 0 ]]; then
echo "All objects OK"
else
echo "$num_fail failed checks"
(( fail_tot = fail_tot + num_fail ))
fi
done
if [[ $fail_pro -eq 0 ]]; then
echo "OK" >> /tmp/allas-health-tmp-$$
fi
done
if [[ fail_tot -gt 0 ]]; then
echo " "
echo "----------------------------------------------------------------"
echo " "
echo "----------------------------------------------------------------"
echo "Summary of Allas health check"
cat /tmp/allas-health-tmp-$$
rm -f /tmp/allas-health-tmp-$$
fi
#store swift autentication if it is done
if [ -n "$ORIG_OS_AUTH_TOKEN" ]
then
export OS_AUTH_TOKEN=("$ORIG_OS_AUTH_TOKEN")
fi
if [ -n "$ORIG_OS_STORAGE_URL" ]
then
export OS_STORAGE_URL=("$ORIG_OS_STORAGE_URL")
fi