· 6 years ago · Nov 09, 2019, 03:34 PM
1#!/usr/bin/env bash
2#
3# Script to test various application reverse proxies, as well as their internal pages, and report to their respective Healthchecks.io checks
4# Tronyx
5
6# Define some variables
7# Primary domain all of your reverse proxies are hosted on
8domain='orejasinc.de'
9
10# Your Organizr API key to get through Org auth
11orgAPIKey='XXXXXXXXXXXXXXXXX'
12
13# Primary Server IP address of the Server all of your applications/containers are hosted on
14# You can add/utilize more Server variables if you would like, as I did below, and if you're running more than one Server like I am
15primaryServerAddress='127.0.0.1'
16hcPingDomain='https://hc-ping.com/'
17
18# Location of the lock file that you can utilize to keep tests paused.
19tempDir='/tmp/'
20# The below temp dir is for use with the Tronitor script
21# https://github.com/christronyxyocum/tronitor
22#tempDir='/tmp/tronitor/'
23healthchecksLockFile="${tempDir}healthchecks.lock"
24
25# You will need to adjust the subDomain, appPort, subDir, and hcUUID variables for each application's function according to your setup
26# I've left in some examples to show the expected format.
27
28# Function to check for healthchecks lock file
29check_lock_file() {
30 if [ -e "${healthchecksLockFile}" ]; then
31 echo "Skipping checks due to lock file being present."
32 exit 0
33 else
34 main
35 fi
36}
37
38# Function to check Bazarr
39check_bazarr() {
40 appPort='32461'
41 subDir='/bazarr'
42 hcUUID='XXXXXXXXXXXXXXXXXXX'
43 extResponse=$(curl -w "%{http_code}\n" -sI -o /dev/null --connect-timeout 10 https://"${domain}${subDir}"/series -H "token: ${orgAPIKey}")
44 intResponse=$(curl -w "%{http_code}\n" -sI -o /dev/null --connect-timeout 10 http://"${primaryServerAddress}":"${appPort}""${subDir}"/series)
45 appName=$(echo ${FUNCNAME[0]} |cut -c7-)
46 appLockFile="${tempDir}${appName}".lock
47 if [ -e "${appLockFile}" ]; then
48 :
49 else
50 if [[ "${extResponse}" = '200' ]] && [[ "${intResponse}" = '200' ]]; then
51 curl -fsS --retry 3 "${hcPingDomain}${hcUUID}" > /dev/null
52 elif [[ "${extResponse}" != '200' ]] || [[ "${intResponse}" != '200' ]]; then
53 curl -fsS --retry 3 "${hcPingDomain}${hcUUID}"/fail > /dev/null
54 fi
55 fi
56}
57
58
59
60
61
62
63# Function to check Grafana
64check_grafana() {
65 appPort='3000'
66 subDir='/grafana/'
67 hcUUID='XXXXXXXXXXXXXXXX'
68 extResponse=$(curl -w "%{http_code}\n" -sI -o /dev/null --connect-timeout 10 https://"${domain}${subDir}" -H "token: ${orgAPIKey}")
69 intResponse=$(curl -w "%{http_code}\n" -sI -o /dev/null --connect-timeout 10 http://"${primaryServerAddress}":"${appPort}""${subDir}")
70 appName=$(echo ${FUNCNAME[0]} |cut -c7-)
71 appLockFile="${tempDir}${appName}".lock
72 if [ -e "${appLockFile}" ]; then
73 :
74 else
75 if [[ "${extResponse}" = '200' ]] && [[ "${intResponse}" = '200' ]]; then
76 curl -fsS --retry 3 "${hcPingDomain}${hcUUID}" > /dev/null
77 elif [[ "${extResponse}" != '200' ]] || [[ "${intResponse}" != '200' ]]; then
78 curl -fsS --retry 3 "${hcPingDomain}${hcUUID}"/fail > /dev/null
79 fi
80 fi
81}
82
83
84# Function to check Jackett
85check_jackett() {
86 appPort='32412'
87 subDir='/jackett/UI/Login'
88 hcUUID='XXXXXXXXXXXXXXX'
89 extResponse=$(curl -w "%{http_code}\n" -s -o /dev/null --connect-timeout 10 https://"${domain}""${subDir}" -H "token: ${orgAPIKey}")
90 intResponse=$(curl -w "%{http_code}" -s -o /dev/null --connect-timeout 10 http://"${primaryServerAddress}":"${appPort}""${subDir}")
91 appName=$(echo ${FUNCNAME[0]} |cut -c7-)
92 appLockFile="${tempDir}${appName}".lock
93 if [ -e "${appLockFile}" ]; then
94 :
95 else
96 if [[ "${extResponse}" = '200' ]] && [[ "${intResponse}" = '200' ]]; then
97 curl -fsS --retry 3 "${hcPingDomain}${hcUUID}" > /dev/null
98 elif [[ "${extResponse}" != '200' ]] || [[ "${intResponse}" != '200' ]]; then
99 curl -fsS --retry 3 "${hcPingDomain}${hcUUID}"/fail > /dev/null
100 fi
101 fi
102}
103
104
105# Function to check Lidarr
106check_lidarr() {
107 appPort='32411'
108 subDir='/lidarr/'
109 hcUUID='XXXXXXXXXXXXXXXXX'
110 extResponse=$(curl -w "%{http_code}\n" -sI -o /dev/null --connect-timeout 10 https://"${domain}${subDir}" -H "token: ${orgAPIKey}")
111 intResponse=$(curl -w "%{http_code}\n" -sI -o /dev/null --connect-timeout 10 http://"${primaryServerAddress}":"${appPort}""${subDir}")
112 appName=$(echo ${FUNCNAME[0]} |cut -c7-)
113 appLockFile="${tempDir}${appName}".lock
114 if [ -e "${appLockFile}" ]; then
115 :
116 else
117 if [[ "${extResponse}" = '200' ]] && [[ "${intResponse}" = '200' ]]; then
118 curl -fsS --retry 3 "${hcPingDomain}${hcUUID}" > /dev/null
119 elif [[ "${extResponse}" != '200' ]] || [[ "${intResponse}" != '200' ]]; then
120 curl -fsS --retry 3 "${hcPingDomain}${hcUUID}"/fail > /dev/null
121 fi
122 fi
123}
124
125
126# Function to check Monitorr
127check_monitorr() {
128 appPort='32418'
129 subDir='/monitorr/'
130 hcUUID='XXXXXXXXXXXXXXXXXX'
131 extResponse=$(curl -w "%{http_code}\n" -sI -o /dev/null --connect-timeout 10 https://"${domain}${subDir}" -H "token: ${orgAPIKey}")
132 intResponse=$(curl -w "%{http_code}\n" -sI -o /dev/null --connect-timeout 10 http://"${primaryServerAddress}":"${appPort}""${subDir}")
133 appName=$(echo ${FUNCNAME[0]} |cut -c7-)
134 appLockFile="${tempDir}${appName}".lock
135 if [ -e "${appLockFile}" ]; then
136 :
137 else
138 if [[ "${extResponse}" = '200' ]] && [[ "${intResponse}" = '200' ]]; then
139 curl -fsS --retry 3 "${hcPingDomain}${hcUUID}" > /dev/null
140 elif [[ "${extResponse}" != '200' ]] || [[ "${intResponse}" != '200' ]]; then
141 curl -fsS --retry 3 "${hcPingDomain}${hcUUID}"/fail > /dev/null
142 fi
143 fi
144}
145
146# Function to check NZBGet
147check_nzbget() {
148 appPort='32407'
149 subDir='/nzbget/'
150 hcUUID='XXXXXXXXXXXXXXXX'
151 extResponse=$(curl -w "%{http_code}\n" -s -o /dev/null --connect-timeout 10 https://"${domain}${subDir}" -H "token: ${orgAPIKey}")
152 intResponse=$(curl -w "%{http_code}\n" -s -o /dev/null --connect-timeout 10 http://"${primaryServerAddress}":"${appPort}")
153 appName=$(echo ${FUNCNAME[0]} |cut -c7-)
154 appLockFile="${tempDir}${appName}".lock
155 if [ -e "${appLockFile}" ]; then
156 :
157 else
158 if [[ "${extResponse}" = '200' ]] && [[ "${intResponse}" = '200' ]]; then
159 curl -fsS --retry 3 "${hcPingDomain}${hcUUID}" > /dev/null
160 elif [[ "${extResponse}" != '200' ]] || [[ "${intResponse}" != '200' ]]; then
161 curl -fsS --retry 3 "${hcPingDomain}${hcUUID}"/fail > /dev/null
162 fi
163 fi
164}
165
166# Function to check NZBHydra/NZBHydra2
167check_nzbhydra() {
168 appPort='32413'
169 subDir='/nzbhydra/'
170 hcUUID='XXXXXXXXXXX'
171 extResponse=$(curl -w "%{http_code}\n" -s -o /dev/null --connect-timeout 10 https://"${domain}${subDir}" -H "token: ${orgAPIKey}")
172 intResponse=$(curl -w "%{http_code}\n" -s -o /dev/null --connect-timeout 10 http://"${primaryServerAddress}":"${appPort}""${subDir}")
173 appName=$(echo ${FUNCNAME[0]} |cut -c7-)
174 appLockFile="${tempDir}${appName}".lock
175 if [ -e "${appLockFile}" ]; then
176 :
177 else
178 if [[ "${extResponse}" = '200' ]] && [[ "${intResponse}" = '200' ]]; then
179 curl -fsS --retry 3 "${hcPingDomain}${hcUUID}" > /dev/null
180 elif [[ "${extResponse}" != '200' ]] || [[ "${intResponse}" != '200' ]]; then
181 curl -fsS --retry 3 "${hcPingDomain}${hcUUID}"/fail > /dev/null
182 fi
183 fi
184}
185
186# Function to check Ombi
187check_ombi() {
188 appPort='32416'
189 subDir='/ombi/'
190 hcUUID='XXXXXXXXXXXXXXXXX'
191 extResponse=$(curl -w "%{http_code}\n" -s -o /dev/null --connect-timeout 10 https://"${domain}${subDir}" -H "token: ${orgAPIKey}")
192 intResponse=$(curl -w "%{http_code}\n" -s -o /dev/null --connect-timeout 10 http://"${primaryServerAddress}":"${appPort}""${subDir}")
193 appName=$(echo ${FUNCNAME[0]} |cut -c7-)
194 appLockFile="${tempDir}${appName}".lock
195 if [ -e "${appLockFile}" ]; then
196 :
197 else
198 if [[ "${extResponse}" = '200' ]] && [[ "${intResponse}" = '200' ]]; then
199 curl -fsS --retry 3 "${hcPingDomain}${hcUUID}" > /dev/null
200 elif [[ "${extResponse}" != '200' ]] || [[ "${intResponse}" != '200' ]]; then
201 curl -fsS --retry 3 "${hcPingDomain}${hcUUID}"/fail > /dev/null
202 fi
203 fi
204}
205
206
207# Function to check Plex
208check_plex() {
209 subDomain='plex'
210 appPort='32400'
211 hcUUID='XXXXXXXXXXXXXXXXXXXXXX'
212 extResponse=$(curl -w "%{http_code}\n" -sI -o /dev/null --connect-timeout 10 https://"${subDomain}"."${domain}"/web/index.html)
213 intResponse=$(curl -w "%{http_code}\n" -sI -o /dev/null --connect-timeout 10 http://"${primaryServerAddress}":"${appPort}"/web/index.html)
214 appName=$(echo ${FUNCNAME[0]} |cut -c7-)
215 appLockFile="${tempDir}${appName}".lock
216 if [ -e "${appLockFile}" ]; then
217 :
218 else
219 if [[ "${extResponse}" = '200' ]] && [[ "${intResponse}" = '200' ]]; then
220 curl -fsS --retry 3 "${hcPingDomain}${hcUUID}" > /dev/null
221 elif [[ "${extResponse}" != '200' ]] || [[ "${intResponse}" != '200' ]]; then
222 curl -fsS --retry 3 "${hcPingDomain}${hcUUID}"/fail > /dev/null
223 fi
224 fi
225}
226
227
228
229
230# Function to check Portainer
231check_portainer() {
232 appPort='9000'
233 subDir='/portainer/'
234 hcUUID='XXXXXXXXXXXXXXXXXXX'
235 extResponse=$(curl -w "%{http_code}\n" -sI -o /dev/null --connect-timeout 10 https://"${domain}${subDir}" -H "token: ${orgAPIKey}")
236 intResponse=$(curl -w "%{http_code}\n" -sI -o /dev/null --connect-timeout 10 http://"${primaryServerAddress}":"${appPort}")
237 appName=$(echo ${FUNCNAME[0]} |cut -c7-)
238 appLockFile="${tempDir}${appName}".lock
239 if [ -e "${appLockFile}" ]; then
240 :
241 else
242 if [[ "${extResponse}" = '200' ]] && [[ "${intResponse}" = '200' ]]; then
243 curl -fsS --retry 3 "${hcPingDomain}${hcUUID}" > /dev/null
244 elif [[ "${extResponse}" != '200' ]] || [[ "${intResponse}" != '200' ]]; then
245 curl -fsS --retry 3 "${hcPingDomain}${hcUUID}"/fail > /dev/null
246 fi
247 fi
248}
249
250# Function to check Radarr
251check_radarr() {
252 appPort='32408'
253 subDir='/radarr/'
254 hcUUID='XXXXXXXXXXXXXXXX'
255 extResponse=$(curl -w "%{http_code}\n" -sI -o /dev/null --connect-timeout 10 https://"${domain}${subDir}" -H "token: ${orgAPIKey}")
256 intResponse=$(curl -w "%{http_code}\n" -sI -o /dev/null --connect-timeout 10 http://"${primaryServerAddress}":"${appPort}""${subDir}")
257 appName=$(echo ${FUNCNAME[0]} |cut -c7-)
258 appLockFile="${tempDir}${appName}".lock
259 if [ -e "${appLockFile}" ]; then
260 :
261 else
262 if [[ "${extResponse}" = '200' ]] && [[ "${intResponse}" = '200' ]]; then
263 curl -fsS --retry 3 "${hcPingDomain}${hcUUID}" > /dev/null
264 elif [[ "${extResponse}" != '200' ]] || [[ "${intResponse}" != '200' ]]; then
265 curl -fsS --retry 3 "${hcPingDomain}${hcUUID}"/fail > /dev/null
266 fi
267 fi
268}
269
270# Function to check Radarr4k
271check_radarr4k() {
272 appPort='32419'
273 subDir='/radarr4k/'
274 hcUUID='XXXXXXXXXXXXXX'
275 extResponse=$(curl -w "%{http_code}\n" -sI -o /dev/null --connect-timeout 10 https://"${domain}${subDir}" -H "token: ${orgAPIKey}")
276 intResponse=$(curl -w "%{http_code}\n" -sI -o /dev/null --connect-timeout 10 http://"${primaryServerAddress}":"${appPort}""${subDir}")
277 appName=$(echo ${FUNCNAME[0]} |cut -c7-)
278 appLockFile="${tempDir}${appName}".lock
279 if [ -e "${appLockFile}" ]; then
280 :
281 else
282 if [[ "${extResponse}" = '200' ]] && [[ "${intResponse}" = '200' ]]; then
283 curl -fsS --retry 3 "${hcPingDomain}${hcUUID}" > /dev/null
284 elif [[ "${extResponse}" != '200' ]] || [[ "${intResponse}" != '200' ]]; then
285 curl -fsS --retry 3 "${hcPingDomain}${hcUUID}"/fail > /dev/null
286 fi
287 fi
288}
289
290
291# Function to check Sonarr
292check_sonarr() {
293 appPort='32409'
294 subDir='/sonarr/'
295 hcUUID='XXXXXXXXXXXXXXX'
296 extResponse=$(curl -w "%{http_code}\n" -sI -o /dev/null --connect-timeout 10 https://"${domain}${subDir}" -H "token: ${orgAPIKey}")
297 intResponse=$(curl -w "%{http_code}\n" -sI -o /dev/null --connect-timeout 10 http://"${primaryServerAddress}":"${appPort}""${subDir}")
298 appName=$(echo ${FUNCNAME[0]} |cut -c7-)
299 appLockFile="${tempDir}${appName}".lock
300 if [ -e "${appLockFile}" ]; then
301 :
302 else
303 if [[ "${extResponse}" = '200' ]] && [[ "${intResponse}" = '200' ]]; then
304 curl -fsS --retry 3 "${hcPingDomain}${hcUUID}" > /dev/null
305 elif [[ "${extResponse}" != '200' ]] || [[ "${intResponse}" != '200' ]]; then
306 curl -fsS --retry 3 "${hcPingDomain}${hcUUID}"/fail > /dev/null
307 fi
308 fi
309}
310
311
312# Function to check Sonarr4k
313check_sonarr4k() {
314 appPort='32420'
315 subDir='/sonarr4k/'
316 hcUUID='XXXXXXXXXXXXXXX'
317 extResponse=$(curl -w "%{http_code}\n" -sI -o /dev/null --connect-timeout 10 https://"${domain}${subDir}" -H "token: ${orgAPIKey}")
318 intResponse=$(curl -w "%{http_code}\n" -sI -o /dev/null --connect-timeout 10 http://"${primaryServerAddress}":"${appPort}""${subDir}")
319 appName=$(echo ${FUNCNAME[0]} |cut -c7-)
320 appLockFile="${tempDir}${appName}".lock
321 if [ -e "${appLockFile}" ]; then
322 :
323 else
324 if [[ "${extResponse}" = '200' ]] && [[ "${intResponse}" = '200' ]]; then
325 curl -fsS --retry 3 "${hcPingDomain}${hcUUID}" > /dev/null
326 elif [[ "${extResponse}" != '200' ]] || [[ "${intResponse}" != '200' ]]; then
327 curl -fsS --retry 3 "${hcPingDomain}${hcUUID}"/fail > /dev/null
328 fi
329 fi
330}
331
332
333
334# Function to check Tautulli
335check_tautulli() {
336 appPort='32414'
337 subDir='/tautulli/auth/login'
338 hcUUID='XXXXXXXXXXXXXX'
339 extResponse=$(curl -w "%{http_code}\n" -sI -o /dev/null --connect-timeout 10 https://"${domain}${subDir}" -H "token: ${orgAPIKey}")
340 intResponse=$(curl -w "%{http_code}\n" -sI -o /dev/null --connect-timeout 10 http://"${primaryServerAddress}":"${appPort}""${subDir}")
341 appName=$(echo ${FUNCNAME[0]} |cut -c7-)
342 appLockFile="${tempDir}${appName}".lock
343 if [ -e "${appLockFile}" ]; then
344 :
345 else
346 if [[ "${extResponse}" = '200' ]] && [[ "${intResponse}" = '200' ]]; then
347 curl -fsS --retry 3 "${hcPingDomain}${hcUUID}" > /dev/null
348 elif [[ "${extResponse}" != '200' ]] || [[ "${intResponse}" != '200' ]]; then
349 curl -fsS --retry 3 "${hcPingDomain}${hcUUID}"/fail > /dev/null
350 fi
351 fi
352}
353
354
355# Function to check Deluge
356check_deluge() {
357 appPort='32453'
358 subDir='/deluge/'
359 hcUUID='XXXXXXXXXXXXX'
360extResponse=$(curl -o /dev/null --connect-timeout 10 -s -w "%{http_code}\n" https://"${domain}""${subDir}" -H "token: ${orgAPIKey}")
361intResponse=$(curl -o /dev/null --connect-timeout 10 -s -w "%{http_code}\n" http://"${primaryServerAddress}":"${appPort}")
362 appName=$(echo ${FUNCNAME[0]} |cut -c7-)
363 appLockFile="${tempDir}${appName}".lock
364 if [ -e "${appLockFile}" ]; then
365 :
366 else
367 if [[ "${extResponse}" = '200' ]] && [[ "${intResponse}" = '200' ]]; then
368 curl -fsS --retry 3 "${hcPingDomain}${hcUUID}" > /dev/null
369 elif [[ "${extResponse}" != '200' ]] || [[ "${intResponse}" != '200' ]]; then
370 curl -fsS --retry 3 "${hcPingDomain}${hcUUID}"/fail > /dev/null
371 fi
372 fi
373}
374
375
376# Main function to run all other functions
377main() {
378
379 check_monitorr
380 check_grafana
381 check_nzbhydra
382 check_jackett
383 check_portainer
384 check_bazarr
385 check_sonarr4k
386 check_sonarr
387 check_radarr4k
388 check_radarr
389 check_lidarr
390 check_tautulli
391 check_ombi
392 check_deluge
393 check_nzbget
394 check_plex
395}
396
397check_lock_file