-
Notifications
You must be signed in to change notification settings - Fork 0
/
pli_netdata.sh
279 lines (209 loc) · 8.69 KB
/
pli_netdata.sh
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
#!/bin/bash
# Get current user id and store as var
USER_ID=$(getent passwd $EUID | cut -d: -f1)
# Set Colour Vars
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m' # No Color
# Authenticate sudo perms before script execution to avoid timeouts or errors
sudo -l > /dev/null 2>&1
# space seperated list
REQ_PACKAGES=(git curl nano)
FUNC_PKG_CHECK(){
echo -e "${GREEN}#########################################################################"
echo -e "${GREEN}## CHECK NECESSARY PACKAGES HAVE BEEN INSTALLED...${NC}"
for i in "${REQ_PACKAGES[@]}"
do
hash $i &> /dev/null
if [ $? -eq 1 ]; then
echo >&2 "package "$i" not found. installing...."
sudo apt install -y "$i"
fi
echo "package "$i" exists. proceeding...."
done
}
FUNC_GET_CLAIMTOKEN(){
FUNC_PKG_CHECK;
echo -e "${GREEN}#########################################################################"
echo -e "${GREEN}## PROMPT FOR NETDATA SPACE CLAIM-TOKEN...${NC}"
echo
echo
while true; do
read -t30 -r -p "Please enter the '--claim-token' value from the Netdata portal: " _INPUT
if [ $? -gt 128 ]; then
echo "timed out waiting for user response - exiting..."
FUNC_EXIT;
elif [[ $_INPUT != '' ]] && [[ ${#_INPUT} == 135 ]]; then
echo
echo
echo -e "${GREEN}## the provided claim token appears valid${NC}"
echo
echo -e "${GREEN}## proceeding to install netdata..."
echo
echo
FUNC_SETUP_NETDATA;
else
echo "token id invalid, please check and retry - exiting.."
FUNC_ERR_EXIT;
break
fi
done
}
FUNC_SETUP_NETDATA(){
echo -e "${GREEN}#########################################################################"
echo -e "${GREEN}## INSTALLING NETDATA WITH CLAIM-TOKEN...${NC}"
#echo "installing with claim-token id : $_INPUT"
#sudo curl https://my-netdata.io/kickstart.sh > /tmp/netdata-kickstart.sh && sh /tmp/netdata-kickstart.sh --stable-channel --disable-telemetry --non-interactive \
sudo curl https://get.netdata.cloud/kickstart.sh > /tmp/netdata-kickstart.sh && sh /tmp/netdata-kickstart.sh --stable-channel --disable-telemetry --non-interactive \
--claim-token $_INPUT \
--claim-url https://app.netdata.cloud
sudo cp /usr/lib/netdata/conf.d/apps_groups.conf /etc/netdata/apps_groups.conf
NDATA_CONF_FILE="/etc/netdata/netdata.conf"
NDATA_APPS_FILE="/etc/netdata/apps_groups.conf"
sudo sed -i.bak '/^.*history*/a \\n process scheduling policy = idle\n OOM score = 1000\n\n dbengine multihost disk space = 1978\n update every = 5\n\n[web]\n web files owner = root\n web files group = netdata\n\n bind to = localhost' $NDATA_CONF_FILE
#sudo sed -i.bak '/^freeswitch*/a \\npli-node: *2_nodeStartPM2* *startNode*\npli-ei: external-initiator* *3_initiatorStartPM2* *startEI*' $NDATA_APPS_FILE
#sudo sed -i.bak '/^freeswitch*/a \\npli-node: *PM2 v5.3.0: God*' $NDATA_APPS_FILE
sudo sed -i.bak '/^freeswitch*/a \\npli-node: *NodeStartPM2*' $NDATA_APPS_FILE
sudo systemctl unmask netdata.service
sudo systemctl restart netdata
sudo systemctl status netdata
#sleep 3s
FUNC_ENABLE_HEALTH_MON;
#FUNC_EXIT;
}
FUNC_ENABLE_HEALTH_MON(){
echo -e "${GREEN}#########################################################################"
echo -e "${GREEN}## ENABLING NETDATA HEALTH MONITOR ALERTING...${NC}"
#echo "copies the default template conf file for common system metric"
#HEALTH_CONFS=(cpu.conf memory.conf load.conf processes.conf disks.conf tcp_resets.conf tcp_conn.conf )
#HEALTH_CONFS=(pli-node.conf pli-ei.conf)
HEALTH_CONFS=(pli-node.conf)
for i in "${HEALTH_CONFS[@]}"; do
echo -e "${GREEN}## enabling health conf file : $i ${NC}"
#sudo cp /usr/lib/netdata/conf.d/health.d/$i /etc/netdata/health.d/$i
sudo cp $i /etc/netdata/health.d/$i
if [ $? == 0 ]; then
echo -e "${GREEN}## health conf file "$i" enabled successfully..${NC}"
fi
done
echo
sleep 3s
echo -e "${GREEN}## RELOADING HEALTH DATA TO ENABLE UPDATES...${NC}"
sudo netdatacli reload-health
if [ $? == 0 ]; then
echo -e "${GREEN}## health monitor settings reloaded successfully..${NC}"
else
echo -e "${RED}## health monitor settings reloaded failed..${NC}"
fi
FUNC_EXIT;
}
FUNC_RECLAIM_TOKEN(){
echo -e "${GREEN}#########################################################################"
echo -e "${GREEN}## PERFORMING NETDATA NODE RECLAIM...${NC}"
#echo "performing node reclaim process"
sudo rm -f /var/lib/netdata/registry/netdata.public.unique.id
echo
echo -e "${GREEN}## RESTARTING NETDATA SERVICE...${NC}"
sudo systemctl restart netdata
sudo systemctl status netdata
FUNC_EXIT;
}
FUNC_RESET_NETDATA(){
echo -e "${GREEN}#########################################################################"
echo -e "${GREEN}## PERFORMING NETDATA UNINSTALL...${NC}"
echo
echo
#echo "performing netdata reset process"
sudo rm -f /etc/netdata/netdata-uninstaller.sh
cd /etc/netdata
sudo wget https://raw.githubusercontent.com/netdata/netdata/master/packaging/installer/netdata-uninstaller.sh && sudo chmod +x ./netdata-uninstaller.sh
sudo ./netdata-uninstaller.sh --yes
#if [ $? != 0 ]; then
# echo
# echo "ERROR :: Error running uninstall script.. exiting"
# echo
# FUNC_ERR_EXIT;
# sleep 2s
#fi
echo -e "${GREEN}## PERFORMING NETDATA FOLDER CLEANUP...${NC}"
echo
cd ~/
sudo rm -rf /var/lib/netdata && sudo rm -rf /var/log/netdata
sudo rm -rf /var/cache/apt/archives/netdata*
sudo rm -f /var/lib/apt/lists/packagecloud.io_netdata_netdata*
sudo rm -f /var/lib/dpkg/info/netdata-repo*
sudo rm -rf /var/lib/netdata
sudo rm -rf /var/cache/netdata/
sudo rm -f /var/lib/systemd/deb-systemd-helper-masked/netdata*
sudo rm -f /etc/apt/sources.list.d/netdata*
sudo rm -f /var/lib/dpkg/info/netdata*
sudo rm -rf /etc/netdata
sudo rm -rf /opt/netdata
sudo rm -f /etc/apt/trusted.gpg.d/netdata-archive-keyring.gpg
sudo rm -f /etc/apt/trusted.gpg.d/netdata-edge-archive-keyring.gpg
sudo rm -f /etc/apt/trusted.gpg.d/netdata-repoconfig-archive-keyring.gpg
sudo rm -f /etc/cron.daily/netdata-updater
sudo rm -f /etc/default/netdata
sudo rm -f /etc/init.d/netdata
sudo rm -f /etc/logrotate.d/netdata
sudo rm -f /etc/rc2.d/S01netdata
sudo rm -f /etc/rc3.d/S01netdata
sudo rm -f /etc/rc4.d/S01netdata
sudo rm -f /etc/rc5.d/S01netdata
sudo rm -f /etc/systemd/system/multi-user.target.wants/netdata.service
sudo rm -f /etc/systemd/system/netdata.service
sudo rm -rf /usr/libexec/netdata
sudo rm -f /var/lib/systemd/deb-systemd-helper-enabled/multi-user.target.wants/netdata.service
sudo rm -f /var/lib/systemd/deb-systemd-helper-enabled/netdata.service.dsh-also
FUNC_EXIT;
}
FUNC_EXIT(){
exit 0
}
FUNC_ERR_EXIT(){
if [ $? != 0 ]; then
#echo
echo "ERROR - Exiting early"
exit 1
else
return
fi
}
#FUNC_PKG_CHECK
#FUNC_GET_CLAIMTOKEN
#FUNC_ENABLE_HEALTH_MON
case "$1" in
-setup)
#_OPTION="-setup"
FUNC_GET_CLAIMTOKEN
;;
-reclaim)
#_OPTION="-conf"
FUNC_RECLAIM_TOKEN
;;
-base-alerts)
#_OPTION="-conf"
FUNC_ENABLE_HEALTH_MON
;;
-reset)
#_OPTION="-conf"
FUNC_RESET_NETDATA
;;
*)
#clear
echo
echo
echo -e "${GREEN}Usage: $0 {function}${NC}"
echo
echo -e "${GREEN}where {function} is one of the following;${NC}"
echo
echo -e "${GREEN} -setup == prompts for claim token id & installs netdata${NC}"
echo -e "${GREEN} -base-alerts == enables base system health monitor alerting${NC}"
echo -e "${GREEN} -reclaim == removes the unique id to allow the node to be claimed again${NC}"
echo
echo -e "${GREEN} -reset == **CAUTION** performs a hard reset of the netdata install removing all files${NC}"
#echo -e "${GREEN} -scp == displays the secure copy (scp) cmds to download backup files${NC}"
#echo
echo
echo
esac