Esempio n. 1
0
func NewWebhooksAlerter(cfg config.Config) Alerter {
	goreq.SetConnectTimeout(5 * time.Second)
	var q = make(chan webhook, 100)
	var w = webhooksAlerter{cmds: q}
	go w.Worker(q)
	return &w
}
Esempio n. 2
0
// buildCommonRequestProps is an internal method to set common properties of requests that will send to OpsGenie.
func (cli *OpsGenieClient) buildCommonRequestProps() goreq.Request {
	if cli.httpTransportSettings == nil {
		cli.makeHTTPTransportSettings()
	}
	goreq.SetConnectTimeout(cli.httpTransportSettings.ConnectionTimeout)
	req := goreq.Request{}
	if cli.proxy != nil {
		req.Proxy = cli.proxy.toString()
	}
	req.UserAgent = userAgentParam.ToString()
	req.Timeout = cli.httpTransportSettings.RequestTimeout
	req.Insecure = true

	return req
}
Esempio n. 3
0
func NewSlackhookAlerter(cfg config.Config) Alerter {

	tmpl := cfg.Slackhook.Template

	t, err := template.New("template").Parse(tmpl)
	if err != nil {
		log.Fatalf("skipping slackhook:error trying to parse slackhook template:%s:err:%v:", tmpl, err)
	}

	goreq.SetConnectTimeout(5 * time.Second)
	var q = make(chan slackhook, 100)
	var w = slackhookAlerter{cmds: q, template: t}
	go w.Worker(q, &cfg.Slackhook)
	return &w
}
Esempio n. 4
0
func main() {
	for _, proxy := range proxys {
		res, err := goreq.Request{
			Uri:       "http://www.baidu.com/",
			UserAgent: "Cyeambot",
			Proxy:     proxy,
			Timeout:   5 * time.Second,
		}.Do()
		goreq.SetConnectTimeout(5 * time.Second)
		if err != nil || res.Body == nil {
			log.Printf("%s fail.\n", proxy)
		} else {
			log.Printf("%s success.\n", proxy)
		}
	}
}
Esempio n. 5
0
func (p *HttpProbe) Start() {
	go func() {
		//TODO: need to do a better job figuring out if the target app is ready to accept connections
		time.Sleep(4 * time.Second)

		log.Info("docker-slim: HTTP probe started...")
		goreq.SetConnectTimeout(10 * time.Second)

		for _, port := range p.Ports {
			for _, cmd := range p.Cmds {
				var protocols []string
				if cmd.Protocol == "" {
					protocols = []string{"http", "https"}
				} else {
					protocols = []string{cmd.Protocol}
				}

				for _, proto := range protocols {
					addr := fmt.Sprintf("%s://%v:%v%v", proto, p.ContainerInspector.DockerHostIP, port, cmd.Resource)
					res, err := goreq.Request{
						Method:  cmd.Method,
						Uri:     addr,
						Body:    cmd.Body,
						Timeout: 5 * time.Second,
						//ShowDebug: true,
					}.Do()

					if err == nil {
						log.Infof("docker-slim: http probe - %v %v => %v\n", cmd.Method, addr, res.StatusCode)
						break
					}

					log.Infof("docker-slim: http probe - %v %v error: %v\n", cmd.Method, addr, err)
				}
			}
		}

		log.Info("docker-slim: HTTP probe done.")
		close(p.doneChan)
	}()
}
Esempio n. 6
0
func (p *HttpProbe) Start() {
	go func(hpHost string, hpPorts []string) {
		//TODO: need to do a better job figuring out if the target app is ready to accept connections
		time.Sleep(3 * time.Second)

		log.Info("docker-slim: HTTP probe started...")
		goreq.SetConnectTimeout(3 * time.Second)

		//very primitive http probe...
		for _, port := range hpPorts {
			httpAddr := fmt.Sprintf("http://%v:%v", hpHost, port)
			hpResHTTP, err := goreq.Request{
				Uri:     httpAddr,
				Timeout: 5 * time.Second,
				//ShowDebug: true,
			}.Do()
			if err != nil {
				log.Infof("docker-slim: http proble - GET %v error: %v\n", httpAddr, err)

				httpsAddr := fmt.Sprintf("https://%v:%v", hpHost, port)
				hpResHTTPS, err := goreq.Request{
					Uri:      httpAddr,
					Insecure: true,
					Timeout:  5 * time.Second,
					//ShowDebug: true,
				}.Do()
				if err != nil {
					log.Infof("docker-slim: http proble - GET %v error: %v\n", httpsAddr, err)
				} else {
					log.Infof("docker-slim: http proble - GET %v %v\n", httpsAddr, hpResHTTPS.StatusCode)
				}
			} else {
				log.Infof("docker-slim: http proble - GET %v %v\n", httpAddr, hpResHTTP.StatusCode)
			}
		}

		log.Info("docker-slim: HTTP probe done.")
	}(p.ContainerInspector.DockerHostIP, p.Ports)
}
Esempio n. 7
0
func GetBingDesktop(path string, idx int, n int) error {
	goreq.SetConnectTimeout(1 * time.Minute)
	// Create HTTP GET request
	resp, err := goreq.Request{
		Uri: "http://www.bing.com/HPImageArchive.aspx",
		QueryString: BingRequest{
			Format: "js",
			Index:  idx,
			Number: n,
			Mkt:    "en-US",
		},
		UserAgent: "GoSiMac",
	}.Do()
	if err != nil {
		glog.Errorf("Net.HTTP: %v\n", err)
		return err
	}

	defer resp.Body.Close()

	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		fmt.Errorf("IO.IOUtil: %v\n", err)
	}
	var bing_resp BingResponse
	json.Unmarshal(body, &bing_resp)

	// Create spreate thread for each image
	for _, image := range bing_resp.Images {
		w.Add(1)
		go getBingImage(path, image)
	}

	// Waiting for getting all the images
	w.Wait()

	return nil
}
Esempio n. 8
0
// UpAndRunning2 Main - The application's entrance-point
func main() {
	// Logger
	lib.SetupLogger()

	// Welcome
	logging.MustGetLogger("").Info("Welcome to UpAndRunning2 v" + VERSION + " [" + goVersion + "@" + goArch + "]!")

	// Config
	lib.ReadConfigurationFromFile("config/local.json")
	lib.SetStaticConfiguration(lib.StaticConfiguration{VERSION, goVersion, goArch})

	// Database
	lib.OpenDatabase(lib.GetConfiguration().Database)

	// Config (again)
	lib.ReadConfigurationFromDatabase(lib.GetDatabase())

	// Admin-User
	admin := lib.Admin{}
	admin.Init()

	// Session-Management
	lib.InitSessionManagement()

	// Additional Libraries
	goreq.SetConnectTimeout(5 * time.Second)
	lib.InitHttpStatusCodeMap()
	go lib.RunTelegramBot()

	// Start Checking and Serving
	checkAllSites()
	startCheckTimer()
	startCleaningTimer()
	serveRequests()

	lib.GetDatabase().Close()
}
Esempio n. 9
0
// 1. POST JSON of auth to https://hub.docker.com/v2/users/login/, get back `{"token": "<whatever it is>"}`
// (? maybe not neccesary) 2. POST JSON of token to https://hub.docker.com/attempt-login/ as `{"jwt": "whatever it is"}` to get back JWT cookie
func createWebAuth(auth *Auth) (wa *webAuth, err error) {
	jar, err := cookiejar.New(nil)
	if err != nil {
		return nil, err
	}
	wa = &webAuth{jar: jar}
	goreq.SetConnectTimeout(10 * time.Second)
	log.WithFields(log.Fields{
		"auth": auth,
	}).Debug("Logging into DockerHub")
	var resJSON struct {
		Token string `json:"token"`
	}
	res, err := wa.callAPI("v2/users/login/", "POST", auth, 200, &resJSON)
	if err != nil {
		return nil, wrapError(err, "login")
	}
	if resJSON.Token == "" {
		return nil, fmt.Errorf("Didnt get a token back from the login")
	}
	wa.token = resJSON.Token
	if err = res.Body.Close(); err != nil {
		return nil, wrapError(err, "closing body of POST login")
	}

	log.WithFields(log.Fields{}).Debug("Posting login back in to get cookie")
	res, err = wa.callAPI("attempt-login/", "POST", struct {
		Jwt string `json:"jwt"`
	}{wa.token}, 200, nil)
	if err != nil {
		return nil, wrapError(err, "login")
	}
	if err = res.Body.Close(); err != nil {
		return nil, wrapError(err, "closing body of POST attempt-login")
	}
	return
}
Esempio n. 10
0
func setup() {
	goreq.SetConnectTimeout(15 * time.Second)
	SetRootPath("tmp")
	must(Setup())
}
Esempio n. 11
0
File: hn.go Progetto: dpzaba/cbot
func init() {
	goreq.SetConnectTimeout(10 * time.Second)
	flag.Parse()
}
Esempio n. 12
0
func init() {
	goreq.SetConnectTimeout(15 * time.Second)
	goreq.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{RootCAs: getCACerts()}
}
func (cli *OpsGenieIntegrationClient) SetConnectionTimeout(timeoutInSeconds time.Duration) {
	goreq.SetConnectTimeout(timeoutInSeconds * time.Second)
}