Skip to content

Commit cc426a4

Browse files
authored
Manage AS400 Collector (#1)
* Manage AS400 Collector * Uninstall collector before uninstall dependencies
1 parent 28f2080 commit cc426a4

31 files changed

Lines changed: 1138 additions & 578 deletions
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Installer Release
2+
3+
on:
4+
release:
5+
types: [ 'released' ]
6+
7+
jobs:
8+
build:
9+
name: Build
10+
runs-on: signing
11+
steps:
12+
- name: Check out code into the right branch
13+
uses: actions/checkout@v2
14+
15+
- name: Set up Go
16+
uses: actions/setup-go@v2
17+
with:
18+
go-version: 1.21
19+
20+
- name: Build and sign installer
21+
run: |
22+
cd ${{ github.workspace }}
23+
24+
$env:GOOS = "linux"
25+
$env:GOARCH = "amd64"
26+
go build -o utmstack_collectors_installer -v .
27+
28+
$env:GOOS = "windows"
29+
go build -o utmstack_collectors_installer.exe -v .
30+
signtool sign /fd SHA256 /tr http://timestamp.digicert.com /td SHA256 /f "${{ vars.SIGN_CERT }}" /csp "eToken Base Cryptographic Provider" /k "[{{${{ secrets.SIGN_KEY }}}}]=${{ secrets.SIGN_CONTAINER }}" "utmstack_collectors_installer.exe"
31+
32+
- name: Create Release
33+
id: create_release
34+
uses: softprops/action-gh-release@v1
35+
env:
36+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
37+
with:
38+
body_path: ./CHANGELOG.md
39+
draft: false
40+
prerelease: false
41+
files: |
42+
./utmstack_collectors_installer
43+
./utmstack_collectors_installer.exe

cmd/enable.go

Lines changed: 0 additions & 49 deletions
This file was deleted.

cmd/root.go

Lines changed: 0 additions & 53 deletions
This file was deleted.

config.go/config.go

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
package config
2+
3+
import (
4+
"collector/utils"
5+
"fmt"
6+
"path/filepath"
7+
"runtime"
8+
"strings"
9+
)
10+
11+
type ServiceTypeConfig struct {
12+
CollectorType Collector `yaml:"collector_type"`
13+
}
14+
15+
const (
16+
As400Jar = "as400-extractor-2.2.0-jar-with-dependencies.jar"
17+
JavaVersion = "jdk-11.0.13.8"
18+
CollectorConfigFile = "collector-config.yaml"
19+
SERV_LOG = "utmstack_collector.log"
20+
)
21+
22+
type ServiceConfig struct {
23+
Name string
24+
DisplayName string
25+
Description string
26+
CMDRun string
27+
CMDArgs []string
28+
CMDPath string
29+
}
30+
31+
type Collector string
32+
33+
var (
34+
AS400 Collector = "as400"
35+
)
36+
37+
func IsValidCollector(c string) bool {
38+
switch c {
39+
case string(AS400):
40+
return true
41+
default:
42+
return false
43+
}
44+
}
45+
46+
func GetJavaPath() string {
47+
currentPath, _ := utils.GetMyPath()
48+
switch runtime.GOOS {
49+
case "windows":
50+
return filepath.Join(currentPath, "dependencies", JavaVersion, "bin", "java.exe")
51+
default:
52+
return ""
53+
}
54+
}
55+
56+
func GetAs400Command(action, host, connectionKey string) (string, []string) {
57+
currentPath, _ := utils.GetMyPath()
58+
cmd := ""
59+
args := []string{}
60+
61+
action = strings.ToUpper(action)
62+
switch runtime.GOOS {
63+
case "windows":
64+
cmd = GetJavaPath()
65+
case "linux":
66+
cmd = "java"
67+
default:
68+
return "unknown operating system", nil
69+
}
70+
71+
args = append(args, "-jar", filepath.Join(currentPath, As400Jar), fmt.Sprintf("-option=%s", action))
72+
if action == "INSTALL" {
73+
args = append(args, fmt.Sprintf("-collector-manager-host=%s", host), "-collector-manager-port=9000", "-logs-port=50051", fmt.Sprintf("-connection-key=%s", connectionKey))
74+
}
75+
return cmd, args
76+
}
77+
78+
func ValidateParams(params []string) bool {
79+
action := params[1]
80+
collector := params[2]
81+
if !IsValidCollector(collector) {
82+
return false
83+
}
84+
85+
if action == "install" {
86+
if len(params) < 5 {
87+
return false
88+
}
89+
} else if action == "uninstall" {
90+
if len(params) < 3 {
91+
return false
92+
}
93+
} else {
94+
return false
95+
}
96+
97+
return true
98+
}
99+
100+
func GetServiceConfig(c Collector) ServiceConfig {
101+
path, _ := utils.GetMyPath()
102+
switch c {
103+
case AS400:
104+
cmd, args := GetAs400Command("run", "", "")
105+
return ServiceConfig{
106+
Name: "UTMStackAS400Collector",
107+
DisplayName: "UTMStack AS400 Collector",
108+
Description: "UTMStack AS400 Collector",
109+
CMDRun: cmd,
110+
CMDArgs: args,
111+
CMDPath: path,
112+
}
113+
default:
114+
return ServiceConfig{}
115+
}
116+
}
117+
118+
func SaveConfig(config *ServiceTypeConfig) error {
119+
path, err := utils.GetMyPath()
120+
if err != nil {
121+
return fmt.Errorf("failed to get current path: %v", err)
122+
}
123+
124+
if err := utils.WriteYAML(filepath.Join(path, CollectorConfigFile), config); err != nil {
125+
return err
126+
}
127+
128+
return nil
129+
}
130+
131+
func ReadConfig() (*ServiceTypeConfig, error) {
132+
path, err := utils.GetMyPath()
133+
if err != nil {
134+
return nil, fmt.Errorf("failed to get current path: %v", err)
135+
}
136+
137+
config := &ServiceTypeConfig{}
138+
if err = utils.ReadYAML(filepath.Join(path, CollectorConfigFile), config); err != nil {
139+
return nil, fmt.Errorf("error reading config file: %v", err)
140+
}
141+
142+
return config, nil
143+
}

go.mod

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,40 @@ module collector
33
go 1.21.1
44

55
require (
6-
github.com/fsnotify/fsnotify v1.7.0 // indirect
7-
github.com/hashicorp/hcl v1.0.0 // indirect
8-
github.com/inconshreveable/mousetrap v1.1.0 // indirect
9-
github.com/magiconair/properties v1.8.7 // indirect
10-
github.com/mitchellh/mapstructure v1.5.0 // indirect
11-
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
12-
github.com/sagikazarmark/locafero v0.4.0 // indirect
13-
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
14-
github.com/sourcegraph/conc v0.3.0 // indirect
15-
github.com/spf13/afero v1.11.0 // indirect
16-
github.com/spf13/cast v1.6.0 // indirect
17-
github.com/spf13/cobra v1.8.0 // indirect
18-
github.com/spf13/pflag v1.0.5 // indirect
19-
github.com/spf13/viper v1.18.2 // indirect
20-
github.com/subosito/gotenv v1.6.0 // indirect
21-
go.uber.org/atomic v1.11.0 // indirect
22-
go.uber.org/multierr v1.11.0 // indirect
23-
golang.org/x/exp v0.0.0-20240213143201-ec583247a57a // indirect
24-
golang.org/x/sys v0.17.0 // indirect
6+
github.com/kardianos/service v1.2.2
7+
github.com/logrusorgru/aurora v2.0.3+incompatible
8+
github.com/threatwinds/logger v1.1.9
9+
github.com/threatwinds/validations v1.0.5
10+
gopkg.in/yaml.v2 v2.4.0
11+
)
12+
13+
require (
14+
github.com/bytedance/sonic v1.11.3 // indirect
15+
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
16+
github.com/chenzhuoyu/iasm v0.9.1 // indirect
17+
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
18+
github.com/gin-contrib/sse v0.1.0 // indirect
19+
github.com/gin-gonic/gin v1.9.1 // indirect
20+
github.com/go-playground/locales v0.14.1 // indirect
21+
github.com/go-playground/universal-translator v0.18.1 // indirect
22+
github.com/go-playground/validator/v10 v10.19.0 // indirect
23+
github.com/goccy/go-json v0.10.2 // indirect
24+
github.com/google/uuid v1.6.0 // indirect
25+
github.com/json-iterator/go v1.1.12 // indirect
26+
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
27+
github.com/leodido/go-urn v1.4.0 // indirect
28+
github.com/mattn/go-isatty v0.0.20 // indirect
29+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
30+
github.com/modern-go/reflect2 v1.0.2 // indirect
31+
github.com/pelletier/go-toml/v2 v2.2.0 // indirect
32+
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
33+
github.com/ugorji/go/codec v1.2.12 // indirect
34+
golang.org/x/arch v0.7.0 // indirect
35+
golang.org/x/crypto v0.22.0 // indirect
36+
golang.org/x/net v0.24.0 // indirect
37+
golang.org/x/sys v0.19.0 // indirect
2538
golang.org/x/text v0.14.0 // indirect
26-
gopkg.in/ini.v1 v1.67.0 // indirect
39+
google.golang.org/protobuf v1.33.0 // indirect
40+
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
2741
gopkg.in/yaml.v3 v3.0.1 // indirect
2842
)

0 commit comments

Comments
 (0)