示例#1
0
func main() {
	var (
		warn int
		crit int
	)

	c := check.New("CheckMemory")
	c.Option.IntVarP(&warn, "warn", "w", 80, "WARN")
	c.Option.IntVarP(&crit, "crit", "c", 90, "CRIT")
	c.Init()

	usage, err := memoryUsage()
	if err != nil {
		c.Error(err)
	}

	switch {
	case usage >= float64(crit):
		c.Critical(fmt.Sprintf("%.0f%%", usage))
	case usage >= float64(warn):
		c.Warning(fmt.Sprintf("%.0f%%", usage))
	default:
		c.Ok(fmt.Sprintf("%.0f%%", usage))
	}
}
func main() {
	var (
		host    string
		port    int
		timeout int
	)

	c := check.New("CheckElasticsearch")
	c.Option.StringVarP(&host, "host", "h", "localhost", "HOST")
	c.Option.IntVarP(&port, "port", "P", 9200, "PORT")
	c.Option.IntVarP(&timeout, "timeout", "t", 30, "TIMEOUT")
	c.Init()

	status, err := healthStatus(host, port, timeout)
	if err != nil {
		c.Error(err)
	}

	switch status {
	case "green":
		c.Ok("Cluster is green")
	case "yellow":
		c.Warning("Cluster is yellow")
	case "red":
		c.Critical("Cluster is red")
	}
}
func main() {
	var (
		host     string
		port     int
		vhost    string
		user     string
		password string
		timeout  int
	)

	c := check.New("CheckRabbitMQ")
	c.Option.StringVarP(&host, "host", "h", "localhost", "HOST")
	c.Option.IntVarP(&port, "port", "P", 15672, "PORT")
	c.Option.StringVarP(&vhost, "vhost", "v", "%2F", "VHOST")
	c.Option.StringVarP(&user, "user", "u", "guest", "USER")
	c.Option.StringVarP(&password, "password", "p", "guest", "PASSWORD")
	c.Option.IntVarP(&timeout, "timeout", "t", 10, "TIMEOUT")
	c.Init()

	status, err := alivenessTest(host, port, vhost, user, password, timeout)
	if err != nil {
		c.Error(err)
	}

	switch status {
	case "ok":
		c.Ok("RabbitMQ server is alive")
	default:
		c.Warning("Object Not Found")
	}
}
示例#4
0
func main() {
	var (
		url      string
		redirect bool
		timeout  int
	)

	c := check.New("CheckHTTP")
	c.Option.StringVarP(&url, "url", "u", "http://localhost/", "URL")
	c.Option.BoolVarP(&redirect, "redirect", "r", false, "REDIRECT")
	c.Option.IntVarP(&timeout, "timeout", "t", 15, "TIMEOUT")
	c.Init()

	status, err := statusCode(url, timeout)
	if err != nil {
		c.Error(err)
	}

	switch {
	case status >= 400:
		c.Critical(strconv.Itoa(status))
	case status >= 300 && redirect:
		c.Ok(strconv.Itoa(status))
	case status >= 300:
		c.Warning(strconv.Itoa(status))
	default:
		c.Ok(strconv.Itoa(status))
	}
}
示例#5
0
func main() {
	var (
		path string
		warn int
		crit int
	)

	c := check.New("CheckPostfix")
	c.Option.StringVarP(&path, "path", "p", "/usr/bin/mailq", "PATH")
	c.Option.IntVarP(&warn, "warn", "w", 5, "WARN")
	c.Option.IntVarP(&crit, "crit", "c", 10, "CRIT")
	c.Init()

	queue, err := mailQueue(path)
	if err != nil {
		c.Error(err)
	}

	switch {
	case queue > crit:
		c.Critical(fmt.Sprintf("%d messages in the postfix mail queue\n", queue))
	case queue > warn:
		c.Warning(fmt.Sprintf("%d messages in the postfix mail queue\n", queue))
	default:
		c.Ok(fmt.Sprintf("%d messages in the postfix mail queue\n", queue))
	}
}
示例#6
0
func main() {
	var (
		warn    int
		crit    int
		warnMnt []string
		critMnt []string
	)

	c := check.New("CheckDisk")
	c.Option.IntVarP(&warn, "warn", "w", 80, "WARN")
	c.Option.IntVarP(&crit, "crit", "c", 100, "CRIT")
	c.Init()

	usage, err := diskUsage()
	if err != nil {
		c.Error(err)
	}

	for _, u := range usage {
		cap, err := strconv.ParseInt(strings.TrimRight(u[1], "%"), 10, 64)
		if err != nil {
			c.Error(err)
		}

		switch {
		case cap >= int64(crit):
			critMnt = append(critMnt, u[0]+" "+u[1])
		case cap >= int64(warn):
			warnMnt = append(warnMnt, u[0]+" "+u[1])
		}
	}

	switch {
	case len(critMnt) > 0:
		c.Critical(strings.Join(critMnt, ", "))
	case len(warnMnt) > 0:
		c.Warning(strings.Join(warnMnt, ", "))
	default:
		c.Ok("OK")
	}
}
示例#7
0
func main() {
	var (
		host    string
		port    int
		timeout int64
	)

	c := check.New("CheckPing")
	c.Option.StringVarP(&host, "host", "h", "localhost", "HOST")
	c.Option.IntVarP(&port, "port", "P", 22, "PORT")
	c.Option.Int64VarP(&timeout, "timeout", "t", 5, "TIMEOUT")
	c.Init()

	address := host + ":" + strconv.Itoa(port)
	conn, err := net.DialTimeout("tcp", address, time.Duration(timeout)*time.Second)

	if err != nil {
		c.Error(err)
	}
	defer conn.Close()

	c.Ok(address)
}
func main() {
	var (
		host     string
		port     int
		database string
		user     string
		password string
	)

	c := check.New("CheckPostgres")
	c.Option.StringVarP(&host, "host", "h", "localhost", "HOST")
	c.Option.IntVarP(&port, "port", "P", 5432, "PORT")
	c.Option.StringVarP(&user, "user", "u", "", "USER")
	c.Option.StringVarP(&password, "password", "p", "", "PASSWORD")
	c.Option.StringVarP(&database, "database", "d", "test", "DATABASE")
	c.Init()

	version, err := selectVersion(host, port, user, password, database)
	if err != nil {
		c.Error(err)
	}

	c.Ok(fmt.Sprint("Server version ", version))
}