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 1
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
+
144
−
0
Side-by-side
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
check_http
0 → 100755
+
144
−
0
View file @ f8ced56e
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
)
TODO
SYNTAX:
$_self
[-h] ...
OPTIONS:
-h this help
-u URL Set url to fetch
-s STATUSCODE Statuscode to ceck
-r REGEX String to check in http response header
-b REGEX String to check in response body
EXAMPLES:
$_self
-u
EOF
}
function
getHeader
(){
set
-vx
echo
"
$1
"
|
sed
-n
"1,
${
2
}
p"
}
function
getHeader
(){
set
-vx
echo
"
$1
"
|
sed
-n
"1,
${
2
}
p"
}
# ----------------------------------------------------------------------
# MAIN
# ----------------------------------------------------------------------
ph.hasParamoption
"h"
"
$@
"
;
bOptHelp
=
$?
if
[
$bOptHelp
-eq
0
-o
$#
-eq
0
]
;
then
showHelp
exit
0
fi
ph.require
"curl"
sUrl
=
$(
ph.getValueWithParam
''
u
"
$@
"
)
iStatus
=
$(
ph.getValueWithParam
'200'
s
"
$@
"
)
sHeader
=
$(
ph.getValueWithParam
''
r
"
$@
"
)
sBody
=
$(
ph.getValueWithParam
''
b
"
$@
"
)
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"
)
# 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+
=
"- Statuscode is not [
${
iStatus
}
];
\n
"
else
sOK+
=
"- Statuscode is [
${
iStatus
}
];
\n
"
fi
fi
if
[
-n
"
$sHeader
"
]
;
then
if
!
grep
-i
"
$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
if
[
-n
"
$sBody
"
]
;
then
if
!
grep
-i
"
$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
test
-n
"
$sProblems
"
&&
sProblems
=
"Problems:
\n
$sProblems
\n
"
test
-n
"
$sOK
"
&&
sOK
=
"Found:
\n
$sOK
"
ph.status
"Url
${
sUrl
}
"
echo
echo
-e
"
${
sProblems
}${
sOK
}
"
echo
# echo "HEADER:"; echo "$_header"
ph.exit
# ----------------------------------------------------------------------
Loading