Created
December 2, 2022 16:34
-
-
Save Logiraptor/f12489776aab6cd85120bf76ff75287c 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
# Replace these with proper values for your Grafana Cloud tenant | |
TENANT_ID="123456" | |
API_KEY="abcde==" | |
USER_AGENT="Customer/0.0.1 shell script" | |
ENDPOINT="https://prometheus-prod-10-prod-us-central-0.grafana.net" | |
# List all rules for your tenant | |
curl --user "$TENANT_ID:$API_KEY" \ | |
--user-agent "$USER_AGENT" \ | |
--header "X-Scope-OrgID: $TENANT_ID" \ | |
"$ENDPOINT/prometheus/config/v1/rules" | |
# Set a single rule group | |
RULE_NAMESPACE="test-rules" | |
RULE_GROUP="test-group" | |
RULE_FILE="test-group.yaml" | |
cat <<EOF > $RULE_FILE | |
name: $RULE_GROUP | |
rules: | |
- record: job:up:sum | |
expr: sum by(job) (up) | |
EOF | |
curl --user "$TENANT_ID:$API_KEY" \ | |
--user-agent "$USER_AGENT" \ | |
--header "X-Scope-Orgid: $TENANT_ID" \ | |
--header "Content-Type: application/yaml" \ | |
--data-binary "@./$RULE_FILE" \ | |
-X POST \ | |
"$ENDPOINT/prometheus/config/v1/rules/$RULE_NAMESPACE" | |
# Get a single rule group | |
RULE_NAMESPACE="test-rules" | |
RULE_GROUP="test-group" | |
curl --user "$TENANT_ID:$API_KEY" \ | |
--user-agent "$USER_AGENT" \ | |
--header "X-Scope-Orgid: $TENANT_ID" \ | |
"$ENDPOINT/prometheus/config/v1/rules/$RULE_NAMESPACE/$RULE_GROUP" | |
# Delete a single rule group | |
RULE_NAMESPACE="test-rules" | |
RULE_GROUP="test-group" | |
curl --user "$TENANT_ID:$API_KEY" \ | |
--user-agent "$USER_AGENT" \ | |
--header "X-Scope-Orgid: $TENANT_ID" \ | |
-X DELETE \ | |
"$ENDPOINT/prometheus/config/v1/rules/$RULE_NAMESPACE/$RULE_GROUP" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment