Skip to content

Commit

Permalink
Merge pull request #31 from ernestio/import-output
Browse files Browse the repository at this point in the history
Import output
  • Loading branch information
g3kk0 authored Mar 29, 2017
2 parents 7e099cf + fe9efcf commit 8c5377d
Show file tree
Hide file tree
Showing 12 changed files with 105 additions and 55 deletions.
10 changes: 7 additions & 3 deletions c_ebs_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ func (n *EBSVolume) Handle(subject string, c component, lines []Message) []Messa
case "ebs_volume.delete":
lines = n.getSingleDetail(c, "Deleted EBS volume ")
case "ebs_volumes.find":
lines = n.getSingleDetail(c, "Found EBS volume ")
for _, cx := range c.getFoundComponents() {
lines = append(lines, n.getSingleDetail(cx, "Found EBS volume")...)
}
}
return lines
}
Expand All @@ -35,15 +37,17 @@ func (n *EBSVolume) getSingleDetail(c component, prefix string) (lines []Message
if status == "errored" {
level = "ERROR"
}
if status != "errored" && status != "completed" {
if status != "errored" && status != "completed" && status != "" {
return lines
}
lines = append(lines, Message{Body: " " + name, Level: level})
id, _ := c["volume_aws_id"].(string)
if id != "" {
lines = append(lines, Message{Body: " AWS ID : " + id, Level: ""})
}
lines = append(lines, Message{Body: " Status : " + status, 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: ""})
Expand Down
11 changes: 7 additions & 4 deletions c_elb.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ func (n *ELB) Handle(subject string, c component, lines []Message) []Message {
case "elb.delete":
lines = n.getSingleDetail(c, "Deleted ELB")
case "elbs.find":
lines = n.getSingleDetail(c, "Found ELB")

for _, cx := range c.getFoundComponents() {
lines = append(lines, n.getSingleDetail(cx, "Found ELB")...)
}
}
return lines
}
Expand All @@ -38,11 +39,13 @@ func (n *ELB) getSingleDetail(c component, prefix string) (lines []Message) {
if status == "errored" {
level = "ERROR"
}
if status != "errored" && status != "completed" {
if status != "errored" && status != "completed" && status != "" {
return lines
}
lines = append(lines, Message{Body: " " + name, Level: level})
lines = append(lines, Message{Body: " Status : " + status, Level: ""})
if status != "" {
lines = append(lines, Message{Body: " Status : " + status, Level: ""})
}
if c["dns_name"] != nil {
dnsName, _ := c["dns_name"].(string)
if dnsName != "" {
Expand Down
16 changes: 10 additions & 6 deletions c_firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ func (n *Firewall) Handle(subject string, c component, lines []Message) []Messag
subject = parts[0] + "." + parts[1]
switch subject {
case "firewall.create":
lines = n.getSingleDetail(c, "Firewall created")
lines = n.getSingleDetail(c, "Created Firewall")
case "firewall.update":
lines = n.getSingleDetail(c, "Firewall updated")
lines = n.getSingleDetail(c, "Updated Firewall")
case "firewall.delete":
lines = n.getSingleDetail(c, "Firewall deleted")
lines = n.getSingleDetail(c, "Deleted Firewall")
case "firewalls.find":
lines = n.getSingleDetail(c, "Firewall found")
for _, cx := range c.getFoundComponents() {
lines = append(lines, n.getSingleDetail(cx, "Found Firewall")...)
}
}
return lines
}
Expand All @@ -37,11 +39,13 @@ func (n *Firewall) getSingleDetail(c component, prefix string) (lines []Message)
if status == "errored" {
level = "ERROR"
}
if status != "errored" && status != "completed" {
if status != "errored" && status != "completed" && status != "" {
return lines
}
lines = append(lines, Message{Body: " " + name, Level: level})
lines = append(lines, Message{Body: " Status : " + status, 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: ""})
Expand Down
16 changes: 10 additions & 6 deletions c_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ func (n *Instance) Handle(subject string, c component, lines []Message) []Messag
subject = parts[0] + "." + parts[1]
switch subject {
case "instance.create":
lines = n.getSingleDetail(c, "Instance created")
lines = n.getSingleDetail(c, "Created Instance")
case "instance.update":
lines = n.getSingleDetail(c, "Instance udpated")
lines = n.getSingleDetail(c, "Updated Instance")
case "instance.delete":
lines = n.getSingleDetail(c, "Instance delete")
lines = n.getSingleDetail(c, "Deleted Instance")
case "instances.find":
lines = n.getSingleDetail(c, "Instance find")
for _, cx := range c.getFoundComponents() {
lines = append(lines, n.getSingleDetail(cx, "Found Instance")...)
}
}
return lines
}
Expand All @@ -38,7 +40,7 @@ func (n *Instance) getSingleDetail(c component, prefix string) (lines []Message)
if status == "errored" {
level = "ERROR"
}
if status != "errored" && status != "completed" {
if status != "errored" && status != "completed" && status != "" {
return lines
}
lines = append(lines, Message{Body: " " + name, Level: level})
Expand All @@ -51,7 +53,9 @@ func (n *Instance) getSingleDetail(c component, prefix string) (lines []Message)
if id != "" {
lines = append(lines, Message{Body: " AWS ID : " + id, Level: ""})
}
lines = append(lines, Message{Body: " Status : " + status, 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: ""})
Expand Down
16 changes: 10 additions & 6 deletions c_nat.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ func (n *Nat) Handle(subject string, c component, lines []Message) []Message {
subject = parts[0] + "." + parts[1]
switch subject {
case "nat.create":
lines = n.getSingleDetail(c, "Nat created")
lines = n.getSingleDetail(c, "Created Nat")
case "nat.update":
lines = n.getSingleDetail(c, "Nat updated")
lines = n.getSingleDetail(c, "Updated Nat")
case "nat.delete":
lines = n.getSingleDetail(c, "Nat deleted")
lines = n.getSingleDetail(c, "Deleted Nat")
case "nats.find":
lines = n.getSingleDetail(c, "Nat created")
for _, cx := range c.getFoundComponents() {
lines = append(lines, n.getSingleDetail(cx, "Found Nat")...)
}
}
return lines
}
Expand All @@ -37,11 +39,13 @@ func (n *Nat) getSingleDetail(c component, prefix string) (lines []Message) {
if status == "errored" {
level = "ERROR"
}
if status != "errored" && status != "completed" {
if status != "errored" && status != "completed" && status != "" {
return lines
}
lines = append(lines, Message{Body: " " + name, Level: level})
lines = append(lines, Message{Body: " Status : " + status, 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: ""})
Expand Down
16 changes: 10 additions & 6 deletions c_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ func (n *Network) Handle(subject string, c component, lines []Message) []Message
subject = parts[0] + "." + parts[1]
switch subject {
case "network.create":
lines = n.getSingleDetail(c, "Network created")
lines = n.getSingleDetail(c, "Created Network")
case "network.delete":
lines = n.getSingleDetail(c, "Network deleted")
lines = n.getSingleDetail(c, "Deleted Network")
case "networks.find":
lines = n.getSingleDetail(c, "Network found")
for _, cx := range c.getFoundComponents() {
lines = append(lines, n.getSingleDetail(cx, "Found Network")...)
}
}
return lines
}
Expand All @@ -36,16 +38,18 @@ func (n *Network) getSingleDetail(c component, prefix string) (lines []Message)
if status == "errored" {
level = "ERROR"
}
if status != "errored" && status != "completed" {
if status != "errored" && status != "completed" && status != "" {
return lines
}
lines = append(lines, Message{Body: " " + name, Level: level})
lines = append(lines, Message{Body: " IP : " + ip, Level: ""})
lines = append(lines, Message{Body: " Subnet : " + ip, Level: ""})
id, _ := c["network_aws_id"].(string)
if id != "" {
lines = append(lines, Message{Body: " AWS ID : " + id, Level: ""})
}
lines = append(lines, Message{Body: " Status : " + status, 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: ""})
Expand Down
12 changes: 7 additions & 5 deletions c_rds_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ func (n *RDSCluster) Handle(subject string, c component, lines []Message) []Mess
subject = parts[0] + "." + parts[1]
switch subject {
case "rds_cluster.create":
lines = n.getSingleDetail(c, "RDS cluster created")
lines = n.getSingleDetail(c, "Created RDS Cluster")
case "rds_cluster.update":
lines = n.getSingleDetail(c, "RDS cluster updated")
lines = n.getSingleDetail(c, "Updated RDS Cluster")
case "rds_cluster.delete":
lines = n.getSingleDetail(c, "RDS cluster deleted")
lines = n.getSingleDetail(c, "Deleted RDS Cluster")
case "rds_clusters.find":
lines = n.getSingleDetail(c, "RDS cluster found")
for _, cx := range c.getFoundComponents() {
lines = append(lines, n.getSingleDetail(cx, "Found RDS Cluster")...)
}
}
return lines
}
Expand All @@ -39,7 +41,7 @@ func (n *RDSCluster) getSingleDetail(c component, prefix string) (lines []Messag
if status == "errored" {
level = "ERROR"
}
if status != "errored" && status != "completed" {
if status != "errored" && status != "completed" && status != "" {
return lines
}
lines = append(lines, Message{Body: " " + name, Level: level})
Expand Down
12 changes: 7 additions & 5 deletions c_rds_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ func (n *RDSInstance) Handle(subject string, c component, lines []Message) []Mes
subject = parts[0] + "." + parts[1]
switch subject {
case "rds_instance.create":
lines = n.getSingleDetail(c, "RDS instance created")
lines = n.getSingleDetail(c, "Created RDS Instance")
case "rds_instance.udpate":
lines = n.getSingleDetail(c, "RDS instance updated")
lines = n.getSingleDetail(c, "Updated RDS Instance")
case "rds_instance.delete":
lines = n.getSingleDetail(c, "RDS instance deleted")
lines = n.getSingleDetail(c, "Deleted RDS Instance")
case "rds_instances.find":
lines = n.getSingleDetail(c, "RDS instance found")
for _, cx := range c.getFoundComponents() {
lines = append(lines, n.getSingleDetail(cx, "Found RDS Instance")...)
}
}
return lines
}
Expand All @@ -40,7 +42,7 @@ func (n *RDSInstance) getSingleDetail(c component, prefix string) (lines []Messa
if status == "errored" {
level = "ERROR"
}
if status != "errored" && status != "completed" {
if status != "errored" && status != "completed" && status != "" {
return lines
}
lines = append(lines, Message{Body: " " + name, Level: level})
Expand Down
6 changes: 4 additions & 2 deletions c_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func (n *Router) Handle(subject string, c component, lines []Message) []Message
switch subject {

case "router.create", "router.update":
lines = n.getSingleDetail(c, "Configured router")
lines = n.getSingleDetail(c, "Configured Router")
}
return lines
}
Expand All @@ -36,7 +36,9 @@ func (n *Router) getSingleDetail(c component, prefix string) (lines []Message) {
return lines
}
lines = append(lines, Message{Body: " " + name, Level: level})
lines = append(lines, Message{Body: " Status : " + status, 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: ""})
Expand Down
16 changes: 10 additions & 6 deletions c_s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ func (n *S3Bucket) Handle(subject string, c component, lines []Message) []Messag
subject = parts[0] + "." + parts[1]
switch subject {
case "s3.create":
lines = n.getSingleDetail(c, "S3 bucket created")
lines = n.getSingleDetail(c, "Created S3 Bucket")
case "s3.update":
lines = n.getSingleDetail(c, "S3 bucket updated")
lines = n.getSingleDetail(c, "Updated S3 Bucket")
case "s3.delete":
lines = n.getSingleDetail(c, "S3 bucket deleted")
lines = n.getSingleDetail(c, "Deleted S3 Bucket")
case "s3s.find":
lines = n.getSingleDetail(c, "S3 bucket imported")
for _, cx := range c.getFoundComponents() {
lines = append(lines, n.getSingleDetail(cx, "Found S3 Bucket")...)
}
}
return lines
}
Expand All @@ -41,12 +43,14 @@ func (n *S3Bucket) getSingleDetail(c component, prefix string) (lines []Message)
if status == "errored" {
level = "ERROR"
}
if status != "errored" && status != "completed" {
if status != "errored" && status != "completed" && status != "" {
return lines
}
lines = append(lines, Message{Body: " " + name, Level: level})
lines = append(lines, Message{Body: " ACL : " + acl, Level: ""})
lines = append(lines, Message{Body: " Status : " + status, 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: ""})
Expand Down
16 changes: 10 additions & 6 deletions c_vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ func (n *Vpc) Handle(subject string, c component, lines []Message) []Message {
subject = parts[0] + "." + parts[1]
switch subject {
case "vpc.create":
lines = n.getSingleDetail(c, "VPC created")
lines = n.getSingleDetail(c, "Created VPC")
case "vpc.update":
lines = n.getSingleDetail(c, "VPC udpated")
lines = n.getSingleDetail(c, "Updated VPC")
case "vpc.delete":
lines = n.getSingleDetail(c, "VPC deleted")
lines = n.getSingleDetail(c, "Deleted VPC")
case "vpcs.find":
lines = n.getSingleDetail(c, "VPC Found")
for _, cx := range c.getFoundComponents() {
lines = append(lines, n.getSingleDetail(cx, "Found VPC")...)
}
}
return lines
}
Expand All @@ -38,12 +40,14 @@ func (n *Vpc) getSingleDetail(c component, prefix string) (lines []Message) {
if status == "errored" {
level = "ERROR"
}
if status != "errored" && status != "completed" {
if status != "errored" && status != "completed" && status != "" {
return lines
}
lines = append(lines, Message{Body: " " + id, Level: level})
lines = append(lines, Message{Body: " Subnet : " + subnet, Level: ""})
lines = append(lines, Message{Body: " Status : " + status, 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: ""})
Expand Down
13 changes: 13 additions & 0 deletions generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ func (m *component) getServicePart() string {
return pieces[len(pieces)-1]
}

func (m *component) getFoundComponents() []component {
var c []component

components, ok := (*m)["components"].([]interface{})
if ok {
for _, x := range components {
c = append(c, x.(map[string]interface{}))
}
}

return c
}

func genericHandler(msg *nats.Msg) {
var msgLines []Message
var c component
Expand Down

0 comments on commit 8c5377d

Please sign in to comment.