init
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
type AuthHandler struct {
|
||||
ClientSecret string
|
||||
}
|
||||
|
||||
func (a *AuthHandler) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) {
|
||||
return map[string]string{"client_secret": a.ClientSecret}, nil
|
||||
}
|
||||
|
||||
func (a *AuthHandler) RequireTransportSecurity() bool {
|
||||
return false
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
pb "github.com/nezhahq/agent/proto"
|
||||
)
|
||||
|
||||
type HostState struct {
|
||||
CPU float64
|
||||
MemUsed uint64
|
||||
SwapUsed uint64
|
||||
DiskUsed uint64
|
||||
NetInTransfer uint64
|
||||
NetOutTransfer uint64
|
||||
NetInSpeed uint64
|
||||
NetOutSpeed uint64
|
||||
Uptime uint64
|
||||
Load1 float64
|
||||
Load5 float64
|
||||
Load15 float64
|
||||
TcpConnCount uint64
|
||||
UdpConnCount uint64
|
||||
ProcessCount uint64
|
||||
}
|
||||
|
||||
func (s *HostState) PB() *pb.State {
|
||||
return &pb.State{
|
||||
Cpu: s.CPU,
|
||||
MemUsed: s.MemUsed,
|
||||
SwapUsed: s.SwapUsed,
|
||||
DiskUsed: s.DiskUsed,
|
||||
NetInTransfer: s.NetInTransfer,
|
||||
NetOutTransfer: s.NetOutTransfer,
|
||||
NetInSpeed: s.NetInSpeed,
|
||||
NetOutSpeed: s.NetOutSpeed,
|
||||
Uptime: s.Uptime,
|
||||
Load1: s.Load1,
|
||||
Load5: s.Load5,
|
||||
Load15: s.Load15,
|
||||
TcpConnCount: s.TcpConnCount,
|
||||
UdpConnCount: s.UdpConnCount,
|
||||
ProcessCount: s.ProcessCount,
|
||||
}
|
||||
}
|
||||
|
||||
type Host struct {
|
||||
Platform string
|
||||
PlatformVersion string
|
||||
CPU []string
|
||||
MemTotal uint64
|
||||
DiskTotal uint64
|
||||
SwapTotal uint64
|
||||
Arch string
|
||||
Virtualization string
|
||||
BootTime uint64
|
||||
IP string `json:"-"`
|
||||
CountryCode string
|
||||
Version string
|
||||
}
|
||||
|
||||
func (h *Host) PB() *pb.Host {
|
||||
return &pb.Host{
|
||||
Platform: h.Platform,
|
||||
PlatformVersion: h.PlatformVersion,
|
||||
Cpu: h.CPU,
|
||||
MemTotal: h.MemTotal,
|
||||
DiskTotal: h.DiskTotal,
|
||||
SwapTotal: h.SwapTotal,
|
||||
Arch: h.Arch,
|
||||
Virtualization: h.Virtualization,
|
||||
BootTime: h.BootTime,
|
||||
Ip: h.IP,
|
||||
CountryCode: h.CountryCode,
|
||||
Version: h.Version,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
"sigs.k8s.io/yaml"
|
||||
)
|
||||
|
||||
type AgentConfig struct {
|
||||
HardDrivePartitionAllowlist []string
|
||||
NICAllowlist map[string]bool
|
||||
v *viper.Viper
|
||||
}
|
||||
|
||||
// Read 从给定的文件目录加载配置文件
|
||||
func (c *AgentConfig) Read(path string) error {
|
||||
c.v = viper.New()
|
||||
c.v.SetConfigFile(path)
|
||||
err := c.v.ReadInConfig()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = c.v.Unmarshal(c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *AgentConfig) Save() error {
|
||||
data, err := yaml.Marshal(c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return os.WriteFile(c.v.ConfigFileUsed(), data, os.ModePerm)
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package model
|
||||
|
||||
const (
|
||||
_ = iota
|
||||
TaskTypeHTTPGET
|
||||
TaskTypeICMPPing
|
||||
TaskTypeTCPPing
|
||||
TaskTypeCommand
|
||||
TaskTypeTerminal
|
||||
TaskTypeUpgrade
|
||||
TaskTypeKeepalive
|
||||
)
|
||||
|
||||
type TerminalTask struct {
|
||||
// websocket 主机名
|
||||
Host string `json:"host,omitempty"`
|
||||
// 是否启用 SSL
|
||||
UseSSL bool `json:"use_ssl,omitempty"`
|
||||
// 会话标识
|
||||
Session string `json:"session,omitempty"`
|
||||
// Agent在连接Server时需要的额外Cookie信息
|
||||
Cookie string `json:"cookie,omitempty"`
|
||||
}
|
||||
Reference in New Issue
Block a user