forked from 0xrawsec/whids
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathendpoint.go
55 lines (48 loc) · 1.67 KB
/
endpoint.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package api
import (
"fmt"
"time"
"github.com/0xrawsec/sod"
"github.com/0xrawsec/whids/agent/config"
"github.com/0xrawsec/whids/agent/sysinfo"
)
// Endpoint structure used to track and interact with endpoints
type Endpoint struct {
sod.Item
Uuid string `json:"uuid" sod:"unique"`
Hostname string `json:"hostname"`
IP string `json:"ip"`
Group string `json:"group"`
Criticality int `json:"criticality"`
Key string `json:"key,omitempty"`
Command *EndpointCommand `json:"command,omitempty"`
Score float64 `json:"score"`
Status string `json:"status"`
SystemInfo *sysinfo.SystemInfo `json:"system-info,omitempty"`
Config *config.Agent `json:"config,omitempty"`
LastEvent time.Time `json:"last-event"`
LastDetection time.Time `json:"last-detection"`
LastConnection time.Time `json:"last-connection"`
}
// NewEndpoint returns a new Endpoint structure
func NewEndpoint(uuid, key string) *Endpoint {
e := &Endpoint{Uuid: uuid, Key: key}
e.Initialize(e.Uuid)
return e
}
// Validate overwrite sod.Item function
func (e *Endpoint) Validate() error {
if e.Criticality < 0 || e.Criticality > 10 {
return fmt.Errorf("criticality field must be in [0;10]")
}
return nil
}
// Copy returns a pointer to a new copy of the Endpoint
func (e *Endpoint) Copy() *Endpoint {
new := *e
return &new
}
// UpdateLastConnection updates the LastConnection member of Endpoint structure
func (e *Endpoint) UpdateLastConnection() {
e.LastConnection = time.Now().UTC()
}