From patchwork Mon Apr 20 21:17:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christopher Baines X-Patchwork-Id: 21371 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 915D527BBE4; Mon, 20 Apr 2020 22:18:13 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, UNPARSEABLE_RELAY autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTP id 38C3D27BBE1 for ; Mon, 20 Apr 2020 22:18:13 +0100 (BST) Received: from localhost ([::1]:42488 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQdnw-00046t-Mg for patchwork@mira.cbaines.net; Mon, 20 Apr 2020 17:18:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41370) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQdnn-00044i-RV for guix-patches@gnu.org; Mon, 20 Apr 2020 17:18:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jQdnn-0000Qh-7n for guix-patches@gnu.org; Mon, 20 Apr 2020 17:18:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:37004) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jQdnm-0000QW-RP for guix-patches@gnu.org; Mon, 20 Apr 2020 17:18:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jQdnm-0002gF-MF for guix-patches@gnu.org; Mon, 20 Apr 2020 17:18:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#40738] [PATCH 4/4] services: Add a service for Alertmanager. Resent-From: Christopher Baines Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 20 Apr 2020 21:18:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 40738 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: moreinfo To: 40738@debbugs.gnu.org Received: via spool by 40738-submit@debbugs.gnu.org id=B40738.158741747110246 (code B ref 40738); Mon, 20 Apr 2020 21:18:02 +0000 Received: (at 40738) by debbugs.gnu.org; 20 Apr 2020 21:17:51 +0000 Received: from localhost ([127.0.0.1]:48538 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jQdnb-0002f7-FB for submit@debbugs.gnu.org; Mon, 20 Apr 2020 17:17:51 -0400 Received: from mira.cbaines.net ([212.71.252.8]:33676) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jQdnW-0002eM-DG for 40738@debbugs.gnu.org; Mon, 20 Apr 2020 17:17:47 -0400 Received: from localhost (unknown [46.237.173.52]) by mira.cbaines.net (Postfix) with ESMTPSA id F0D3927BBEB for <40738@debbugs.gnu.org>; Mon, 20 Apr 2020 22:17:45 +0100 (BST) Received: from localhost (localhost [local]) by localhost (OpenSMTPD) with ESMTPA id a4197032 for <40738@debbugs.gnu.org>; Mon, 20 Apr 2020 21:17:43 +0000 (UTC) From: Christopher Baines Date: Mon, 20 Apr 2020 22:17:43 +0100 Message-Id: <20200420211743.23476-4-mail@cbaines.net> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200420211743.23476-1-mail@cbaines.net> References: <87v9lt50d4.fsf@cbaines.net> <20200420211743.23476-1-mail@cbaines.net> MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-Received-From: 209.51.188.43 X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches --- gnu/services/monitoring.scm | 82 +++++++++++++++++++++++++++++++++++++ gnu/tests/monitoring.scm | 71 ++++++++++++++++++++++++++++++++ 2 files changed, 153 insertions(+) diff --git a/gnu/services/monitoring.scm b/gnu/services/monitoring.scm index a37dfd80d8..50a4b7302c 100644 --- a/gnu/services/monitoring.scm +++ b/gnu/services/monitoring.scm @@ -51,6 +51,17 @@ prometheus-configuration-storage-tsdb-path prometheus-configuration-extra-options + alertmanager-service-type + + alertmanager-configuration + alertmanager-configuration-package + alertmanager-configuration-user + alertmanager-configuration-group + alertmanager-configuration-config-file + alertmanager-configuration-web-listen-address + alertmanager-configuration-storage-path + alertmanager-configuration-extra-options + zabbix-server-configuration zabbix-server-service-type zabbix-agent-configuration @@ -226,6 +237,77 @@ prometheus.") (compose list prometheus-node-exporter-shepherd-service)))) (default-value (prometheus-node-exporter-configuration)))) + +;;; +;;; Alertmanager +;;; + +(define-record-type* + alertmanager-configuration + make-alertmanager-configuration + alertmanager-configuration? + (package alertmanager-configuration-package + (default alertmanager)) + (user alertmanager-configuration-user + (default "alertmanager")) + (group alertmanagerconfiguration-group + (default "alertmanager")) + (config-file alertmanager-config-file + (default (plain-file "alertmanager.yml" ""))) + (web-listen-address alertmanager-web-listen-address + (default ":9093")) + (storage-tsdb-path alertmanager-storage-tsdb-path + (default "/var/lib/alertmanager/data/")) + (extra-options alertmanager-configuration-extra-options + (default '()))) + +(define alertmanager-shepherd-service + (match-lambda + (($ package user group + config-file web-listen-address + storage-tsdb-path extra-options) + (shepherd-service + (documentation "Alertmanager monitoring system and time series database.") + (provision '(alertmanager)) + (requirement '(networking)) + (start #~(make-forkexec-constructor + (list #$(file-append package "/bin/alertmanager") + "--config.file" #$config-file + "--web.listen-address" #$web-listen-address + "--storage.path" #$storage-tsdb-path + #$@extra-options) + #:user #$user + #:group #$group + #:log-file "/var/log/alertmanager.log")) + (stop #~(make-kill-destructor)))))) + +(define (alertmanager-account config) + (match-record config + (user group) + (list (user-group + (name group) + (system? #t)) + (user-account + (name user) + (group group) + (system? #t) + (comment "Alertmanager user") + (home-directory "/var/lib/alertmanager") + (shell (file-append shadow "/sbin/nologin")))))) + +(define alertmanager-service-type + (service-type + (name 'alertmanager) + (description + "Run @command{alertmanager} to scrape targets for mertrics and provide the +web interface.") + (extensions + (list (service-extension shepherd-root-service-type + (compose list alertmanager-shepherd-service)) + (service-extension account-service-type + alertmanager-account))) + (default-value (alertmanager-configuration)))) + ;;; ;;; Zabbix server diff --git a/gnu/tests/monitoring.scm b/gnu/tests/monitoring.scm index e8c0847229..b77b654abc 100644 --- a/gnu/tests/monitoring.scm +++ b/gnu/tests/monitoring.scm @@ -33,6 +33,7 @@ #:use-module (guix gexp) #:export (%test-prometheus %test-prometheus-node-exporter + %test-alertmanager %test-zabbix)) @@ -176,6 +177,76 @@ (value (run-prometheus-node-exporter-server-test name %prometheus-node-exporter-os)))) + +;;; +;;; Alertmanager +;;; + +(define* (run-alertmanager-test name test-os) + "Run tests in %TEST-OS, which has Alertmanager running." + (define os + (marionette-operating-system + test-os + #:imported-modules '((gnu services herd)))) + + (define vm + (virtual-machine + (operating-system os) + (port-forwardings '((8080 . 9093))))) + + (define test + (with-imported-modules '((gnu build marionette)) + #~(begin + (use-modules (srfi srfi-11) + (srfi srfi-64) + (gnu build marionette) + (web client) + (web response)) + + (define marionette + (make-marionette (list #$vm))) + + (mkdir #$output) + (chdir #$output) + + (test-begin #$name) + + (test-assert "alertmanager running" + (marionette-eval + '(begin + (use-modules (gnu services herd)) + (match (start-service 'alertmanager) + (#f #f) + (('service response-parts ...) + (match (assq-ref response-parts 'running) + ((pid) (number? pid)))))) + marionette)) + + (test-equal "alertmanager healthy" + 200 + (begin + (wait-for-tcp-port 9090 marionette) + (let-values (((response text) + (http-get "http://localhost:8080/-/healthy"))) + (response-code response)))) + + (test-end) + (exit (= (test-runner-fail-count (test-runner-current)) 0))))) + + (gexp->derivation (string-append name "-test") test)) + +(define %alertmanager-test-os + (simple-operating-system + (service dhcp-client-service-type) + (service alertmanager-service-type))) + +(define %test-alertmanager + (system-test + (name "alertmanager") + (description "Connect to a running Alertmanager service.") + (value (run-alertmanager-test name + %alertmanager-test-os)))) + ;;; ;;; Zabbix