mirror of
https://github.com/dragonheim/gagent.git
synced 2025-01-18 09:36:28 -08:00
Minor cleanup and and got the client sending agents again.
This commit is contained in:
parent
42623f63c6
commit
134f33cd6a
7 changed files with 50 additions and 64 deletions
|
@ -1,4 +1,4 @@
|
|||
FROM dragonheim/golang:1.17 as builder
|
||||
FROM dragonheim/golang:1.18 as builder
|
||||
ARG SEMVER
|
||||
|
||||
WORKDIR /gagent
|
||||
|
@ -12,7 +12,7 @@ RUN apk add --no-cache zeromq-dev build-base git
|
|||
RUN go build -o /gagent/bin/gagent -ldflags "-X main.semVER=${SEMVER}" cmd/gagent/main.go
|
||||
RUN strip /gagent/bin/gagent
|
||||
|
||||
FROM alpine:3.15
|
||||
FROM alpine:3.16
|
||||
ARG SEMVER
|
||||
LABEL Name="G'Agent"
|
||||
LABEL Maintainer="jwells@dragonheim.net"
|
||||
|
@ -23,8 +23,8 @@ RUN apk add --no-cache zeromq && mkdir -p -m 0700 /etc/gagent
|
|||
COPY --from=builder /gagent/assets/examples/gagent.hcl /etc/gagent/gagent.hcl
|
||||
COPY --from=builder /gagent/bin/gagent /usr/bin/
|
||||
|
||||
# Router Client Worker
|
||||
EXPOSE 35570/tcp 35571/tcp 35572/tcp
|
||||
# Router Client Worker Prometheus
|
||||
EXPOSE 35570/tcp 35572/tcp 35571/tcp 9101/tcp
|
||||
VOLUME /etc/gagent
|
||||
|
||||
CMD ["/usr/bin/gagent"]
|
||||
|
|
|
@ -9,4 +9,5 @@
|
|||
"clients": {
|
||||
"client": "7e9d13fe-5151-5876-66c0-20ca03e8fca4"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -143,35 +143,28 @@ func init() {
|
|||
config.UUID = uuid.NewV4UUID().String()
|
||||
|
||||
/*
|
||||
* By default, we want to listen on all IP addresses. It can be overridden
|
||||
* in the configuration file by setting listenaddr
|
||||
* By default, we want to listen on all IP addresses.
|
||||
*/
|
||||
config.ListenAddr = "0.0.0.0"
|
||||
|
||||
/*
|
||||
* By default, G'Agent will use port 9101 or monitoring via prometheus.
|
||||
* It can be overridden in the configuration file by setting clientport
|
||||
* G'Agent will use this port for monitoring via prometheus., If set
|
||||
* is set to 0, G'Agent will not listen for prometheus metrics.
|
||||
*/
|
||||
config.MonitorPort = 9101
|
||||
|
||||
/*
|
||||
* By default, G'Agent client will use port 35572 to communicate with the
|
||||
* routers, but you can override it by setting the clientport in the
|
||||
* configuration file
|
||||
* G'Agent client will use this port to communicate with the routers.
|
||||
*/
|
||||
config.ClientPort = 35572
|
||||
|
||||
/*
|
||||
* By default, G'Agent router will use port 35570 to communicate with
|
||||
* other routers, but you can override it by setting the routerport in
|
||||
* the configuration file
|
||||
* G'Agent router will use this port to communicate with other routers.
|
||||
*/
|
||||
config.RouterPort = 35570
|
||||
|
||||
/*
|
||||
* By default, G'Agent worker will use port 35571 to communicate with the
|
||||
* routers, but you can override it by setting the workerport in the
|
||||
* configuration file
|
||||
* G'Agent worker will use this port to communicate with the routers.
|
||||
*/
|
||||
config.WorkerPort = 35571
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package client
|
|||
|
||||
import (
|
||||
sha "crypto/sha256"
|
||||
hex "encoding/hex"
|
||||
fmt "fmt"
|
||||
ioutil "io/ioutil"
|
||||
log "log"
|
||||
|
@ -40,9 +41,10 @@ func Main(wg *sync.WaitGroup, config gstructs.GagentConfig) {
|
|||
log.Printf("[DEBUG] Agent file contents: \n----- -----\n%s\n----- -----\n", agent.ScriptCode)
|
||||
}
|
||||
agent.Client = config.UUID
|
||||
agent.Shasum = fmt.Sprintf("%s", sha.Sum256(agent.ScriptCode))
|
||||
tmpsum := sha.Sum256([]byte(agent.ScriptCode))
|
||||
agent.Shasum = fmt.Sprintf("%v", hex.EncodeToString(tmpsum[:]))
|
||||
log.Printf("[INFO] SHA256 of Agent file: %s", agent.Shasum)
|
||||
agent.Status = "loaded"
|
||||
agent.Status = 1
|
||||
agent.Hints = getTagsFromHints(agent)
|
||||
agent.Answer = nil
|
||||
|
||||
|
|
|
@ -28,7 +28,8 @@ func NewConsulClient(addr string) (Client, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &client{consul: c}, nil
|
||||
return &client{c}, nil
|
||||
//return &client{consul: c}, nil
|
||||
}
|
||||
|
||||
// Register a service with consul local agent
|
||||
|
@ -51,10 +52,10 @@ func (c *client) Service(service, tag string) ([]*consul.ServiceEntry, *consul.Q
|
|||
passingOnly := true
|
||||
addrs, meta, err := c.consul.Health().Service(service, tag, passingOnly, nil)
|
||||
if len(addrs) == 0 && err == nil {
|
||||
return nil, fmt.Errorf("service ( %s ) was not found", service)
|
||||
return nil, nil, fmt.Errorf("service ( %s ) was not found", service)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
return addrs, meta, nil
|
||||
}
|
||||
|
|
|
@ -24,16 +24,14 @@ type GagentConfig struct {
|
|||
*/
|
||||
type ClientDetails struct {
|
||||
/*
|
||||
* Client name for display purposes in logs and
|
||||
* diagnostics.
|
||||
* Client name for display purposes in logs and diagnostics.
|
||||
*/
|
||||
ClientName string `hcl:",label"`
|
||||
|
||||
/*
|
||||
* UUID String for the client node. This is used by
|
||||
* the router to determine which MQ client to send
|
||||
* the agent's results to. This attempts to keep the
|
||||
* clients unique globally.
|
||||
* UUID String for the client node. This is used by the router to
|
||||
* determine which MQ client to send the agent's results to. This
|
||||
* attempts to keep the clients unique globally.
|
||||
*/
|
||||
ClientID string `hcl:"clientid,optional"`
|
||||
}
|
||||
|
@ -43,52 +41,44 @@ type ClientDetails struct {
|
|||
*/
|
||||
type RouterDetails struct {
|
||||
/*
|
||||
* Router name for display purposes in logs and
|
||||
* diagnostics
|
||||
* Router name for display purposes in logs and diagnostics.
|
||||
*/
|
||||
RouterName string `hcl:",label"`
|
||||
|
||||
/*
|
||||
* UUID String for the router node. This is used by
|
||||
* the clients, routers, and workers to determine
|
||||
* which MQ router to send the agent's requests to.
|
||||
* This attempts to keep the routers unique globally.
|
||||
* UUID String for the router node. This is used by the clients,
|
||||
* routers, and workers to determine which MQ router to send the
|
||||
* agent's requests to. This attempts to keep the routers unique
|
||||
* globally.
|
||||
*/
|
||||
RouterID string `hcl:"routerid,attr"`
|
||||
|
||||
/*
|
||||
* This is the IP address or hostname the router
|
||||
* will listen on. The router will start up a 0MQ
|
||||
* service that clients and workers will connect to.
|
||||
* This is the IP address or hostname the router will listen on. The
|
||||
* router will start up a 0MQ service that clients and workers will
|
||||
* connect to.
|
||||
*/
|
||||
RouterAddr string `hcl:"address,attr"`
|
||||
|
||||
/*
|
||||
* This is the is the port that the router listens
|
||||
* on for clients. If not defined, it will default
|
||||
* to 35571.
|
||||
* G'Agent client will use this port to communicate with the routers.
|
||||
*/
|
||||
ClientPort int64 `hcl:"clientport,optional"`
|
||||
|
||||
/*
|
||||
* This is the is the port that the router listens
|
||||
* on for routers. If not defined, it will default
|
||||
* to 35570.
|
||||
* G'Agent router will use this port to communicate with other routers.
|
||||
*/
|
||||
RouterPort int64 `hcl:"routerport,optional"`
|
||||
|
||||
/*
|
||||
* This is the is the port that the router listens
|
||||
* on for clients. If not defined, it will default
|
||||
* to 35572.
|
||||
* G'Agent worker will use this port to communicate with the routers.
|
||||
*/
|
||||
WorkerPort int64 `hcl:"workerport,optional"`
|
||||
|
||||
/*
|
||||
* These tags will be passed to the router upon
|
||||
* connection. The router will then use these
|
||||
* tags to help determine which worker / client
|
||||
* to send the client's requests and results to.
|
||||
* These tags will be passed to the router upon connection. The router
|
||||
* will then use these tags to help determine which worker / client to
|
||||
* send the client's requests and results to.
|
||||
*/
|
||||
RouterTags []string `hcl:"tags,optional"`
|
||||
}
|
||||
|
@ -98,33 +88,30 @@ type RouterDetails struct {
|
|||
*/
|
||||
type WorkerDetails struct {
|
||||
/*
|
||||
* Router name for display purposes in logs and
|
||||
* diagnostics
|
||||
* Router name for display purposes in logs and diagnostics.
|
||||
*/
|
||||
WorkerName string `hcl:",label"`
|
||||
|
||||
/*
|
||||
* UUID String for the worker node. This is used
|
||||
* by the router to determine which MQ client to
|
||||
* send agents to. This attempts to keep the
|
||||
* workers unique globally.
|
||||
* UUID String for the worker node. This is used by the router to
|
||||
* determine which MQ client to send agents to. This attempts to keep
|
||||
* the workers unique globally.
|
||||
*/
|
||||
WorkerID string `hcl:"workerid,attr"`
|
||||
|
||||
/*
|
||||
* These tags will be passed to the router upon
|
||||
* connection. The router will then use these
|
||||
* tags to help determine which worker / client
|
||||
* to send the agent and it's results to.
|
||||
* These tags will be passed to the router upon connection. The router
|
||||
* will then use these tags to help determine which worker / client to
|
||||
* send the agent and it's results to.
|
||||
*/
|
||||
WorkerTags []string `hcl:"tags,optional"`
|
||||
}
|
||||
|
||||
type AgentDetails struct {
|
||||
Client string `hcl:"client"`
|
||||
Status int64 `hcl:"status"`
|
||||
Shasum string `hcl:"shasum"`
|
||||
Status string `hcl:"status"`
|
||||
ScriptCode []byte
|
||||
Hints []string
|
||||
ScriptCode []byte
|
||||
Answer []byte
|
||||
}
|
||||
|
|
|
@ -57,7 +57,9 @@ func getAgent(wg *sync.WaitGroup, uuid string, connectString string) {
|
|||
subscriber, _ := zmq.NewSocket(zmq.REP)
|
||||
defer subscriber.Close()
|
||||
|
||||
_ = subscriber.Connect(connectString)
|
||||
// _ = subscriber.Connect(connectString)
|
||||
foo := subscriber.Connect(connectString)
|
||||
log.Printf("[DEBUG] Connected to %s\n", foo)
|
||||
|
||||
msg, err := subscriber.Recv(0)
|
||||
if err != nil {
|
||||
|
|
Loading…
Add table
Reference in a new issue