Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
icinga-checks
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IML Open Source
icinga-checks
Commits
4e62949f
Commit
4e62949f
authored
1 year ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
check_hhtp - handle empty response
parent
dc06fdb7
No related branches found
No related tags found
1 merge request
!164
check_http - handle empty response
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
check_http
+70
-71
70 additions, 71 deletions
check_http
with
70 additions
and
71 deletions
check_http
+
70
−
71
View file @
4e62949f
...
@@ -33,7 +33,7 @@ Additionally you can verify the response by
...
@@ -33,7 +33,7 @@ Additionally you can verify the response by
SYNTAX:
SYNTAX:
$_self
[-h]
$_self
[-h]
$_self
[-m METHOD] -u URL
\\
$_self
[-m METHOD] -u URL
[-c PARAMS]
\\
[-b REGEX] [-j FILTER] [-n REGEX]
\\
[-b REGEX] [-j FILTER] [-n REGEX]
\\
[-r REGEX]
\\
[-r REGEX]
\\
[-s STATUSCODE]
\\
[-s STATUSCODE]
\\
...
@@ -48,7 +48,8 @@ PARAMETERS:
...
@@ -48,7 +48,8 @@ PARAMETERS:
Define request:
Define request:
-u URL Set url to fetch; eg. https://www.example.com/
-u URL Set url to fetch; eg. https://www.example.com/
-m METHOD Set a method, eg. HEAD; default: GET
-m METHOD Set a method, eg. HEAD; default: GET
-c PARAMS additional curl params
-c PARAMS additional curl params; curl will be executed
with '[PARAMS] -si -X [METHOD] --connect-timeout 10 [URL]'
What to check:
What to check:
-s STATUSCODE exact Statuscode to check; 3 digits; by default critical
-s STATUSCODE exact Statuscode to check; 3 digits; by default critical
...
@@ -112,7 +113,7 @@ sNotInBody=$( ph.getValueWithParam '' n "$@")
...
@@ -112,7 +113,7 @@ sNotInBody=$( ph.getValueWithParam '' n "$@")
sJq
=
$(
ph.getValueWithParam
''
j
"
$@
"
)
sJq
=
$(
ph.getValueWithParam
''
j
"
$@
"
)
sLabel
=
$(
ph.getValueWithParam
""
l
"
$@
"
)
sLabel
=
$(
ph.getValueWithParam
""
l
"
$@
"
)
curlParams+
=
" -si -X
$sMethod
"
curlParams+
=
" -si -X
$sMethod
--connect-timeout 10
"
sProblems
=
sProblems
=
sOK
=
sOK
=
...
@@ -123,11 +124,13 @@ if [ -z "$sUrl" ]; then
...
@@ -123,11 +124,13 @@ if [ -z "$sUrl" ]; then
fi
fi
out
=
$(
curl
$curlParams
"
$sUrl
"
)
out
=
$(
curl
$curlParams
"
$sUrl
"
)
if
[
-z
"
$out
"
]
;
then
ph.setStatus critical
sProblems+
=
"- Url [
${
sUrl
}
] not reachable - response is empty;
\n
"
iHttpStatus
=
'???'
else
iHeaderEnd
=
$(
echo
"
$out
"
|
grep
-n
^
$'
\r
'
|
cut
-f
1
-d
':'
|
head
-1
)
iHeaderEnd
=
$(
echo
"
$out
"
|
grep
-n
^
$'
\r
'
|
cut
-f
1
-d
':'
|
head
-1
)
# echo "$out" | grep -n ^$'\r'; echo "cut header and body on line $iHeaderEnd"
_header
=
$(
echo
"
$out
"
|
sed
-n
"1,
${
iHeaderEnd
}
p"
)
_header
=
$(
echo
"
$out
"
|
sed
-n
"1,
${
iHeaderEnd
}
p"
)
_body
=
$(
echo
"
$out
"
|
sed
-n
"
${
iHeaderEnd
}
,
\$
p"
)
_body
=
$(
echo
"
$out
"
|
sed
-n
"
${
iHeaderEnd
}
,
\$
p"
)
...
@@ -135,10 +138,6 @@ if [ -n "$sJq" ]; then
...
@@ -135,10 +138,6 @@ if [ -n "$sJq" ]; then
_body
=
$(
jq
"
$sJq
"
<<<
"
$_body
"
2>/dev/null
)
_body
=
$(
jq
"
$sJq
"
<<<
"
$_body
"
2>/dev/null
)
fi
fi
# echo "HEADER"; echo "$_header"
# echo "BODY"; echo "$_body"
# --- test status
# --- test status
typeset
-i
iHttpStatus
typeset
-i
iHttpStatus
iHttpStatus
=
$(
grep
-i
"^HTTP/[0-9
\.
]* "
<<<
"
${
_header
}
"
|
awk
'{ print $2 }'
)
iHttpStatus
=
$(
grep
-i
"^HTTP/[0-9
\.
]* "
<<<
"
${
_header
}
"
|
awk
'{ print $2 }'
)
...
@@ -201,6 +200,8 @@ if [ -n "$sNotInBody" ]; then
...
@@ -201,6 +200,8 @@ if [ -n "$sNotInBody" ]; then
fi
fi
fi
# --- output
# --- output
test
-n
"
$sProblems
"
&&
sProblems
=
"Problems:
\n
$sProblems
\n
"
test
-n
"
$sProblems
"
&&
sProblems
=
"Problems:
\n
$sProblems
\n
"
test
-n
"
$sOK
"
&&
sOK
=
"Found:
\n
$sOK
"
test
-n
"
$sOK
"
&&
sOK
=
"Found:
\n
$sOK
"
...
@@ -211,8 +212,6 @@ test -n "$sLabel" && (
...
@@ -211,8 +212,6 @@ test -n "$sLabel" && (
)
)
test
-n
"
$sLabel
"
||
ph.status
"
$sMethod
$sUrl
(
$iHttpStatus
)"
test
-n
"
$sLabel
"
||
ph.status
"
$sMethod
$sUrl
(
$iHttpStatus
)"
echo
echo
Command: curl
$curlParams
"
$sUrl
"
echo
echo
echo
-e
"
${
sProblems
}${
sOK
}
"
echo
-e
"
${
sProblems
}${
sOK
}
"
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment