Skip to content

Conversation

@avlitman
Copy link
Collaborator

Adding new API:
/api/v1/alerting/rules | PATCH
/api/v1/alerting/rules/ruleId | PATCH

update user defined alert:
RULE_ID="TestSinglePatch/15a2940d8cdb3cfd51c81261ad11636094c959259469d41ddce1dd3581531bb3" && curl -s -X PATCH "http://localhost:9001/api/v1/alerting/rules/$RULE_ID" -H "Content-Type: application/json" -d '{"alertingRule":{"alert":"TestSinglePatch","expr":"cpu > 85","for":"5m","labels":{"severity":"critical","team":"frontend","environment":"production"},"annotations":{"summary":"Critical CPU usage","description":"CPU usage is above 85% for 5 minutes"}}}' | jq '.'

{
  "id": "TestSinglePatc;35b9655987a18272b4c5a5e298f2056162992a1e8c41d1487378fb926c340301",
  "status_code": 204
}

bulk update user defined alerts:
RULE1_ID="BulkTestAlert1/cde519b0d13ed1705006250e84025cf7817e9d0b9b93be59788d0039ed4c2ac3" && RULE2_ID="BulkTestAlert2/78d297397da44f293ab542b16268d0e83138f60cf8f02628df0a7c28fb416ea7" && curl -s -X PATCH "http://localhost:9001/api/v1/alerting/rules" -H "Content-Type: application/json" -d "{"ruleIds":["$RULE1_ID","$RULE2_ID"],"labels":{"severity":"critical","team":"sre","environment":"production"}}" | jq '.'

{
  "rules": [
    {
      "id": "BulkTestAlert1;6bda8aac4121f0f3e3b2fa8205ce85d3ac142514d01a83ba8614f63e18fd0730",
      "status_code": 204
    },
    {
      "id": "BulkTestAlert2;6428c8746d9f1862fb2e384dc489008efdec8a196f123242d97b5bec0c1c7dc9",
      "status_code": 204
    }
  ]
}

update platform alert:
RULE_ID="TestPlatformPatchSingle;73e926c75ad7f21249d72be4052f714aae009e9c430c15a5f49483760eaf8d8f" && curl -s -X PATCH "http://localhost:9001/api/v1/alerting/rules/$RULE_ID" -H "Content-Type: application/json" -d '{"alertingRule":{"alert":"TestPlatformPatchSingle","expr":"up == 0","for":"2m","labels":{"severity":"critical","team":"platform","environment":"production"},"annotations":{"summary":"Testing single patch for platform alerts","description":"This is a test alert for platform single patch"}}}' | jq '.'
{
"id": "TestPlatformPatchSingle;73e926c75ad7f21249d72be4052f714aae009e9c430c15a5f49483760eaf8d8f",
"status_code": 204
}

kubectl get alertrelabelconfig alertmanagement-testplatformpatchsingle-73e926c75ad7f21249d72be4052f714aae009e9c430c15a5f49483760eaf8d8f -n openshift-monitoring -o yaml | grep -A 30 "spec:"

spec:
  configs:
  - action: Replace
    regex: TestPlatformPatchSingle;.*
    replacement: critical
    sourceLabels:
    - alertname
    - severity
    targetLabel: severity
  - action: Replace
    regex: TestPlatformPatchSingle;.*
    replacement: production
    sourceLabels:
    - alertname
    - environment
    targetLabel: environment

bulk update platform alert:
RULE1_ID="TestPlatformBulkNew1;58eb54715dc0ea0d1da4cae0aa7a556c7281dd662500635ee3e49c9d0a25920d" && RULE2_ID="TestPlatformBulkNew2;e43e9eabc0467e3912b96c3854fbc79ce7face00037f4e94b0e3feb4337baf83" && curl -s -X PATCH "http://localhost:9001/api/v1/alerting/rules" -H "Content-Type: application/json" -d "{"ruleIds":["$RULE1_ID","$RULE2_ID"],"labels":{"severity":"critical","team":"platform",
"environment":"production"}}" | jq '.'

{
  "rules": [
    {
      "id": "TestPlatformBulkNew1;58eb54715dc0ea0d1da4cae0aa7a556c7281dd662500635ee3e49c9d0a25920d",
      "status_code": 204
    },
    {
      "id": "TestPlatformBulkNew2;e43e9eabc0467e3912b96c3854fbc79ce7face00037f4e94b0e3feb4337baf83",
      "status_code": 204
    }
  ]
}

kubectl get alertrelabelconfig -n openshift-monitoring -o json | jq -r '.items[] | select(.metadata.name | contains("testplatformbulknew")) | {name: .metadata.name, namespace: .metadata.namespace, configs: .spec.configs}' | head -50

{
  "name": "alertmanagement-testplatformbulknew1-58eb54715dc0ea0d1da4cae0aa7a556c7281dd662500635ee3e49c9d0a25920d",
  "namespace": "openshift-monitoring",
  "configs": [
    {
      "action": "Replace",
      "regex": "TestPlatformBulkNew1;.*",
      "replacement": "critical",
      "sourceLabels": [
        "alertname",
        "severity"
      ],
      "targetLabel": "severity"
    },
    {
      "action": "Replace",
      "regex": "TestPlatformBulkNew1;.*",
      "replacement": "platform",
      "sourceLabels": [
        "alertname",
        "team"
      ],
      "targetLabel": "team"
    },
    {
      "action": "Replace",
      "regex": "TestPlatformBulkNew1;.*",
      "replacement": "production",
      "sourceLabels": [
        "alertname",
        "environment"
      ],
      "targetLabel": "environment"
    }
  ]
}
{
  "name": "alertmanagement-testplatformbulknew2-e43e9eabc0467e3912b96c3854fbc79ce7face00037f4e94b0e3feb4337baf83",
  "namespace": "openshift-monitoring",
  "configs": [
    {
      "action": "Replace",
      "regex": "TestPlatformBulkNew2;.*",
      "replacement": "platform",
      "sourceLabels": [
        "alertname",
        "team"
      ],
      "targetLabel": "team"
    },

@avlitman avlitman force-pushed the add-patch-api branch 4 times, most recently from 49c415f to 3b0b11a Compare December 21, 2025 18:29
Signed-off-by: alitman <alitman@alitman-thinkpadp1gen7.raanaii.csb>
@machadovilaca machadovilaca merged commit 14d2066 into machadovilaca:add-alert-management-api-base Dec 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants