Query a metric from Prometheus and use current hostname as variable


we are monitoring our systems and use Prometheus data beside the Check_MK Agent. The metric we want to retrieve has a label called “server” with the value of the current hostname. Since I do not want to create individual roles for every host where I have to write a query like my_prom_query{server=“myhostname”}, I would like to have a more generic query where I could use the current hostname as a variable like


but I think that this is not possible. Or do I miss something?

Any help is appreciated.

Thanks and best regards


Not sure about Prometheus, but in other rules Nagios Macros could be used:


Hello Mike!

Thanks for your reply, but it seems not to work. I get this error message:

PromQL expression (x509_cert_expiry{job="myjob",env="myenv",host="$HOSTNAME$"}/86400) does not produce a valid result

Any other ideas?

Kind regards