updated for unix build
This commit is contained in:
parent
66aca05028
commit
e20edcc9ad
37 changed files with 1001 additions and 257 deletions
|
|
@ -25,7 +25,7 @@ func CheckRunner(agentID string) error {
|
|||
for {
|
||||
interval, err := GetCheckInterval(agentID)
|
||||
if err == nil && !ChecksRunning() {
|
||||
_, err = system.CMD(system.GetProgramEXE(), []string{"-m", "checkrunner"}, 600, false)
|
||||
_, err = system.CMD(system.GetProgramBin(), []string{"-m", "checkrunner"}, 600, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -66,7 +66,7 @@ Out:
|
|||
if p.PID == 0 {
|
||||
continue
|
||||
}
|
||||
if p.Exe != system.GetProgramEXE() {
|
||||
if p.Exe != system.GetProgramBin() {
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
|
|||
38
agent/tactical/config/config_unix.go
Normal file
38
agent/tactical/config/config_unix.go
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package config
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
func NewAgentConfig() *AgentConfig {
|
||||
viper.SetConfigName("tacticalagent")
|
||||
viper.SetConfigType("json")
|
||||
viper.AddConfigPath("/etc/")
|
||||
viper.AddConfigPath(".")
|
||||
err := viper.ReadInConfig()
|
||||
|
||||
if err != nil {
|
||||
return &AgentConfig{}
|
||||
}
|
||||
|
||||
agentpk := viper.GetString("agentpk")
|
||||
pk, _ := strconv.Atoi(agentpk)
|
||||
|
||||
ret := &AgentConfig{
|
||||
BaseURL: viper.GetString("baseurl"),
|
||||
AgentID: viper.GetString("agentid"),
|
||||
APIURL: viper.GetString("apiurl"),
|
||||
Token: viper.GetString("token"),
|
||||
AgentPK: agentpk,
|
||||
PK: pk,
|
||||
Cert: viper.GetString("cert"),
|
||||
Proxy: viper.GetString("proxy"),
|
||||
CustomMeshDir: viper.GetString("meshdir"),
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
|
@ -1,6 +1,10 @@
|
|||
package mesh
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"github.com/amidaware/rmmagent/agent/system"
|
||||
"github.com/amidaware/rmmagent/agent/tactical/api"
|
||||
"github.com/amidaware/rmmagent/agent/tactical/config"
|
||||
"github.com/amidaware/rmmagent/agent/utils"
|
||||
|
|
@ -26,3 +30,23 @@ func SyncMeshNodeID() error {
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetMeshNodeID() (string, error) {
|
||||
out, err := system.CMD(GetMeshBinLocation(), []string{"-nodeid"}, 10, false)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
stdout := out[0]
|
||||
stderr := out[1]
|
||||
|
||||
if stderr != "" {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if stdout == "" || strings.Contains(strings.ToLower(utils.StripAll(stdout)), "not defined") {
|
||||
return "", errors.New("failed to get mesh node id")
|
||||
}
|
||||
|
||||
return stdout, nil
|
||||
}
|
||||
24
agent/tactical/mesh/mesh_unix.go
Normal file
24
agent/tactical/mesh/mesh_unix.go
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package mesh
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
|
||||
"github.com/amidaware/rmmagent/agent/tactical/config"
|
||||
)
|
||||
|
||||
func GetMeshBinLocation() string {
|
||||
ac := config.NewAgentConfig()
|
||||
var MeshSysBin string
|
||||
if len(ac.CustomMeshDir) > 0 {
|
||||
MeshSysBin = filepath.Join(ac.CustomMeshDir, "meshagent")
|
||||
} else {
|
||||
MeshSysBin = "/opt/tacticalmesh/meshagent"
|
||||
}
|
||||
|
||||
return MeshSysBin
|
||||
}
|
||||
|
||||
func RecoverMesh() { }
|
||||
|
|
@ -41,27 +41,7 @@ func ForceKillMesh() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func GetMeshNodeID() (string, error) {
|
||||
out, err := system.CMD(getMeshBinLocation(), []string{"-nodeid"}, 10, false)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
stdout := out[0]
|
||||
stderr := out[1]
|
||||
|
||||
if stderr != "" {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if stdout == "" || strings.Contains(strings.ToLower(utils.StripAll(stdout)), "not defined") {
|
||||
return "", errors.New("failed to get mesh node id")
|
||||
}
|
||||
|
||||
return stdout, nil
|
||||
}
|
||||
|
||||
func getMeshBinLocation() string {
|
||||
func GetMeshBinLocation() string {
|
||||
ac := config.NewAgentConfig()
|
||||
var MeshSysBin string
|
||||
if len(ac.CustomMeshDir) > 0 {
|
||||
|
|
|
|||
|
|
@ -131,7 +131,6 @@ func RunRPC(version string) {
|
|||
var resp []byte
|
||||
ret := codec.NewEncoderBytes(&resp, new(codec.MsgpackHandle))
|
||||
procs := system.GetProcsRPC()
|
||||
//a.Logger.Debugln(procs)
|
||||
ret.Encode(procs)
|
||||
msg.Respond(resp)
|
||||
}()
|
||||
|
|
@ -365,7 +364,7 @@ func RunRPC(version string) {
|
|||
} else {
|
||||
ret.Encode("ok")
|
||||
msg.Respond(resp)
|
||||
_, checkerr := system.CMD(system.GetProgramEXE(), []string{"-m", "runchecks"}, 600, false)
|
||||
_, checkerr := system.CMD(system.GetProgramBin(), []string{"-m", "runchecks"}, 600, false)
|
||||
if checkerr != nil {
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
package rpc
|
||||
|
||||
func RunRPC(version string) {
|
||||
}
|
||||
|
|
@ -2,23 +2,16 @@ package service
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/amidaware/rmmagent/agent/disk"
|
||||
"github.com/amidaware/rmmagent/agent/network"
|
||||
"github.com/amidaware/rmmagent/agent/services"
|
||||
"github.com/amidaware/rmmagent/agent/system"
|
||||
"github.com/amidaware/rmmagent/agent/tactical/api"
|
||||
"github.com/amidaware/rmmagent/agent/tactical/checks"
|
||||
"github.com/amidaware/rmmagent/agent/tactical/config"
|
||||
"github.com/amidaware/rmmagent/agent/tactical/mesh"
|
||||
"github.com/amidaware/rmmagent/agent/tactical/shared"
|
||||
"github.com/amidaware/rmmagent/agent/utils"
|
||||
"github.com/amidaware/rmmagent/agent/wmi"
|
||||
"github.com/nats-io/nats.go"
|
||||
"github.com/ugorji/go/codec"
|
||||
)
|
||||
|
||||
var natsCheckin = []string{"agent-hello", "agent-agentinfo", "agent-disks", "agent-winsvc", "agent-publicip", "agent-wmi"}
|
||||
|
|
@ -98,65 +91,6 @@ func SetupNatsOptions() []nats.Option {
|
|||
return opts
|
||||
}
|
||||
|
||||
func NatsMessage(version string, nc *nats.Conn, mode string) {
|
||||
config := config.NewAgentConfig()
|
||||
var resp []byte
|
||||
var payload interface{}
|
||||
ret := codec.NewEncoderBytes(&resp, new(codec.MsgpackHandle))
|
||||
|
||||
switch mode {
|
||||
case "agent-hello":
|
||||
payload = CheckInNats{
|
||||
Agentid: config.AgentID,
|
||||
Version: version,
|
||||
}
|
||||
case "agent-winsvc":
|
||||
svcs, _, _ := services.GetServices()
|
||||
payload = WinSvcNats{
|
||||
Agentid: config.AgentID,
|
||||
WinSvcs: svcs,
|
||||
}
|
||||
case "agent-agentinfo":
|
||||
osinfo := system.OsString()
|
||||
reboot, err := system.SystemRebootRequired()
|
||||
if err != nil {
|
||||
reboot = false
|
||||
}
|
||||
payload = AgentInfoNats{
|
||||
Agentid: config.AgentID,
|
||||
Username: system.LoggedOnUser(),
|
||||
Hostname: system.GetHostname(),
|
||||
OS: osinfo,
|
||||
Platform: runtime.GOOS,
|
||||
TotalRAM: system.TotalRAM(),
|
||||
BootTime: system.BootTime(),
|
||||
RebootNeeded: reboot,
|
||||
GoArch: runtime.GOARCH,
|
||||
}
|
||||
case "agent-wmi":
|
||||
wmiinfo, _ := wmi.GetWMIInfo()
|
||||
payload = WinWMINats{
|
||||
Agentid: config.AgentID,
|
||||
WMI: wmiinfo,
|
||||
}
|
||||
case "agent-disks":
|
||||
disks, _ := disk.GetDisks()
|
||||
payload = WinDisksNats{
|
||||
Agentid: config.AgentID,
|
||||
Disks: disks,
|
||||
}
|
||||
case "agent-publicip":
|
||||
payload = PublicIPNats{
|
||||
Agentid: config.AgentID,
|
||||
PublicIP: network.PublicIP(config.Proxy),
|
||||
}
|
||||
}
|
||||
|
||||
//a.Logger.Debugln(mode, payload)
|
||||
ret.Encode(payload)
|
||||
nc.PublishRequest(config.AgentID, mode, resp)
|
||||
}
|
||||
|
||||
func DoNatsCheckIn(version string) {
|
||||
opts := SetupNatsOptions()
|
||||
server := fmt.Sprintf("tls://%s:4222", config.NewAgentConfig().APIURL)
|
||||
|
|
|
|||
75
agent/tactical/service/service_unix.go
Normal file
75
agent/tactical/service/service_unix.go
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package service
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
|
||||
"github.com/amidaware/rmmagent/agent/disk"
|
||||
"github.com/amidaware/rmmagent/agent/network"
|
||||
"github.com/amidaware/rmmagent/agent/services"
|
||||
"github.com/amidaware/rmmagent/agent/system"
|
||||
"github.com/amidaware/rmmagent/agent/tactical/config"
|
||||
"github.com/amidaware/rmmagent/agent/umi"
|
||||
"github.com/nats-io/nats.go"
|
||||
"github.com/ugorji/go/codec"
|
||||
)
|
||||
|
||||
func NatsMessage(version string, nc *nats.Conn, mode string) {
|
||||
config := config.NewAgentConfig()
|
||||
var resp []byte
|
||||
var payload interface{}
|
||||
ret := codec.NewEncoderBytes(&resp, new(codec.MsgpackHandle))
|
||||
|
||||
switch mode {
|
||||
case "agent-hello":
|
||||
payload = CheckInNats{
|
||||
Agentid: config.AgentID,
|
||||
Version: version,
|
||||
}
|
||||
case "agent-winsvc":
|
||||
svcs, _, _ := services.GetServices()
|
||||
payload = WinSvcNats{
|
||||
Agentid: config.AgentID,
|
||||
WinSvcs: svcs,
|
||||
}
|
||||
case "agent-agentinfo":
|
||||
osinfo := system.OsString()
|
||||
reboot, err := system.SystemRebootRequired()
|
||||
if err != nil {
|
||||
reboot = false
|
||||
}
|
||||
payload = AgentInfoNats{
|
||||
Agentid: config.AgentID,
|
||||
Username: system.LoggedOnUser(),
|
||||
Hostname: system.GetHostname(),
|
||||
OS: osinfo,
|
||||
Platform: runtime.GOOS,
|
||||
TotalRAM: system.TotalRAM(),
|
||||
BootTime: system.BootTime(),
|
||||
RebootNeeded: reboot,
|
||||
GoArch: runtime.GOARCH,
|
||||
}
|
||||
case "agent-wmi":
|
||||
wmiinfo, _ := umi.GetInfo()
|
||||
payload = WinWMINats{
|
||||
Agentid: config.AgentID,
|
||||
WMI: wmiinfo,
|
||||
}
|
||||
case "agent-disks":
|
||||
disks, _ := disk.GetDisks()
|
||||
payload = WinDisksNats{
|
||||
Agentid: config.AgentID,
|
||||
Disks: disks,
|
||||
}
|
||||
case "agent-publicip":
|
||||
payload = PublicIPNats{
|
||||
Agentid: config.AgentID,
|
||||
PublicIP: network.PublicIP(config.Proxy),
|
||||
}
|
||||
}
|
||||
|
||||
ret.Encode(payload)
|
||||
nc.PublishRequest(config.AgentID, mode, resp)
|
||||
}
|
||||
60
agent/tactical/service/service_windows.go
Normal file
60
agent/tactical/service/service_windows.go
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
package service
|
||||
|
||||
func NatsMessage(version string, nc *nats.Conn, mode string) {
|
||||
config := config.NewAgentConfig()
|
||||
var resp []byte
|
||||
var payload interface{}
|
||||
ret := codec.NewEncoderBytes(&resp, new(codec.MsgpackHandle))
|
||||
|
||||
switch mode {
|
||||
case "agent-hello":
|
||||
payload = CheckInNats{
|
||||
Agentid: config.AgentID,
|
||||
Version: version,
|
||||
}
|
||||
case "agent-winsvc":
|
||||
svcs, _, _ := services.GetServices()
|
||||
payload = WinSvcNats{
|
||||
Agentid: config.AgentID,
|
||||
WinSvcs: svcs,
|
||||
}
|
||||
case "agent-agentinfo":
|
||||
osinfo := system.OsString()
|
||||
reboot, err := system.SystemRebootRequired()
|
||||
if err != nil {
|
||||
reboot = false
|
||||
}
|
||||
payload = AgentInfoNats{
|
||||
Agentid: config.AgentID,
|
||||
Username: system.LoggedOnUser(),
|
||||
Hostname: system.GetHostname(),
|
||||
OS: osinfo,
|
||||
Platform: runtime.GOOS,
|
||||
TotalRAM: system.TotalRAM(),
|
||||
BootTime: system.BootTime(),
|
||||
RebootNeeded: reboot,
|
||||
GoArch: runtime.GOARCH,
|
||||
}
|
||||
case "agent-wmi":
|
||||
wmiinfo, _ := wmi.GetWMIInfo()
|
||||
payload = WinWMINats{
|
||||
Agentid: config.AgentID,
|
||||
WMI: wmiinfo,
|
||||
}
|
||||
case "agent-disks":
|
||||
disks, _ := disk.GetDisks()
|
||||
payload = WinDisksNats{
|
||||
Agentid: config.AgentID,
|
||||
Disks: disks,
|
||||
}
|
||||
case "agent-publicip":
|
||||
payload = PublicIPNats{
|
||||
Agentid: config.AgentID,
|
||||
PublicIP: network.PublicIP(config.Proxy),
|
||||
}
|
||||
}
|
||||
|
||||
//a.Logger.Debugln(mode, payload)
|
||||
ret.Encode(payload)
|
||||
nc.PublishRequest(config.AgentID, mode, resp)
|
||||
}
|
||||
|
|
@ -16,4 +16,4 @@ func SendSoftware() error {
|
|||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
8
agent/tactical/shared/shared_unix.go
Normal file
8
agent/tactical/shared/shared_unix.go
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package shared
|
||||
|
||||
func GetPython(force bool) {}
|
||||
|
||||
func RunMigrations() {}
|
||||
|
|
@ -67,4 +67,4 @@ func RunMigrations() {
|
|||
os.Remove(nssm)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -7,6 +7,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/amidaware/rmmagent/agent/system"
|
||||
"github.com/amidaware/rmmagent/agent/tactical/mesh"
|
||||
"github.com/amidaware/rmmagent/agent/utils"
|
||||
"github.com/amidaware/rmmagent/shared"
|
||||
"github.com/go-resty/resty/v2"
|
||||
|
|
@ -166,7 +167,7 @@ func RecoverMesh(agentID string) {
|
|||
opts := system.NewCMDOpts()
|
||||
opts.Command = "systemctl restart meshagent.service"
|
||||
system.CmdV2(opts)
|
||||
SyncMeshNodeID()
|
||||
mesh.SyncMeshNodeID()
|
||||
}
|
||||
|
||||
func UninstallCleanup() {}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue