moved middleware into more relevant location. Adding send test notifications handler. making sure that config is available from web handler functions.
parent
c913cf39b9
commit
78a619b09d
@ -0,0 +1,39 @@
|
|||||||
|
package handler
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/analogj/scrutiny/webapp/backend/pkg/config"
|
||||||
|
dbModels "github.com/analogj/scrutiny/webapp/backend/pkg/models/db"
|
||||||
|
"github.com/analogj/scrutiny/webapp/backend/pkg/notify"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Send test notification
|
||||||
|
func SendTestNotification(c *gin.Context) {
|
||||||
|
appConfig := c.MustGet("CONFIG").(config.Interface)
|
||||||
|
|
||||||
|
testNotify := notify.Notify{
|
||||||
|
Config: appConfig,
|
||||||
|
Payload: notify.Payload{
|
||||||
|
Mailer: os.Args[0],
|
||||||
|
Subject: fmt.Sprintf("Scrutiny SMART error (EmailTest) detected on disk: XXXXX"),
|
||||||
|
FailureType: "EmailTest",
|
||||||
|
Device: "/dev/sda",
|
||||||
|
DeviceType: "ata",
|
||||||
|
DeviceString: "/dev/sda",
|
||||||
|
Message: "TEST EMAIL from smartd for device: /dev/sda",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
err := testNotify.Send()
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"success": false,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
c.JSON(http.StatusOK, dbModels.DeviceWrapper{
|
||||||
|
Success: true,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
package middleware
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/analogj/scrutiny/webapp/backend/pkg/config"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ConfigMiddleware(appConfig config.Interface) gin.HandlerFunc {
|
||||||
|
return func(c *gin.Context) {
|
||||||
|
c.Set("CONFIG", appConfig)
|
||||||
|
c.Next()
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue