in tools/amGithubNotifier/main.go [49:98]
func main() {
/*
Example `alerts.rules.yml`:
```
groups:
- name: groupname
rules:
- alert: alertname
expr: up == 0
labels:
severity: info
prNum: '{{ $labels.prNum }}'
org: prometheus
repo: prombench
annotations:
description: 'description of the alert'
```
*/
log.SetFlags(log.Ltime | log.Lshortfile)
cfg := ghWebhookReceiverConfig{}
app := kingpin.New(filepath.Base(os.Args[0]), `alertmanager github webhook receiver
Example: ./amGithubNotifier --org=prometheus --repo=prometheus --port=8080
Note: All alerts sent to amGithubNotifier must have the prNum label and description
annotation, org and repo labels are optional but will take precedence over cli args
if provided.
`)
app.Flag("authfile", "path to github oauth token file").Default("/etc/github/oauth").StringVar(&cfg.authFile)
app.Flag("org", "name of the org").Required().StringVar(&cfg.org)
app.Flag("repo", "name of the repo").Required().StringVar(&cfg.repo)
app.Flag("port", "port number to run the server in").Default("8080").StringVar(&cfg.portNo)
app.Flag("dryrun", "dry run for github api").BoolVar(&cfg.dryRun)
kingpin.MustParse(app.Parse(os.Args[1:]))
client, err := newGhWebhookReceiver(cfg)
if err != nil {
log.Fatalf("failed to create GitHub Webhook Receiver client: %v", err)
}
hl := ghWebhookHandler{client}
http.Handle("/hook", hl)
log.Printf("finished setting up gh client. starting amGithubNotifier with %v/%v",
client.cfg.org, client.cfg.repo)
err = http.ListenAndServe(fmt.Sprintf(":%v", client.cfg.portNo), nil)
if err != nil {
log.Fatal("amGithubNotifier exited unexpectedly")
}
}