diff --git a/Agent/Makefile b/Agent/Makefile new file mode 100644 index 0000000..716996a --- /dev/null +++ b/Agent/Makefile @@ -0,0 +1,17 @@ +.PHONY: build build-windows build-linux clean + +BINARY=nexus-agent +VERSION=$(shell git describe --tags --always --dirty 2>/dev/null || echo "dev") +LDFLAGS=-ldflags "-s -w -X main.version=$(VERSION)" + +build: + go build $(LDFLAGS) -o bin/$(BINARY) ./cmd/agent + +build-windows: + GOOS=windows GOARCH=amd64 go build $(LDFLAGS) -o bin/$(BINARY).exe ./cmd/agent + +build-linux: + GOOS=linux GOARCH=amd64 go build $(LDFLAGS) -o bin/$(BINARY)-linux ./cmd/agent + +clean: + rm -rf bin/ diff --git a/Agent/agent.exe b/Agent/agent.exe new file mode 100644 index 0000000..4fe5c14 Binary files /dev/null and b/Agent/agent.exe differ diff --git a/Agent/cmd/agent/main.go b/Agent/cmd/agent/main.go new file mode 100644 index 0000000..6d2d26b --- /dev/null +++ b/Agent/cmd/agent/main.go @@ -0,0 +1,9 @@ +package main + +import "fmt" + +var version = "dev" + +func main() { + fmt.Printf("NexusRMM Agent %s\n", version) +} diff --git a/Agent/go.mod b/Agent/go.mod new file mode 100644 index 0000000..f323ee1 --- /dev/null +++ b/Agent/go.mod @@ -0,0 +1,24 @@ +module github.com/nexusrmm/agent + +go 1.22 + +require ( + github.com/shirou/gopsutil/v4 v4.24.0 + google.golang.org/grpc v1.60.0 + google.golang.org/protobuf v1.32.0 + gopkg.in/yaml.v3 v3.0.1 +) + +require ( + github.com/ebitengine/purego v0.7.0 // indirect + github.com/golang/protobuf v1.5.3 // indirect + github.com/lufia/plan9stats v0.0.0-20240513124658-fba389f38bae // indirect + github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d84 // indirect + github.com/tklauser/go-sysconf v0.3.14 // indirect + github.com/tklauser/numcpus v0.8.0 // indirect + github.com/yusufpapurcu/info v0.0.0-20240514213526-8f62d0eb11ac // indirect + golang.org/x/net v0.21.0 // indirect + golang.org/x/sys v0.17.0 // indirect + golang.org/x/text v0.14.0 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240221002015-b0ce06bbee7c // indirect +) diff --git a/Agent/internal/config/config.go b/Agent/internal/config/config.go new file mode 100644 index 0000000..817535c --- /dev/null +++ b/Agent/internal/config/config.go @@ -0,0 +1,40 @@ +package config + +import ( + "os" + + "gopkg.in/yaml.v3" +) + +type Config struct { + ServerAddress string `yaml:"server_address"` + AgentID string `yaml:"agent_id"` + HeartbeatInterval int `yaml:"heartbeat_interval"` + TLSEnabled bool `yaml:"tls_enabled"` +} + +func Load(path string) (*Config, error) { + cfg := &Config{ + ServerAddress: "localhost:5001", + HeartbeatInterval: 60, + } + data, err := os.ReadFile(path) + if err != nil { + if os.IsNotExist(err) { + return cfg, nil + } + return nil, err + } + if err := yaml.Unmarshal(data, cfg); err != nil { + return nil, err + } + return cfg, nil +} + +func (c *Config) Save(path string) error { + data, err := yaml.Marshal(c) + if err != nil { + return err + } + return os.WriteFile(path, data, 0600) +}