Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug: T156245 Introduces a Nagios adapter for Grafana alerts and sets one up for WebPageTest. Change-Id: Ieb902f45b9b3e54e7e21a8bae461df58f3d09f7a
- Loading branch information
Showing
9 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# == Class: icinga::monitor::performance | ||
# | ||
# Monitor Performance | ||
class icinga::monitor::performance { | ||
monitoring::grafana_alert { 'db/webpagetest-alerts': | ||
contact_group => 'performance', | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# == Define: monitoring::grafana_alert | ||
# | ||
# Provisions an Icinga check that "forwards" Grafana alerts | ||
# for a given dashboard. | ||
# | ||
# === Parameters | ||
# | ||
# [*metric*] | ||
# Grafana dashboard uri. For example: 'db/webpagetest-alerts'. | ||
# Defaults to the resource title. | ||
# | ||
# [*grafana_url*] | ||
# URL of Grafana. | ||
# Defaults to 'https://grafana.wikimedia.org'. | ||
# | ||
# [*contact_group*] | ||
# Icinga contact group that should receive alerts. | ||
# Defaults to 'admins'. | ||
# | ||
# === Examples | ||
# | ||
# # Emit a critical if any grafana alert on the db/webpagetest-alerts | ||
# # dashboard is in "alterting" state. | ||
# monitoring::grafana_alert { 'db/webpagetest-alerts': | ||
# contact_group => 'performance', | ||
# } | ||
# | ||
define monitoring::grafana_alert( | ||
$dashboard = $title, | ||
$ensure = present, | ||
$grafana_url = 'https://grafana.wikimedia.org', | ||
$contact_group = 'admins' | ||
) { | ||
monitoring::service { $title: | ||
ensure => $ensure, | ||
description => "${grafana_url}/dashboard/${title} grafana alert", | ||
check_command => "check_grafana_alert!${title}!${grafana_url}", | ||
contact_group => $contact_group, | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
modules/nagios_common/files/check_commands/check_grafana_alert.cfg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
define command{ | ||
command_name check_grafana_alert | ||
command_line $USER1$/check_grafana_alert.py $ARG1$ $ARG2$ | ||
} |
56 changes: 56 additions & 0 deletions
56
modules/nagios_common/files/check_commands/check_grafana_alert.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
""" | ||
check_grafana_alert | ||
~~~~~~~~~~~~~~~~~~~~~~~~ | ||
Checks a Grafana dashboard and generates CRITICAL states if | ||
it has Grafana alerts in "alerting" state. | ||
Usage: | ||
check_grafana_alert DASHBOARD_URI GRAFANA_URL | ||
Positional arguments: | ||
DASHBOARD_URI Grafana dashboard URI | ||
GRAFANA_URL URL of grafana | ||
""" | ||
from __future__ import print_function | ||
|
||
import sys | ||
reload(sys) | ||
sys.setdefaultencoding("utf-8") | ||
|
||
import argparse | ||
import json | ||
import urllib2 | ||
|
||
|
||
ap = argparse.ArgumentParser(description='Grafana dashboard alert') | ||
ap.add_argument('dashboard', help='dashboard URI') | ||
ap.add_argument('grafana_url', help="URL of grafana") | ||
args = ap.parse_args() | ||
|
||
alerting_names = [] | ||
|
||
try: | ||
url = args.grafana_url + '/api/alerts' | ||
data = json.load(urllib2.urlopen(url)) | ||
|
||
for record in data: | ||
if 'dashboardUri' in record and record['dashboardUri'] == args.dashboard: | ||
if 'state' in record and record['state'] == 'alerting' and 'name' in record: | ||
alerting_names.append(record['name']) | ||
except Exception as e: | ||
print('UNKNOWN: failed to check %s/dashboard/%s due to exception: %s' % ( | ||
args.grafana_url, args.dashboard, e.msg)) | ||
sys.exit(3) | ||
|
||
if len(alerting_names) > 0: | ||
print('CRITICAL: %s/dashboard/%s is alerting: %s.' % ( | ||
args.grafana_url, args.dashboard, ', '.join(alerting_names)), file=sys.stderr) | ||
sys.exit(2) | ||
else: | ||
print('OK: %s/dashboard/%s is not alerting.' % ( | ||
args.grafana_url, args.dashboard), file=sys.stderr) | ||
sys.exit(0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters