-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathswarm-client-healthCheck.sh
More file actions
executable file
·59 lines (48 loc) · 2.11 KB
/
Copy pathswarm-client-healthCheck.sh
File metadata and controls
executable file
·59 lines (48 loc) · 2.11 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
#!/usr/bin/env bash
# Jenkins Swarm Client integration for NUT CI farm
# Copyright (C)
# 2021-2026 by Jim Klimov <jimklimov+nut@gmail.com>
# License: MIT
# Check what Jenkins controller thinks about this agent -
# is it known? online? ...known failed to launch?
# See also jenkins-agent-toggle.sh
SCRIPTDIR="`dirname \"$0\"`"
SCRIPTDIR="`cd \"${SCRIPTDIR}\" && pwd`"
[ -n "${AGENT_NAME-}" ] || AGENT_NAME="`hostname | sed 's,\..*$,,'`"
cd "${SCRIPTDIR}/../jenkins-${AGENT_NAME}/" || exit
( command -v curl || command -v wget ) >/dev/null 2>&1 || exit
JENKINS_URL="`grep -E '^url:' jenkins-swarm.yml | awk '{print $NF}' | sed -e 's,^\"\(.*\)\"$,\1,' -e 's,/*$,,'`"
# Hopefully same as AGENT_NAME:
NODENAME="`grep -E '^name:' jenkins-swarm.yml | awk '{print $NF}' | sed 's,^\"\(.*\)\"$,\1,'`"
TEMP="`mktemp -p \"${TMPDIR:-/tmp}\" -d swarm-client-healthCheck.XXXXXX`" || exit
trap 'rm -rf "$TEMP"' 0 1 2 3 15
API_URL="${JENKINS_URL}/computer/${NODENAME}/api/json"
if command -v curl >/dev/null 2>&1 ; then
curl -vkL "$API_URL"
else
wget -O - "$API_URL"
fi 1>"$TEMP/json-api.out" 2>"$TEMP/json-api.err"
if grep -E '^(< H|H)TTP.* 200' "$TEMP/json-api.err" >/dev/null ; then
# Parse JSON
if grep '"offline":true' "$TEMP/json-api.out" >/dev/null \
&& grep '"temporarilyOffline":false' "$TEMP/json-api.out" >/dev/null \
; then
echo "VERDICT: Query for $API_URL returned HTTP/200 and JSON indicates the agent is known, offline, and not administratively downed (not temporarilyOffline)" >&2
if grep 'OfflineCause$LaunchFailed' "$TEMP/json-api.out" >/dev/null ; then
echo "VERDICT: Hit 'OfflineCause - LaunchFailed' " >&2
exit 43
fi
fi
# else the agent is online okay or administratively down
exit 0
else
if grep -E '^(< H|H)TTP.* 404' "$TEMP/json-api.err" >/dev/null ; then
echo "VERDICT: Query for $API_URL returned HTTP/404 - assuming node is not recognized" >&2
exit 44
else
echo "VERDICT: Query for $API_URL did not return HTTP/404 nor HTTP/200 - assuming query timeout etc." >&2
exit 0
fi
fi
# Should not get here
exit 0