|
|
|
@ -1,6 +1,6 @@ |
|
|
|
|
#!/bin/sh |
|
|
|
|
# |
|
|
|
|
# 2015 Steven Armstrong (steven-cdist at armstrong.cc) |
|
|
|
|
# 2015-2016 Steven Armstrong (steven-cdist at armstrong.cc) |
|
|
|
|
# |
|
|
|
|
# This file is part of cdist. |
|
|
|
|
# |
|
|
|
@ -24,12 +24,24 @@ conf_file="check_${name}.json" |
|
|
|
|
state="$(cat "$__object/parameter/state")" |
|
|
|
|
|
|
|
|
|
# Sanity checks |
|
|
|
|
if [ -f "$__object/parameter/script" -a -f "$__object/parameter/ttl" ]; then |
|
|
|
|
echo "Use either --script together with --interval OR --ttl, but not both" >&2 |
|
|
|
|
exit 1 |
|
|
|
|
if [ -f "$__object/parameter/ttl" ]; then |
|
|
|
|
for conflicts_ttl in 'docker-container-id' 'http' 'script' 'tcp' 'timeout'; do |
|
|
|
|
if [ -f "$__object/parameter/${conflicts_ttl}" ]; then |
|
|
|
|
echo "Can not use --ttl together with --${conflicts_ttl}." >&2 |
|
|
|
|
exit 1 |
|
|
|
|
fi |
|
|
|
|
done |
|
|
|
|
fi |
|
|
|
|
if [ ! -f "$__object/parameter/interval" ]; then |
|
|
|
|
for requires_interval in 'docker-id' 'http' 'script' 'tcp'; do |
|
|
|
|
if [ -f "$__object/parameter/${requires_interval}" ]; then |
|
|
|
|
echo "When using --${requires_interval} you must also define --interval." >&2 |
|
|
|
|
exit 1 |
|
|
|
|
fi |
|
|
|
|
done |
|
|
|
|
fi |
|
|
|
|
if [ -f "$__object/parameter/script" -a ! -f "$__object/parameter/interval" ]; then |
|
|
|
|
echo "When using --script you must also define --interval" >&2 |
|
|
|
|
if [ -f "$__object/parameter/docker-container-id" -a ! -f "$__object/parameter/script" ]; then |
|
|
|
|
echo "When using --docker-container-id you must also define --script." >&2 |
|
|
|
|
exit 1 |
|
|
|
|
fi |
|
|
|
|
|
|
|
|
@ -40,11 +52,7 @@ printf ' "check": {\n' |
|
|
|
|
printf ' "name": "%s"\n' "$name" |
|
|
|
|
for param in $(ls "$__object/parameter/"); do |
|
|
|
|
case "$param" in |
|
|
|
|
state|name|interval) continue ;; |
|
|
|
|
script) |
|
|
|
|
printf ' ,"script": "%s"\n' "$(cat "$__object/parameter/script")" |
|
|
|
|
printf ' ,"interval": "%s"\n' "$(cat "$__object/parameter/interval")" |
|
|
|
|
;; |
|
|
|
|
state|name) continue ;; |
|
|
|
|
*) |
|
|
|
|
key="$(echo "$param" | tr '-' '_')" |
|
|
|
|
printf ' ,"%s": "%s"\n' "$key" "$(cat "$__object/parameter/$param")" |
|
|
|
|