grafana-sms-alert

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 07ee2a1b0ee3598da0f174fce6c17dbd7d277993
parent d795d5a4a1263563814b4f259e6cdc20568b54bc
Author: Daniel Barlow <dan@telent.net>
Date:   Fri, 16 Sep 2022 22:43:21 +0100

example of nixos module/systemd service

Diffstat:
MREADME.md | 21++++++++++++---------
Amodule-example.nix | 22++++++++++++++++++++++
2 files changed, 34 insertions(+), 9 deletions(-)

diff --git a/README.md b/README.md @@ -1,25 +1,28 @@ # Grafana SMS alert -Send Grafana alerts via SMS to a mobile phone, using a GSM modem that +Send Grafana alerts via SMS to a mobile phone, using a GSM modem that understands AT commands, such as the Huawei E3131 broadband USB dongle. Fancy SaaS alerting services are great, but what if you want to know that the internet is down? This runs as a service on `localhost:8201` - once you've started it, -create a "Webhook" type contact point in your Grafana instance +create a "Webhook" type contact point in your Grafana instance, with the url `http://localhost:8201`. -See Grafana [alerting contact points](https://grafana.com/docs/grafana/latest/alerting/contact-points/) documentation for background +See Grafana [alerting contact points](https://grafana.com/docs/grafana/latest/alerting/contact-points/) documentation for background. -## Installation (Nix) +## Building and use (Nix) -TBD +### Try it quickly -## Testing + $ nix-build build.nix + $ cp config.json.example config.json # and edit it + $ ./result/bin/grafana-sms-alert config.json -Use the sample-alert.json in this repo to simulate the Grafana webhook -invocation and check it's operational + $ curl -v --data @sample-alert.json http://localhost:8201 +### Install it meaningfully - curl -v --data @sample-alert.json http://localhost:8201 +The derivation in `default.nix` works with `callPackage`, so see +`module-example.nix` for a sketch. diff --git a/module-example.nix b/module-example.nix @@ -0,0 +1,22 @@ +{ config, lib, pkgs, ... }: +let + grafana-sms-alert = pkgs.callPackage (fetchTarball "https://gti.telent.net/dan/grafana-sms-alert/archive/main.tar.gz") {}; + smsConfig = builtins.toFile "config.json" + (builtins.toJSON { + smsc = "+447958879879"; + number = "447000123456"; + device = "/dev/serial/by-id/usb-HUAWEI_HUAWEI_HiLink-if00-port0"; + }); +in { + config.systemd.services.grafana-sms = { + description = "SMS webhook for Grafana"; + wantedBy = [ "multi-user.target" ]; + serviceConfig = { + Restart = "always"; + SyslogIdentifier = "grafana-sms"; + ExecStart = '' + ${grafana-sms-alert}/bin/grafana-sms-alert ${smsConfig} + ''; + }; + }; +}