Skip to content

Conversation

@heliapb
Copy link
Member

@heliapb heliapb commented Oct 10, 2025

Description

Add support for monospace in pushoverConfig in alertmanager config, from version 0.29.0 onwards prometheus/alertmanager#4362

Type of change

What type of changes does your code introduce to the Prometheus operator? Put an x in the box that apply.

  • CHANGE (fix or feature that would cause existing functionality to not work as expected)
  • FEATURE (non-breaking change which adds functionality)
  • BUGFIX (non-breaking change which fixes an issue)
  • ENHANCEMENT (non-breaking change which improves existing functionality)
  • NONE (if none of the other choices apply. Example, tooling, build system, CI, docs, etc.)

Verification

Please check the Prometheus-Operator testing guidelines for recommendations about automated tests.

Changelog entry

Please put a one-line changelog entry below. This will be copied to the changelog file during the release process.

feat: add support for monospace in pushoverConfig 

@heliapb heliapb requested a review from a team as a code owner October 10, 2025 21:25
@heliapb heliapb force-pushed the feat/pushover_config branch 2 times, most recently from 8dab075 to e54836d Compare October 15, 2025 15:54
slashpai
slashpai previously approved these changes Oct 16, 2025
Copy link
Contributor

@slashpai slashpai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm
probably can wait till Alertmanager v0.29 release

@heliapb heliapb force-pushed the feat/pushover_config branch 2 times, most recently from 1b46a23 to f6b74e3 Compare November 5, 2025 12:48
@heliapb heliapb requested a review from slashpai November 5, 2025 12:48
@heliapb
Copy link
Member Author

heliapb commented Nov 11, 2025

lgtm probably can wait till Alertmanager v0.29 release

hi @slashpai I think this can be merged now. thanks

Copy link
Contributor

@slashpai slashpai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a couple of nits after checking again

