Add logging levels to custom plugin logs.

This commit is contained in:
Archit Bansal
2020-08-28 12:51:50 -07:00
parent 7fa34545b7
commit 8c94d5e60c
2 changed files with 7 additions and 7 deletions
@@ -271,7 +271,7 @@ func (c *customPluginMonitor) generateStatus(result cpmtypes.Result) *types.Stat
}
// Log only if condition has changed
if len(activeProblemEvents) != 0 || len(inactiveProblemEvents) != 0 {
glog.Infof("New status generated: %+v", status)
glog.V(0).Infof("New status generated: %+v", status)
}
return status
}
+6 -6
View File
@@ -115,7 +115,6 @@ func (p *Plugin) runRules() {
// Let the result be logged at a higher verbosity level. If there is a change in status it is logged later.
glog.V(3).Infof("Add check result %+v for rule %+v", result, rule)
glog.Infof("Ran rule %+v", rule)
}(rule)
}
@@ -219,12 +218,13 @@ func (p *Plugin) run(rule cpmtypes.CustomRule) (exitStatus cpmtypes.Status, outp
exitCode := cmd.ProcessState.Sys().(syscall.WaitStatus).ExitStatus()
switch exitCode {
case 0:
logPluginStderr(rule, string(stderr), 3)
return cpmtypes.OK, output
case 1:
logPluginStderr(rule.Path, string(stderr))
logPluginStderr(rule, string(stderr), 0)
return cpmtypes.NonOK, output
default:
logPluginStderr(rule.Path, string(stderr))
logPluginStderr(rule, string(stderr), 0)
return cpmtypes.Unknown, output
}
}
@@ -234,9 +234,9 @@ func (p *Plugin) Stop() {
glog.Info("Stop plugin execution")
}
func logPluginStderr(path, logs string) {
func logPluginStderr(rule cpmtypes.CustomRule, logs string, logLevel glog.Level) {
if len(logs) != 0 {
glog.Infof("Start logs from plugin %q \n %s", path, string(logs))
glog.Infof("End logs from plugin %q", path)
glog.V(logLevel).Infof("Start logs from plugin %+v \n %s", rule, logs)
glog.V(logLevel).Infof("End logs from plugin %+v", rule)
}
}