Created
July 7, 2022 04:16
-
-
Save sanchezl/7a75821ef5dcbf3ef7a01ae2282bdc86 to your computer and use it in GitHub Desktop.
Watch OpenShift alerts from CLI
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
#!/usr/bin/env bash | |
prometheus_host="$1" | |
token="$2" | |
prometheus_rules_url="https://${prometheus_host}/api/v1/rules" | |
curl --silent --insecure --header "Authorization: Bearer ${token}" "$prometheus_rules_url" \ | |
| jq -r '.data.groups[]|.rules[]|select(.name==("APIRemovedInNextReleaseInUse","APIRemovedInNextEUSReleaseInUse"))|.alerts[]|[.labels.alertname,.state,(.labels|.resource+"."+.version+"."+.group)]|@tsv' \ | |
| sort \ | |
| column -t -N ALERT,STATUS,API\ | |
| sed \ | |
-e "1!s/^\S*/$(tput setaf 6)\0$(tput sgr0)/" \ | |
-e "s/pending/$(tput setaf 3)$(tput bold)\0$(tput sgr0)/" \ | |
-e "s/firing/$(tput setaf 1)$(tput bold)\0$(tput sgr0)/" |
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
#!/usr/bin/env bash | |
prometheus_host="$(oc get route prometheus-k8s -n openshift-monitoring -o jsonpath='{@.spec.host}')" | |
token="$(oc create token prometheus-k8s -n openshift-monitoring)" | |
watch --interval 1 --no-title --color ./alerts.sh "$prometheus_host" "$token" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment