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
42d5fc59
Commit
42d5fc59
authored
1 year ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
couchdb: add pending updates
parent
6adcf000
No related branches found
No related tags found
1 merge request
!150
6588 add couchdb check - add pending updates
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
check_couchdb
+52
-25
52 additions, 25 deletions
check_couchdb
with
52 additions
and
25 deletions
check_couchdb
+
52
−
25
View file @
42d5fc59
...
@@ -16,13 +16,15 @@
...
@@ -16,13 +16,15 @@
# 2023-08-28 v0.1 <axel.hahn@unibe.ch> first lines
# 2023-08-28 v0.1 <axel.hahn@unibe.ch> first lines
# 2023-08-28 v0.2 <axel.hahn@unibe.ch> first check "up"
# 2023-08-28 v0.2 <axel.hahn@unibe.ch> first check "up"
# 2023-08-28 v0.3 <axel.hahn@unibe.ch> add check "replication"
# 2023-08-28 v0.3 <axel.hahn@unibe.ch> add check "replication"
# 2023-08-28 v0.4 <axel.hahn@unibe.ch> add check "pending"
# ======================================================================
# ======================================================================
.
$(
dirname
$0
)
/inc_pluginfunctions
.
$(
dirname
$0
)
/inc_pluginfunctions
export
self_APPVERSION
=
0.
3
export
self_APPVERSION
=
0.
4
cfgfile
=
/etc/icingaclient/.couchdb
cfgfile
=
/etc/icingaclient/.couchdb
export
RESPONSE
# ----------------------------------------------------------------------
# ----------------------------------------------------------------------
# FUNCTIONS
# FUNCTIONS
...
@@ -49,6 +51,7 @@ OPTIONS:
...
@@ -49,6 +51,7 @@ OPTIONS:
MODE is one of
MODE is one of
up show general couchdb status
up show general couchdb status
replication show last replication status
replication show last replication status
pending show count of pending updates for nodes, dbs and users
EXAMPLE:
EXAMPLE:
$_self
-m up
$_self
-m up
...
@@ -59,21 +62,18 @@ EOF
...
@@ -59,21 +62,18 @@ EOF
# get couchdb status by given url and a filter
# get couchdb status by given url and a filter
# The check aborts here if no data were found.
# The check aborts here if no data were found.
# Response is written into global var RESPONSE
#
# param string url to request; the part behind couchdb base url
# param string url to request; the part behind couchdb base url
# param string string to search for in the content
# param string string to search for in the content
function
get
(){
_path
=
"
$1
"
curl
-s
"
${
COUCH_URL
}${
_path
}
"
}
function
abortOnWrongResponse
(){
function
abortOnWrongResponse
(){
_response
=
"
$1
"
_path
=
"
$1
"
_path
=
"
$2
"
_filter
=
"
$2
"
_filter
=
"
$3
"
if
!
grep
"
$_filter
"
<<<
"
$_response
"
>
/dev/null
;
then
RESPONSE
=
$(
curl
-s
"
${
COUCH_URL
}${
_path
}
"
)
if
!
grep
"
$_filter
"
<<<
"
$RESPONSE
"
>
/dev/null
;
then
echo
"ERROR: Wrong response from
$_path
- it does not contain
$_filter
"
echo
"ERROR: Wrong response from
$_path
- it does not contain
$_filter
"
curl
-si
"
${
COUCH_URL
}${
2
}
"
curl
-si
"
${
COUCH_URL
}${
_path
}
"
ph.abort
ph.abort
fi
fi
}
}
...
@@ -105,29 +105,31 @@ fi
...
@@ -105,29 +105,31 @@ fi
if
[
-z
"
$COUCH_URL
"
]
;
then
if
[
-z
"
$COUCH_URL
"
]
;
then
echo
"ERROR: I have no couchdb url + authentication yet."
echo
"ERROR: I have no couchdb url + authentication yet."
echo
"
Maybe you need to add -t /etc/telegraf/telegraf.conf.
"
echo
"
set 'export COUCH_URL=http://USER:PW@localhost:5984' in
$cfgfile
"
ph.abort
ph.abort
fi
fi
# ----------------------------------------------------------------------
# ----------------------------------------------------------------------
case
"
${
sMode
}
"
in
case
"
${
sMode
}
"
in
# ............................................................
"up"
)
"up"
)
response
=
$(
get
"
/_up
"
)
REQ
=
/_up
abortOnWrongResponse
"
$
response
"
"/_up
"
'"status":"'
abortOnWrongResponse
"
$
{
REQ
}
"
'"status":"'
_status
=
$(
jq
'.status'
<<<
"
${
response
}
"
|
tr
-d
'"'
)
_status
=
$(
jq
'.status'
<<<
"
${
RESPONSE
}
"
|
tr
-d
'"'
)
if
!
echo
"
$_status
"
|
grep
"ok"
>
/dev/null
;
then
if
!
echo
"
$_status
"
|
grep
"ok"
>
/dev/null
;
then
ph.setStatus critical
ph.setStatus critical
fi
fi
ph.status
"Couchdb status (value 'status' in
/_up
is '
$_status
')"
ph.status
"Couchdb
:: health
status (value 'status' in
${
REQ
}
is '
$_status
')"
echo
"Reponse: "
;
echo
"
${
response
}
"
| jq
echo
"Reponse
of
${
REQ
}
: "
;
echo
"
${
RESPONSE
}
"
| jq
;;
;;
# ............................................................
"replication"
)
"replication"
)
response
=
$(
get
"
/_up
"
)
REQ
=
/_up
abortOnWrongResponse
"
$
response
"
"/_up
"
'"status":"'
abortOnWrongResponse
"
$
{
REQ
}
"
'"status":"'
_status
=
$(
jq
'.seeds[] | .last_replication_status'
<<<
"
${
response
}
"
|
grep
-v
"null"
|
tr
-d
'"'
)
_status
=
$(
jq
'.seeds[] | .last_replication_status'
<<<
"
${
RESPONSE
}
"
|
grep
-v
"null"
|
tr
-d
'"'
)
# there can be multiple sections "seeds" and multiple line responses.
# there can be multiple sections "seeds" and multiple line responses.
# remove all lines with "ok" and check if there is any "bad content" left
# remove all lines with "ok" and check if there is any "bad content" left
...
@@ -135,12 +137,37 @@ case "${sMode}" in
...
@@ -135,12 +137,37 @@ case "${sMode}" in
if
[
-n
"
$_nonok
"
]
;
then
if
[
-n
"
$_nonok
"
]
;
then
ph.setStatus critical
ph.setStatus critical
fi
fi
if
!
echo
"
$_status
"
|
grep
"ok"
>
/dev/null
;
then
ph.setStatus critical
ph.status
"Couchdb :: replication (values 'last_replication_status' in
${
REQ
}
are '
$_status
')"
fi
echo
"Reponse: of
${
REQ
}
"
;
echo
"
${
RESPONSE
}
"
| jq
ph.status
"Couchdb replication"
;;
echo
"Reponse: "
;
echo
"
${
response
}
"
| jq
# ............................................................
"pending"
)
REQ
=
/_up
abortOnWrongResponse
"
${
REQ
}
"
'"status":"'
_status
=
$(
jq
'.seeds[] | .pending_updates'
<<<
"
${
RESPONSE
}
"
|
grep
-v
"null"
|
tr
-d
'"'
)
typeset
-i
_iSumme
typeset
-i
_iTotal
_iTotal
=
0
for
myvar
in
_nodes _dbs _users
do
_iSumme
=
0
for
myvalue
in
$(
grep
"
$myvar
"
<<<
"
$_status
"
|
cut
-f
2
-d
':'
|
tr
-d
','
)
do
_iSumme+
=
$myvalue
test
"
$myvalue
"
-gt
0
&&
ph.setStatus warning
done
ph.perfadd
"
$myvar
"
"
$_iSumme
"
""
""
_iTotal+
=
$_iSumme
done
ph.status
"Couchdb :: pending updates:
$_iTotal
(values below 'pending_updates' in
${
REQ
}
)"
echo
"Reponse: of
${
REQ
}
"
;
echo
"
${
RESPONSE
}
"
| jq
;;
;;
# ............................................................
*
)
*
)
echo
"ERRROR: [
${
sMode
}
] is an INVALID mode"
echo
"ERRROR: [
${
sMode
}
] is an INVALID mode"
showHelp
showHelp
...
...
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