示例#1
0
// Run shells out external program and store the output on c.Data.
func (s *Shell) Run() error {
	if s.Command != "" {
		s.Command = libstring.ExpandTildeAndEnv(s.Command)

		readersDataJsonBytes, err := json.Marshal(s.GetReadersData())
		if err != nil {
			return err
		}

		cmd := libprocess.NewCmd(s.Command)
		cmd.Stdin = bytes.NewReader(readersDataJsonBytes)

		outputJson, err := cmd.CombinedOutput()

		var output map[string]interface{}
		json.Unmarshal(outputJson, &output)

		s.Data["Output"] = output

		if err != nil {
			s.Data["ExitStatus"] = 1
		} else {
			s.Data["ExitStatus"] = 0
		}
	}

	return nil
}
示例#2
0
// Run NagiosPlugins out external program and store the output on c.Data.
func (s *NagiosPlugin) Run() error {
	if s.Command != "" {
		s.Command = libstring.ExpandTildeAndEnv(s.Command)

		nagiosPluginOutputBytes, err := libprocess.NewCmd(s.Command).CombinedOutput()
		if err != nil {
			s.Data["ExitStatus"] = 1
		} else {
			s.Data["ExitStatus"] = 0
		}

		nagiosPluginOutput := strings.TrimSpace(string(nagiosPluginOutputBytes))

		if strings.Contains(nagiosPluginOutput, "OK") {
			s.Data["ExitStatus"] = 0
			s.Data["Message"] = nagiosPluginOutput
		} else if strings.Contains(nagiosPluginOutput, "WARNING") {
			s.Data["ExitStatus"] = 1
			s.Data["Message"] = nagiosPluginOutput
		} else if strings.Contains(nagiosPluginOutput, "CRITICAL") {
			s.Data["ExitStatus"] = 2
			s.Data["Message"] = nagiosPluginOutput
		} else if strings.Contains(nagiosPluginOutput, "UNKNOWN") {
			s.Data["ExitStatus"] = 3
			s.Data["Message"] = nagiosPluginOutput
		}
	}

	return nil
}
示例#3
0
// Run shells out external program and store the output on c.Data.
func (s *Shell) Run() error {
	s.Data["Conditions"] = s.Conditions

	if s.IsConditionMet() && s.LowThresholdExceeded() && !s.HighThresholdExceeded() {
		output, err := libprocess.NewCmd(s.Command).CombinedOutput()
		s.Data["Output"] = string(output)

		if err != nil {
			s.Data["Error"] = err.Error()
			s.Data["ExitStatus"] = 1
		} else {
			s.Data["ExitStatus"] = 0
		}
	}

	return nil
}
示例#4
0
// Run shells out external program and store the output on c.Data.
func (s *Shell) Run() error {
	if s.Command != "" {
		s.Command = libstring.ExpandTildeAndEnv(s.Command)

		outputJson, err := libprocess.NewCmd(s.Command).CombinedOutput()

		var output map[string]interface{}
		json.Unmarshal(outputJson, &output)

		s.Data["Output"] = output

		if err != nil {
			s.Data["ExitStatus"] = 1
		} else {
			s.Data["ExitStatus"] = 0
		}
	}

	return nil
}
示例#5
0
// GenerateData pulls ReadersData field and set it to Data field.
// If JsonProcessor is defined, use it to mangle JSON and save the new JSON on Data field.
func (b *Base) GenerateData() error {
	var err error

	processorPath := b.GetJsonProcessor()
	if processorPath == "" {
		// If there's no JsonProcessor
		b.SetData(b.GetReadersData())

	} else {
		// If there is a JsonProcessor
		cmd := libprocess.NewCmd(processorPath)

		readersData := b.GetReadersData()

		readersDataJsonBytes, err := json.Marshal(readersData)
		if err != nil {
			return err
		}

		cmd.Stdin = bytes.NewReader(readersDataJsonBytes)

		postProcessingDataBytes, err := cmd.Output()
		if err != nil {
			return err
		}

		var postProcessingData interface{}
		err = json.Unmarshal(postProcessingDataBytes, &postProcessingData)
		if err != nil {
			return err
		}

		b.SetData(postProcessingData)
	}

	return err
}