func main() {
	log.Print("Starting sendgrid webhook endpoint...")

	statsdHost := flag.String("statsd_host", "127.0.0.1:8125", "")
	statsdClientName := flag.String("client_name", "sendgrid", "")

	conf, err := globalconf.New("sendgridstatsd")
	conf.ParseAll()

	log.Printf("Sending to statdsd host: %+v", *statsdHost)

	// first create a client
	client, err := statsd.New(*statsdHost, *statsdClientName)
	// handle any errors
	if err != nil {
		log.Fatal(err)
	}
	// make sure to clean up
	defer client.Close()

	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		handler(w, r, client)
	})

	log.Print("done\n")
	http.ListenAndServe(":9090", nil)
}
Example #2
0
File: main.go Project: deuill/sigil
func setup(name string) error {
	var (
		conf *globalconf.GlobalConf
		file string
		err  error
	)

	// Check for environment variable override, and return error if override is set but file is
	// inaccessible. Otherwise, try for the default global location (in the "/etc" directory).
	if file := os.Getenv(strings.ToUpper(name) + "_CONFIG"); file != "" {
		if _, err = os.Stat(file); err != nil {
			return err
		}
	} else {
		file = "/etc/" + name + "/" + name + ".conf"
		if _, err = os.Stat(file); err != nil {
			file = ""
		}
	}

	// Load from specific configuration file if set, or use local configuration file as a fallback.
	if file != "" {
		options := &globalconf.Options{Filename: file, EnvPrefix: ""}
		if conf, err = globalconf.NewWithOptions(options); err != nil {
			return err
		}
	} else if conf, err = globalconf.New(name); err != nil {
		return err
	}

	conf.EnvPrefix = strings.ToUpper(name) + "_"
	conf.ParseAll()

	return nil
}
Example #3
0
func NewChallenge(name string) Challenge {
	cfg, err := globalconf.New(name)
	if err != nil {
		log.Fatal(err)
	}

	c := Challenge{
		Name:         name,
		conf:         cfg,
		CurrentLevel: flag.String("level", IndexToID(0, name), "Current Level"),
	}
	return c
}
Example #4
0
func init() {
	// ホームディレクトリ以下の設定を読み込む
	conf, err := globalconf.New("twstream")
	if err != nil {
		log.Fatalf("Can't load config: %s", err)
	}
	conf.ParseAll()

	// タイムアウトの値をtime.Durationに変換する
	timeout, err = time.ParseDuration(*timeoutString)
	if err != nil {
		log.Fatalf("Can't parse timeout(%s) :%s", *timeoutString, err)
	}
}
Example #5
0
func configureInstainerClient(apikey string) {
	conf, err := globalconf.New("instainer")
	conf.ParseAll()
	if err != nil {
		fmt.Printf("%s", err)
		os.Exit(1)
	}

	f := &flag.Flag{Name: "apikey", Value: newFlagValue(apikey)}
	conf.Set("", f)
	conf.ParseAll()

	instainerGet("/instainer-cli")

}
Example #6
0
func main() {

	conf, err := globalconf.New(appName)
	if err != nil {
		log.Fatal(err)
	}
	conf.ParseAll()

	if *flagStdout == false {
		logwriter, err := syslog.New(syslog.LOG_NOTICE, appName)
		if err == nil {
			log.SetOutput(logwriter)
		}
	}

	db, err := bolt.Open(*flagDB, 0600, &bolt.Options{Timeout: 1 * time.Second})
	if err != nil {
		log.Fatal(err)
	}
	defer db.Close()

	if *flagSetIP != "" {
		if err := addresses.DBinit(db); err != nil {
			log.Fatal(err)
		}
		splited := strings.Split(*flagSetIP, ":")
		if len(splited) < 3 {
			log.Fatal("ID:Link:CIDR required")
		}
		id, link, ip := splited[0], splited[1], splited[2]
		addresses.CommandSetIP(id, link, ip)
		os.Exit(0)
	}

	api := rest.NewApi()

	router, err := rest.MakeRouter(
		&rest.Route{"GET", "/interfaces", interfaces.GetIfaces},
		&rest.Route{"GET", "/interfaces/:iface", interfaces.GetIface},

		&rest.Route{"GET", "/addresses", addresses.GetAddresses},
		&rest.Route{"POST", "/addresses", addresses.PostAddress},
		&rest.Route{"GET", "/addresses/:address", addresses.GetAddress},
		&rest.Route{"PUT", "/addresses/:address", addresses.PutAddress},
		&rest.Route{"DELETE", "/addresses/:address", addresses.DeleteAddress},

		&rest.Route{"GET", "/dhcp", dhcp.GetDhcp},
		&rest.Route{"POST", "/dhcp", dhcp.PostDhcp},

		&rest.Route{"GET", "/dns", dns.GetDNS},
		&rest.Route{"POST", "/dns", dns.PostDNS},

		&rest.Route{"GET", "/routes", getRoutes},
		&rest.Route{"POST", "/routes/gateway", gateway.PostGateway},
		&rest.Route{"GET", "/routes/gateway", gateway.GetGateway},
	)
	if err != nil {
		log.Fatal(err)
	}

	api.SetApp(router)

	var network string
	if _, err = net.ResolveTCPAddr("tcp", *flagBind); err == nil {
		network = "tcp"
	} else {
		network = "unix"
	}
	ln, err = net.Listen(network, *flagBind)
	if nil != err {
		log.Fatal(err)
	}
	defer ln.Close()

	if *flagOwner != "" && network == "unix" {
		user, err := user.Lookup(*flagOwner)
		if err != nil {
			log.Fatal(err)
		}
		uid, err := strconv.Atoi(user.Uid)
		var gid int
		if *flagGroup != -1 {
			gid = *flagGroup
		} else {
			gid, err = strconv.Atoi(user.Gid)
		}
		if err := os.Chown(*flagBind, uid, gid); err != nil {
			log.Fatal(err)
		}
		if err := os.Chmod(*flagBind, 0660); err != nil {
			log.Fatal(err)
		}
	}

	if err := dhcp.DBinit(db); err != nil {
		log.Fatal(err)
	}
	if err := addresses.DBinit(db); err != nil {
		log.Fatal(err)
	}
	if err := dns.DBinit(db); err != nil {
		log.Fatal(err)
	}
	if err := gateway.DBinit(db); err != nil {
		log.Fatal(err)
	}

	// Handle common process-killing signals so we can gracefully shut down:
	sigc := make(chan os.Signal, 1)
	signal.Notify(sigc, os.Interrupt, os.Kill, syscall.SIGTERM)
	go func(c chan os.Signal) {
		// Wait for a SIGINT or SIGKILL:
		sig := <-c
		log.Printf("Caught signal %s: shutting down.", sig)
		// Stop listening (and unlink the socket if unix type):
		ln.Close()
		db.Close()
		os.Exit(0)
	}(sigc)

	log.Printf("Now listening to bind %s", *flagBind)
	log.Fatal(http.Serve(ln, api.MakeHandler()))
}
Example #7
0
File: myqt.go Project: wfd3/myq
func main() {
	var m myq.MyQ
	var d myq.Device
	var err error
	var username, password string
	var debug, machine_parsable bool
	var conf *globalconf.GlobalConf

	flag.Usage = usage

	flag.StringVar(&username, "user", "", "Username")
	flag.StringVar(&password, "password", "", "Password")
	flag.BoolVar(&debug, "D", false, "Debugging enabled")
	flag.BoolVar(&machine_parsable, "M", false, "Machine parsable output")

	flag.Parse()
	if flag.NArg() < 1 {
		fmt.Println("No command(s)")
		usage()
		os.Exit(0)
	}

	if flag.Arg(0) == "help" {
		usage()
		os.Exit(0)
	}

	// read confg
	if conf, err = globalconf.New("myqt"); err != nil {
		fmt.Printf("Error: %s\n", err)
		os.Exit(1)
	}
	conf.ParseAll()

	if err := m.New(username, password, debug, machine_parsable); err != nil {
		fmt.Printf("Error: %s\n", err)
		os.Exit(1)
	}

	command := flag.Arg(0)
	door := flag.Arg(1)
	switch command {
	case "help":
		usage()
	case "state":
		if d, err = m.FindDoorByName(door); err != nil {
			fmt.Printf("Error: %s\n", err)
			os.Exit(1)
		}
		m.GetState(d)
	case "details":
		if d, err = m.FindDoorByName(door); err != nil {
			fmt.Printf("Error: %s\n", err)
			os.Exit(1)
		}
		m.DoorDetails(d)
	case "open":
		if d, err = m.FindDoorByName(door); err != nil {
			fmt.Printf("Error: %s\n", err)
			os.Exit(1)
		}
		if err = m.Open(d); err != nil {
			fmt.Printf("Error: %s\n", err)
			os.Exit(1)
		}
	case "close":
		if d, err = m.FindDoorByName(door); err != nil {
			fmt.Printf("Error: %s\n", err)
			os.Exit(1)
		}
		if err = m.Close(d); err != nil {
			fmt.Printf("Error: %s\n", err)
			os.Exit(1)
		}
	case "list":
		m.ShowDoors()
	case "locations":
		m.ShowLocations()
	case "listopen":
		m.ShowByState("Open")
	case "listclosed":
		m.ShowByState("Closed")
	default:
		fmt.Printf("unknown command '%s'\n", command)
		os.Exit(1)
	}
}
Example #8
0
func main() {
	conf, err := globalconf.New("instainer")
	conf.ParseAll()
	if err != nil {
		fmt.Printf("%s", err)
		os.Exit(1)
	}

	app := cli.NewApp()
	app.Name = "instainer-cli"
	app.Usage = "Instant Docker containers on the cloud"
	app.Version = "1.0.0"

	app.Commands = []cli.Command{
		{
			Name:  "config",
			Usage: "Configure instainer client",
			Action: func(c *cli.Context) {
				if len(c.Args()) == 0 {
					fmt.Println("Please enter a valid API key")
					os.Exit(1)
				}
				configureInstainerClient(c.Args()[0])
			},
		},
		{
			Name:  "run",
			Usage: "Run a container",

			Flags: []cli.Flag{
				cli.StringSliceFlag{
					Name:  "volume,v",
					Usage: "volume to mount",
				},
				cli.StringSliceFlag{
					Name:  "env,e",
					Usage: "environment variable to add",
				},
			},
			Action: func(c *cli.Context) {
				createContainer(c.Args()[0], c.StringSlice("volume"), c.StringSlice("env"))
			},
		},
		{
			Name:  "bash",
			Usage: "Bash into container",
			Action: func(c *cli.Context) {
				bashContainer(c.Args()[0])
			},
		},
		{
			Name:  "ps",
			Usage: "List containers",
			Action: func(c *cli.Context) {
				listContainers()
			},
		},
		{
			Name:  "exec",
			Usage: "Exec into container",
			Action: func(c *cli.Context) {
				execCommand(c.Args()[0], c.Args()[1])
			},
		},
		{
			Name:  "logs",
			Usage: "Get logs from container",
			Action: func(c *cli.Context) {
				getLogs(c.Args()[0])
			},
		},
		{
			Name:  "compose",
			Usage: "Up compose file",
			Subcommands: []cli.Command{
				{
					Name:  "up",
					Usage: "up new docker-compose file",
					Action: func(c *cli.Context) {
						upCompose(c.Args().First())
					},
				},
			},
		},
	}
	app.Run(os.Args)
}