Skip to content
This repository was archived by the owner on Apr 10, 2020. It is now read-only.

Commit 2239db5

Browse files
author
ned
committed
SQS long polling, swallow CloudTrail validation messages
Swallow CloudTrail validation messages per suggestion by atward in issue #4 Added SQS long polling per suggestion by Tenzer in issue #5 Credit contributors
1 parent fa8a858 commit 2239db5

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ The data in CloudTrail is essential, but it's unfortunately trapped in many tiny
2121
* Easy to setup: under 15 minutes
2222
* Self-contained Kibana 3.1.2 release
2323
* HTTPS server with custom SSL cert/key or optional self-signed cert
24-
* Single Linux/OSX binaries
24+
* Easy-to-deploy Linux/OSX binaries, or a Docker image
2525
* ElasticSearch proxy ensures your logs are secure and read-only
2626
* No need to open direct access to your ElasticSearch instance
2727
* Helps to achieve PCI and HIPAA compliance in the cloud
@@ -173,5 +173,12 @@ $ make
173173
To cross-compile, you'll need to follow these steps first:
174174
http://dave.cheney.net/2012/09/08/an-introduction-to-cross-compilation-with-go
175175

176+
## Contributors
177+
* [nmcclain](https://github.com/nmcclain)
178+
* [matthewrkrieger](https://github.com/matthewrkrieger)
179+
* [swindmill](https://github.com/swindmill)
180+
* [atward](https://github.com/atward)
181+
* [Tenzer](https://github.com/Tenzer)
182+
176183
## License
177184
MIT

bindata.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ func kibana_app_dashboards_default_json() (*asset, error) {
176176
return nil, err
177177
}
178178

179-
info := bindata_file_info{name: "kibana/app/dashboards/default.json", size: 8681, mode: os.FileMode(436), modTime: time.Unix(1424966498, 0)}
179+
info := bindata_file_info{name: "kibana/app/dashboards/default.json", size: 8681, mode: os.FileMode(436), modTime: time.Unix(1424968096, 0)}
180180
a := &asset{bytes: bytes, info: info}
181181
return a, nil
182182
}
@@ -2316,7 +2316,7 @@ func kibana_config_js() (*asset, error) {
23162316
return nil, err
23172317
}
23182318

2319-
info := bindata_file_info{name: "kibana/config.js", size: 2379, mode: os.FileMode(436), modTime: time.Unix(1424966498, 0)}
2319+
info := bindata_file_info{name: "kibana/config.js", size: 2379, mode: os.FileMode(436), modTime: time.Unix(1424968096, 0)}
23202320
a := &asset{bytes: bytes, info: info}
23212321
return a, nil
23222322
}

traildash.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"time"
2121
)
2222

23-
const version = "0.8"
23+
const version = "0.0.9"
2424

2525
const usage = `traildash: easy AWS CloudTrail dashboard
2626
@@ -250,8 +250,7 @@ func (c *config) workLogs() {
250250
kerblowie("Error dequeing from SQS: %s", err.Error())
251251
continue
252252
} else if m == nil {
253-
log.Printf("Empty queue... sleeping for a minute.")
254-
time.Sleep(60 * time.Second)
253+
log.Printf("Empty queue... polling for 20 seconds.")
255254
continue
256255
}
257256
c.debug("Fetched sqs://%s [s3://%s/%s]", m.MessageID, m.S3Bucket, m.S3ObjectKey[0])
@@ -294,6 +293,7 @@ func (c *config) dequeue() (*cloudtrailNotification, error) {
294293
req := sqs.ReceiveMessageRequest{
295294
QueueURL: aws.String(c.queueURL),
296295
MaxNumberOfMessages: aws.Integer(numRequested),
296+
WaitTimeSeconds: aws.Integer(20), // max allowed
297297
}
298298
resp, err := q.ReceiveMessage(&req)
299299
if err != nil {
@@ -310,15 +310,20 @@ func (c *config) dequeue() (*cloudtrailNotification, error) {
310310

311311
not := sqsNotification{}
312312
if err := json.Unmarshal([]byte(body), &not); err != nil {
313-
return nil, fmt.Errorf("Outer JSON Unmarshal error [id: %s]: %s", not.MessageID, err.Error())
313+
return nil, fmt.Errorf("SQS message JSON error [id: %s]: %s", not.MessageID, err.Error())
314314
}
315315

316316
n := cloudtrailNotification{}
317-
if err := json.Unmarshal([]byte(not.Message), &n); err != nil {
318-
return nil, fmt.Errorf("Inner JSON Unmarshal error [id: %s]: %s", not.MessageID, err.Error())
319-
}
320317
n.MessageID = not.MessageID
321318
n.ReceiptHandle = *m.ReceiptHandle
319+
if not.Message == "CloudTrail validation message." { // swallow validation messages
320+
if err = c.deleteSQS(&n); err != nil {
321+
return nil, fmt.Errorf("Error deleting CloudTrail validation message [id: %s]: %s", not.MessageID, err.Error())
322+
}
323+
return nil, fmt.Errorf("Deleted CloudTrail validation message id %s", not.MessageID)
324+
} else if err := json.Unmarshal([]byte(not.Message), &n); err != nil {
325+
return nil, fmt.Errorf("CloudTrail JSON error [id: %s]: %s", not.MessageID, err.Error())
326+
}
322327
return &n, nil
323328
}
324329

0 commit comments

Comments
 (0)