Created
January 8, 2021 12:08
-
-
Save pysysops/a59a562f527822b775ae03b1179642e9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
--- | |
- job: | |
name: ops/cloudflare-abuse | |
description: 'Checks Cloudflare for domains that have abuse reports and alerts @ops ' | |
defaults: global | |
properties: | |
- build-discarder: | |
num-to-keep: 100 | |
artifact-num-to-keep: 1 | |
triggers: | |
- timed: 'H * * * *' | |
wrappers: | |
- ansicolor | |
- timestamps | |
- credentials-binding: | |
- username-password-separated: | |
credential-id: CF-API-CREDS | |
username: CF_API_EMAIL | |
password: CF_API_KEY | |
- text: | |
credential-id: CF-ZONE-ID | |
variable: CF_ZONE_ID | |
- text: | |
credentials-id: CF-DASH-URL | |
variable: CF_DASH_URL | |
- env-script: | |
script-content: | | |
#!/bin/bash | |
set -eux -o pipefail | |
curl -s -X GET "https://api.cloudflare.com/client/v4/zones/${CF_ZONE_ID}/abuse_urls" \ | |
-H "X-Auth-Email: ${CF_API_EMAIL}" \ | |
-H "X-Auth-Key: ${CF_API_KEY}" \ | |
-H "Content-Type: application/json" -o abuse.json | |
bad_count=$(jq '.result | select(.[].status=="active") | length' abuse.json) | |
echo BAD_COUNT=${bad_count:-0} | |
if [[ ${bad_count} -gt 0 ]]; then | |
echo DESCRIPTION="⚠️ Sites: ${bad_count}" | |
echo :warning: @pro Sites reported by Cloudflare: ${bad_count} \\r\\n\\ > message.txt | |
jq -r '.result[] | " - :poop: Site " + .type + ": https://" + .url + " Status: " + .status + " \\r\\n\\"' abuse.json >> message.txt | |
echo SLACK_MESSAGE="$(cat message.txt)" | |
fi | |
builders: | |
- shell: | | |
#!/bin/bash | |
set -eu +x -o pipefail | |
if [[ ${BAD_COUNT} -gt 0 ]]; then | |
echo | |
echo $SLACK_MESSAGE | |
echo | |
exit 1 | |
fi | |
exit 0 | |
publishers: | |
- slack: | |
room: '#monitoring_' | |
notify-failure: true | |
notify-repeated-failure: true | |
include-custom-message: true | |
custom-message: | | |
$SLACK_MESSAGE | |
See: ${CF_DASH_URL} | |
- description-setter: | |
regexp: '.*' | |
regexp-for-failed: '.*' | |
description: | | |
Sites reported: $BAD_COUNT | |
description-for-failed: | | |
Sites reported: $BAD_COUNT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment