I have a grafana with Prometheus, InfluxDB and MySQL plugins installed. I want to get the IP behind a domain name, for example, get 8.8.8.8
when querying dns.google.com
, and show the result in a Grafana Dashboard.
I tried to :
gethostbyname($ip)
do exactly what I want, but I can't execute PHP.I don't want to save the result to have an history, I just want a real-time DNS manager to check for some DNS entry.
How can I do it? Like how to execute PHP in Grafana?
Not sure that this is the best idea to do DNS resolving directly in Grafana (did you try to do it by your datasource means?), but you may play with JavaScript and external services to achieve that.
Change disable_sanitize_html to true in grafana.ini:
disable_sanitize_html = true
Now you can use JavaScript in Text panel (sample external service ip-api.com is used in this example, domain name is specified by dashboard variable ${domain}
):
<p id="ipAddress"></p>
<script type="text/javascript">function cb (x){ document.getElementById('ipAddress').innerHTML=x.query }</script>
<script type='text/javascript' src='http://ip-api.com/json/${domain}?callback=cb'></script>
Result: