Пример #1
0
Файл: run.go Проект: garthk/nag
		cfg, err := naglib.ParseConfig(nrpeCfgFile)
		if err != nil {
			return err
		}

		context := naglib.PluginContext{
			NagiosConfig:        cfg,
			ExitStatusTreatment: treatment,
		}

		if len(args) == 0 {
			return errors.New("nag run: executable required")
		} else {
			cmd.SilenceUsage = true
			result, err := naglib.RunPlugin(&context, args[0], args[1:]...)
			return processPluginResult(context, result, err)
		}
	},
}

func processPluginResult(context naglib.PluginContext, result naglib.PluginResult, err error) error {
	for _, msg := range context.Messages {
		printStatusLine(msg.Severity, msg.Message)
	}
	if err == nil {
		printStatusLine(result.Status, result.Output)
	}
	return err
}
Пример #2
0
		commandline := cfg.Commands[command]
		if commandline == "" {
			// TODO: exit CRITICAL
			return errors.New(fmt.Sprintf("%s: command %s not known; try %s",
				cmd.CommandPath(),
				command,
				listCmd.CommandPath()))
		}

		context := naglib.PluginContext{
			NagiosConfig:        cfg,
			ExitStatusTreatment: treatment,
		}

		// TODO: add command prefix
		// TODO: substitute arguments
		shell := os.ExpandEnv("$SHELL")
		if len(shell) == 0 {
			shell = "/bin/bash"
		}
		result, err := naglib.RunPlugin(&context, shell, "-c", commandline)
		return processPluginResult(context, result, err)
	},
}

func init() {
	RootCmd.AddCommand(checkCmd)
	addExitStatusFlags(runCmd)
}