Skip to content

Commit a8c0f1b

Browse files
authored
Merge pull request #43 from ConSol-Monitoring/check-nsc-web-environment-variables
Check nsc web environment variables
2 parents 163cd82 + 4340bfc commit a8c0f1b

10 files changed

Lines changed: 48 additions & 9 deletions

Changes

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
This file documents the revision history for the Mod-Gearman-Worker-Go
22

3+
Next -------
4+
- support passing environment variables to internal checks
5+
- update internal check_nsc_web handler
6+
37
1.6.0 Fri Mar 27 10:26:20 CET 2026
48
- fix crash on shutdown
59
- add internal check_prometheus handler

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.26.1
44

55
require (
66
github.com/appscode/g2 v0.0.0-20190123131438-388ba74fd273
7-
github.com/consol-monitoring/check_nsc_web v0.7.4
7+
github.com/consol-monitoring/check_nsc_web v0.7.5
88
github.com/consol-monitoring/check_prometheus v0.0.0-20260211103550-7975b0b2fb41
99
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
1010
github.com/kdar/factorlog v0.0.0-20211012144011-6ea75a169038

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ github.com/clipperhouse/uax29/v2 v2.7.0 h1:+gs4oBZ2gPfVrKPthwbMzWZDaAFPGYK72F0NJ
1212
github.com/clipperhouse/uax29/v2 v2.7.0/go.mod h1:EFJ2TJMRUaplDxHKj1qAEhCtQPW2tJSwu5BF98AuoVM=
1313
github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0/go.mod h1:4Zcjuz89kmFXt9morQgcfYZAYZ5n8WHjt81YYWIwtTM=
1414
github.com/codeskyblue/go-sh v0.0.0-20200712050446-30169cf553fe/go.mod h1:VQx0hjo2oUeQkQUET7wRwradO6f+fN5jzXgB/zROxxE=
15-
github.com/consol-monitoring/check_nsc_web v0.7.4 h1:EF9wO0NRmYuefSOkIB3c+oepqPRua+/cM4Znb5YQnhk=
16-
github.com/consol-monitoring/check_nsc_web v0.7.4/go.mod h1:erbc72XmMAiTK7IbZcclFBNjdEKB1xKVDk38dI4WR/k=
15+
github.com/consol-monitoring/check_nsc_web v0.7.5 h1:Fw7LgON8dAzADenDNDeWrVaarOTBka/PmAZD/UJeleM=
16+
github.com/consol-monitoring/check_nsc_web v0.7.5/go.mod h1:+CJERdSAKaQ2b5+zayinPRgny12VQYmUBcER8zquQgA=
1717
github.com/consol-monitoring/check_prometheus v0.0.0-20260211103550-7975b0b2fb41 h1:SBviw8FuSWWGNOShoJNJQu6ebxPtWkAN3rZhU+4sxu8=
1818
github.com/consol-monitoring/check_prometheus v0.0.0-20260211103550-7975b0b2fb41/go.mod h1:9N9L50PJGZXunjkeQF+GF2WODirKIPEBwbuFUg+iX/I=
1919
github.com/consol-monitoring/check_x v0.0.0-20260108170459-f7c19720a9ad h1:vf0rv/4E0dT4fc6A8H0hL/U9zUQBJPq2EXLEfwqc+yI=

pkg/modgearman/command.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,14 @@ func (com *command) appendEnv(envs []string) {
8989
com.Env[splitted[0]] = splitted[1]
9090
}
9191
}
92+
93+
// converts command environment to os.Environ() style, where they turn into an []string of <key>=<value>
94+
func (com *command) convertEnvToArray() []string {
95+
env := make([]string, 0, len(com.Env))
96+
97+
for key, value := range com.Env {
98+
env = append(env, key+"="+value)
99+
}
100+
101+
return env
102+
}

