mirror of
https://github.com/Monibuca/plugin-record.git
synced 2025-10-06 01:07:00 +08:00
1.增加事件录像,事件录像列表接口
2.将下载时间范围内的录像及播放时间范围内的录像参数统一为start和end 3.增加事件录像入数据库功能
This commit is contained in:
44
exception.go
Normal file
44
exception.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package record
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/shirou/gopsutil/v3/disk"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
// 向第三方发送异常报警
|
||||
func SendToThirdPartyAPI(exception *Exception) {
|
||||
exception.Timestamp = time.Now().Format("20060102150405")
|
||||
exception.ServerIP = RecordPluginConfig.LocalIp
|
||||
data, err := json.Marshal(exception)
|
||||
if err != nil {
|
||||
fmt.Println("Error marshalling exception:", 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", Channel: streamPath}
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
Reference in New Issue
Block a user