Compare commits
2 Commits
d795d5a4a1
...
7a5017fd17
Author | SHA1 | Date |
---|---|---|
Daniel Barlow | 7a5017fd17 | |
Daniel Barlow | 07ee2a1b0e |
21
README.md
21
README.md
|
@ -1,25 +1,28 @@
|
||||||
# Grafana SMS alert
|
# 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.
|
understands AT commands, such as the Huawei E3131 broadband USB dongle.
|
||||||
Fancy SaaS alerting services are great, but what if you want to know
|
Fancy SaaS alerting services are great, but what if you want to know
|
||||||
that the internet is down?
|
that the internet is down?
|
||||||
|
|
||||||
This runs as a service on `localhost:8201` - once you've started it,
|
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`.
|
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
|
$ curl -v --data @sample-alert.json http://localhost:8201
|
||||||
invocation and check it's operational
|
|
||||||
|
|
||||||
|
### 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.
|
||||||
|
|
|
@ -21,7 +21,10 @@ in stdenv.mkDerivation {
|
||||||
lua_path="`lua -e 'print(package.path)'`"
|
lua_path="`lua -e 'print(package.path)'`"
|
||||||
lua_cpath="`lua -e 'print(package.cpath)'`"
|
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"
|
--add-flags "$out/lib/main.fnl"
|
||||||
'';
|
'';
|
||||||
buildInputs = [lua myfennel];
|
buildInputs = [lua myfennel];
|
||||||
|
|
5
main.fnl
5
main.fnl
|
@ -1,5 +1,4 @@
|
||||||
(set _G.modem-spew io.stderr)
|
; (set _G.modem-spew io.stderr)
|
||||||
|
|
||||||
(local server (require :server))
|
(local server (require :server))
|
||||||
(local webhook (require :webhook))
|
(local webhook (require :webhook))
|
||||||
(local json (require :dkjson))
|
(local json (require :dkjson))
|
||||||
|
@ -13,8 +12,6 @@
|
||||||
(nil pos err) (error (.. "reading " filename ": " err)))))
|
(nil pos err) (error (.. "reading " filename ": " err)))))
|
||||||
|
|
||||||
(local { : view} (require :fennel))
|
(local { : view} (require :fennel))
|
||||||
;(print (view m) (view err))
|
|
||||||
|
|
||||||
|
|
||||||
(local sms ((. (require :sms) :new) { :smsc smsc :device device }))
|
(local sms ((. (require :sms) :new) { :smsc smsc :device device }))
|
||||||
|
|
||||||
|
|
|
@ -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}
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
Loading…
Reference in New Issue