Create an alert from Advisor results
Create a Grafana alert rule that monitors Advisor check results and fires when Advisor detects failures.
Before you begin
Before you create the alert, ensure you have:
- Grafana permissions: The
Adminrole, to create a service account and a data source, and permission to create alert rules. - Plugins: The Infinity data source (opens in new tab), version 3.3.0 or later, which supports the JQ parser used in this guide.
Create a service account and token
Advisor results are available through the Advisor HTTP API. To query the API, create a service account and a token:
- Click Administration > Users and access > Service accounts in the left-side menu.
- Click Add service account.
- Enter a name, for example
advisor-alert-service-account. - Set the role to Admin, which gives the service account the required permissions.
- Click Create.
- In the service account details, click Add service account token.
- Enter a token name and set an expiration date.
- Click Generate token.
Caution
Copy the token value immediately and store it securely. You can't view it again.
Set up the Infinity data source
The Infinity data source queries the Advisor HTTP API using the service account token.
- Click Connections > Add new connection.
- Search for
Infinity. - If the plugin isn't installed, click Install and wait for the installation to finish.
- On the plugin page, click Add new data source.
- Configure the data source:
- Name: Enter a descriptive name, for example
Advisor API. - Auth type: Select Bearer Token, then paste the service account token in Auth details.
- Allowed hosts: Enter
https://<GRAFANA_HOST>and click Add. Replace<GRAFANA_HOST>with the host of your Grafana instance.
- Name: Enter a descriptive name, for example
- Click Save & test to verify the connection.
Create the alert rule
- Click Alerting > Alert rules in the left-side menu.
- Click New alert rule.
- Enter a rule name, for example
Advisor failures alert.
Configure the query
- In Data source, select the Infinity data source you set up.
- Configure the query settings:
- Type: JSON
- Parser: JQ
- Source: URL
- Format: Table
- Method: GET
- URL:
https://<GRAFANA_HOST>/apis/advisor.grafana.app/v0alpha1/namespaces/<NAMESPACE>/checks
Replace the following placeholders in the URL:
<GRAFANA_HOST>: The host of your Grafana instance.<NAMESPACE>: The namespace of your Grafana instance. To find it, refer to the namespace API reference (opens in new tab).
For more information about this endpoint, refer to the Advisor HTTP API (opens in new tab).
Configure parsing options
In Rows/Root, paste the following JQ expression:
.items | map({
type: .metadata.labels["advisor.grafana.app/type"],
creationTimestamp: .metadata.creationTimestamp,
failuresCount: (.status.report.failures | length)
}) | group_by(.type) | map(sort_by(.creationTimestamp) | last)
This expression returns the most recent result for each check type, with its timestamp and failure count. You can use it to alert when any check type has more than 0 failures.
In Columns, add the following columns:
| Selector | Format |
|---|---|
creationTimestamp | Time |
failuresCount | Number |
type | String |
Filter by check type
Optionally, alert only on specific check types:
- Go to the Computed columns, Filter, Group by section.
- Add a Filter, for example
type == "license". Replacelicensewith the check type you want to alert on.
Set the alert condition
- In Alert condition, select WHEN Last OF QUERY Is above 0. The alert fires when any check type has failures.
- Click Preview alert rule condition to view the result of the query.
Complete the alert configuration
Select your evaluation behavior, for example every 24 hours, and configure the notification settings.
Save the alert rule
Click Save and verify that the alert fires as expected.