Compare commits

...

2 Commits

Author SHA1 Message Date
Daniel Barlow 7a5017fd17 fix package search path in wrapper 2022-09-16 23:21:07 +01:00
Daniel Barlow 07ee2a1b0e example of nixos module/systemd service 2022-09-16 22:43:21 +01:00
4 changed files with 39 additions and 14 deletions

View File

@ -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.

View File

@ -21,7 +21,10 @@ in stdenv.mkDerivation {
lua_path="`lua -e 'print(package.path)'`"
lua_cpath="`lua -e 'print(package.cpath)'`"
makeWrapper ${myfennel}/bin/fennel $out/bin/grafana-sms-alert \
makeWrapper ${myfennel}/bin/fennel \
$out/bin/grafana-sms-alert \
--add-flags "--add-fennel-path $out/lib/?.fnl" \
--add-flags "--add-package-path $out/lib/?.lua" \
--add-flags "$out/lib/main.fnl"
'';
buildInputs = [lua myfennel];

View File

@ -1,5 +1,4 @@
(set _G.modem-spew io.stderr)
; (set _G.modem-spew io.stderr)
(local server (require :server))
(local webhook (require :webhook))
(local json (require :dkjson))
@ -13,8 +12,6 @@
(nil pos err) (error (.. "reading " filename ": " err)))))
(local { : view} (require :fennel))
;(print (view m) (view err))
(local sms ((. (require :sms) :new) { :smsc smsc :device device }))

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