support for nats websocket amidaware/tacticalrmm@42e1717455
This commit is contained in:
parent
aed33b9a95
commit
8d2511129c
@ -66,6 +66,9 @@ type Agent struct {
|
||||
Platform string
|
||||
GoArch string
|
||||
ServiceConfig *service.Config
|
||||
NatsServer string
|
||||
NatsProxyPath string
|
||||
NatsProxyPort string
|
||||
}
|
||||
|
||||
const (
|
||||
@ -139,6 +142,17 @@ func New(logger *logrus.Logger, version string) *Agent {
|
||||
},
|
||||
}
|
||||
|
||||
var natsProxyPath, natsProxyPort string
|
||||
if ac.NatsProxyPath == "" {
|
||||
natsProxyPath = "natsws"
|
||||
}
|
||||
|
||||
if ac.NatsProxyPort == "" {
|
||||
natsProxyPort = "443"
|
||||
}
|
||||
|
||||
natsServer := fmt.Sprintf("wss://%s:%s", ac.APIURL, natsProxyPort)
|
||||
|
||||
return &Agent{
|
||||
Hostname: info.Hostname,
|
||||
BaseURL: ac.BaseURL,
|
||||
@ -163,6 +177,9 @@ func New(logger *logrus.Logger, version string) *Agent {
|
||||
Platform: runtime.GOOS,
|
||||
GoArch: runtime.GOARCH,
|
||||
ServiceConfig: svcConf,
|
||||
NatsServer: natsServer,
|
||||
NatsProxyPath: natsProxyPath,
|
||||
NatsProxyPort: natsProxyPort,
|
||||
}
|
||||
}
|
||||
|
||||
@ -359,6 +376,7 @@ func (a *Agent) setupNatsOptions() []nats.Option {
|
||||
opts = append(opts, nats.RetryOnFailedConnect(true))
|
||||
opts = append(opts, nats.MaxReconnects(-1))
|
||||
opts = append(opts, nats.ReconnectBufSize(-1))
|
||||
opts = append(opts, nats.ProxyPath("natsws"))
|
||||
return opts
|
||||
}
|
||||
|
||||
|
@ -154,6 +154,8 @@ func NewAgentConfig() *rmm.AgentConfig {
|
||||
Cert: viper.GetString("cert"),
|
||||
Proxy: viper.GetString("proxy"),
|
||||
CustomMeshDir: viper.GetString("meshdir"),
|
||||
NatsProxyPath: viper.GetString("natsproxypath"),
|
||||
NatsProxyPort: viper.GetString("natsproxyport"),
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
@ -61,6 +61,8 @@ func NewAgentConfig() *rmm.AgentConfig {
|
||||
cert, _, _ := k.GetStringValue("Cert")
|
||||
proxy, _, _ := k.GetStringValue("Proxy")
|
||||
customMeshDir, _, _ := k.GetStringValue("MeshDir")
|
||||
natsProxyPath, _, _ := k.GetStringValue("NatsProxyPath")
|
||||
natsProxyPort, _, _ := k.GetStringValue("NatsProxyPort")
|
||||
|
||||
return &rmm.AgentConfig{
|
||||
BaseURL: baseurl,
|
||||
@ -72,6 +74,8 @@ func NewAgentConfig() *rmm.AgentConfig {
|
||||
Cert: cert,
|
||||
Proxy: proxy,
|
||||
CustomMeshDir: customMeshDir,
|
||||
NatsProxyPath: natsProxyPath,
|
||||
NatsProxyPort: natsProxyPort,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,6 @@ https://license.tacticalrmm.com
|
||||
package agent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
@ -78,8 +77,7 @@ func (a *Agent) NatsMessage(nc *nats.Conn, mode string) {
|
||||
|
||||
func (a *Agent) DoNatsCheckIn() {
|
||||
opts := a.setupNatsOptions()
|
||||
server := fmt.Sprintf("tls://%s:4222", a.ApiURL)
|
||||
nc, err := nats.Connect(server, opts...)
|
||||
nc, err := nats.Connect(a.NatsServer, opts...)
|
||||
if err != nil {
|
||||
a.Logger.Errorln(err)
|
||||
return
|
||||
|
@ -82,11 +82,6 @@ func (a *Agent) Install(i *Installer) {
|
||||
|
||||
a.Logger.Debugln("API:", i.SaltMaster)
|
||||
|
||||
terr := TestTCP(fmt.Sprintf("%s:4222", i.SaltMaster))
|
||||
if terr != nil {
|
||||
a.installerMsg(fmt.Sprintf("ERROR: Either port 4222 TCP is not open on your RMM, or nats.service is not running.\n\n%s", terr.Error()), "error", i.Silent)
|
||||
}
|
||||
|
||||
baseURL := u.Scheme + "://" + u.Host
|
||||
a.Logger.Debugln("Base URL:", baseURL)
|
||||
|
||||
|
@ -54,8 +54,7 @@ func (a *Agent) RunRPC() {
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(1)
|
||||
opts := a.setupNatsOptions()
|
||||
server := fmt.Sprintf("tls://%s:4222", a.ApiURL)
|
||||
nc, err := nats.Connect(server, opts...)
|
||||
nc, err := nats.Connect(a.NatsServer, opts...)
|
||||
if err != nil {
|
||||
a.Logger.Fatalln("RunRPC() nats.Connect()", err)
|
||||
}
|
||||
|
@ -12,7 +12,6 @@ https://license.tacticalrmm.com
|
||||
package agent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@ -38,8 +37,7 @@ func (a *Agent) AgentSvc() {
|
||||
time.Sleep(time.Duration(sleepDelay) * time.Second)
|
||||
|
||||
opts := a.setupNatsOptions()
|
||||
server := fmt.Sprintf("tls://%s:4222", a.ApiURL)
|
||||
nc, err := nats.Connect(server, opts...)
|
||||
nc, err := nats.Connect(a.NatsServer, opts...)
|
||||
if err != nil {
|
||||
a.Logger.Fatalln("AgentSvc() nats.Connect()", err)
|
||||
}
|
||||
|
@ -42,6 +42,8 @@ type AgentConfig struct {
|
||||
Cert string
|
||||
Proxy string
|
||||
CustomMeshDir string
|
||||
NatsProxyPath string
|
||||
NatsProxyPort string
|
||||
}
|
||||
|
||||
type RunScriptResp struct {
|
||||
|
Loading…
Reference in New Issue
Block a user