Esempio n. 1
0
func (opts *options) run() *checkers.Checker {
	missingInstances, missingMembers, err := check(opts)
	if err != nil {
		return checkers.Unknown(err.Error())
	}

	if len(missingInstances) != 0 {
		var ipAddrs []string
		for _, instance := range missingInstances {
			ipAddrs = append(ipAddrs, aws.StringValue(instance.PrivateIpAddress))
		}

		return checkers.Critical(fmt.Sprintf("%d instance(s) left from Consul cluster: %v", len(ipAddrs), ipAddrs))
	}

	if len(missingMembers) != 0 {
		var ipAddrs []string
		for _, member := range missingMembers {
			ipAddrs = append(ipAddrs, fmt.Sprintf("%s(%s)", member.Node, member.Address))
		}

		return checkers.Warning(fmt.Sprintf("%d instance(s) not properly tagged: %v", len(ipAddrs), ipAddrs))
	}

	return checkers.Ok("OK")
}
func checkUptime() *checkers.Checker {
	opts := connectionOpts{}
	psr := flags.NewParser(&opts, flags.Default)
	_, err := psr.Parse()
	if err != nil {
		os.Exit(1)
	}

	db := mysql.New("tcp", "", fmt.Sprintf("%s:%s", opts.mysqlSetting.Host, opts.mysqlSetting.Port), opts.mysqlSetting.User, opts.mysqlSetting.Pass, "")
	err = db.Connect()
	if err != nil {
		return checkers.Critical("couldn't connect DB")
	}
	defer db.Close()

	rows, res, err := db.Query("SHOW GLOBAL STATUS LIKE 'Uptime'")
	if err != nil {
		return checkers.Critical("couldn't execute query")
	}

	idxValue := res.Map("Value")
	Uptime := rows[0].Int64(idxValue)

	if opts.Crit > 0 && Uptime < opts.Crit {
		return checkers.Critical(fmt.Sprintf("up %s < %s", uptime2str(Uptime), uptime2str(opts.Crit)))
	} else if opts.Warn > 0 && Uptime < opts.Warn {
		return checkers.Warning(fmt.Sprintf("up %s < %s", uptime2str(Uptime), uptime2str(opts.Warn)))
	}
	return checkers.Ok(fmt.Sprintf("up %s", uptime2str(Uptime)))
}
Esempio n. 3
0
func (opts *sshOpts) run() *checkers.Checker {
	// prevent changing output of some commands
	os.Setenv("LANG", "C")
	os.Setenv("LC_ALL", "C")

	config, err := opts.makeClientConfig()
	if err != nil {
		return checkers.Unknown(err.Error())
	}

	start := time.Now()
	client, err := opts.dial(config)
	if err != nil {
		if addrerr, ok := err.(*net.AddrError); ok {
			if addrerr.Timeout() {
				elapsed := time.Now().Sub(start)
				return opts.checkTimeoutError(elapsed, err)
			} else if addrerr.Temporary() {
				return checkers.Warning(err.Error())
			}
		}
		return checkers.Critical(err.Error())
	}
	session, err := client.NewSession()
	if err != nil {
		return checkers.Critical(err.Error())
	}
	err = session.Close()
	if err != nil {
		return checkers.Unknown(err.Error())
	}
	elapsed := time.Now().Sub(start)
	return opts.checkTimeout(elapsed)
}