fix alert bug, respect alarmactive
This commit is contained in:
parent
855c9f2964
commit
cf648cb9a2
3
alert.go
3
alert.go
|
|
@ -39,7 +39,8 @@ func sendSMS(phonenumber string, alertMessage string) {
|
|||
func sendAlert(deveui string, alertMessage string) {
|
||||
fmt.Printf("sendAlert: deveui=%s, message=%s\n", deveui, alertMessage)
|
||||
smsnumber := getSmsnumber(deveui)
|
||||
if (smsnumber != "") {
|
||||
alarmactive := getDevAlarmactive(deveui)
|
||||
if ((smsnumber != "") && (alarmactive == "1")) {
|
||||
// we strip of the leading +
|
||||
smsnumber = strings.Replace(smsnumber, "+", "", -1)
|
||||
sendSMS(smsnumber,alertMessage)
|
||||
|
|
|
|||
|
|
@ -168,6 +168,8 @@ func DecodePayload(s string, deveui string, devaddr string, lrrlat float32, lrrl
|
|||
if val, ok := alertMap[deveui]; ok {
|
||||
sendAlert(deveui,val)
|
||||
delete(alertMap,deveui)
|
||||
// alte Werte loeschen
|
||||
deleteValues(deveui)
|
||||
}
|
||||
if val2, ok2 := alertLogMap[deveui]; ok2 {
|
||||
WriteStringToFile(val2)
|
||||
|
|
@ -204,8 +206,6 @@ func WriteDatapoint(mytime int64, deveui string, devaddr string, v uint8, h uint
|
|||
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)
|
||||
// alte Werte loeschen
|
||||
deleteValues(deveui)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -153,6 +153,24 @@ func getDevAlias(deveui string) string {
|
|||
return res
|
||||
}
|
||||
|
||||
func getDevAlarmactive(deveui string) string {
|
||||
res := "0"
|
||||
|
||||
if deveui == "" {
|
||||
return res
|
||||
}
|
||||
|
||||
conn := globalPool.Get()
|
||||
defer conn.Close()
|
||||
|
||||
alarmactive, err := redis.String(conn.Do("HGET", devPrefix+deveui, "alarmactive"))
|
||||
if err == nil {
|
||||
res = alarmactive
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
func getSmsnumber(deveui string) string {
|
||||
res := ""
|
||||
if deveui == "" {
|
||||
|
|
|
|||
Loading…
Reference in New Issue