diff --git a/check_systemd_service.sh b/check_systemd_service.sh index c1332f8..299bcc1 100755 --- a/check_systemd_service.sh +++ b/check_systemd_service.sh @@ -91,9 +91,23 @@ if [ -n "$end_time" ] && [ "$end_time" != "n/a" ] && [ -z "$end_time" ]; then end_time_str=" Exited at $end_time." fi +# ============= +# Build output + if [ "$IS_TIMER" = true ] && { [ "$substate" = "exited" ] || [ "$active" = "inactive" ]; }; then - echo "OK - $UNIT_NAME is active and exited (returned $exit_code) and enabled.$end_time_str $end_time_diff_perf" + status="exited (returned $exit_code)" else - echo "OK - $UNIT_NAME is active and enabled.$start_time_str $start_time_diff_perf" + status="active" fi + +if [ "$enabled" = "enabled" ] || [ "$IS_ALLOWED_DISABLED" != true ]; then + status+=" and enabled" +fi + +if [ "$IS_TIMER" = true ] && { [ "$substate" = "exited" ] || [ "$active" = "inactive" ]; }; then + echo "OK - $UNIT_NAME is $status.$end_time_str $end_time_diff_perf" +else + echo "OK - $UNIT_NAME is $status.$start_time_str $start_time_diff_perf" +fi + exit 0