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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IML Open Source
icinga-checks
Commits
e002363f
Commit
e002363f
authored
3 years ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
haproxy status: use updated haproxy paser in sourced file
parent
a990964c
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
check_haproxy_health
+3
-0
3 additions, 0 deletions
check_haproxy_health
check_haproxy_status
+10
-71
10 additions, 71 deletions
check_haproxy_status
inc_haproxy_cfg.sh
+1
-1
1 addition, 1 deletion
inc_haproxy_cfg.sh
with
14 additions
and
72 deletions
check_haproxy_health
+
3
−
0
View file @
e002363f
...
...
@@ -39,6 +39,9 @@ fi
# ----------------------------------------------------------------------
url
=
$(
getHealthUri
)
if
[
-z
"
$url
"
]
;
then
ph.abort
"UNKNOWN: Unable to detect url for health status."
fi
# remove password for showing url in output
safeurl
=
$(
echo
$url
|
sed
"s#
\(
://
\)\(
.*@
\)
#
\1
#g"
)
...
...
This diff is collapsed.
Click to expand it.
check_haproxy_status
+
10
−
71
View file @
e002363f
...
...
@@ -14,12 +14,13 @@
# 2020-04-29 v1.2 <axel.hahn@iml.unibe.ch> parse ini section by given section
# 2020-06-03 v1.3 <axel.hahn@iml.unibe.ch> added ping to each backend server
# 2020-12-03 v1.4 <axel.hahn@iml.unibe.ch> added support of multiple front- and backends
# 2021-12-14 v1.5 <axel.hahn@iml.unibe.ch> use updated haproxy paser in sourced file
# ======================================================================
.
`
dirname
$0
`
/inc_pluginfunctions
.
`
dirname
$0
`
/inc_haproxy_cfg.sh
cfgfile
=
/etc/haproxy/haproxy.cfg
cfgfile2
=
/tmp/haproxy.config
tmpfile
=
/tmp/check_haproxy_status_
$$
tmpfile2
=
/tmp/check_haproxy_status2_
$$
...
...
@@ -51,51 +52,6 @@ fi
# functions
# ----------------------------------------------------------------------
# rewrite the ha proxy config file to parse it by section
function
cfgrewriter
(){
local
_section
=
IFS
=
''
while
read
line
do
echo
$line
|
grep
"^[a-z]"
>
/dev/null
if
[
$?
-eq
0
]
;
then
_section
=
$line
echo
"# new section:
$_section
"
fi
echo
$line
|
grep
"^
\ \
[a-z]*"
>
/dev/null
if
[
$?
-eq
0
]
;
then
echo
-n
"
$_section
: "
echo
$line
|
sed
"s#
\ \
# #g"
fi
done
<
$cfgfile
}
# get a value from a given a given section
function
_getCfgVarFromSection
(){
local
_var
=
$1
local
_section
=
$2
grep
"^
${
_section
}
:
\ \
${
_var
}
\
"
$cfgfile2
>
/dev/null
&&
(
typeset
-i
local
_iColumnVal
=
`
echo
"
${
_section
}
:
$_var
"
|
wc
-c
`
+1
grep
"^
${
_section
}
:
\ \
${
_var
}
\
"
$cfgfile2
|
cut
-c
${
_iColumnVal
}
-
)
}
# get a value from config - with autoscan of other sections
function
getCfgvar
(){
local
_var
=
$1
local
_section
=
$2
_getCfgVarFromSection
"
${
_var
}
"
"
${
_section
}
"
\
||
_getCfgVarFromSection
"
${
_var
}
"
"frontend stats_frontend"
\
||
_getCfgVarFromSection
"
${
_var
}
"
"frontend couchdb_frontend"
\
||
_getCfgVarFromSection
"
${
_var
}
"
"frontend postgresql_frontend"
\
||
_getCfgVarFromSection
"
${
_var
}
"
"frontend opencpu"
\
||
_getCfgVarFromSection
"
${
_var
}
"
"frontend apache_fop"
\
||
_getCfgVarFromSection
"
${
_var
}
"
"defaults"
\
||
_getCfgVarFromSection
"
${
_var
}
"
"global"
}
# find a column number of a given field name in haproxy csv
function
getColnumber
(){
...
...
@@ -132,32 +88,15 @@ function checkStatus(){
# build url
# ----------------------------------------------------------------------
cfgrewriter
>
$cfgfile2
# getCfgvar "bind" "frontend stats_frontend"
# getCfgvar "stats auth" "frontend stats_frontend"
# exit
proto
=
http
auth
=
host
=
localhost
typeset
-i
port
=
80
uri
=
getCfgvar
"bind"
"frontend stats_frontend"
|
grep
"
\
ssl
\
"
>
/dev/null
&&
proto
=
https
auth
=
`
getCfgvar
"stats auth"
"frontend stats_frontend"
`
port
=
`
getCfgvar
"bind"
"frontend stats_frontend"
|
cut
-f
2
-d
':'
|
cut
-f
1
-d
" "
`
host
=
`
getCfgvar
"bind"
"frontend stats_frontend"
|
cut
-f
1
-d
':'
`
uri
=
`
getCfgvar
"stats uri"
"frontend stats_frontend"
`
if
[
"
$host
"
=
"*"
]
;
then
host
=
"localhost"
url
=
$(
getStatusUri
)
if
[
-z
"
$url
"
]
;
then
ph.abort
"UNKNOWN: Unable to detect url for status page."
fi
url
=
"
$proto
://
${
auth
}
@
${
host
}
:
${
port
}${
uri
}
;csv;norefresh"
urlmasked
=
"
$proto
://*password*@
${
host
}
:
${
port
}${
uri
}
;csv;norefresh"
url
=
"
${
url
}
;csv;norefresh"
# remove password for showing url in output
urlmasked
=
$(
echo
$url
|
sed
"s#
\(
://
\)\(
.*@
\)
#
\1
#g"
)
# ----------------------------------------------------------------------
# check output
...
...
@@ -167,7 +106,7 @@ urlmasked="$proto://*password*@${host}:${port}${uri};csv;norefresh"
# --- get status page
wget
--no-check-certificate
-O
$tmpfile
$url
2>/dev/null
if
[
$?
-ne
0
]
;
then
rm
-f
$tmpfile
$cfgfile2
rm
-f
$tmpfile
ph.abort
"UNKNOWN: url
$urlmasked
did not respond.
`
wget
--no-check-certificate
-O
-
-S
$url
`
"
fi
...
...
@@ -252,7 +191,7 @@ do
done
<
$tmpfile2
rm
-f
$cfgfile2
$tmpfile
$tmpfile2
2>/dev/null
rm
-f
$tmpfile
$tmpfile2
2>/dev/null
ph.exit
# ----------------------------------------------------------------------
This diff is collapsed.
Click to expand it.
inc_haproxy_cfg.sh
+
1
−
1
View file @
e002363f
...
...
@@ -19,7 +19,7 @@ HAPROXYdoCache=0
# TESTING ONLY
# HAPROXYcfgfile=./haproxy-
ldap
01.cfg
# HAPROXYcfgfile=./haproxy-01.cfg
# /TESTING
...
...
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