agent

package
v0.0.0-...-a13a442 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 23, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AGENT_NAME_LONG   = "RMM Agent"
	AGENT_TEMP_DIR    = "rmm"
	NATS_DEFAULT_PORT = 4222

	TASK_PREFIX = "RMM_"
)
View Source
const (
	NATS_CMD_AGENT_UNINSTALL    = "uninstall"
	NATS_CMD_AGENT_UPDATE       = "agentupdate"
	NATS_CMD_CHOCO_INSTALL      = "installwithchoco"
	NATS_CMD_CPULOADAVG         = "cpuloadavg"
	NATS_CMD_EVENTLOG           = "eventlog"
	NATS_CMD_GETWINUPDATES      = "getwinupdates"
	NATS_CMD_INSTALL_CHOCO      = "installchoco"
	NATS_CMD_INSTALL_WINUPDATES = "installwinupdates"
	NATS_CMD_PING               = "ping"
	NATS_CMD_PROCS_KILL         = "killproc"
	NATS_CMD_PROCS_LIST         = "procs"
	NATS_CMD_PUBLICIP           = "publicip"
	NATS_CMD_RAWCMD             = "rawcmd"
	NATS_CMD_REBOOT_NEEDED      = "needsreboot"
	NATS_CMD_REBOOT_NOW         = "rebootnow"
	NATS_CMD_RECOVER            = "recover"
	NATS_CMD_RUNCHECKS          = "runchecks"
	NATS_CMD_SCRIPT_RUN         = "runscript"
	NATS_CMD_SCRIPT_RUN_FULL    = "runscriptfull"
	NATS_CMD_SOFTWARE_LIST      = "softwarelist"
	NATS_CMD_SYNC               = "sync"
	NATS_CMD_SYSINFO            = "sysinfo"
	NATS_CMD_TASK_ADD           = "schedtask"
	NATS_CMD_TASK_DEL           = "delschedtask"
	NATS_CMD_TASK_ENABLE        = "enableschedtask"
	NATS_CMD_TASK_LIST          = "listschedtasks"
	NATS_CMD_TASK_RUN           = "runtask"
	NATS_CMD_WINSERVICES        = "winservices"
	NATS_CMD_WINSVC_ACTION      = "winsvcaction"
	NATS_CMD_WINSVC_DETAIL      = "winsvcdetail"
	NATS_CMD_WINSVC_EDIT        = "editwinsvc"
	NATS_CMD_WMI                = "wmi"
)

Variables

This section is empty.

Functions

func FileExists

func FileExists(path string) bool

func GenerateAgentID

func GenerateAgentID() (ulid.ULID, error)

GenerateAgentID creates and returns a unique agent ULID

func GetMonth

func GetMonth(month string) time.Month

func IsValidIP

func IsValidIP(ip string) bool

IsValidIP checks for a valid IPv4 or IPv6 address

func KillProc

func KillProc(pid int32) error

KillProc kills a process and its children

func StripAll

func StripAll(s string) string

StripAll strips all whitespace and newline chars

func TestTCP

func TestTCP(addr string) error

func Unzip

func Unzip(src, dest string) error

Unzip a source file to a destination Source: https://golangcode.com/unzip-files-in-go/

Types

type Agent

type Agent struct {
	IAgent
	*AgentConfig
	Logger  *logrus.Logger
	RClient *resty.Client
}

func (*Agent) BootTime

func (a *Agent) BootTime() int64

BootTime returns system boot time as a Unix timestamp

func (*Agent) CreateAgentTempDir

func (a *Agent) CreateAgentTempDir()

CreateAgentTempDir Create the temp directory for running scripts

func (*Agent) GetHostname

func (a *Agent) GetHostname() string

func (*Agent) OSInfo

func (a *Agent) OSInfo() (plat, osFullName string)

OSInfo returns formatted OS names

func (*Agent) PublicIP

func (a *Agent) PublicIP() string

PublicIP returns the agent's public IP address Tries 3 times before giving up

func (*Agent) SetupNatsOptions

func (a *Agent) SetupNatsOptions() []nats.Option

SetupNatsOptions todo: review authentication https://docs.nats.io/running-a-nats-service/configuration/securing_nats/auth_intro/nkey_auth

func (*Agent) Start

func (a *Agent) Start(s service.Service) error

func (*Agent) Stop

func (a *Agent) Stop(s service.Service) error

func (*Agent) TotalRAM

func (a *Agent) TotalRAM() float64

TotalRAM returns total RAM in GB

type AgentConfig

type AgentConfig struct {
	AgentID  string // Username (as ULID)
	AgentPK  int    // Primary Key on server?
	BaseURL  string // Server URL
	ApiURL   string // NATS
	ApiPort  int    // NATS Port (4222)
	Token    string // Authorization token
	Cert     string // Root Certificate
	Arch     string // "x86_64", "x86"
	Debug    bool
	Hostname string
	Version  string
	Headers  map[string]string
}

type IAgent

type IAgent interface {
	InfoCollector
	PackageManager
	RpcProcessor // Messenger
	service.Interface
	// contains filtered or unexported methods
}

type IAgentConfig

type IAgentConfig interface {
	// contains filtered or unexported methods
}

type InfoCollector

type InfoCollector interface {
	PublicIP() string
	TotalRAM() float64
	BootTime() int64
	GetInstalledSoftware() []jrmm.Software
	OSInfo() (plat, osFullName string)
	SysInfo()
	GetStorage() []jrmm.StorageDrive
	LoggedOnUser() string
	GetCPULoadAvg() int
}

type InstallInfo

type InstallInfo struct {
	Headers     map[string]string
	ServerURL   string        // JSON endpoint URL
	ApiURL      string        // RPC endpoint (NATS) URL
	ClientID    int           // Client ID
	SiteID      int           // Client Site ID
	Description string        // Defaults to hostname
	Token       string        // Authorization token (password)
	RootCert    string        // Trusted Root Certificate
	Timeout     time.Duration // Installation timeout
	Silent      bool          // Silent installation

}

type Messenger

type Messenger interface {
	RpcProcessor
	Send(any)
	Receive(any)
}

Messenger is our communication interface (for RPC, JSON, etc.)

type PackageManager

type PackageManager interface {
	InstallPkgMgr(mgr string)
	RemovePkgMgr(mgr string)
	InstallPackage(mgr string, name string) (string, error)
	RemovePackage(mgr string, name string) (string, error)
	UpdatePackage(mgr string, name string) (string, error)
}

type RpcProcessor

type RpcProcessor interface {
	ProcessRpcMsg(conn *nats.Conn, msg *nats.Msg)
}

type ServiceManager

type ServiceManager interface {
}

todo

type TaskChecker

type TaskChecker interface {
	ScriptCheck(data shared.Check, r *resty.Client)
	DiskCheck(data shared.Check, r *resty.Client)
	CPULoadCheck(data shared.Check, r *resty.Client)
	MemCheck(data shared.Check, r *resty.Client)
	PingCheck(data shared.Check, r *resty.Client)
}

type TaskScheduler

type TaskScheduler interface {
	RunTask(int) // currently in baseAgent
	CreateTask(task any) (bool, error)
	DeleteTask(task string) error
	EnableTask(task any) error
	DisableTask(task any) error
	CleanupTasks()
	ListTasks() []string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL