example of nixos module/systemd service

main
Daniel Barlow 2022-09-16 22:43:21 +01:00
parent d795d5a4a1
commit 07ee2a1b0e
2 changed files with 34 additions and 9 deletions

View File

@ -6,20 +6,23 @@ 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.

22
module-example.nix Normal file
View File

@ -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}
'';
};
};
}