Exemplo n.º 1
0
Arquivo: main.go Projeto: macb/notif
func main() {
	pagerkey := envflag.String("PAGERDUTY_KEY", "", "Pager API string")
	consulKV := envflag.String("CONSUL_KV_ADDR", "127.0.0.1:8500", "Address to consul to use for KV.")
	consulWatch := envflag.String("CONSUL_WATCH_ADDR", "127.0.0.1:8500", "Address to consul to use for watch.")
	bootstrap := envflag.Bool("NOTIF_BOOTSTRAP", false, "Starts the daemon in bootstrap mode. This prevents it from emitting any notifications and should be used to pre-populate the KV store with the current state of the world.")

	slackWebhook := envflag.String("SLACK_WEBHOOK_URL", "", "The webhook URL for slack.")
	slackUsername := envflag.String("SLACK_USERNAME", "notif", "The username for the slack webhook to be posted as.")
	slackChannel := envflag.String("SLACK_CHANNEL", "", "The channel for the slack webhook to be post to.")
	slackIcon := envflag.String("SLACK_ICON", "", "The icon to use when posting the slack webhook.")

	envflag.Parse()

	logrus.SetLevel(logrus.DebugLevel)
	logrus.SetFormatter(&logrus.JSONFormatter{})

	drain := make(chan *consulapi.HealthCheck)

	var pager notif.Notifier
	if *bootstrap {
		pager = &notif.NoopNotifier{}
	} else if *pagerkey != "" {
		pager = notif.NewPager(*pagerkey, nil)
	} else if *slackWebhook != "" {
		pager = notif.NewSlackNotifier(*slackUsername, *slackWebhook, *slackIcon, *slackChannel)
	} else {
		pager = &notif.PrintNotifier{}
	}

	w, err := notif.NewWatcher(*consulWatch, "checks", drain)
	if err != nil {
		logrus.WithFields(logrus.Fields{"err": err}).Error("faild to build watcher")
	}

	go w.Run()

	config := *consulapi.DefaultConfig()
	config.Address = *consulKV
	cc, err := consulapi.NewClient(&config)
	if err != nil {
		panic(err)
	}
	p := notif.NewProcessor(drain, pager, cc)
	p.Run()
}
Exemplo n.º 2
0
	"github.com/lgtmco/lgtm/router/middleware"

	"github.com/Sirupsen/logrus"
	"github.com/gin-gonic/contrib/ginrus"
	"github.com/ianschenck/envflag"
	_ "github.com/joho/godotenv/autoload"

	_ "github.com/lgtmco/lgtm/approval/org"
)

var (
	addr = envflag.String("SERVER_ADDR", ":8000", "")
	cert = envflag.String("SERVER_CERT", "", "")
	key  = envflag.String("SERVER_KEY", "", "")

	debug = envflag.Bool("DEBUG", false, "")
)

func main() {
	envflag.Parse()

	if *debug {
		logrus.SetLevel(logrus.DebugLevel)
	} else {
		logrus.SetLevel(logrus.WarnLevel)
	}

	handler := router.Load(
		ginrus.Ginrus(logrus.StandardLogger(), time.RFC3339, true),
		middleware.Version,
		middleware.Store(),
Exemplo n.º 3
0
	DoMerge         bool   `json:"do_merge" toml:"do_merge"`
	DoVersion       bool   `json:"do_version" toml:"do_version"`
	ApprovalAlg     string `json:"approval_algorithm" toml:"approval_algorithm"`
	VersionAlg      string `json:"version_algorithm" toml:"version_algorithm"`
	VersionFormat   string `json:"version_format" toml:"version_format"`
	DoComment       bool   `json:"do_comment" toml:"do_comment"`
	DoDeployment    bool   `json:"do_deploy" toml:"do_deploy"`
	DeploymentMap   DeploymentConfigs
	re              *regexp.Regexp
}

var (
	approvals       = envflag.Int("LGTM_APPROVALS", 2, "")
	pattern         = envflag.String("LGTM_PATTERN", `(?i)^LGTM\s*(\S*)`, "")
	team            = envflag.String("LGTM_TEAM", "MAINTAINERS", "")
	selfApprovalOff = envflag.Bool("LGTM_SELF_APPROVAL_OFF", false, "")
	approvalAlg     = envflag.String("LGTM_APPROVAL_ALGORITHM", "simple", "")
	versionAlg      = envflag.String("LGTM_VERSION_ALGORITHM", "semver", "")
)

// ParseConfig parses a projects .lgtm file
func ParseConfig(configData []byte, deployData []byte) (*Config, error) {
	c, err := ParseConfigStr(string(configData))
	if err != nil {
		return nil, err
	}
	if c.DoDeployment {
		c.DeploymentMap, err = loadDeploymentMap(string(deployData))
	}
	if err != nil {
		return nil, err