feat: healthcheck backend and fix data types
also small various features
This commit is contained in:
+14
-14
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user