How to show hostname in alert telegram

hi there,

how to show hostname in alert telegram?
image

i have tried to set summary
“{{ $labels.instance }} of job {{ $labels.job }} has been down”
and
“{{ $labels.hostname }} of job {{ $labels.job }} has been down”

for {{ $labels.instance }} it showing IP address but {{ $labels.hostname }} not showing hostname

image

Looking at the last screenshot, it doesn’t look like the alert has a hostname label?

when i try
{{ $labels.hostname }} it not showing hostname, just returns no value

i want to display hostname in summary alert
how do i show hostname in alert telegram?

To use {{ $labels.hostname }} your datasource needs to return a label called hostname. However, looking at the screenshots it only returns a label called instance, not hostname.

Hello

How we can retrieve hostname for alerting in Telegram if it don’t exist( under the hood maybe exist :slight_smile: ) in labels?
BUT the hostname is by default located in node_uname_info(nodename) metric in Grafana - found it in node_exporter configuration file

{{ with $values }}
{{ range $k, $v := . }}
Hostname: {{$v.Labels.host.hostname}}
{{ end }}
{{ end }} ;

  • Instance: {{ index $node_uname_info “nodename”}} etc doesn’t work for me

Labels like hostname have to come from the datasource in these cases (unless you want to create an alert rule per host, which I do not recommend) It looks like the label in your datasource is called nodename. Just use that?

1 Like

Datasource is prometheus
in my case: in alerts - where we need the hostname(FQDN).
I just have to add this query above and call the
$labels ''nodename" right?
Or $labels.nodename, $labels.hostname - I’ve tried to play with many different options in Annotations.summary
But it seems Grafana can’t see that “label”(or whatever).
I’m wondering - Is really such basic thing as hostname not included in default labels in Grafana?
If not, please share your thoughts about the variation above - How I can use it in Annotations summary?

Here is a basic alert and labels:

labels for:
node_uname_info{nodename="wltdevopstest1.test"} query - Executed in separate alertrule.
I tried adding the query to alert above - zero reaction, Buuut

This works , only on it’s own :smiling_face_with_tear:
image

Your annotation looks good to me! {{ index $labels "nodename" }} would be correct.

I’m wondering - Is really such basic thing as hostname not included in default labels in Grafana?

Grafana does not include any labels by default other than alertname and grafana_folder. All other labels must come from your datasource.

1 Like

Yes, very logical to me too
Just to put {{ index $labels "nodename" }} in my working alertrule


And that’s what I got
image
Query for this rule:

So here I tried to combine two queries: query E - that gave me the chance to retrieve hostname in separate alertrule in the message above - don’t work in my main alertrule. You can notice Annotations - {{ index $labels "nodename" }} - here gives me nothing

I suspect there are two problems here: 1. Query E is not used in the execution graph that calculates the alert condition 2. Grafana does not know how to join the data from query A with the data from query E because there are no common labels between them.

I think you need to add the nodename label to your metrics in Query A.

Thank you for replying.
Now I know that this idea is at least possible

Can you help me with this? Adding nodename to query?
100-((node_filesystem_avail_bytes{instance="10.206.73.125:9100",job="node_exporter_test_server",device!~'rootfs'} * 100) / node_filesystem_size_bytes{instance="10.206.73.125:9100",job="node_exporter_test_server",device!~'rootfs'})
and
node_memory_Active_bytes * on(instance) group_left(nodename) (node_uname_info)

I really have no idea how combine these two queries