Check API and Notify on Failure #1363
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Check API and Notify on Failure | |
on: | |
push: | |
branches: ["main"] | |
schedule: | |
- cron: '0 * * * *' | |
jobs: | |
check-api: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check APIs status | |
id: check_status | |
run: | | |
apis=() | |
while IFS= read -r line || [ -n "$line" ]; do | |
apis+=("$line") | |
done <<< "${{ secrets.NEED_CHECK_URLS }}" | |
for api in "${apis[@]}"; do | |
echo "Accessing API with element $api" | |
response=$(curl -o /dev/null -s -w "%{http_code}\n" "$api") | |
if [ "$response" != "200" ] && [ "$response" != "301" && [ "$response" != "302" ]; then | |
echo "HTTP状态码不等于200且不等于301/302,发送通知..." | |
curl -X POST \ | |
-H 'Content-Type: application/json' \ | |
-d '{ | |
"msg_type": "text", | |
"content": { | |
"text": "'"$api"': API check failed. Status code: '"$response"'" | |
} | |
}' "${{ secrets.FEISHU_WEBHOOK }}" | |
fi | |
done |