fix alerting
This commit is contained in:
+7
-3
@@ -33,7 +33,6 @@ type MessageProperties struct {
|
||||
type Message struct {
|
||||
Prop MessageProperties `json:"DevEUI_uplink"`
|
||||
}
|
||||
|
||||
type payload_128 struct {
|
||||
Version uint8
|
||||
Vbat uint8
|
||||
@@ -87,6 +86,7 @@ type payload_1 struct {
|
||||
var file *os.File
|
||||
|
||||
var alertMap map[string]string
|
||||
var alertLogMap map[string]string
|
||||
|
||||
func DecodePayload(s string, deveui string, devaddr string, lrrlat float32, lrrlon float32, write2file bool) {
|
||||
var ba []byte
|
||||
@@ -165,6 +165,10 @@ func DecodePayload(s string, deveui string, devaddr string, lrrlat float32, lrrl
|
||||
sendAlert(deveui,val)
|
||||
delete(alertMap,deveui)
|
||||
}
|
||||
if val2, ok2 := alertLogMap[deveui]; ok2 {
|
||||
WriteStringToFile(val2)
|
||||
delete(alertLogMap,deveui)
|
||||
}
|
||||
}
|
||||
|
||||
func WriteDatapoint(mytime int64, deveui string, devaddr string, v uint8, h uint8, p uint8, w uint16, w1 int32, w2 int32, t int16, lrrlat float32, lrrlon float32) {
|
||||
@@ -193,10 +197,9 @@ func WriteDatapoint(mytime int64, deveui string, devaddr string, v uint8, h uint
|
||||
w_loss := getMaxValue(deveui) - w_gram;
|
||||
if (w_loss > 500) {
|
||||
// Schwarmalarm!
|
||||
s = fmt.Sprintf("alert,deveui=%s reason=\"swarmalarm\",w=%di,w_loss=%di %d\n",deveui,w_gram,w_loss,mytime*60*1000*1000*1000)
|
||||
alertLogMap[deveui] = fmt.Sprintf("alert,deveui=%s reason=\"swarmalarm\",w=%di,w_loss=%di %d\n",deveui,w_gram,w_loss,mytime*60*1000*1000*1000)
|
||||
location, _ := time.LoadLocation("Europe/Zurich")
|
||||
alertMap[deveui] = fmt.Sprintf("*** Schwarmalarm ***\n%s\n%s\nGewichtsverlust: %d g",getDevAlias(deveui),time.Unix(mytime*60,0).In(location).Format("02.01.2006 15:04"),w_loss)
|
||||
WriteStringToFile(s)
|
||||
|
||||
}
|
||||
}
|
||||
@@ -220,6 +223,7 @@ func main() {
|
||||
|
||||
// Init alertMap
|
||||
alertMap = make(map[string]string)
|
||||
alertLogMap = make(map[string]string)
|
||||
|
||||
// Open Output File
|
||||
f, err := os.OpenFile(outputfile,os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644)
|
||||
|
||||
+1
-1
@@ -1,3 +1,3 @@
|
||||
#!/bin/bash
|
||||
|
||||
awk '{$3=strftime("%Y-%m-%d %H:%M:%S", substr($3,1,10)); print $0}' lorahandler.log
|
||||
awk '{$3=strftime("%Y-%m-%d %H:%M:%S", substr($NF,1,10)); print $0}' lorahandler.log
|
||||
|
||||
Reference in New Issue
Block a user