From 36add9007dacb5d33c378a936c97226b768266cd Mon Sep 17 00:00:00 2001 From: Tom Bevan Date: Tue, 4 Apr 2017 16:31:49 +0100 Subject: [PATCH] added internet gateway output --- c_internet_gateway.go | 56 +++++++++++++++++++++++++++++++++++++++++++ generic.go | 3 +++ 2 files changed, 59 insertions(+) create mode 100644 c_internet_gateway.go diff --git a/c_internet_gateway.go b/c_internet_gateway.go new file mode 100644 index 0000000..d8bf615 --- /dev/null +++ b/c_internet_gateway.go @@ -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 +} diff --git a/generic.go b/generic.go index 9c6fda9..8585945 100644 --- a/generic.go +++ b/generic.go @@ -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) }