sending notifications on failure.
This commit is contained in:
@@ -1,14 +1,12 @@
|
||||
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"
|
||||
"github.com/sirupsen/logrus"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Send test notification
|
||||
@@ -17,15 +15,14 @@ func SendTestNotification(c *gin.Context) {
|
||||
logger := c.MustGet("LOGGER").(logrus.FieldLogger)
|
||||
|
||||
testNotify := notify.Notify{
|
||||
Logger: logger,
|
||||
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",
|
||||
DeviceSerial: "FAKEWDDJ324KSO",
|
||||
DeviceType: dbModels.DeviceProtocolAta,
|
||||
DeviceName: "/dev/sda",
|
||||
Test: true,
|
||||
},
|
||||
}
|
||||
err := testNotify.Send()
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"github.com/analogj/scrutiny/webapp/backend/pkg/config"
|
||||
"github.com/analogj/scrutiny/webapp/backend/pkg/models/collector"
|
||||
dbModels "github.com/analogj/scrutiny/webapp/backend/pkg/models/db"
|
||||
"github.com/analogj/scrutiny/webapp/backend/pkg/notify"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/jinzhu/gorm"
|
||||
"github.com/sirupsen/logrus"
|
||||
@@ -12,6 +14,7 @@ import (
|
||||
func UploadDeviceMetrics(c *gin.Context) {
|
||||
db := c.MustGet("DB").(*gorm.DB)
|
||||
logger := c.MustGet("LOGGER").(logrus.FieldLogger)
|
||||
appConfig := c.MustGet("CONFIG").(config.Interface)
|
||||
|
||||
var collectorSmartData collector.SmartInfo
|
||||
err := c.BindJSON(&collectorSmartData)
|
||||
@@ -45,5 +48,21 @@ func UploadDeviceMetrics(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
//check for error
|
||||
if deviceSmartData.SmartStatus == dbModels.SmartStatusFailed {
|
||||
//send notifications
|
||||
testNotify := notify.Notify{
|
||||
Config: appConfig,
|
||||
Payload: notify.Payload{
|
||||
FailureType: notify.NotifyFailureTypeSmartFailure,
|
||||
DeviceName: device.DeviceName,
|
||||
DeviceType: device.DeviceProtocol,
|
||||
DeviceSerial: device.SerialNumber,
|
||||
Test: false,
|
||||
},
|
||||
}
|
||||
_ = testNotify.Send() //we ignore error message when sending notifications.
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"success": true})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user