update
This commit is contained in:
@@ -8,6 +8,8 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
@@ -119,6 +121,78 @@ func Route(db *gorm.DB) {
|
||||
w.Write([]byte("success"))
|
||||
}))
|
||||
|
||||
http.HandleFunc("/server-down-notification", middleware.ResponseTimeMiddleware(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodGet {
|
||||
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
||||
}
|
||||
|
||||
sessionID := helper.GenerateSessionID()
|
||||
module := "SERVER DOWN NOTIFICATION"
|
||||
log.Printf("%+v %+v request %+v", sessionID, module, nil)
|
||||
|
||||
subject := "Server Down 🚨"
|
||||
|
||||
sendTo := strings.Split(os.Getenv("ALERT_EMAIL"), ",")
|
||||
|
||||
type Data struct {
|
||||
TimeAt string
|
||||
Host string
|
||||
}
|
||||
|
||||
data := Data{TimeAt: time.Now().Format("2006-01-02 15:04:05"), Host: "36.66.3.44"}
|
||||
|
||||
htmlString := helper.ParseHTML("template/server-down.html", data)
|
||||
|
||||
go func() {
|
||||
log.Printf("%+v %+v SENDING EMAIL TO %+v", sessionID, module, sendTo)
|
||||
err := helper.SendEmail(sendTo, sendTo, "", subject, "", htmlString)
|
||||
if err != nil {
|
||||
log.Printf("%+v %+v response %+v", sessionID, module, err.Error())
|
||||
} else {
|
||||
log.Printf("%+v %+v EMAIL SENT TO %+v", sessionID, module, sendTo)
|
||||
}
|
||||
}()
|
||||
|
||||
log.Printf("%+v %+v response %+v", sessionID, module, "success")
|
||||
w.Write([]byte("success"))
|
||||
}))
|
||||
|
||||
http.HandleFunc("/high-memory-notification", middleware.ResponseTimeMiddleware(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodGet {
|
||||
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
||||
}
|
||||
|
||||
sessionID := helper.GenerateSessionID()
|
||||
module := "HIGH MEMORY USAGE NOTIFICATION"
|
||||
log.Printf("%+v %+v request %+v", sessionID, module, nil)
|
||||
|
||||
subject := "High Memory Usage 🚨"
|
||||
|
||||
sendTo := strings.Split(os.Getenv("ALERT_EMAIL"), ",")
|
||||
|
||||
type Data struct {
|
||||
TimeAt string
|
||||
Host string
|
||||
}
|
||||
|
||||
data := Data{TimeAt: time.Now().Format("2006-01-02 15:04:05"), Host: "36.66.3.44"}
|
||||
|
||||
htmlString := helper.ParseHTML("template/high-memory-usage.html", data)
|
||||
|
||||
go func() {
|
||||
log.Printf("%+v %+v SENDING EMAIL TO %+v", sessionID, module, sendTo)
|
||||
err := helper.SendEmail(sendTo, sendTo, "", subject, "", htmlString)
|
||||
if err != nil {
|
||||
log.Printf("%+v %+v response %+v", sessionID, module, err.Error())
|
||||
} else {
|
||||
log.Printf("%+v %+v EMAIL SENT TO %+v", sessionID, module, sendTo)
|
||||
}
|
||||
}()
|
||||
|
||||
log.Printf("%+v %+v response %+v", sessionID, module, "success")
|
||||
w.Write([]byte("success"))
|
||||
}))
|
||||
|
||||
http.HandleFunc("*", middleware.ResponseTimeMiddleware(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(404)
|
||||
w.Write([]byte("what are you looking for!?"))
|
||||
|
||||
Reference in New Issue
Block a user