Files
plugin-record/exception.go
pg 9b33cbd5db 1.自动删除最旧的录像文件的功能
2.增加字段用于区分record对象是自动的普通录像还是事件录像
3.修复自动录像时,订阅却订阅失败时会生成小文件的问题
2024-10-02 10:45:21 +08:00

49 lines
1.2 KiB
Go

package record
import (
"bytes"
"encoding/json"
"fmt"
"github.com/shirou/gopsutil/v3/disk"
"net/http"
"time"
)
// 向第三方发送异常报警
func SendToThirdPartyAPI(exception *Exception) {
exception.CreateTime = time.Now().Format("2006-01-02 15:04:05")
exception.ServerIP = RecordPluginConfig.LocalIp
data, err := json.Marshal(exception)
if err != nil {
fmt.Println("Error marshalling exception:", err)
return
}
err = db.Create(&exception).Error
if err != nil {
fmt.Println("异常数据插入数据库失败:", err)
return
}
resp, err := http.Post(RecordPluginConfig.ExceptionPostUrl, "application/json", bytes.NewBuffer(data))
if err != nil {
fmt.Println("Error sending exception to third party API:", err)
return
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
fmt.Println("Failed to send exception, status code:", resp.StatusCode)
} else {
fmt.Println("Exception sent successfully!")
}
}
// 磁盘超上限报警
func getDisckException(streamPath string) bool {
d, _ := disk.Usage("/")
if d.UsedPercent >= RecordPluginConfig.DiskMaxPercent {
exceptionChannel <- &Exception{AlarmType: "disk alarm", AlarmDesc: "disk is full", StreamPath: streamPath}
return true
}
return false
}