// monospace optional HTML/monospace formatting for the message, see https://pushover.net/api#html
// html and monospace formatting are mutually exclusive.
// +optional
Monospace bool `json:"monospace,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since optional make this as *bool?

I see for HTML as well its bool may be we should update that

cc: @simonpasquier

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed both to pointers as suggested.

@heliapb heliapb force-pushed the feat/pushover_config branch from 570e9d5 to a6f0f7c Compare November 17, 2025 22:34
Copy link
Contributor

@simonpasquier simonpasquier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! We need to drop invalid AlertmanagerConfigs (e.g. with both monospace and html being true) before we sanitize. It should happen in checkPushoverConfigs().

@heliapb
Copy link
Member Author

heliapb commented Nov 19, 2025

Thanks for the PR! We need to drop invalid AlertmanagerConfigs (e.g. with both monospace and html being true) before we sanitize. It should happen in checkPushoverConfigs().

thanks I added that and also noticed that I've missed the checks in validations, added those as well.

Signed-off-by: Hélia Barroso <[email protected]>
HTML bool `json:"html,omitempty"`
HTML *bool `json:"html,omitempty"`
// monospace optional HTML/monospace formatting for the message, see https://pushover.net/api#html
// html and monospace formatting are mutually exclusive.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

html and monospace formatting are mutually exclusive.

Should this message be added to the HTML description as well?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've merged to have the PR in the next release but the comment is valid and we can address in a follow-up PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, will open as follow up

@simonpasquier simonpasquier merged commit d1ff82e into prometheus-operator:main Nov 20, 2025
22 checks passed
@heliapb heliapb deleted the feat/pushover_config branch November 20, 2025 14:33
@heliapb heliapb mentioned this pull request Nov 20, 2025
5 tasks
@onedr0p
Copy link

onedr0p commented Dec 9, 2025

@heliapb This PR broke HTML rendering for me. I upgraded to 0.87.0 and changed none of my configs, now HTML will not render in my notifications.

kubectl get alertmanagerconfigs.monitoring.coreos.com -n observability alertmanager -oyaml
apiVersion: monitoring.coreos.com/v1alpha1
kind: AlertmanagerConfig
metadata:
  creationTimestamp: "2025-11-01T17:05:04Z"
  generation: 3
  labels:
    kustomize.toolkit.fluxcd.io/name: kube-prometheus-stack
    kustomize.toolkit.fluxcd.io/namespace: observability
  name: alertmanager
  namespace: observability
  resourceVersion: "37268901"
  uid: 430cb801-8300-466f-addc-b844c14fbfd2
spec:
  inhibitRules:
  - equal:
    - alertname
    - namespace
    sourceMatch:
    - matchType: =
      name: severity
      value: critical
    targetMatch:
    - matchType: =
      name: severity
      value: warning
  receivers:
  - name: blackhole
  - name: buddy-heartbeat
    webhookConfigs:
    - httpConfig:
        bearerTokenSecret:
          key: BUDDY_HEARTBEAT_TOKEN
          name: alertmanager-secret
      urlSecret:
        key: BUDDY_HEARTBEAT_URL
        name: alertmanager-secret
  - name: pushover
    pushoverConfigs:
    - html: true
      message: |-
        {{- range .Alerts }}
          {{- if ne .Annotations.description "" }}
            {{ .Annotations.description }}
          {{- else if ne .Annotations.summary "" }}
            {{ .Annotations.summary }}
          {{- else if ne .Annotations.message "" }}
            {{ .Annotations.message }}
          {{- else }}
            Alert description not available
          {{- end }}
          {{- if gt (len .Labels.SortedPairs) 0 }}
            <small>
              {{- range .Labels.SortedPairs }}
                <b>{{ .Name }}:</b> {{ .Value }}
              {{- end }}
            </small>
          {{- end }}
        {{- end }}
      monospace: false
      priority: '{{ if eq .Status "firing" }}1{{ else }}0{{ end }}'
      sendResolved: true
      sound: gamelan
      title: '[{{ .Status | toUpper }}{{ if eq .Status "firing" }}:{{ .Alerts.Firing
        | len }}{{ end }}] {{ .CommonLabels.alertname }}'
      token:
        key: ALERTMANAGER_PUSHOVER_TOKEN
        name: alertmanager-secret
      ttl: 86400s
      urlTitle: View in Alertmanager
      userKey:
        key: PUSHOVER_USER_KEY
        name: alertmanager-secret
  route:
    groupBy:
    - alertname
    - cluster
    - job
    groupInterval: 5m
    groupWait: 1m
    receiver: pushover
    repeatInterval: 12h
    routes:
    - matchers:
      - matchType: =
        name: alertname
        value: InfoInhibitor
      receiver: blackhole
    - groupInterval: 2m
      groupWait: 0s
      matchers:
      - matchType: =
        name: alertname
        value: Watchdog
      receiver: buddy-heartbeat
      repeatInterval: 2m30s
    - matchers:
      - matchType: =
        name: severity
        value: critical
      receiver: pushover

@onedr0p
Copy link

onedr0p commented Dec 9, 2025

Actually it looks like the html field is dropped completely when the config is rendered...

image

@onedr0p
Copy link

onedr0p commented Dec 9, 2025

Opened issue #8152 for further discussion

URL: in.URL,
URLTitle: in.URLTitle,
Priority: in.Priority,
HTML: in.HTML,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops

@heliapb
Copy link
Member Author

heliapb commented Dec 9, 2025

@heliapb This PR broke HTML rendering for me. I upgraded to 0.87.0 and changed none of my configs, now HTML will not render in my notifications.

kubectl get alertmanagerconfigs.monitoring.coreos.com -n observability alertmanager -oyaml
apiVersion: monitoring.coreos.com/v1alpha1
kind: AlertmanagerConfig
metadata:
  creationTimestamp: "2025-11-01T17:05:04Z"
  generation: 3
  labels:
    kustomize.toolkit.fluxcd.io/name: kube-prometheus-stack
    kustomize.toolkit.fluxcd.io/namespace: observability
  name: alertmanager
  namespace: observability
  resourceVersion: "37268901"
  uid: 430cb801-8300-466f-addc-b844c14fbfd2
spec:
  inhibitRules:
  - equal:
    - alertname
    - namespace
    sourceMatch:
    - matchType: =
      name: severity
      value: critical
    targetMatch:
    - matchType: =
      name: severity
      value: warning
  receivers:
  - name: blackhole
  - name: buddy-heartbeat
    webhookConfigs:
    - httpConfig:
        bearerTokenSecret:
          key: BUDDY_HEARTBEAT_TOKEN
          name: alertmanager-secret
      urlSecret:
        key: BUDDY_HEARTBEAT_URL
        name: alertmanager-secret
  - name: pushover
    pushoverConfigs:
    - html: true
      message: |-
        {{- range .Alerts }}
          {{- if ne .Annotations.description "" }}
            {{ .Annotations.description }}
          {{- else if ne .Annotations.summary "" }}
            {{ .Annotations.summary }}
          {{- else if ne .Annotations.message "" }}
            {{ .Annotations.message }}
          {{- else }}
            Alert description not available
          {{- end }}
          {{- if gt (len .Labels.SortedPairs) 0 }}
            <small>
              {{- range .Labels.SortedPairs }}
                <b>{{ .Name }}:</b> {{ .Value }}
              {{- end }}
            </small>
          {{- end }}
        {{- end }}
      monospace: false
      priority: '{{ if eq .Status "firing" }}1{{ else }}0{{ end }}'
      sendResolved: true
      sound: gamelan
      title: '[{{ .Status | toUpper }}{{ if eq .Status "firing" }}:{{ .Alerts.Firing
        | len }}{{ end }}] {{ .CommonLabels.alertname }}'
      token:
        key: ALERTMANAGER_PUSHOVER_TOKEN
        name: alertmanager-secret
      ttl: 86400s
      urlTitle: View in Alertmanager
      userKey:
        key: PUSHOVER_USER_KEY
        name: alertmanager-secret
  route:
    groupBy:
    - alertname
    - cluster
    - job
    groupInterval: 5m
    groupWait: 1m
    receiver: pushover
    repeatInterval: 12h
    routes:
    - matchers:
      - matchType: =
        name: alertname
        value: InfoInhibitor
      receiver: blackhole
    - groupInterval: 2m
      groupWait: 0s
      matchers:
      - matchType: =
        name: alertname
        value: Watchdog
      receiver: buddy-heartbeat
      repeatInterval: 2m30s
    - matchers:
      - matchType: =
        name: severity
        value: critical
      receiver: pushover

@onedr0p sorry my bad, I guess I deleted by mistake instead of adding monospace, seen that @simonpasquier already opened a pr with the fix 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants