Beispiel #1
0
func main() {
	flag.Parse()
	haproxy := new(haproxyctl.HaProxy)

	if len(*f) > 0 {
		haproxy.Loadenv(*f)
	} else {
		haproxy.Loadenv("/etc/haproxy/haproxy.cfg")
	}

	if len(*binding) > 0 && len(*client) > 0 {
		http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
			handler(w, r, haproxy, *client)
		})
		http.ListenAndServe(*binding, nil)
	}

	if *configcheck {
		haproxy.Configcheck()
	}

	if len(*action) > 0 {
		switch *action {
		case "socketexec":
			res := haproxy.Exec(*execution)
			for _, r := range res {
				fmt.Print(r)
			}
		case "showstatus":
			res := haproxy.Showstatus()
			fmt.Print(res)
		case "showbackend":
			res := haproxy.ShowRegexp("BACKEND")
			fmt.Print(res)
		case "showhealth":
			res := haproxy.Showhealth()
			fmt.Print(res)
		case "showregexp":
			res := haproxy.ShowRegexp(*execution)
			fmt.Print(res)
		case "enable":
			en := strings.Split(*execution, "/")
			res := haproxy.EnableServer(en[0], en[1])
			fmt.Printf(res)
		case "enableall":
			haproxy.EnableAll(*execution)
		case "disable":
			dis := strings.Split(*execution, "/")
			res := haproxy.DisableServer(dis[0], dis[1])
			fmt.Printf(res)
		case "disableall":
			haproxy.DisableAll(*execution)
		default:
			flag.PrintDefaults()
		}
	}
}