-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcek-status-node.sh
More file actions
96 lines (91 loc) · 1.68 KB
/
cek-status-node.sh
File metadata and controls
96 lines (91 loc) · 1.68 KB
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
#!/bin/bash
remote_servers=(
10.40.1.173
10.40.1.35
172.28.220.56
10.40.27.26
10.40.27.52
10.40.1.51
10.40.8.152
10.40.30.33
10.40.5.169
10.40.5.53
10.40.5.136
10.40.5.131
10.40.5.114
10.40.27.117
10.40.1.158
10.40.27.90
10.40.5.231
10.40.5.173
10.40.5.223
10.40.5.227
10.40.27.14
10.40.27.24
10.40.27.33
10.40.27.115
10.40.27.177
10.40.9.116
10.40.1.31
10.40.5.29
10.40.5.161
10.40.5.64
10.40.5.210
10.40.5.186
10.40.1.69
10.40.1.193
10.40.1.87
10.40.1.147
10.40.1.127
10.40.1.141
10.40.5.248
10.40.1.229
10.40.1.154
10.40.1.232
10.40.1.132
10.40.1.112
10.40.1.212
10.40.5.214
10.40.5.92
10.40.5.37
10.40.1.29
10.26.2.20
10.40.7.90
10.40.8.44
10.40.8.222
172.28.216.204
10.40.17.216
10.40.30.58
10.40.30.208
10.40.17.106
10.40.17.63
)
ssh_key="~/devops.pem"
max_retries=1
timeout=3
for remote_server in "${remote_servers[@]}"
do
echo "Checking node_exporter on ${remote_server}..."
for ssh_user in "ubuntu" "cloud-user" "centos"
do
ssh_successful=false
retries=0
while ! $ssh_successful && [ $retries -lt $max_retries ]
do
ssh -i "$ssh_key" -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o GSSAPIAuthentication=no -o ConnectTimeout=$timeout "$ssh_user@$remote_server" 'systemctl is-active node_exporter.service >/dev/null 2>&1'
if [ $? -eq 0 ]; then
echo "node_exporter is active on ${remote_server} (user: ${ssh_user})"
ssh_successful=true
else
echo "Unable to connect to ${remote_server} using ${ssh_user} user"
retries=$((retries+1))
fi
done
if $ssh_successful; then
break
fi
done
if ! $ssh_successful; then
echo "Unable to check node_exporter on ${remote_server} using any user"
fi
done