Skip to content

Commit 634cc71

Browse files
authored
Merge pull request #4 from Napsty/fix-issue-3
Detect invalid hostname (non-API hostname)
2 parents 4aa1d36 + aef7903 commit 634cc71

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

check_rancher2.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
# 20181107 beta8 Missing pod check type in help, documentation completed #
3232
# 20181109 1.0.0 Do not alert for succeeded pods #
3333
# 20190308 1.1.0 Added node(s) check #
34+
# 20190903 1.1.1 Detect invalid hostname (non-API hostname) #
3435
##########################################################################################
3536
# (Pre-)Define some fixed variables
3637
STATE_OK=0 # define the exit code if status is OK
@@ -39,7 +40,7 @@ STATE_CRITICAL=2 # define the exit code if status is Critical
3940
STATE_UNKNOWN=3 # define the exit code if status is Unknown
4041
export PATH=/usr/local/bin:/usr/bin:/bin:$PATH # Set path
4142
proto=http # Protocol to use, default is http, can be overwritten with -S parameter
42-
version=1.1.0
43+
version=1.1.1
4344

4445
# Check for necessary commands
4546
for cmd in jshon curl [
@@ -108,7 +109,9 @@ if [ -z $type ]; then echo -e "CHECK_RANCHER2 UNKNOWN - Missing check type"; exi
108109
apicheck=$(curl -s -o /dev/null -w "%{http_code}" -u "${apiuser}:${apipass}" "${proto}://${apihost}/v3/project")
109110

110111
# Detect failures
111-
if [[ $apicheck = 301 ]]
112+
if [[ $apicheck = 000 ]]
113+
then echo -e "CHECK_RANCHER2 UNKNOWN - Invalid host address detected: ${apihost}. Use valid IP or DNS name on which the Rancher 2 API is accessible."; exit ${STATE_UNKNOWN}
114+
elif [[ $apicheck = 301 ]]
112115
then echo -e "CHECK_RANCHER2 UNKNOWN - Redirect detected. Maybe http to https? Use -S parameter."; exit ${STATE_UNKNOWN}
113116
elif [[ $apicheck = 302 ]]
114117
then echo -e "CHECK_RANCHER2 UNKNOWN - Redirect detected. Maybe http to https? Use -S parameter."; exit ${STATE_UNKNOWN}

0 commit comments

Comments
 (0)