102 lines
2.3 KiB
Bash
Executable file
102 lines
2.3 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
. /usr/lib/nagios/plugins/utils.sh
|
|
|
|
check_return() {
|
|
if [[ $1 -ne 0 ]]; then
|
|
echo "CRITICAL - Service FAIL"
|
|
exit $STATE_CRITICAL
|
|
fi
|
|
}
|
|
|
|
exec_status=$(curl -s https://api.swedenconnect.se/testid/prod/execution-status | jq --raw-output .)
|
|
|
|
exec_status_result=$?
|
|
check_return "$exec_status_result"
|
|
|
|
calculate_time() {
|
|
md_date=$(date -d "$1" +%s)
|
|
now=$(date +%s)
|
|
diff=$(("$md_date"-"$now"))
|
|
|
|
if ((diff < 0)); then ((diff*=-1)); fi
|
|
echo $diff
|
|
}
|
|
|
|
exec_time=$(echo "$exec_status" | jq --raw-output '."last execution result".executiontimestamp')
|
|
|
|
exec_time_result=$?
|
|
check_return "$exec_time_result"
|
|
|
|
diff_exec_time=$(calculate_time "$exec_time")
|
|
|
|
day=$(( 24 * 3600))
|
|
|
|
if [ "$diff_exec_time" -gt "$day" ]; then
|
|
echo "CRITICAL - tests are too old!!"
|
|
exit $STATE_CRITICAL
|
|
|
|
fi
|
|
|
|
raw_not_executed_test=$(echo "$exec_status" | jq --raw-output '."last execution result".notExecutedTests[2]')
|
|
|
|
declare -a not_executed_test=($(echo "$raw_not_executed_test" | tr "\n" " "))
|
|
|
|
if [ "$not_executed_test" != null ]
|
|
then
|
|
echo "more than two lands not executed "
|
|
exit $STATE_CRITICAL
|
|
fi
|
|
|
|
raw_lands=$(echo "$exec_status" | jq --raw-output '."last execution result".failed[].result')
|
|
|
|
raw_lands_result=$?
|
|
check_return "$raw_lands_result"
|
|
|
|
declare -a lands=($(echo "$raw_lands" | tr "\n" " "))
|
|
|
|
exit_status_warning=0
|
|
exit_status_critical=0
|
|
output=""
|
|
|
|
for land in "${lands[@]}"
|
|
do
|
|
if [ "$land" ]
|
|
then
|
|
first_failed=$(curl -s https://api.swedenconnect.se/testid/prod/failed-tests | jq --raw-output '."failed tests"[].'\"$land\"'|select( . != null )')
|
|
|
|
diff_failed=$(calculate_time "$first_failed")
|
|
|
|
half_day=$((12 * 3600))
|
|
sec_to_hrs=$(("$diff_failed" / 3600))
|
|
|
|
if [ "$diff_failed" -gt "$day" ]; then
|
|
exit_status_critical=1
|
|
output="$output CRITICAL - $land is failing for $sec_to_hrs hours!"
|
|
|
|
elif [ "$diff_failed" -gt "$half_day" ]; then
|
|
exit_status_warning=1
|
|
output="$output WARNING - $land is failing for $sec_to_hrs hours!"
|
|
fi
|
|
fi
|
|
done
|
|
|
|
if [ "$exit_status_critical" -gt 0 ]
|
|
then
|
|
echo "$output"
|
|
exit $STATE_CRITICAL
|
|
|
|
elif [ "$exit_status_warning" -gt 0 ]
|
|
then
|
|
echo "$output"
|
|
exit $STATE_WARNING
|
|
|
|
elif [ -z "${lands[*]}" ]
|
|
then
|
|
echo "Tests on production lands are error free"
|
|
exit $STATE_OK
|
|
|
|
else
|
|
echo "${lands[*]} failing"
|
|
exit $STATE_OK
|
|
fi
|