Skip to content

Commit

Permalink
FEATURE: check_zrancid_fetch: Allow to get data via HTTP api
Browse files Browse the repository at this point in the history
  • Loading branch information
julthomas committed Oct 1, 2024
1 parent af97813 commit 34450a8
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion bin/check_zrancid_fresh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Options:
-c, --critical SECONDS Critical threshold in seconds
-s, --min-size BYTES File size in bytes
-mod, --max-output-detail NUM Add error devices to output
-u, --url Get data via HTTP api
-t, --timeout Timeout when --url is used
-h, --help Display this help
"
exit 3
Expand Down Expand Up @@ -43,6 +45,8 @@ declare -A perf=(
declare -A warn=()
declare -A crit=()
max_output_detail=0
url=
timeout=5

while (( $# > 0 )); do
case "$1" in
Expand All @@ -51,6 +55,8 @@ while (( $# > 0 )); do
-c|--critical) crit[too_old]=$2; shift ;;
-s|--min-size) crit[too_small]=$2; shift ;;
-mod|--max-output-detail) max_output_detail=$2; shift ;;
-u|--url) url=$2; shift ;;
-t|--timeout) timeout=$2; shift ;;
*) nagios_exit_usage ;;
esac
shift
Expand All @@ -59,6 +65,7 @@ done
[[ -z $entity ]] && nagios_exit_usage
for i in "${warn[@]}" "${crit[@]}"; do [[ -n ${i//[0-9]} ]] && nagios_exit_usage; done
[[ -n ${max_output_detail//[0-9]} ]] && nagios_exit_usage
[[ -n ${timeout//[0-9]} ]] && nagios_exit_usage

now=$(date +%s)
state=0
Expand Down Expand Up @@ -108,7 +115,11 @@ while read -r device last size; do

done < <(
# avoid temporary file, here-string included
zrancid-ls -e "$entity"
if [[ -z $url ]]; then
zrancid-ls -e "$entity"
else
curl -kfsS -m "$timeout" --get --data-urlencode "entity=$entity" "$url"
fi
echo "#pipestatus:$?"
)

Expand Down

0 comments on commit 34450a8

Please sign in to comment.