示例#1
0
func TestAgentGetError(t *testing.T) {
	value, err := zabbix.Get("localhost", "xxx", timeout)
	if err != nil {
		t.Error("xxx failed", err)
	}
	if value != zabbix.ErrorMessage {
		t.Error("xxx value expected: ", zabbix.ErrorMessage, "got:", value)
	}
}
示例#2
0
func TestAgentGetUptime(t *testing.T) {
	value, err := zabbix.Get("localhost", "agent.uptime", timeout)
	if err != nil {
		t.Error("get agent.ping failed", err)
	}
	if value != "123" {
		t.Error("agent.uptime value expected: 123, got:", value)
	}
}
示例#3
0
func TestAgentGetTimeout(t *testing.T) {
	_, err := zabbix.Get("localhost", "timeout", timeout)
	if err == nil {
		t.Error("timeout must be timeouted.", err)
	}
	if _err := err.(*net.OpError); !_err.Timeout() {
		t.Error("err expected i/o timeout. got:", err)
	}
	log.Println("client timeout")
}
示例#4
0
func main() {
	var (
		port        int
		server      string
		key         string
		timeout     int
		showVersion bool
		format      string
		outputKey   string
	)
	flag.IntVar(&port, "p", 10050, "port")
	flag.StringVar(&server, "s", "127.0.0.1", "hostname or IP")
	flag.StringVar(&key, "k", "", "key")
	flag.IntVar(&timeout, "t", 30, "timeout")
	flag.BoolVar(&showVersion, "V", false, "show Version")
	flag.StringVar(&format, "f", "zabbix", "output format (zabbix or sensu)")
	flag.StringVar(&outputKey, "o", "", "output key string (format=sensu only)")
	flag.Parse()

	if showVersion {
		fmt.Printf("go-zabbix-get version %s\n", Version)
		os.Exit(255)
	}

	if key == "" {
		flag.PrintDefaults()
		os.Exit(255)
	}

	address := fmt.Sprintf("%s:%d", server, port)
	value, err := zabbix.Get(address, key, time.Duration(timeout)*time.Second)
	if err != nil {
		log.Fatalf("error: %s", err)
	}

	switch format {
	case "sensu":
		if outputKey == "" {
			printFormatSensu(key, value)
		} else {
			printFormatSensu(outputKey, value)
		}
	default:
		printFormatZabbix(value)
	}
}
示例#5
0
func TestAgentShutdown(t *testing.T) {
	zabbix.Get("localhost", "shutdown", timeout)
	<-done
}
示例#6
0
func TestAgentCannotConnect(t *testing.T) {
	value, err := zabbix.Get("localhost:10049", "agent.ping", timeout)
	if err == nil {
		t.Errorf("agent is not runnig, but not error value:", value)
	}
}