fix a couple checks
This commit is contained in:
parent
5e1490b760
commit
503c40cad3
|
@ -15,7 +15,8 @@ usage() {
|
||||||
-M Set the HTTP mode (default: GET)
|
-M Set the HTTP mode (default: GET)
|
||||||
-t Timeout in seconds
|
-t Timeout in seconds
|
||||||
-s Ignore the response status code.
|
-s Ignore the response status code.
|
||||||
-e Expected status code."
|
-e Expected status code.
|
||||||
|
-S Sanitize HTML when printing to console. Good for Icinga2 Web."
|
||||||
exit 3
|
exit 3
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,9 +32,10 @@ IGNORE_STATUS=""
|
||||||
TIMEOUT="30"
|
TIMEOUT="30"
|
||||||
HTTP_METHOD="-X GET"
|
HTTP_METHOD="-X GET"
|
||||||
EXPECTED_STATUS_CODE=""
|
EXPECTED_STATUS_CODE=""
|
||||||
|
SANITIZE_HTML=false
|
||||||
|
|
||||||
# Parse arguments
|
# Parse arguments
|
||||||
while getopts "u:w:c:C:LH:M:IpR:st:e:h" opt; do
|
while getopts "u:w:c:C:LH:M:IpR:st:e:hS" opt; do
|
||||||
case $opt in
|
case $opt in
|
||||||
u)
|
u)
|
||||||
URL="$OPTARG"
|
URL="$OPTARG"
|
||||||
|
@ -77,6 +79,9 @@ while getopts "u:w:c:C:LH:M:IpR:st:e:h" opt; do
|
||||||
h)
|
h)
|
||||||
usage
|
usage
|
||||||
;;
|
;;
|
||||||
|
S)
|
||||||
|
SANITIZE_HTML=true
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Invalid option: -$OPTARG" >&2
|
echo "Invalid option: -$OPTARG" >&2
|
||||||
usage
|
usage
|
||||||
|
@ -411,10 +416,12 @@ fi
|
||||||
BODY_CONTAINS=" "
|
BODY_CONTAINS=" "
|
||||||
if [ -n "$CRIT_STRING" ]; then
|
if [ -n "$CRIT_STRING" ]; then
|
||||||
BODY=$(curl -s $FOLLOW_REDIRECTS $INSECURE $HEADERS $RESOLVE $TIMEOUT $URL)
|
BODY=$(curl -s $FOLLOW_REDIRECTS $INSECURE $HEADERS $RESOLVE $TIMEOUT $URL)
|
||||||
|
if $SANITIZE_HTML; then
|
||||||
|
BODY=$(echo "$BODY" | sed 's/</\</g' | sed 's/>/\>/g')
|
||||||
|
fi
|
||||||
# shellcheck disable=SC2076
|
# shellcheck disable=SC2076
|
||||||
if ! [[ $BODY =~ "$CRIT_STRING" ]]; then
|
if ! [[ $BODY =~ "$CRIT_STRING" ]]; then
|
||||||
# if ! echo "$BODY" | grep -q "$CRIT_STRING"; then
|
echo "CRITICAL - response body does not contain the required string: $BODY"
|
||||||
echo "CRITICAL - response body does not contain '$CRIT_STRING': $BODY"
|
|
||||||
exit 2
|
exit 2
|
||||||
else
|
else
|
||||||
BODY_CONTAINS=" and contained substring "
|
BODY_CONTAINS=" and contained substring "
|
||||||
|
|
|
@ -68,12 +68,21 @@ fi
|
||||||
start_time=$(systemctl show "$UNIT_NAME" --property=ExecMainStartTimestamp --value)
|
start_time=$(systemctl show "$UNIT_NAME" --property=ExecMainStartTimestamp --value)
|
||||||
end_time=$(systemctl show "$UNIT_NAME" --property=ExecMainExitTimestamp --value)
|
end_time=$(systemctl show "$UNIT_NAME" --property=ExecMainExitTimestamp --value)
|
||||||
current_time=$(date +%s)
|
current_time=$(date +%s)
|
||||||
|
start_time_diff="undefined"
|
||||||
|
end_time_diff="undefined"
|
||||||
|
|
||||||
|
if [ -n "$start_time" ]; then
|
||||||
start_time_diff=$((current_time - $(date -d "$start_time" +%s)))
|
start_time_diff=$((current_time - $(date -d "$start_time" +%s)))
|
||||||
|
start_time_diff_perf="| uptime=${start_time_diff}s"
|
||||||
|
fi
|
||||||
|
if [ -n "$end_time" ] && [ "$end_time" != "n/a" ]; then
|
||||||
end_time_diff=$((current_time - $(date -d "$end_time" +%s)))
|
end_time_diff=$((current_time - $(date -d "$end_time" +%s)))
|
||||||
|
end_time_diff_perf="| downtime=${end_time_diff}s"
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "$IS_TIMER" = true ] && { [ "$substate" = "exited" ] || [ "$active" = "inactive" ]; }; then
|
if [ "$IS_TIMER" = true ] && { [ "$substate" = "exited" ] || [ "$active" = "inactive" ]; }; then
|
||||||
echo "OK - $UNIT_NAME is active and exited (returned $exit_code) and enabled. Exited at $end_time. | downtime=${end_time_diff}s"
|
echo "OK - $UNIT_NAME is active and exited (returned $exit_code) and enabled. Exited at $end_time. $end_time_diff_perf"
|
||||||
else
|
else
|
||||||
echo "OK - $UNIT_NAME is active and enabled. Started at $start_time. | uptime=${start_time_diff}s"
|
echo "OK - $UNIT_NAME is active and enabled. Started at $start_time. $start_time_diff_perf"
|
||||||
fi
|
fi
|
||||||
exit 0
|
exit 0
|
||||||
|
|
Loading…
Reference in New Issue