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
7421bb01
Commit
7421bb01
authored
1 year ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
add check replication
parent
0c2289d8
No related branches found
No related tags found
1 merge request
!149
6588 add couchdb check
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
check_couchdb
+54
-5
54 additions, 5 deletions
check_couchdb
with
54 additions
and
5 deletions
check_couchdb
+
54
−
5
View file @
7421bb01
...
...
@@ -15,11 +15,12 @@
# ----------------------------------------------------------------------
# 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.3 <axel.hahn@unibe.ch> add check "replication"
# ======================================================================
.
$(
dirname
$0
)
/inc_pluginfunctions
export
self_APPVERSION
=
0.
2
export
self_APPVERSION
=
0.
3
cfgfile
=
/etc/icingaclient/.couchdb
...
...
@@ -42,7 +43,12 @@ OPTIONS:
-h or --help show this help.
-c CFGFILE set a custom config file
default:
${
cfgfile
}
-m MODE test a value; for debugging purposes
-m MODE test a value; for debugging purposes the full json
response will be shown
MODE is one of
up show general couchdb status
replication show last replication status
EXAMPLE:
$_self
-m up
...
...
@@ -51,6 +57,27 @@ $_self -m up
EOF
}
# get couchdb status by given url and a filter
# The check aborts here if no data were found.
# param string url to request; the part behind couchdb base url
# param string string to search for in the content
function
get
(){
_path
=
"
$1
"
curl
-s
"
${
COUCH_URL
}${
_path
}
"
}
function
abortOnWrongResponse
(){
_response
=
"
$1
"
_path
=
"
$2
"
_filter
=
"
$3
"
if
!
grep
"
$_filter
"
<<<
"
$_response
"
>
/dev/null
;
then
echo
"ERROR: Wrong response from
$_path
- it does not contain
$_filter
"
curl
-si
"
${
COUCH_URL
}${
2
}
"
ph.abort
fi
}
# ----------------------------------------------------------------------
# MAIN
# ----------------------------------------------------------------------
...
...
@@ -64,6 +91,8 @@ case "$1" in
*
)
esac
ph.require jq
sMode
=
$(
ph.getValueWithParam
''
"m"
"
$@
"
)
cfgfile
=
$(
ph.getValueWithParam
"
${
cfgfile
}
"
"c"
"
$@
"
)
...
...
@@ -84,12 +113,32 @@ fi
case
"
${
sMode
}
"
in
"up"
)
response
=
$(
curl
-s
"
${
COUCH_URL
}
/_up"
)
response
=
$(
get
"/_up"
)
abortOnWrongResponse
"
$response
"
"/_up"
'"status":"'
_status
=
$(
jq
'.status'
<<<
"
${
response
}
"
|
tr
-d
'"'
)
if
!
echo
"
$_status
"
|
grep
"ok"
>
/dev/null
;
then
ph.setStatus critical
fi
ph.status
"Couchdb status (value in /_up is '
$_status
')"
ph.status
"Couchdb status (value 'status' in /_up is '
$_status
')"
echo
"Reponse: "
;
echo
"
${
response
}
"
| jq
;;
"replication"
)
response
=
$(
get
"/_up"
)
abortOnWrongResponse
"
$response
"
"/_up"
'"status":"'
_status
=
$(
jq
'.seeds[] | .last_replication_status'
<<<
"
${
response
}
"
|
grep
-v
"null"
|
tr
-d
'"'
)
# there can be multiple sections "seeds" and multiple line responses.
# remove all lines with "ok" and check if there is any "bad content" left
_nonok
=
$(
echo
"
$_status
"
|
grep
-v
"ok"
)
if
[
-n
"
$_nonok
"
]
;
then
ph.setStatus critical
fi
if
!
echo
"
$_status
"
|
grep
"ok"
>
/dev/null
;
then
ph.setStatus critical
fi
ph.status
"Couchdb replication"
echo
"Reponse: "
;
echo
"
${
response
}
"
| jq
;;
*
)
...
...
@@ -101,4 +150,4 @@ esac
ph.exit
# ----------------------------------------------------------------------
# ----------------------------------------------------------------------
\ No newline at end of file
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