Skip to content

Commit

Permalink
agent: sync file_ext from elkeid
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskaliX committed Dec 2, 2023
1 parent aa15300 commit f497654
Show file tree
Hide file tree
Showing 20 changed files with 190 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ type INetRetry interface {
func IRetry(ctx context.Context, netRetry INetRetry, config Config) (err error) {
var retries, delay uint
ticker := time.NewTicker(config.BeforeDelay)
zap.S().Infof("%s starts first connection after %d secs", netRetry.String(), int(config.BeforeDelay.Seconds()))
defer ticker.Stop()
select {
case <-ctx.Done():
return
case <-ticker.C:
}
zap.S().Infof("iretry %s start connection after %d secs", netRetry.String(), int(config.BeforeDelay.Seconds()))
for {
select {
case <-ctx.Done():
Expand Down
2 changes: 1 addition & 1 deletion agent/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ pre_show:

.PHONY: build_agent
build_agent:
CGO_ENABLED=0 $(CMD_GO) build -ldflags "-X agent/agent.Version=$(BUILD_VERSION)" -o hades-agent
CGO_ENABLED=0 $(CMD_GO) build -ldflags "-X github.com/chriskaliX/Hades/agent/agent.Version=$(BUILD_VERSION)" -o hades-agent
4 changes: 2 additions & 2 deletions agent/agent/update.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package agent

import (
"agent/proto"
"agent/utils"
"github.com/chriskaliX/Hades/agent/proto"
"github.com/chriskaliX/Hades/agent/utils"
"context"
"os/exec"
"path"
Expand Down
3 changes: 0 additions & 3 deletions agent/deploy/hades-agent.service
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,17 @@
Description=hades-agent
Wants=network-online.target
After=network-online.target network.target syslog.target

[Service]
Type=simple
ExecStart=/etc/hades/hades-agent
WorkingDirectory=/etc/hades
Restart=always
RestartSec=60
KillMode=control-group
# 兼容性
MemoryMax=250M
MemoryLimit=250M
CPUQuota=10%
Delegate=yes
EnvironmentFile=-/etc/hades/specified_env

[Install]
WantedBy=multi-user.target
4 changes: 2 additions & 2 deletions agent/deploy/nfpm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
# check https://nfpm.goreleaser.com/configuration for detailed usage
#
name: "hades-agent"
arch: amd64
arch: arm64
platform: "linux"
epoch: 3
version: v1.1.0
version: v1.1.3
release: 1
section: "default"
priority: "extra"
Expand Down
2 changes: 1 addition & 1 deletion agent/go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module agent
module github.com/chriskaliX/Hades/agent

go 1.19

Expand Down
4 changes: 2 additions & 2 deletions agent/log/log.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package log

import (
"agent/proto"
"agent/transport"
"github.com/chriskaliX/Hades/agent/proto"
"github.com/chriskaliX/Hades/agent/transport"
"encoding/json"
"strconv"
"time"
Expand Down
13 changes: 7 additions & 6 deletions agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import (
"syscall"
"time"

"agent/agent"
"agent/log"
"agent/metrics"
"agent/plugin"
"agent/transport"
"agent/transport/connection"
"github.com/chriskaliX/Hades/agent/agent"
"github.com/chriskaliX/Hades/agent/log"
"github.com/chriskaliX/Hades/agent/metrics"
"github.com/chriskaliX/Hades/agent/plugin"
"github.com/chriskaliX/Hades/agent/transport"
"github.com/chriskaliX/Hades/agent/transport/connection"

"github.com/nightlyone/lockfile"
"go.uber.org/zap"
Expand Down Expand Up @@ -71,6 +71,7 @@ func main() {
defer logger.Sync()
zap.ReplaceGlobals(logger)

zap.S().Infof("agent starts, version: %s", agent.Version)
if os.Getenv("service_type") == "sysvinit" {
l, _ := lockfile.New("/var/run/hades-agent.pid")
if err := l.TryLock(); err != nil {
Expand Down
10 changes: 5 additions & 5 deletions agent/metrics/metric_agent.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package metrics

import (
"agent/agent"
"agent/plugin"
"agent/proto"
"agent/transport"
"agent/transport/connection"
"github.com/chriskaliX/Hades/agent/agent"
"github.com/chriskaliX/Hades/agent/plugin"
"github.com/chriskaliX/Hades/agent/proto"
"github.com/chriskaliX/Hades/agent/transport"
"github.com/chriskaliX/Hades/agent/transport/connection"
"os"
"runtime"
"strconv"
Expand Down
2 changes: 1 addition & 1 deletion agent/metrics/metric_host.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package metrics

import (
"agent/agent"
"github.com/chriskaliX/Hades/agent/agent"
"net"
"os"
"strings"
Expand Down
6 changes: 6 additions & 0 deletions agent/metrics/metric_net.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// later, not now
package metrics

type NetMetric struct {

}
6 changes: 3 additions & 3 deletions agent/metrics/metric_plugin.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package metrics

import (
"agent/plugin"
"agent/proto"
"agent/transport"
"github.com/chriskaliX/Hades/agent/plugin"
"github.com/chriskaliX/Hades/agent/proto"
"github.com/chriskaliX/Hades/agent/transport"
"strconv"
"time"

Expand Down
4 changes: 2 additions & 2 deletions agent/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ func addMetric(m IMetric) {
// exported Startup function
func Startup(ctx context.Context, wg *sync.WaitGroup) {
defer wg.Done()
defer zap.S().Info("metrics deamon exits")
zap.S().Info("metrics daemon starts")
defer zap.S().Info("[deamon] metrics exits")
zap.S().Info("[daemon] metrics starts")
ticker := time.NewTicker(time.Minute)
defer ticker.Stop()
for {
Expand Down
9 changes: 4 additions & 5 deletions agent/plugin/manager.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package plugin

import (
"agent/agent"
"agent/proto"
"agent/transport/pool"
"github.com/chriskaliX/Hades/agent/agent"
"github.com/chriskaliX/Hades/agent/proto"
"github.com/chriskaliX/Hades/agent/transport"
"github.com/chriskaliX/Hades/agent/transport/pool"
"context"
"errors"
"fmt"
"os"
"sync"

"agent/transport"

SDK "github.com/chriskaliX/SDK/transport"
"github.com/chriskaliX/SDK/transport/server"
"go.uber.org/zap"
Expand Down
8 changes: 4 additions & 4 deletions agent/plugin/plugin.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package plugin

import (
"agent/agent"
"agent/transport"
"github.com/chriskaliX/Hades/agent/agent"
"github.com/chriskaliX/Hades/agent/transport"
"context"
"fmt"
"sync"
Expand All @@ -13,8 +13,8 @@ import (

func Startup(ctx context.Context, wg *sync.WaitGroup) {
defer wg.Done()
defer zap.S().Info("plugin deamon exits")
zap.S().Info("plugin deamon starts")
defer zap.S().Info("[deamon] plugin exits")
zap.S().Info("[deamon] plugin starts")
for {
select {
case <-ctx.Done():
Expand Down
17 changes: 9 additions & 8 deletions agent/transport/client.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package transport

import (
"agent/proto"
"github.com/chriskaliX/Hades/agent/proto"
"context"
"sync"
"time"

_ "agent/transport/compressor"
"agent/transport/connection"
_ "github.com/chriskaliX/Hades/agent/transport/compressor"
"github.com/chriskaliX/Hades/agent/transport/connection"

"go.uber.org/zap"
"google.golang.org/grpc"
Expand All @@ -17,8 +17,8 @@ import (
func Startup(ctx context.Context, wg *sync.WaitGroup) {
var client proto.Transfer_TransferClient
defer wg.Done()
defer zap.S().Info("grpc deamon exits")
zap.S().Info("grpc transport starts")
defer zap.S().Info("[deamon] grpc transport exits")
zap.S().Info("[deamon] grpc transport starts")
subWg := &sync.WaitGroup{}
for {
select {
Expand All @@ -39,7 +39,8 @@ func Startup(ctx context.Context, wg *sync.WaitGroup) {
continue
}
// client start successfully, start the goroutines and wait
subWg.Add(2)
subWg.Add(3)
go startFileExt(subCtx, subWg)
go handleSend(subCtx, subWg, client)
go func() {
handleReceive(subCtx, subWg, client)
Expand Down Expand Up @@ -74,8 +75,8 @@ func handleSend(ctx context.Context, wg *sync.WaitGroup, c proto.Transfer_Transf

func handleReceive(ctx context.Context, wg *sync.WaitGroup, client proto.Transfer_TransferClient) {
defer wg.Done()
defer zap.S().Info("handle receive is exited")
zap.S().Info("handle receive starts")
defer zap.S().Info("receive handler is exited")
zap.S().Info("receive handler starts")
for {
select {
case <-ctx.Done():
Expand Down
File renamed without changes.
Loading

0 comments on commit f497654

Please sign in to comment.