pkg/modgearman/command_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,26 @@ func TestCommandParser_BackslashSingle(t *testing.T) {
7878
assert.Equal(t, []string{`\t\n`}, cmd.Args)
7979
assert.Equal(t, map[string]string{}, cmd.Env)
8080
}
81+
82+
func TestEnvironmentVariablesWithInternalChecks(t *testing.T) {
83+
cfg := config{}
84+
cfg.setDefaultValues()
85+
cfg.internalCheckNscWeb = true
86+
cmdLine := "check_nsc_web_password=hello " +
87+
"/omd/sites/dev/lib/monitoring-plugins/check_nsc_web " +
88+
"-u \"http://host.docker.internal:8443\" " +
89+
"check_drive_io " +
90+
"warn=\"write_bytes_rate > 1Mb\" "
91+
cmd := parseCommand(cmdLine, &cfg)
92+
assert.Equal(t, Internal, cmd.ExecType)
93+
assert.Equal(t, "/omd/sites/dev/lib/monitoring-plugins/check_nsc_web", cmd.Command)
94+
assert.Equal(t, []string{
95+
"-u",
96+
"http://host.docker.internal:8443",
97+
"check_drive_io",
98+
"warn=write_bytes_rate > 1Mb",
99+
}, cmd.Args)
100+
assert.Equal(t, map[string]string{
101+
"check_nsc_web_password": "hello",
102+
}, cmd.Env)
103+
}

pkg/modgearman/internal_check_dummy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
type InternalCheckDummy struct{}
1111

12-
func (chk *InternalCheckDummy) Check(_ context.Context, output *bytes.Buffer, args []string) (rc int) {
12+
func (chk *InternalCheckDummy) Check(_ context.Context, output *bytes.Buffer, args, _ []string) (rc int) {
1313
if len(args) == 0 {
1414
chk.printHelp(output)
1515

pkg/modgearman/internal_check_nsc_web.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ import (
99

1010
type InternalCheckNSCWeb struct{}
1111

12-
func (chk *InternalCheckNSCWeb) Check(ctx context.Context, output *bytes.Buffer, args []string) int {
13-
return checknscweb.Check(ctx, output, args)
12+
func (chk *InternalCheckNSCWeb) Check(ctx context.Context, output *bytes.Buffer, args, env []string) int {
13+
return checknscweb.Check(ctx, output, args, env)
1414
}

pkg/modgearman/internal_check_prometheus.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
type internalCheckPrometheus struct{}
1111

12-
func (chk *internalCheckPrometheus) Check(_ context.Context, output *bytes.Buffer, args []string) int {
12+
func (chk *internalCheckPrometheus) Check(_ context.Context, output *bytes.Buffer, args, _ []string) int {
1313
// args passed to this function does not have the executable as first element.
1414
// The cli parser library of check_prometheus however expects a program name
1515
// Just like a normal argc , argv invocation

pkg/modgearman/internal_checks.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
)
99

1010
type InternalCheck interface {
11-
Check(ctx context.Context, output *bytes.Buffer, args []string) int
11+
Check(ctx context.Context, output *bytes.Buffer, args []string, env []string) int
1212
}
1313

1414
func execInternal(result *answer, cmd *command, received *request) {
@@ -20,7 +20,7 @@ func execInternal(result *answer, cmd *command, received *request) {
2020
go func() {
2121
defer logPanicExit()
2222
output := bytes.NewBuffer(nil)
23-
rc := cmd.InternalCheck.Check(ctx, output, cmd.Args)
23+
rc := cmd.InternalCheck.Check(ctx, output, cmd.Args, cmd.convertEnvToArray())
2424
result.output = output.String()
2525
result.returnCode = rc
2626
cancel()

pkg/modgearman/mod_gearman_worker.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,7 @@ Basic Settings:
471471
--config=<configfile>
472472
--server=<server>
473473
--dupserver=<server>
474+
-d / --daemon : Turns on the daemon mode. A second process will serve requests while the main process exits after starting it.
474475
475476
Encryption:
476477
--encryption=<yes|no>

0 commit comments

Comments
 (0)