-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaws-events.go
82 lines (62 loc) · 1.74 KB
/
aws-events.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package main
import (
"flag"
"os"
ledisdbConfig "github.com/siddontang/ledisdb/config"
"github.com/siddontang/ledisdb/ledis"
log "github.com/sirupsen/logrus"
)
// var myFlags arrayFlags
var (
application = &app{}
regionListFlags regionArrayFromFlags
configPath = ""
)
// var application = &app{}
func init() {
application.loadConfig()
cfg := ledisdbConfig.NewConfigDefault()
cfg.DataDir = application.Config.Ledis.Path
cfg.Databases = 1
l, _ := ledis.Open(cfg)
db, _ := l.Select(0)
application.DB = db
// Log as JSON instead of the default ASCII formatter.
log.SetFormatter(&log.TextFormatter{})
// Output to stdout instead of the default stderr
// Can be any io.Writer, see below for File example
log.SetOutput(os.Stdout)
}
func main() {
log.Info("Starting event alerter")
flag.Var(®ionListFlags, "region", "Check a single region. Optional, default is to check all regions.")
config := flag.String("config", ".", "Define a config file to use")
flag.Parse()
configPath = *config
// fmt.Println(*configFile)
// Get region list
// If user passes a list of regions we'll use that otherwise we'll check all
var regionList []string
var err error
if len(regionListFlags) > 0 {
regionList = regionListFlags
} else {
regionList, err = fetchRegionList()
if err != err {
log.Fatal("Unable to fetch region list")
}
}
//Check each region
for _, awsRegionName := range regionList {
resp, err := getRegionInstanceStatus(awsRegionName)
if err != nil {
log.Fatal(err)
}
log.WithFields(log.Fields{
"awsProfile": application.Config.AWS.Profile,
"awsRegion": awsRegionName,
}).Info("Processing region")
// Process instance to see if we need to open event
processInstance(resp, awsRegionName)
}
}