Grafana allows for dynamic datasource queries by making use of variables. This functionality gives the ability to create graph/dashboard templates that may be re-used. For instance, switching your view between a production or development environment while maintaining the same underlying queries.
In CheckMK it is possible to create custom action buttons on hosts or services. Leveraging this, quick links can be created to integrate external resources such as ticketing systems, or in this case, Grafana.
This article will provide a simple example of such an integration by creating a dashboard template and an action icon for a host.
First, we will set up a variable for "hostname". For simplicity here we will use a "Constant".
These can be found in the dashboard settings.
Building the Query
Once the variables are in place, they will need to be inserted into a query so we can use them.
These values of the variables are interpolated in Grafana before the query is run against the datasource.
For this dashboard, we will create a single graph for CPU utilization.
In the query "[[hostname]]" will be expanded to what is set for the "hostname" variable.
This can be set via a drop down menu on the dashboard, or in the URL simply by appending "&var-hostname=myhostname".
Note that these graphs are blank by default as there will be no variable initially set.
Creating a Check_MK Action.
An "action" will need to be created in CheckMK. This action can be applied to specific hosts or services by using rules.
Actions are managed under "Global Settings" > "User Interface" > "Custom Icons and Actions".
CheckMK allows several macros to be used in actions. Such as host name, service name.
In the action above, we are creating a link to our host dashboard and setting the host name variable in the URL.
Once the action has been created we can now apply it to hosts.
These rules can be found under "Host and Service Parameters" > "Monitoring Configuration" > "Various" > "Custom icons or actions for hosts in status GUI".
When creating the rule, we choose from our list of configured actions.