How to display host lable in alerting

Grafana version:v9.2.4

I am using grafana to send an alerting message to slack, and I can get the value of the lable of host in the description:

{{ with $values }}
{{ range $k, $v := . }}

{{ $ }}
{{ $v.Value | printf "%.0f" }} 
{{ end }}
{{ end }}

I want it to display the label of the host when it is alerting, so that I can only silence the alert rule of host=xxx instead of all the memory alerting of all the host.

Hi! You will either need to create a custom label called Host, or get your datasource to return a Host label. It looks like you might have some of this information available looking at the Description annotation, can you share the template for it?

Thank your reply.
Yes,I can add a host label, but this alert rule contains multiple servers, and I’m not sure how to set the value of this host as a variable.

And the follow is my message template:

{{ define "default.alert" }}
  {{- range .Labels.SortedPairs }}
    `{{ .Name }}`: {{ .Value -}}
  {{ end }}

  {{- if gt (len .Annotations) 0 }}
  {{- range .Annotations.SortedPairs }}
    `{{ .Name }}`: {{ .Value -}}
  {{ end }}
  {{ end -}}

  {{ if gt (len .SilenceURL ) 0 }}- <{{ .SilenceURL }}|Silence Alert> {{ end }}
  {{ if gt (len .DashboardURL ) 0 }}- <{{ .DashboardURL }}|Dashboard> {{ end }}
  {{ if gt (len .PanelURL) 0 }}- <{{ .PanelURL }}|Panel> {{ end }}
  {{ if gt (len .GeneratorURL) 0 }}- <{{ .GeneratorURL }}|Generator> {{ end }}
{{ end }}

I’m not sure how it get the host label in the description.

Hi! With multi-dimensional alerting, provided each server has a different host or instance label, then each server will create a separate alert. All alerts have their own set of labels and annotations which you print in your default.alert template.

The Host should be set as a Custom Label or an annotation in your alert rule. Your message template doesn’t need to be changed as it prints all labels and annotations for every alert.