apiVersion: v1
kind: Secret
metadata:
  name: alertmanager-main
  namespace: openshift-monitoring
type: Opaque
stringData:
  alertmanager.yaml: |
    global:
      resolve_timeout: 5m
    inhibit_rules:
    - source_match:
        severity: critical
      target_match_re:
        severity: warning|info
      equal:
      - namespace
      - alertname
    - source_match:
        severity: warning
      target_match_re:
        severity: info
      equal:
      - namespace
      - alertname
    # https://github.com/openshift/configure-alertmanager-operator/blob/c9032fd13a9dcd7d374d1491db4b23af1120ba11/pkg/controller/secret/secret_controller.go#L349-L350
    # The degraded alert is critical, and usually has more details
    - source_match:
        alertname: ClusterOperatorDegraded
      target_match_re:
        alertname: ClusterOperatorDown
      equal:
      - namespace
      - name
    - source_match:
        alertname: KubeNodeNotReady
      target_match_re:
        alertname: KubeNodeUnreachable
      equal:
      - node
      - instance
    - source_match:
        alertname: KubeNodeUnreachable
      target_match_re:
        alertname: SDNPodNotReady|TargetDown
    - source_match:
        alertname: KubeNodeNotReady
      target_match_re:
        alertname: KubeDaemonSetRolloutStuck|KubeDaemonSetMisScheduled|KubeDeploymentReplicasMismatch|KubeStatefulSetReplicasMismatch|KubePodNotReady
      equal:
      - instance
    - source_match:
        alertname: KubeDeploymentReplicasMismatch
      target_match_re:
        alertname: KubePodNotReady|KubePodCrashLooping
      equal:
      - namespace
    - source_match:
        alertname: ElasticsearchOperatorCSVNotSuccessful
      target_match_re:
        alertname: ElasticsearchClusterNotHealthy
      equal:
      - dummylabel
    receivers:
      - name: Watchdog
      - name: "null"
      - name: Github
        webhook_configs:
          - url: 'http://receiver.openshift-github-alert-receiver.svc.cluster.local:9393/v1/receiver'
    route:
      receiver: "null"
      group_by:
        - namespace
        - alertname
      routes:
        - receiver: "null"
          group_by:
            - namespace
            - severity
            - alertname
          continue: true
          routes:
            # Alerts we do not want to receive
            - receiver: "null"
              match:
                alertname: CPUThrottlingHigh
            - receiver: "null"
              match:
                namespace: openshift-customer-monitoring
            - receiver: "null"
              match:
                namespace: openshift-operators
            - receiver: "null"
              match:
                exported_namespace: openshift-operators
            - receiver: "null"
              match:
                alertname: CustomResourceDetected
            - receiver: "null"
              match:
                alertname: ImagePruningDisabled
            - receiver: "null"
              match:
                severity: info
            - receiver: "null"
              match:
                severity: warning
              match_re:
                alertname: ^etcd.*
            - receiver: "null"
              match:
                alertname: PodDisruptionBudgetLimit
              match_re:
                namespace: ^redhat-.*
            - receiver: "null"
              match:
                alertname: PodDisruptionBudgetAtLimit
              match_re:
                namespace: ^redhat-.*
            - receiver: "null"
              match:
                alertname: TargetDown
              match_re:
                namespace: ^redhat-.*
            - receiver: "null"
              match:
                alertname: KubeJobFailed
                namespace: openshift-logging
              match_re:
                job_name: ^elasticsearch.*
            - receiver: "null"
              match:
                alertname: HAProxyReloadFail
                severity: critical
            - receiver: "null"
              match:
                alertname: PrometheusRuleFailures
            - receiver: "null"
              match:
                alertname: ClusterOperatorDegraded
                name: authentication
                reason: IdentityProviderConfig_Error
            - receiver: "null"
              match:
                alertname: ClusterOperatorDegraded
                name: authentication
                reason: OAuthServerConfigObservation_Error
            - receiver: "null"
              match:
                alertname: CannotRetrieveUpdates
            - receiver: "null"
              match:
                alertname: PrometheusNotIngestingSamples
                namespace: openshift-user-workload-monitoring
            - receiver: "null"
              match:
                alertname: PrometheusRemoteStorageFailures
                namespace: openshift-monitoring
            - receiver: "null"
              match:
                alertname: PrometheusRemoteWriteDesiredShards
                namespace: openshift-monitoring
            - receiver: "null"
              match:
                alertname: PrometheusRemoteWriteBehind
                namespace: openshift-monitoring
            - receiver: "null"
              match:
                alertname: UpdateAvailable
            - receiver: "null"
              match:
                alertname: KubePodNotReady            # See: https://github.com/operate-first/SRE/issues/297
                namespace: openshift-pipelines
            - receiver: "null"
              match:
                alertname: KubeContainerWaiting       # See: https://github.com/operate-first/SRE/issues/297
                namespace: openshift-pipelines
            - receiver: "null"
              match:
                alertname: KubeJobFailed
                namespace: openshift-logging
            - receiver: "null"
              match:
                alertname: FluentdQueueLengthBurst
                namespace: openshift-logging
            # Alerts we want to send to github
            - receiver: Github
              match:
                alertname: KubeAPILatencyHigh
                severity: critical
            - receiver: Github
              match:
                prometheus: openshift-monitoring/k8s
              match_re:
                exported_namespace: ^kube.*|^openshift.*|^redhat-.*
            - receiver: Github
              match:
                exported_namespace: ""
                prometheus: openshift-monitoring/k8s
              match_re:
                namespace: ^kube.*|^openshift.*|^redhat-.*
            - receiver: Github
              match:
                job: fluentd
                prometheus: openshift-monitoring/k8s
            - receiver: Github
              match:
                alertname: FluentdNodeDown
                prometheus: openshift-monitoring/k8s
            - receiver: Github
              match:
                cluster: elasticsearch
                prometheus: openshift-monitoring/k8s
        - receiver: Watchdog
          match:
            alertname: Watchdog
          repeat_interval: 5m
      group_wait: 30s
      group_interval: 5m
      repeat_interval: 12h
