feat: healthcheck backend and fix data types

also small various features
This commit is contained in:
kilyabin
2026-04-28 00:10:06 +04:00
parent 1cb93a1f31
commit 78e5c90ed0
9 changed files with 305 additions and 132 deletions
+14 -14
View File
@@ -87,8 +87,8 @@ func (d *DB) CreatePacketStat(s *PacketStat) error {
}
type SeverityCount struct {
Severity string
Count int64
Severity string `json:"severity"`
Count int64 `json:"count"`
}
func (d *DB) AlertsBySeverity() ([]SeverityCount, error) {
@@ -101,8 +101,8 @@ func (d *DB) AlertsBySeverity() ([]SeverityCount, error) {
}
type TypeCount struct {
Type string
Count int64
Type string `json:"type"`
Count int64 `json:"count"`
}
func (d *DB) AlertsByType() ([]TypeCount, error) {
@@ -115,8 +115,8 @@ func (d *DB) AlertsByType() ([]TypeCount, error) {
}
type IPCount struct {
SrcIP string
Count int64
SrcIP string `json:"src_ip"`
Count int64 `json:"count"`
}
func (d *DB) TopSourceIPs(limit int) ([]IPCount, error) {
@@ -131,16 +131,16 @@ func (d *DB) TopSourceIPs(limit int) ([]IPCount, error) {
}
type TimelinePoint struct {
Hour string
Count int64
Hour string `json:"hour"`
Count int64 `json:"count"`
}
func (d *DB) AlertsTimeline(hours int) ([]TimelinePoint, error) {
since := time.Now().Add(-time.Duration(hours) * time.Hour)
since := time.Now().UTC().Add(-time.Duration(hours) * time.Hour)
var result []TimelinePoint
err := d.db.Model(&Alert{}).
Select("strftime('%Y-%m-%dT%H:00:00', created_at) as hour, count(*) as count").
Where("created_at >= ?", since).
Select("strftime('%Y-%m-%dT%H:00:00Z', created_at) as hour, count(*) as count").
Where("created_at >= datetime(?)", since.Format("2006-01-02 15:04:05")).
Group("hour").
Order("hour asc").
Find(&result).Error
@@ -154,9 +154,9 @@ func (d *DB) TotalAlerts() (int64, error) {
}
type ProtocolCount struct {
Protocol string
Count int64
Bytes int64
Protocol string `json:"protocol"`
Count int64 `json:"count"`
Bytes int64 `json:"bytes"`
}
func (d *DB) TrafficByProtocol() ([]ProtocolCount, error) {