From 138af6b4ac6cb48697048c0a9537734139b9f538 Mon Sep 17 00:00:00 2001 From: Joerg Lehmann Date: Fri, 22 Jul 2022 19:28:45 +0200 Subject: [PATCH] only send abo reminder 10, 5 and 0 days before expiration --- check_nodes.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/check_nodes.go b/check_nodes.go index de86c7a..d3498ad 100644 --- a/check_nodes.go +++ b/check_nodes.go @@ -34,9 +34,6 @@ func sendEmailAbo(username string, alias string, deveui string, days_left int, l } else if days_left > 0 { fmt.Printf("SEND EMAIL ABO (%s) - %s:%s\n", level, username, deveui) ablauftext = "Das Abo von \"" + alias + "\" (DevEUI: " + deveui + ") laeuft in " + strconv.Itoa(days_left) + " Tagen ab." - } else { - fmt.Printf("DO NOT SEND EMAIL ABO (%s) - %s:%s\n", level, username, deveui) - return } mail_message := "To: " + username + ` From: info@mini-beieli.ch @@ -84,6 +81,10 @@ func CheckThreshold(d string, vp int, u2 string, last_metric OneMetric, info_thr return true } +func sendReminder(days int) bool { + return (days == 0 || days == 5 || days == 10) +} + func checkNodes() { logit("Starting check_battery...") @@ -105,7 +106,7 @@ func checkNodes() { } } // Jetzt der Alarm wegen der Abodauer - if last_metric.DaysUntilDeactivated < 30 { + if sendReminder(last_metric.DaysUntilDeactivated) { fmt.Printf("SEND EMAIL %s:%s:%s Percent:%s:%d\n", u2, d, last_metric.BatteryPercent, last_metric.ActiveUntil, last_metric.DaysUntilDeactivated) alias := getDevAlias(d) sendEmailAbo(u2, alias, d, last_metric.DaysUntilDeactivated, "INFO")