Skip to content

Commit

Permalink
Move config.identifier before perfdata (#33)
Browse files Browse the repository at this point in the history
* Move config.identifier before perfdata

* Add worker config.identifier position option in plugin output result

* Blank line before return

* Rework into single variable
  • Loading branch information
dvnscr authored Sep 3, 2024
1 parent 693d647 commit b8f4639
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
6 changes: 3 additions & 3 deletions pkg/modgearman/configuration_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ type config struct {
flagCPUProfile string
flagMemProfile string
// append worker hostname to result output
workerNameInResult bool
workerNameInResult string
}

// setDefaultValues sets reasonable defaults
Expand Down Expand Up @@ -104,7 +104,7 @@ func (config *config) setDefaultValues() {
config.internalNegate = true
config.internalCheckDummy = true
config.internalCheckNscWeb = true
config.workerNameInResult = false
config.workerNameInResult = "off"
filename, err := os.Executable()
if err == nil {
config.p1File = path.Join(path.Dir(filename), "mod_gearman_worker_epn.pl")
Expand Down Expand Up @@ -335,7 +335,7 @@ func (config *config) parseConfigItem(raw string) error {
case "internal_check_nsc_web":
config.internalCheckNscWeb = getBool(value)
case "worker_name_in_result":
config.workerNameInResult = getBool(value)
config.workerNameInResult = value
case "fork_on_exec":
// skip legacy option
case "workaround_rc_25":
Expand Down
17 changes: 15 additions & 2 deletions pkg/modgearman/readAndExecute.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,21 @@ func execEPN(result *answer, cmd *command, received *request) {

func fixReturnCodes(result *answer, config *config, state *os.ProcessState) {
if result.returnCode >= 0 && result.returnCode <= 3 {
if config.workerNameInResult {
result.output = fmt.Sprintf("%s (worker: %s)", result.output, config.identifier)
if config.workerNameInResult != "off" {

Check failure on line 294 in pkg/modgearman/readAndExecute.go

View workflow job for this annotation

GitHub Actions / test

unnecessary leading newline (whitespace)

switch config.workerNameInResult {
case "on":
result.output = fmt.Sprintf("(worker: %s) %s", config.identifier, result.output)
case "pre_perfdata":
outputparts := strings.SplitN(result.output, "|", 2)
if len(outputparts) > 1 {
result.output = fmt.Sprintf("%s (worker: %s) |%s", outputparts[0], config.identifier, outputparts[1])
} else {
result.output = fmt.Sprintf("%s (worker: %s)", result.output, config.identifier)
}
default:
log.Warnf("unknown worker_name_in_result value: %s. Defaulting to 'off'", config.workerNameInResult)
}
}

return
Expand Down
10 changes: 7 additions & 3 deletions worker.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,14 @@ use_perl_cache=on
# use internal check_dummy plugin
#internal_check_dummy = 1


# Show worker identifier in result output
#worker_name_in_result=no

# Possible values:
# off: Do not show worker identifier.
# on: The worker identifier is displayed at the beginning of the plugin output. E.g. "(worker: w1) Service is Running"
# pre_perfdata: The worker identifier is displayed at the end of the plugin output text, but before the perfdata. E.g. "Service is Running (worker: w1) | duration=10ms, version=1"
#
# Default is off
#worker_name_in_result=off

# Prometheus
# export prometheus metrics
Expand Down

0 comments on commit b8f4639

Please sign in to comment.