From 07ee2a1b0ee3598da0f174fce6c17dbd7d277993 Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Fri, 16 Sep 2022 22:43:21 +0100 Subject: [PATCH] example of nixos module/systemd service --- README.md | 21 ++++++++++++--------- module-example.nix | 22 ++++++++++++++++++++++ 2 files changed, 34 insertions(+), 9 deletions(-) create mode 100644 module-example.nix diff --git a/README.md b/README.md index 6b31a44..229af45 100644 --- 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 new file mode 100644 index 0000000..8a0fc8d --- /dev/null +++ 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} + ''; + }; + }; +}