Grafana 9 how to provision alerts with helm chart

Hello,

I would like to provision alert rule, contact poit and notification policy from a Helm chart in grafana.

I’ve tried with the examples in the values file from the grafana Helm chart helm-charts/values.yaml at main · grafana/helm-charts · GitHub

Below an extract of my vaules files :

grafana:
  alerting:
    rules.yaml: |
      apiVersion: 1
      groups:
        - orgId: 1
          name: '{{ .Chart.Name }}_pdu_group'
          folder: pdu_folder
          interval: 60s
          rules:
          - uid: pdu_id_1
            title: 'CCT - PDUs - Alert Current Overloaded on rack'
            condition: B
            data:
              - refId: A
                queryType: ''
                relativeTimeRange:
                  from: 3600
                  to: 0
                datasourceUid: PBFA97CFB590B2093
                model:
                  datasource:
                    type: prometheus
                    uid: PBFA97CFB590B2093
                  editorMode: code
                  expr: cct_rnx_current
                  format: time_series
                  hide: false
                  interval: ''
                  intervalFactor: 1
                  legendFormat: "{{rack}} - {{pduname}} -  {{phasename}}"
                  range: true
                  refId: A
                  intervalMs: 15000
              - refId: B
                datasourceUid: "-100"
                queryType: ''
                model:
                  refId: B
                  hide: false
                  type: classic_conditions
                  datasource:
                    uid: "-100"
                    type: __expr__
                  conditions:
                  - type: query
                    evaluator:
                      params:
                      - 30
                      type: gt
                    operator:
                      type: and
                    query:
                      params:
                      - A
                    reducer:
                      params: []
                      type: last
                  expression: A
            for: 5m
            annotations:
              __dashboardUid__: aWp9z1DVk
              __panelId__: '8'
            labels: {}

But I get the following error in the log of the pod and the alert isn’t creted :

logger=ngalert.multiorg.alertmanager t=2022-11-11T16:31:01.427705671Z level=info msg="starting MultiOrg Alertmanager"

logger=context traceID=00000000000000000000000000000000 t=2022-11-11T16:31:10.581937412Z level=error msg="Failed to look up user based on cookie" error="user token not found"

logger=context traceID=00000000000000000000000000000000 userId=0 orgId=0 uname= t=2022-11-11T16:31:10.582471549Z level=info msg="Request Completed" method=GET path=/api/v1/ngalert/alertmanagers status=401 remote_addr=10.155.10.76 time_ms=3 duration=3.284607ms size=27 referer=https://tstpdumon.unil.ch/alerting/admin traceID=00000000000000000000000000000000 handler=/api/v1/ngalert/alertmanagers

Any help would be appreciated.

Best regards
Danil

Hello,

Where did you place the file with the alert’s configuration? Did you enable any additional configurations to Grafana’s heIm like sidecar for alerting and which type of alerts u are using - unified or legacy.

I’m curious, because I tried everything I found here and inside the documentation but could not provision any rule.

  • About the token, you can create a one via the UI with different rights and use it for reload.

BR,
Elena

Hi Elena,

I’ve put the defined rule in the file /etc/grafana/provisioning/alerting/rules.json

I didn’t enabled sidecar.

If y would like to use a Token, I should find a way to create it as code also.

Best regards
Daniel