Beispiel #1
0
// メトリック取得
func getMetrics(plugin_name string, plugin_option string) (string, error) {
	var plugin string

	for _, base_path := range strings.Split(happo_agent.SENSU_PLUGIN_PATHS, ",") {
		plugin = path.Join(base_path, plugin_name)
		_, err := os.Stat(plugin)
		if err == nil {
			if !util.Production {
				log.Println(plugin)
			}
			break
		}
	}
	_, err := os.Stat(plugin)
	if err != nil {
		log.Println("Plugin not found:" + plugin)
		return "", nil
	}

	if !util.Production {
		log.Println("Execute metric plugin:" + plugin)
	}
	exitstatus, stdout, _, err := util.ExecCommand(plugin, plugin_option)

	if err != nil {
		return "", err
	}
	if exitstatus != 0 {
		log.Println("Fail to get metrics:" + plugin)
		return "", nil
	}

	return stdout, nil
}
Beispiel #2
0
func execPluginCommand(plugin_name string, plugin_option string) (int, string, error) {
	var plugin string

	for _, base_path := range strings.Split(happo_agent.NAGIOS_PLUGIN_PATHS, ",") {
		plugin = path.Join(base_path, plugin_name)
		_, err := os.Stat(plugin)
		if err == nil {
			if !util.Production {
				log.Println(plugin)
			}
			break
		}
	}

	exitstatus, stdout, _, err := util.ExecCommand(plugin, plugin_option)

	if err != nil {
		return happo_agent.MONITOR_UNKNOWN, "", err
	}

	return exitstatus, stdout, nil
}
Beispiel #3
0
func saveMachineState() error {
	logged_time := time.Now()

	result := ""
	for _, cmd := range strings.Split(ERROR_LOG_COMMANDS, ",") {
		cmd := strings.Split(cmd, " ")
		if len(cmd) == 1 {
			cmd = append(cmd, "")
		}
		exitstatus, stdout, _, err := util.ExecCommand(cmd[0], cmd[1])
		if exitstatus == 0 && err == nil {
			result += fmt.Sprintf("********** %s %s (%s) **********\n", cmd[0], cmd[1], logged_time.Format(time.RFC3339))
			result += stdout
			result += "\n\n"
		}
	}

	file_suffix_time := fmt.Sprintf("%04d%02d%02d_%02d%02d%02d", logged_time.Year(), logged_time.Month(), logged_time.Day(), logged_time.Hour(), logged_time.Minute(), logged_time.Second())
	filepath := path.Join(ERROR_LOG_OUTPUT_PATH, fmt.Sprintf(ERROR_LOG_OUTPUT_FILENAME, file_suffix_time))
	err := ioutil.WriteFile(filepath, []byte(result), os.ModePerm)

	return err
}