2024-12-14 15:45:40 +01:00

106 lines
6.9 KiB
Go

package models
import (
"time"
"github.com/google/uuid"
)
// Model for the user accounts
type Account struct {
ID uuid.UUID `json:"id" db:"id"`
FirstName string `json:"first_name" db:"first_name"`
LastName string `json:"last_name" db:"last_name"`
PasswordHash string `json:"password_hash" db:"password_hash"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
}
type Organization struct {
ID uuid.UUID `json:"id" db:"id"`
Name string `json:"name" db:"name"`
Description string `json:"description" db:"description"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
}
// Model for the hosts managed by zadmin
type Machine struct {
Id uuid.UUID `json:"id" db:"id"` // machine ID
CreatedAt time.Time `json:"created_at" db:"created_at"` // Time created in zadmin
MachineName string `json:"machine_name" db:"machine_name"` // Name of machine
Description *string `json:"description" db:"description"` // Description of machine
Organization Organization `json:"organization" db:"organization"` // Organization this machine belongs to
OsType string `json:"os_type" db:"os_type"` // OS Type
OsArch string `json:"os_arch" db:"os_arch"` // OS arch
FirstSeen *time.Time `json:"first_seen" db:"first_seen"` // Time of first contact with zadmin
LastSeen *time.Time `json:"last_seen" db:"last_seen"` // Time of last contact with zadmin
Hostname *string `json:"hostname" db:"hostname"` // Configured system hostname
PublicIPv4Address *string `json:"public_ipv4_address" db:"public_ipv4_address"` // Public IPv4 address
PublicIPv6Address *string `json:"public_ipv6_address" db:"public_ipv6_address"` // Public IPv6 address
NetworkInterfaces []MachineInterfaceDetails `json:"machine_interfaces" db:"network_interfaces"` // Interface details
AntivirusInfo AntivirusInfo `json:"antivirus_info" db:"antivirus_info"` // Antivirus info
UsageStatistics UsageStatistics `json:"usage_statistics" db:"usage_statistics"` // Usage statistics of machine
SoftwareCatalog []Software `json:"software_catalog" db:"software_catalog"` // Software installed on machine
UptimeSeconds *int `json:"uptime_seconds" db:"uptime_seconds"` // Machine uptime in seconds
LoggedOnUsers *[]string `json:"logged_on_users" db:"logged_on_users"` // Currently logged on users
OsVersion *string `json:"os_version" db:"os_version"` // OS version
}
// Software installed on a Machine
type Software struct {
Name string `db:"name"`
Publisher string `db:"publisher"`
}
type AntivirusInfo struct {
AVType string `json:"av_type" db:"av_type"` // Antivirus type
AVState string `json:"av_state" db:"av_state"` // Antivirus state
}
type UsageStatistics struct {
TimeCollected time.Time `json:"time_collected" db:"time_collected"` // Time metrics were collected at
CpuUser uint64 `json:"cpu_user" db:"cpu_user"` // The amount of time the CPU spends executing user-level processes
CpuSystem uint64 `json:"cpu_system" db:"cpu_system"` // The time the CPU spends executing kernel-level processes
CpuIdle uint64 `json:"cpu_idle" db:"cpu_idle"` // The percentage of time the CPU is idle and not doing any work
CpuIowait uint64 `json:"cpu_iowait" db:"cpu_iowait"` // The time the CPU spends waiting for I/O operations to complete
CpuSteal uint64 `json:"cpu_steal" db:"cpu_steal"` // The amount of time a virtual CPU waits for the hypervisor to service its requests
CpuCount int `json:"cpu_count" db:"cpu_count"` // Amount of CPUs present in machine
MemoryTotal uint64 `json:"memory_total" db:"memory_total"` // Total memory
MemoryUsed uint64 `json:"memory_used" db:"memory_used"` // Used memory
MemoryCached uint64 `json:"memory_cached" db:"memory_cached"` // Cached memory
MemoryFree uint64 `json:"memory_free" db:"memory_free"` // Free memory
MemoryAvailable uint64 `json:"memory_available" db:"memory_available"` // Available memory
LoadAVG1 float64 `json:"loadavg_1" db:"load_avg_1"` // 1-minute Load Average
LoadAVG5 float64 `json:"loadavg_5" db:"load_avg_5"` // 5-minute Load Average
LoadAVG15 float64 `json:"loadavg_15" db:"load_avg_15"` // 15-minute Load Average
}
type DiskInformation struct {
Name string `json:"name" db:"name"` // Name of disk
Mountpoint string `json:"mountpoint" db:"mountpoint"` // Mountpoint of disk
SizeB int `json:"size_b" db:"size_b"` // Size of disk in bytes
UsedB int `json:"used_b" db:"used_b"` // Used disk space in bytes
FreeB int `json:"free_b" db:"free_b"` // Free disk space in bytes
}
type MachineInterfaceDetails struct {
InterfaceName string `json:"interface_name" db:"interface_name"` // Name of the network interface
InterfaceMac string `json:"interface_mac" db:"interface_mac"` // Interface MAC address
Addressess []string `json:"addressess" db:"addressess"` // Interface IP addressess
}
type Agent struct {
ID uuid.UUID `json:"id" db:"id"`
Machine Machine `json:"machine" db:"machine"`
CreatedAt time.Time `json:"created_at" db:"created_at"` // Time created in zadmin
}
// Configuration to be used by the agent on a machine
type MachineAgentConfig struct {
RESTServerHostname string `json:"rest_server_hostname" db:"rest_server_hostname"` // Hostname used for REST requests
RESTServerPort int `json:"rest_server_port" db:"rest_server_port"` // Port used for REST requests
NATSServerUrl string `json:"nats_server_url" db:"nats_server_url"` // URL used to contact nats.io
HelloInterval int `json:"checkin_interval" db:"hello_interval"` // interval of sending hello message, indicating host is online
MetricsInterval int `json:"metrics_interval" db:"metrics_interval"` // interval of sending hello message, indicating host is online
GetIPv4Endpoint string `json:"get_ipv4_endpoint" db:"get_i_pv_4_endpoint"` // endpoint that returns a json doc with the IPv4 address
GetIPv6Endpoint string `json:"get_ipv6_endpoint" db:"get_i_pv_6_endpoint"` // endpoint that returns a json doc with the IPv6 address
}