-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.go
52 lines (49 loc) · 1.15 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
52
package main
import (
"context"
"flag"
"github.com/bangunindo/trap2json/logger"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"os"
"path"
)
const defaultConfigPath = "/etc/trap2json"
func main() {
configPath := flag.String(
"config",
path.Join(defaultConfigPath, "config.yml"),
"path to config file",
)
snmptrapdConfPath := flag.String(
"generate",
"",
"generate snmptrapd.conf",
)
flag.Parse()
logger.InitLogger(logger.Config{
Level: zerolog.InfoLevel,
Format: logger.FormatConsole,
}, os.Stderr)
c, err := parseConfig(*configPath)
if err != nil {
log.Fatal().
Str("module", "config").
Err(err).
Msg("failed reading environment/configuration file")
}
logger.InitLogger(c.Logger, os.Stderr)
if *snmptrapdConfPath != "" {
log.Info().Str("module", "generate").Msg("generating snmptrapd.conf file")
if err = c.SnmpTrapD.Serialize(*snmptrapdConfPath); err != nil {
log.Fatal().
Str("module", "generate").
Err(err).
Msg("failed generating snmptrapd.conf file")
}
} else {
log.Info().Msg("starting trap2json")
Run(context.Background(), c, os.Stdin, false)
log.Info().Msg("trap2json exited")
}
}