parent
a36876194d
commit
81e6837294
@ -0,0 +1 @@ |
||||
config.json |
@ -0,0 +1,5 @@ |
||||
{ |
||||
"smsc": "+447958879879", |
||||
"number": "447000123456", |
||||
"device": "/dev/serial/by-id/usb-HUAWEI_HUAWEI_HiLink-if00-port0" |
||||
} |
@ -1,8 +1,28 @@ |
||||
(set _G.modem-spew io.stderr) |
||||
|
||||
(local server (require :server)) |
||||
(local handler (require :handler)) |
||||
(local sms (require :sms)) |
||||
(local webhook (require :webhook)) |
||||
(local json (require :dkjson)) |
||||
|
||||
(local {: smsc : number : device } |
||||
(let [filename (assert (. arg 1) "missing argument") |
||||
text (with-open [config (io.open filename :r)] |
||||
(config:read "*a"))] |
||||
(match (json.decode text) |
||||
a a |
||||
(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 })) |
||||
|
||||
(print "Ready") |
||||
(doto (server.new handler.handle) |
||||
(doto (server.new |
||||
(fn handle [body] |
||||
(let [message (webhook.parse body)] |
||||
(sms:send number message) |
||||
"Sent"))) |
||||
(: :listen) |
||||
(print "server ready") |
||||
(: :loop)) |
||||
|
@ -1,26 +1,10 @@ |
||||
(local json (require :dkjson)) |
||||
(local unistd (require :posix.unistd)) |
||||
|
||||
(local sms |
||||
((. (require :sms) :new) |
||||
{ |
||||
:smsc "+447958879879" |
||||
:device "/dev/serial/by-id/usb-HUAWEI_HUAWEI_HiLink-if00-port0" |
||||
:verbose true |
||||
})) |
||||
|
||||
(fn send-sms [body] |
||||
(print :send-sms body) |
||||
(sms:send "447000123456" body) |
||||
"Sent") |
||||
|
||||
(fn handle [s] |
||||
(let [(m pos err) (json.decode s 1 nil)] |
||||
(fn parse [body] |
||||
(let [(m pos err) (json.decode body 1 nil)] |
||||
(when m |
||||
(send-sms |
||||
(.. m.title " " (. (. m.alerts 1) :valueString)))) |
||||
"ok")) |
||||
(.. m.title " " (. (. m.alerts 1) :valueString))))) |
||||
; |
||||
;;;; {"receiver":"","status":"firing","alerts":[{"status":"firing","labels":{"alertname":"TestAlert","instance":"Grafana"},"annotations":{"summary":"Notification test"},"startsAt":"2022-09-13T21:14:29.77765882+01:00","endsAt":"0001-01-01T00:00:00Z","generatorURL":"","fingerprint":"57c6d9296de2ad39","silenceURL":"http://garf.telent.net:3002/alerting/silence/new?alertmanager=grafana\u0026matcher=alertname%3DTestAlert\u0026matcher=instance%3DGrafana","dashboardURL":"","panelURL":"","valueString":"[ metric='foo' labels={instance=bar} value=10 ]"}],"groupLabels":{},"commonLabels":{"alertname":"TestAlert","instance":"Grafana"},"commonAnnotations":{"summary":"Notification test"},"externalURL":"http://garf.telent.net:3002/","version":"1","groupKey":"{alertname=\"TestAlert\", instance=\"Grafana\"}2022-09-13 21:14:29.77765882 +0100 BST m=+644632.184951212","truncatedAlerts":0,"orgId":1,"title":"[FIRING:1] (TestAlert Grafana)","state":"alerting","message":"**Firing**\n\nValue: [ metric='foo' labels={instance=bar} value=10 ]\nLabels:\n - alertname = TestAlert\n - instance = Grafana\nAnnotations:\n - summary = Notification test\nSilence: http://garf.telent.net:3002/alerting/silence/new?alertmanager=grafana\u0026matcher=alertname%3DTestAlert\u0026matcher=instance%3DGrafana\n"} |
||||
|
||||
{: handle} |
||||
{: parse} |
Loading…
Reference in new issue