-
Notifications
You must be signed in to change notification settings - Fork 31
/
main.go
51 lines (38 loc) · 1.48 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
flag "flag"
sync "sync"
config "github.com/chrusty/prometheus_webhook_snmptrapper/config"
snmptrapper "github.com/chrusty/prometheus_webhook_snmptrapper/snmptrapper"
types "github.com/chrusty/prometheus_webhook_snmptrapper/types"
webhook "github.com/chrusty/prometheus_webhook_snmptrapper/webhook"
logrus "github.com/Sirupsen/logrus"
)
var (
conf config.Config
log = logrus.WithFields(logrus.Fields{"logger": "main"})
waitGroup = &sync.WaitGroup{}
)
func init() {
// Process the command-line parameters:
flag.StringVar(&conf.SNMPTrapAddress, "snmptrapaddress", "127.0.0.1:162", "Address to send SNMP traps to")
flag.StringVar(&conf.SNMPCommunity, "snmpcommunity", "public", "SNMP community string")
flag.UintVar(&conf.SNMPRetries, "snmpretries", 1, "Number of times to retry sending SNMP traps")
flag.StringVar(&conf.WebhookAddress, "webhookaddress", "0.0.0.0:9099", "Address and port to listen for webhooks on")
flag.Parse()
// Set the log-level:
logrus.SetLevel(logrus.DebugLevel)
}
func main() {
// Make sure we wait for everything to complete before bailing out:
defer waitGroup.Wait()
// Prepare a channel of events (to feed the digester):
log.Info("Preparing the alerts channel")
alertsChannel := make(chan types.Alert)
// Prepare to have background GoRoutines running:
waitGroup.Add(1)
// Start webhook server:
go webhook.Run(conf, alertsChannel, waitGroup)
// Start the SNMP trapper:
go snmptrapper.Run(conf, alertsChannel, waitGroup)
}