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
Merge requests
!162
check_http first lines
Code
Review changes
Check out branch
Download
Patches
Plain diff
Expand sidebar
Merged
check_http first lines
add-systemdunit
into
master
Overview
0
Commits
7
Pipelines
0
Changes
1
Merged
Hahn Axel (hahn)
requested to merge
add-systemdunit
into
master
1 year ago
Overview
0
Commits
7
Pipelines
0
Changes
1
0
0
Merge request reports
Compare
master
version 4
af1c1137
1 year ago
version 3
84b4fb05
1 year ago
version 2
c2a55b20
1 year ago
version 1
f8ced56e
1 year ago
master (base)
and
version 3
latest version
961c63cd
7 commits,
1 year ago
version 4
af1c1137
4 commits,
1 year ago
version 3
84b4fb05
3 commits,
1 year ago
version 2
c2a55b20
2 commits,
1 year ago
version 1
f8ced56e
1 commit,
1 year ago
1 file
+
161
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
check_http
0 → 100755
+
161
−
0
View file @ 84b4fb05
Edit in single-file editor
Open in Web IDE
#!/bin/bash
# ================================================================================
#
# CHECK HTTP
#
#
# -------------------------------------------------------------------------------
# 2023-09-05 v0.1 <axel.hahn@unibe.ch>
# ================================================================================
.
$(
dirname
$0
)
/inc_pluginfunctions
export
self_APPVERSION
=
1.0
# ----------------------------------------------------------------------
# FUNCTIONS
# ----------------------------------------------------------------------
# show help text
function
showHelp
(){
local
_self
;
_self
=
$(
basename
$0
)
cat
<<
EOF
$(
ph.showImlHelpHeader
)
Makes an http request to chewck the response by
- http status code
- content in http response header
- content in http response body
SYNTAX:
$_self
[-h] ...
OPTIONS:
-h this help
PARAMETERS:
Define request:
-u URL Set url to fetch
-m METHOD Set a method, eg. HEAD; default: GET
What to check:
-s STATUSCODE Statuscode to ceck
-r REGEX String to check in http response header
-j JQ-FILTER for JSON Response: filter data by a jq
-b REGEX String to check in response body
Output:
-l LABEL set a custom label; default: METHOD + URL eg.
"GET https://example.com/status"
EXAMPLES:
$_self
...
EOF
}
# ----------------------------------------------------------------------
# MAIN
# ----------------------------------------------------------------------
ph.hasParamoption
"h"
"
$@
"
;
bOptHelp
=
$?
if
[
$bOptHelp
-eq
0
-o
$#
-eq
0
]
;
then
showHelp
exit
0
fi
ph.require
"curl"
sUrl
=
$(
ph.getValueWithParam
''
u
"
$@
"
)
sMethod
=
$(
ph.getValueWithParam
'GET'
m
"
$@
"
|
tr
[
:lower:]
[
:upper:]
)
iStatus
=
$(
ph.getValueWithParam
'200'
s
"
$@
"
)
sHeader
=
$(
ph.getValueWithParam
''
r
"
$@
"
)
sBody
=
$(
ph.getValueWithParam
''
b
"
$@
"
)
sJq
=
$(
ph.getValueWithParam
''
j
"
$@
"
)
sLabel
=
$(
ph.getValueWithParam
"
$sMethod
$sUrl
"
l
"
$@
"
)
curlParams
=
"-si"
sProblems
=
sOK
=
if
[
-z
"
$sUrl
"
]
;
then
ph.setStatus unknown
ph.status
"Wrong parameters - no url was given."
ph.exit
fi
# test -z "$sBody" && curlParams+=" -I"
out
=
$(
curl
$curlParams
"
$sUrl
"
)
iHeaderEnd
=
$(
echo
"
$out
"
|
grep
-n
^
$'
\r
'
|
cut
-f
1
-d
':'
)
_header
=
$(
echo
"
$out
"
|
sed
-n
"1,
${
iHeaderEnd
}
p"
)
_body
=
$(
echo
"
$out
"
|
sed
-n
"
${
iHeaderEnd
}
,
\$
p"
)
if
[
-n
"
$sJq
"
]
;
then
_body
=
$(
jq
"
$sJq
"
<<<
"
$_body
"
2>/dev/null
)
fi
# echo "HEADER"; echo "$_header"
# echo "BODY"; echo "$_body"
# --- test status
if
[
-n
"
$iStatus
"
]
;
then
if
!
grep
-i
"^HTTP/[0-9
\.
]*
${
iStatus
}
"
<<<
"
${
_header
}
"
>
/dev/null
;
then
ph.setStatus critical
sProblems+
=
"- Http status is not [
${
iStatus
}
];
\n
"
else
sOK+
=
"- Http status is [
${
iStatus
}
];
\n
"
fi
fi
# --- search in http response header
if
[
-n
"
$sHeader
"
]
;
then
if
!
grep
-iE
"
$sHeader
"
<<<
"
${
_header
}
"
>
/dev/null
;
then
ph.setStatus critical
sProblems+
=
"- Header does not contain [
${
sHeader
}
];
\n
"
else
sOK+
=
"- [
${
sHeader
}
] was found in header;
\n
"
fi
fi
# --- search in http response body
if
[
-n
"
$sBody
"
]
;
then
if
!
grep
-iE
"
$sBody
"
<<<
"
${
_body
}
"
>
/dev/null
;
then
ph.setStatus critical
sProblems+
=
"- Body does not contain [
${
sBody
}
];
\n
"
else
sOK+
=
"- [
${
sBody
}
] was found in body;
\n
"
fi
fi
# --- output
test
-n
"
$sProblems
"
&&
sProblems
=
"Problems:
\n
$sProblems
\n
"
test
-n
"
$sOK
"
&&
sOK
=
"Found:
\n
$sOK
"
ph.status
"
$sLabel
"
if
[
"
$sLabel
"
!=
"
$sMethod
$sUrl
"
]
;
then
echo
"
$sMethod
$sUrl
"
fi
echo
echo
-e
"
${
sProblems
}${
sOK
}
"
echo
"HEADER:"
;
echo
;
echo
"
$_header
"
echo
-n
"Eapsed time: "
;
ph.showtimer
ph.exit
# ----------------------------------------------------------------------
Loading