diff --git a/pkg/modgearman/configuration_parser.go b/pkg/modgearman/configuration_parser.go index 6f0307f..10d6d51 100644 --- a/pkg/modgearman/configuration_parser.go +++ b/pkg/modgearman/configuration_parser.go @@ -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 @@ -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") @@ -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": diff --git a/pkg/modgearman/readAndExecute.go b/pkg/modgearman/readAndExecute.go index f42a67e..0eadbd2 100644 --- a/pkg/modgearman/readAndExecute.go +++ b/pkg/modgearman/readAndExecute.go @@ -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" { + + 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 diff --git a/worker.cfg b/worker.cfg index 9d6124a..3d49747 100644 --- a/worker.cfg +++ b/worker.cfg @@ -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