Skip to content

Commit

Permalink
Merge pull request #32 from ernestio/internet-gateway
Browse files Browse the repository at this point in the history
added internet gateway output
  • Loading branch information
adriacidre authored Apr 5, 2017
2 parents 8c5377d + 36add90 commit de77cb1
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
56 changes: 56 additions & 0 deletions c_internet_gateway.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package main

import "strings"

// InternetGateway : ...
type InternetGateway struct {
}

// Handle : ...
func (n *InternetGateway) Handle(subject string, c component, lines []Message) []Message {
parts := strings.Split(subject, ".")
subject = parts[0] + "." + parts[1]
switch subject {
case "internet_gateway.create":
lines = n.getSingleDetail(c, "Created Internet Gateway")
case "internet_gateway.delete":
lines = n.getSingleDetail(c, "Deleted Internet Gateway")
case "internet_gateways.find":
for _, cx := range c.getFoundComponents() {
lines = append(lines, n.getSingleDetail(cx, "Found Internet Gateway")...)
}
}
return lines
}

func (n *InternetGateway) getSingleDetail(c component, prefix string) (lines []Message) {
name, _ := c["name"].(string)
if prefix != "" {
name = prefix + " " + name
}
status, _ := c["_state"].(string)
level := "INFO"
if status == "errored" {
level = "ERROR"
}
if status != "errored" && status != "completed" && status != "" {
return lines
}
lines = append(lines, Message{Body: " " + name, Level: level})
id, _ := c["internet_gateway_aws_id"].(string)
if id != "" {
lines = append(lines, Message{Body: " AWS ID : " + id, Level: ""})
}
if status != "" {
lines = append(lines, Message{Body: " Status : " + status, Level: ""})
}
if status == "errored" {
err, _ := c["error"].(string)
lines = append(lines, Message{Body: " Error : " + err, Level: ""})
}
return lines
}
3 changes: 3 additions & 0 deletions generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ func genericHandler(msg *nats.Msg) {
case "rds_instances", "rds_instance":
var nt RDSInstance
msgLines = nt.Handle(msg.Subject, c, msgLines)
case "internet_gateway", "internet_gateways":
var nt InternetGateway
msgLines = nt.Handle(msg.Subject, c, msgLines)
default:
log.Println("unsupported: " + msg.Subject)
}
Expand Down

0 comments on commit de77cb1

Please sign in to comment.