From 07baae1ebbf516d11af7fb232e0bf3b590a3896b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Cidre?= Date: Wed, 1 Mar 2017 14:14:18 +0100 Subject: [PATCH] Support for single resources monitoring --- c_bootstrap.go | 32 ++++++++++++++++++------- c_ebs_volume.go | 59 +++++++++++++++++++++++++++++++---------------- c_elb.go | 51 +++++++++++++++++++++++++++++----------- c_execution.go | 31 ++++++++++++++++++------- c_firewall.go | 37 ++++++++++++++++++++++------- c_instance.go | 57 ++++++++++++++++++++++++++++++--------------- c_nat.go | 37 ++++++++++++++++++++++------- c_network.go | 47 ++++++++++++++++++++++++++----------- c_rds_cluster.go | 43 +++++++++++++++++++++++++--------- c_rds_instance.go | 48 +++++++++++++++++++++++++++----------- c_router.go | 38 +++++++++++++++++++++--------- c_s3.go | 47 ++++++++++++++++++++++++++----------- c_service.go | 2 ++ c_vpc.go | 41 ++++++++++++++++++++++++-------- 14 files changed, 414 insertions(+), 156 deletions(-) diff --git a/c_bootstrap.go b/c_bootstrap.go index 2dc2911..8729f8e 100644 --- a/c_bootstrap.go +++ b/c_bootstrap.go @@ -4,9 +4,11 @@ package main +// Bootstrap : .. type Bootstrap struct { } +// Handle : .. func (n *Bootstrap) Handle(subject string, components []interface{}, lines []Message) []Message { switch subject { case "bootstraps.create": @@ -17,22 +19,36 @@ func (n *Bootstrap) Handle(subject string, components []interface{}, lines []Mes case "bootstraps.create.error": lines = n.getDetails(components) return append(lines, Message{Body: "Bootstrap failed", Level: "INFO"}) + + case "bootstrap.create.done", "bootstrap.create.error": + lines = n.getSingleDetail(components, "Bootstrap ran") } + return lines } func (n *Bootstrap) getDetails(components []interface{}) (lines []Message) { for _, v := range components { - r := v.(map[string]interface{}) - name, _ := r["name"].(string) - status, _ := r["status"].(string) - lines = append(lines, Message{Body: " - " + name, Level: ""}) - lines = append(lines, Message{Body: " Status : " + status, Level: ""}) - if status == "errored" { - err, _ := r["error"].(string) - lines = append(lines, Message{Body: " Error : " + err, Level: "ERROR"}) + for _, l := range n.getSingleDetail(v, "") { + lines = append(lines, l) } } return lines } + +func (n *Bootstrap) getSingleDetail(v interface{}, prefix string) (lines []Message) { + r := v.(map[string]interface{}) + name, _ := r["name"].(string) + if prefix != "" { + name = prefix + " " + name + } + status, _ := r["status"].(string) + lines = append(lines, Message{Body: " - " + name, Level: ""}) + lines = append(lines, Message{Body: " Status : " + status, Level: ""}) + if status == "errored" { + err, _ := r["error"].(string) + lines = append(lines, Message{Body: " Error : " + err, Level: "ERROR"}) + } + return lines +} diff --git a/c_ebs_volume.go b/c_ebs_volume.go index ddb6898..f00f9d9 100644 --- a/c_ebs_volume.go +++ b/c_ebs_volume.go @@ -4,54 +4,73 @@ package main +// EBSVolume : ... type EBSVolume struct { } -func (v *EBSVolume) Handle(subject string, components []interface{}, lines []Message) []Message { +// Handle : ... +func (n *EBSVolume) Handle(subject string, components []interface{}, lines []Message) []Message { switch subject { case "ebs_volumes.create": return append(lines, Message{Body: "Creating ebs volumes:", Level: "INFO"}) case "ebs_volumes.create.done": - lines = v.getDetails(components) + lines = n.getDetails(components) return append(lines, Message{Body: "EBS volumes successfully created", Level: "INFO"}) case "ebs_volumes.create.error": - lines = v.getDetails(components) + lines = n.getDetails(components) return append(lines, Message{Body: "EBS volumes creation failed", Level: "INFO"}) case "ebs_volumes.delete": return append(lines, Message{Body: "Deleting ebs volumes:", Level: "INFO"}) case "ebs_volumes.delete.done": - lines = v.getDetails(components) + lines = n.getDetails(components) return append(lines, Message{Body: "EBS volumes deleted", Level: "INFO"}) case "ebs_volumes.delete.error": - lines = v.getDetails(components) + lines = n.getDetails(components) return append(lines, Message{Body: "EBS volumes deletion failed", Level: "INFO"}) case "ebs_volumes.find": return append(lines, Message{Body: "Importing ebs volumes:", Level: "INFO"}) case "ebs_volumes.find.done": - lines = v.getDetails(components) + lines = n.getDetails(components) return append(lines, Message{Body: "EBS volumes successfully imported", Level: "INFO"}) case "ebs_volumes.find.error": - lines = v.getDetails(components) + lines = n.getDetails(components) return append(lines, Message{Body: "EBS volumes import failed", Level: "INFO"}) + + case "ebs_volume.create.done", "ebs_volume.create.error": + lines = n.getSingleDetail(components, "Created EBS volume ") + case "ebs_volume.delete.done", "ebs_volume.delete.error": + lines = n.getSingleDetail(components, "Deleted EBS volume ") + case "ebs_volume.find.done", "ebs_volume.find.error": + lines = n.getSingleDetail(components, "Found EBS volume ") } return lines } -func (v *EBSVolume) getDetails(components []interface{}) (lines []Message) { +func (n *EBSVolume) getDetails(components []interface{}) (lines []Message) { for _, v := range components { - r := v.(map[string]interface{}) - name, _ := r["name"].(string) - status, _ := r["status"].(string) - lines = append(lines, Message{Body: " - " + name, Level: ""}) - id, _ := r["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 == "errored" { - err, _ := r["error"].(string) - lines = append(lines, Message{Body: " Error : " + err, Level: "ERROR"}) + for _, l := range n.getSingleDetail(v, "") { + lines = append(lines, l) } } return lines } + +func (n *EBSVolume) getSingleDetail(v interface{}, prefix string) (lines []Message) { + r := v.(map[string]interface{}) + name, _ := r["name"].(string) + if prefix != "" { + name = prefix + " " + name + } + status, _ := r["status"].(string) + lines = append(lines, Message{Body: " - " + name, Level: ""}) + id, _ := r["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 == "errored" { + err, _ := r["error"].(string) + lines = append(lines, Message{Body: " Error : " + err, Level: "ERROR"}) + } + return lines +} diff --git a/c_elb.go b/c_elb.go index dd77508..db54574 100644 --- a/c_elb.go +++ b/c_elb.go @@ -4,9 +4,11 @@ package main +// ELB : ... type ELB struct { } +// Handle : ... func (n *ELB) Handle(subject string, components []interface{}, lines []Message) []Message { switch subject { case "elbs.create": @@ -41,29 +43,50 @@ func (n *ELB) Handle(subject string, components []interface{}, lines []Message) case "elbs.find.error": lines = n.getDetails(components) return append(lines, Message{Body: "ELBs import failed", Level: "INFO"}) + + case "elb.create.done", "elb.create.error": + lines = n.getSingleDetail(components, "Created ELB") + case "elb.update.done", "elb.update.error": + lines = n.getSingleDetail(components, "Updated ELB") + case "elb.delete.done", "elb.delete.error": + lines = n.getSingleDetail(components, "Deleted ELB") + case "elb.find.done", "elb.find.error": + lines = n.getSingleDetail(components, "Found ELB") + } return lines } func (n *ELB) getDetails(components []interface{}) (lines []Message) { for _, v := range components { - r := v.(map[string]interface{}) - name, _ := r["name"].(string) - status, _ := r["status"].(string) - lines = append(lines, Message{Body: " - " + name, Level: ""}) - lines = append(lines, Message{Body: " Status : " + status, Level: ""}) - if r["dns_name"] != nil { - dnsName, _ := r["dns_name"].(string) - if dnsName != "" { - lines = append(lines, Message{Body: " DNS : " + dnsName, Level: ""}) - } + for _, l := range n.getSingleDetail(v, "") { + lines = append(lines, l) } - lines = append(lines) - if status == "errored" { - err, _ := r["error"].(string) - lines = append(lines, Message{Body: " Error : " + err, Level: "ERROR"}) + } + + return lines +} + +func (n *ELB) getSingleDetail(v interface{}, prefix string) (lines []Message) { + r := v.(map[string]interface{}) + name, _ := r["name"].(string) + if prefix != "" { + name = prefix + " " + name + } + status, _ := r["status"].(string) + lines = append(lines, Message{Body: " - " + name, Level: ""}) + lines = append(lines, Message{Body: " Status : " + status, Level: ""}) + if r["dns_name"] != nil { + dnsName, _ := r["dns_name"].(string) + if dnsName != "" { + lines = append(lines, Message{Body: " DNS : " + dnsName, Level: ""}) } } + lines = append(lines) + if status == "errored" { + err, _ := r["error"].(string) + lines = append(lines, Message{Body: " Error : " + err, Level: "ERROR"}) + } return lines } diff --git a/c_execution.go b/c_execution.go index d8441bd..ca45751 100644 --- a/c_execution.go +++ b/c_execution.go @@ -4,9 +4,11 @@ package main +// Execution : ... type Execution struct { } +// Handle : ... func (n *Execution) Handle(subject string, components []interface{}, lines []Message) []Message { switch subject { case "executions.create": @@ -17,22 +19,35 @@ func (n *Execution) Handle(subject string, components []interface{}, lines []Mes case "executions.create.error": lines = n.getDetails(components) return append(lines, Message{Body: "Executions failed", Level: "INFO"}) + + case "execution.create.done", "execution.create.error": + lines = n.getSingleDetail(components, "Ran execution") } return lines } func (n *Execution) getDetails(components []interface{}) (lines []Message) { for _, v := range components { - r := v.(map[string]interface{}) - name, _ := r["name"].(string) - status, _ := r["status"].(string) - lines = append(lines, Message{Body: " - " + name, Level: ""}) - lines = append(lines, Message{Body: " Status : " + status, Level: ""}) - if status == "errored" { - err, _ := r["error"].(string) - lines = append(lines, Message{Body: " Error : " + err, Level: "ERROR"}) + for _, l := range n.getSingleDetail(v, "") { + lines = append(lines, l) } } return lines } + +func (n *Execution) getSingleDetail(v interface{}, prefix string) (lines []Message) { + r := v.(map[string]interface{}) + name, _ := r["name"].(string) + if prefix != "" { + name = prefix + " " + name + } + status, _ := r["status"].(string) + lines = append(lines, Message{Body: " - " + name, Level: ""}) + lines = append(lines, Message{Body: " Status : " + status, Level: ""}) + if status == "errored" { + err, _ := r["error"].(string) + lines = append(lines, Message{Body: " Error : " + err, Level: "ERROR"}) + } + return lines +} diff --git a/c_firewall.go b/c_firewall.go index bfb5ead..f168c13 100644 --- a/c_firewall.go +++ b/c_firewall.go @@ -4,9 +4,11 @@ package main +// Firewall : ... type Firewall struct { } +// Handle : ... func (n *Firewall) Handle(subject string, components []interface{}, lines []Message) []Message { switch subject { case "firewalls.create": @@ -41,22 +43,41 @@ func (n *Firewall) Handle(subject string, components []interface{}, lines []Mess case "firewalls.find.error": lines = n.getDetails(components) return append(lines, Message{Body: "Firewalls import failed", Level: "INFO"}) + + case "firewall.create.done", "firewall.create.error": + lines = n.getSingleDetail(components, "Firewall created") + case "firewall.update.done", "firewall.update.error": + lines = n.getSingleDetail(components, "Firewall updated") + case "firewall.delete.done", "firewall.delete.error": + lines = n.getSingleDetail(components, "Firewall deleted") + case "firewall.find.done", "firewall.find.error": + lines = n.getSingleDetail(components, "Firewall found") } return lines } func (n *Firewall) getDetails(components []interface{}) (lines []Message) { for _, v := range components { - r := v.(map[string]interface{}) - name, _ := r["name"].(string) - status, _ := r["status"].(string) - lines = append(lines, Message{Body: " - " + name, Level: ""}) - lines = append(lines, Message{Body: " Status : " + status, Level: ""}) - if status == "errored" { - err, _ := r["error"].(string) - lines = append(lines, Message{Body: " Error : " + err, Level: "ERROR"}) + for _, l := range n.getSingleDetail(v, "") { + lines = append(lines, l) } } return lines } + +func (n *Firewall) getSingleDetail(v interface{}, prefix string) (lines []Message) { + r := v.(map[string]interface{}) + name, _ := r["name"].(string) + if prefix != "" { + name = prefix + " " + name + } + status, _ := r["status"].(string) + lines = append(lines, Message{Body: " - " + name, Level: ""}) + lines = append(lines, Message{Body: " Status : " + status, Level: ""}) + if status == "errored" { + err, _ := r["error"].(string) + lines = append(lines, Message{Body: " Error : " + err, Level: "ERROR"}) + } + return lines +} diff --git a/c_instance.go b/c_instance.go index d71a4eb..bff90ff 100644 --- a/c_instance.go +++ b/c_instance.go @@ -4,9 +4,11 @@ package main +// Instance : ... type Instance struct { } +// Handle : ... func (n *Instance) Handle(subject string, components []interface{}, lines []Message) []Message { switch subject { case "instances.create": @@ -41,32 +43,51 @@ func (n *Instance) Handle(subject string, components []interface{}, lines []Mess case "instances.find.error": lines = n.getDetails(components) return append(lines, Message{Body: "Instances import failed", Level: "INFO"}) + + case "instance.create.done", "instance.create.error": + lines = n.getSingleDetail(components, "Instance created") + case "instance.update.done", "instance.update.error": + lines = n.getSingleDetail(components, "Instance udpated") + case "instance.delete.done", "instance.delete.error": + lines = n.getSingleDetail(components, "Instance delete") + case "instance.find.done", "instance.find.error": + lines = n.getSingleDetail(components, "Instance find") } return lines } func (n *Instance) getDetails(components []interface{}) (lines []Message) { for _, v := range components { - r := v.(map[string]interface{}) - ip, _ := r["ip"].(string) - name, _ := r["name"].(string) - status, _ := r["status"].(string) - lines = append(lines, Message{Body: " - " + name, Level: ""}) - lines = append(lines, Message{Body: " IP : " + ip, Level: ""}) - public_ip, _ := r["public_ip"].(string) - if public_ip != "" { - lines = append(lines, Message{Body: " PUBLIC IP : " + public_ip, Level: ""}) - } - id, _ := r["instance_aws_id"].(string) - if id != "" { - lines = append(lines, Message{Body: " AWS ID : " + id, Level: ""}) - } - lines = append(lines, Message{Body: " Status : " + status, Level: ""}) - if status == "errored" { - err, _ := r["error"].(string) - lines = append(lines, Message{Body: " Error : " + err, Level: "ERROR"}) + for _, l := range n.getSingleDetail(v, "") { + lines = append(lines, l) } } return lines } + +func (n *Instance) getSingleDetail(v interface{}, prefix string) (lines []Message) { + r := v.(map[string]interface{}) + ip, _ := r["ip"].(string) + name, _ := r["name"].(string) + if prefix != "" { + name = prefix + " " + name + } + status, _ := r["status"].(string) + lines = append(lines, Message{Body: " - " + name, Level: ""}) + lines = append(lines, Message{Body: " IP : " + ip, Level: ""}) + publicIP, _ := r["public_ip"].(string) + if publicIP != "" { + lines = append(lines, Message{Body: " PUBLIC IP : " + publicIP, Level: ""}) + } + id, _ := r["instance_aws_id"].(string) + if id != "" { + lines = append(lines, Message{Body: " AWS ID : " + id, Level: ""}) + } + lines = append(lines, Message{Body: " Status : " + status, Level: ""}) + if status == "errored" { + err, _ := r["error"].(string) + lines = append(lines, Message{Body: " Error : " + err, Level: "ERROR"}) + } + return lines +} diff --git a/c_nat.go b/c_nat.go index 37a0496..47403c0 100644 --- a/c_nat.go +++ b/c_nat.go @@ -4,9 +4,11 @@ package main +// Nat : ... type Nat struct { } +// Handle : ... func (n *Nat) Handle(subject string, components []interface{}, lines []Message) []Message { switch subject { case "nats.create": @@ -41,22 +43,41 @@ func (n *Nat) Handle(subject string, components []interface{}, lines []Message) case "nats.find.error": lines = n.getDetails(components) return append(lines, Message{Body: "Nats import failed", Level: "INFO"}) + + case "nat.create.done", "nat.create.error": + lines = n.getSingleDetail(components, "Nat created") + case "nat.update.done", "nat.update.error": + lines = n.getSingleDetail(components, "Nat updated") + case "nat.delete.done", "nat.delete.error": + lines = n.getSingleDetail(components, "Nat deleted") + case "nat.find.done", "nat.find.error": + lines = n.getSingleDetail(components, "Nat created") } return lines } func (n *Nat) getDetails(components []interface{}) (lines []Message) { for _, v := range components { - r := v.(map[string]interface{}) - name, _ := r["name"].(string) - status, _ := r["status"].(string) - lines = append(lines, Message{Body: " - " + name, Level: ""}) - lines = append(lines, Message{Body: " Status : " + status, Level: ""}) - if status == "errored" { - err, _ := r["error"].(string) - lines = append(lines, Message{Body: " Error : " + err, Level: "ERROR"}) + for _, l := range n.getSingleDetail(v, "") { + lines = append(lines, l) } } return lines } + +func (n *Nat) getSingleDetail(v interface{}, prefix string) (lines []Message) { + r := v.(map[string]interface{}) + name, _ := r["name"].(string) + if prefix != "" { + name = prefix + " " + name + } + status, _ := r["status"].(string) + lines = append(lines, Message{Body: " - " + name, Level: ""}) + lines = append(lines, Message{Body: " Status : " + status, Level: ""}) + if status == "errored" { + err, _ := r["error"].(string) + lines = append(lines, Message{Body: " Error : " + err, Level: "ERROR"}) + } + return lines +} diff --git a/c_network.go b/c_network.go index b7f6b3c..cb35f0e 100644 --- a/c_network.go +++ b/c_network.go @@ -4,9 +4,11 @@ package main +// Network : ... type Network struct { } +// Handle : ... func (n *Network) Handle(subject string, components []interface{}, lines []Message) []Message { switch subject { case "networks.create": @@ -33,27 +35,44 @@ func (n *Network) Handle(subject string, components []interface{}, lines []Messa case "networks.find.error": lines = n.getDetails(components) return append(lines, Message{Body: "Networks import failed", Level: "INFO"}) + + case "network.create.done", "network.create.error": + lines = n.getSingleDetail(components, "Network created") + case "network.delete.done", "network.delete.error": + lines = n.getSingleDetail(components, "Network deleted") + case "network.find.done", "network.find.error": + lines = n.getSingleDetail(components, "Network found") } return lines } func (n *Network) getDetails(components []interface{}) (lines []Message) { for _, v := range components { - r := v.(map[string]interface{}) - ip, _ := r["range"].(string) - name, _ := r["name"].(string) - status, _ := r["status"].(string) - lines = append(lines, Message{Body: " - " + name, Level: ""}) - lines = append(lines, Message{Body: " IP : " + ip, Level: ""}) - id, _ := r["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 == "errored" { - err, _ := r["error"].(string) - lines = append(lines, Message{Body: " Error : " + err, Level: "ERROR"}) + for _, l := range n.getSingleDetail(v, "") { + lines = append(lines, l) } } return lines } + +func (n *Network) getSingleDetail(v interface{}, prefix string) (lines []Message) { + r := v.(map[string]interface{}) + ip, _ := r["range"].(string) + name, _ := r["name"].(string) + if prefix != "" { + name = prefix + " " + name + } + status, _ := r["status"].(string) + lines = append(lines, Message{Body: " - " + name, Level: ""}) + lines = append(lines, Message{Body: " IP : " + ip, Level: ""}) + id, _ := r["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 == "errored" { + err, _ := r["error"].(string) + lines = append(lines, Message{Body: " Error : " + err, Level: "ERROR"}) + } + return lines +} diff --git a/c_rds_cluster.go b/c_rds_cluster.go index d78e378..f3283c0 100644 --- a/c_rds_cluster.go +++ b/c_rds_cluster.go @@ -4,9 +4,11 @@ package main +// RDSCluster : ... type RDSCluster struct { } +// Handle : ... func (n *RDSCluster) Handle(subject string, components []interface{}, lines []Message) []Message { switch subject { case "rds_clusters.create": @@ -41,25 +43,44 @@ func (n *RDSCluster) Handle(subject string, components []interface{}, lines []Me case "rds_clusters.find.error": lines = n.getDetails(components) return append(lines, Message{Body: "RDS clusters import failed", Level: "INFO"}) + + case "rds_cluster.create.done", "rds_cluster.create.error": + lines = n.getSingleDetail(components, "RDS cluster created") + case "rds_cluster.update.done", "rds_cluster.update.error": + lines = n.getSingleDetail(components, "RDS cluster updated") + case "rds_cluster.delete.done", "rds_cluster.delete.error": + lines = n.getSingleDetail(components, "RDS cluster deleted") + case "rds_cluster.find.done", "rds_cluster.find.error": + lines = n.getSingleDetail(components, "RDS cluster found") } return lines } func (n *RDSCluster) getDetails(components []interface{}) (lines []Message) { for _, v := range components { - r := v.(map[string]interface{}) - name, _ := r["name"].(string) - engine, _ := r["engine"].(string) - endpoint, _ := r["endpoint"].(string) - status, _ := r["status"].(string) - lines = append(lines, Message{Body: " - " + name, Level: ""}) - lines = append(lines, Message{Body: " Engine : " + engine, Level: ""}) - lines = append(lines, Message{Body: " Endpoint : " + endpoint, Level: ""}) - if status == "errored" { - err, _ := r["error"].(string) - lines = append(lines, Message{Body: " Error : " + err, Level: "ERROR"}) + for _, l := range n.getSingleDetail(v, "") { + lines = append(lines, l) } } return lines } + +func (n *RDSCluster) getSingleDetail(v interface{}, prefix string) (lines []Message) { + r := v.(map[string]interface{}) + name, _ := r["name"].(string) + if prefix != "" { + name = prefix + " " + name + } + engine, _ := r["engine"].(string) + endpoint, _ := r["endpoint"].(string) + status, _ := r["status"].(string) + lines = append(lines, Message{Body: " - " + name, Level: ""}) + lines = append(lines, Message{Body: " Engine : " + engine, Level: ""}) + lines = append(lines, Message{Body: " Endpoint : " + endpoint, Level: ""}) + if status == "errored" { + err, _ := r["error"].(string) + lines = append(lines, Message{Body: " Error : " + err, Level: "ERROR"}) + } + return lines +} diff --git a/c_rds_instance.go b/c_rds_instance.go index 4225b0a..3b755da 100644 --- a/c_rds_instance.go +++ b/c_rds_instance.go @@ -4,9 +4,11 @@ package main +// RDSInstance : ... type RDSInstance struct { } +// Handle : ... func (n *RDSInstance) Handle(subject string, components []interface{}, lines []Message) []Message { switch subject { case "rds_instances.create": @@ -41,27 +43,47 @@ func (n *RDSInstance) Handle(subject string, components []interface{}, lines []M case "rds_instances.find.error": lines = n.getDetails(components) return append(lines, Message{Body: "RDS instances import failed", Level: "INFO"}) + + case "rds_instance.create.done", "rds_instance.create.error": + lines = n.getSingleDetail(components, "RDS instance created") + case "rds_instance.udpate.done", "rds_instance.update.error": + lines = n.getSingleDetail(components, "RDS instance updated") + case "rds_instance.delete.done", "rds_instance.delete.error": + lines = n.getSingleDetail(components, "RDS instance deleted") + case "rds_instance.find.done", "rds_instance.find.error": + lines = n.getSingleDetail(components, "RDS instance found") } return lines } func (n *RDSInstance) getDetails(components []interface{}) (lines []Message) { for _, v := range components { - r := v.(map[string]interface{}) - name, _ := r["name"].(string) - engine, _ := r["engine"].(string) - cluster, _ := r["cluster"].(string) - endpoint, _ := r["endpoint"].(string) - status, _ := r["status"].(string) - lines = append(lines, Message{Body: " - " + name, Level: ""}) - lines = append(lines, Message{Body: " Engine : " + engine, Level: ""}) - lines = append(lines, Message{Body: " Cluster : " + cluster, Level: ""}) - lines = append(lines, Message{Body: " Endpoint : " + endpoint, Level: ""}) - if status == "errored" { - err, _ := r["error"].(string) - lines = append(lines, Message{Body: " Error : " + err, Level: "ERROR"}) + for _, l := range n.getSingleDetail(v, "") { + lines = append(lines, l) } } return lines } + +func (n *RDSInstance) getSingleDetail(v interface{}, prefix string) (lines []Message) { + r := v.(map[string]interface{}) + name, _ := r["name"].(string) + if prefix != "" { + name = prefix + " " + name + } + engine, _ := r["engine"].(string) + cluster, _ := r["cluster"].(string) + endpoint, _ := r["endpoint"].(string) + status, _ := r["status"].(string) + lines = append(lines, Message{Body: " - " + name, Level: ""}) + lines = append(lines, Message{Body: " Engine : " + engine, Level: ""}) + lines = append(lines, Message{Body: " Cluster : " + cluster, Level: ""}) + lines = append(lines, Message{Body: " Endpoint : " + endpoint, Level: ""}) + if status == "errored" { + err, _ := r["error"].(string) + lines = append(lines, Message{Body: " Error : " + err, Level: "ERROR"}) + } + + return lines +} diff --git a/c_router.go b/c_router.go index 9aafb02..9d74388 100644 --- a/c_router.go +++ b/c_router.go @@ -4,9 +4,11 @@ package main +// Router : ... type Router struct { } +// Handle : ... func (n *Router) Handle(subject string, components []interface{}, lines []Message) []Message { switch subject { case "routers.create": @@ -24,23 +26,37 @@ func (n *Router) Handle(subject string, components []interface{}, lines []Messag case "routers.delete.error": lines = n.getDetails(components) return append(lines, Message{Body: "Routers deletion failed", Level: "INFO"}) + + case "router.create.done", "router.create.error": + lines = n.getSingleDetail(components, "Created router") + case "router.delete.done", "router.delete.error": + lines = n.getSingleDetail(components, "Deleted router") } return lines } func (n *Router) getDetails(components []interface{}) (lines []Message) { for _, v := range components { - r := v.(map[string]interface{}) - name, _ := r["name"].(string) - status, _ := r["status"].(string) - ip, _ := r["ip"].(string) - lines = append(lines, Message{Body: " - " + name, Level: ""}) - lines = append(lines, Message{Body: " IP : " + ip, Level: ""}) - lines = append(lines, Message{Body: " Status : " + status, Level: ""}) - if status == "errored" { - err, _ := r["error"].(string) - lines = append(lines, Message{Body: " Error : " + err, Level: "ERROR"}) - } + lines = append(lines, n.getSingleDetail(v, "")...) + } + + return lines +} + +func (n *Router) getSingleDetail(v interface{}, prefix string) (lines []Message) { + r := v.(map[string]interface{}) + name, _ := r["name"].(string) + if prefix != "" { + name = prefix + " " + name + } + status, _ := r["status"].(string) + ip, _ := r["ip"].(string) + lines = append(lines, Message{Body: " - " + name, Level: ""}) + lines = append(lines, Message{Body: " IP : " + ip, Level: ""}) + lines = append(lines, Message{Body: " Status : " + status, Level: ""}) + if status == "errored" { + err, _ := r["error"].(string) + lines = append(lines, Message{Body: " Error : " + err, Level: "ERROR"}) } return lines diff --git a/c_s3.go b/c_s3.go index 789fde0..8ed7b30 100644 --- a/c_s3.go +++ b/c_s3.go @@ -4,9 +4,11 @@ package main +// S3Bucket : ... type S3Bucket struct { } +// Handle : ... func (n *S3Bucket) Handle(subject string, components []interface{}, lines []Message) []Message { switch subject { case "s3s.create": @@ -41,27 +43,46 @@ func (n *S3Bucket) Handle(subject string, components []interface{}, lines []Mess case "s3s.find.error": lines = n.getDetails(components) return append(lines, Message{Body: "S3 buckets import failed", Level: "INFO"}) + + case "s3.create.done", "s3.create.error": + lines = n.getSingleDetail(components, "S3 bucket created") + case "s3.update.done", "s3.update.error": + lines = n.getSingleDetail(components, "S3 bucket updated") + case "s3.delete.done", "s3.delete.error": + lines = n.getSingleDetail(components, "S3 bucket deleted") + case "s3.find.done", "s3.find.error": + lines = n.getSingleDetail(components, "S3 bucket imported") } return lines } func (n *S3Bucket) getDetails(components []interface{}) (lines []Message) { for _, v := range components { - r := v.(map[string]interface{}) - name, _ := r["name"].(string) - acl, _ := r["acl"].(string) - if acl == "" { - acl = "by grantees" - } - status, _ := r["status"].(string) - lines = append(lines, Message{Body: " - " + name, Level: ""}) - lines = append(lines, Message{Body: " ACL : " + acl, Level: ""}) - lines = append(lines, Message{Body: " Status : " + status, Level: ""}) - if status == "errored" { - err, _ := r["error"].(string) - lines = append(lines, Message{Body: " Error : " + err, Level: "ERROR"}) + for _, l := range n.getSingleDetail(v, "") { + lines = append(lines, l) } } return lines } + +func (n *S3Bucket) getSingleDetail(v interface{}, prefix string) (lines []Message) { + r := v.(map[string]interface{}) + name, _ := r["name"].(string) + if prefix != "" { + name = prefix + " " + name + } + acl, _ := r["acl"].(string) + if acl == "" { + acl = "by grantees" + } + status, _ := r["status"].(string) + lines = append(lines, Message{Body: " - " + name, Level: ""}) + lines = append(lines, Message{Body: " ACL : " + acl, Level: ""}) + lines = append(lines, Message{Body: " Status : " + status, Level: ""}) + if status == "errored" { + err, _ := r["error"].(string) + lines = append(lines, Message{Body: " Error : " + err, Level: "ERROR"}) + } + return lines +} diff --git a/c_service.go b/c_service.go index 1142e7b..9455baa 100644 --- a/c_service.go +++ b/c_service.go @@ -4,9 +4,11 @@ package main +// Service : ... type Service struct { } +// Handle : ... func (n *Service) Handle(subject string, lines []Message) []Message { switch subject { case "service.create": diff --git a/c_vpc.go b/c_vpc.go index d9df0f0..1fad064 100644 --- a/c_vpc.go +++ b/c_vpc.go @@ -4,9 +4,11 @@ package main +// Vpc : ... type Vpc struct { } +// Handle : ... func (n *Vpc) Handle(subject string, components []interface{}, lines []Message) []Message { switch subject { case "vpcs.create": @@ -32,24 +34,43 @@ func (n *Vpc) Handle(subject string, components []interface{}, lines []Message) case "vpcs.find.error": lines = n.getDetails(components) return append(lines, Message{Body: "Vpc import failed", Level: "INFO"}) + + case "vpc.create.done", "vpc.create.error": + lines = n.getSingleDetail(components, "VPC created") + case "vpc.update.done", "vpc.update.error": + lines = n.getSingleDetail(components, "VPC udpated") + case "vpc.delete.done", "vpc.delete.error": + lines = n.getSingleDetail(components, "VPC deleted") + case "vpc.find.done", "vpc.find.error": + lines = n.getSingleDetail(components, "VPC Found") } return lines } func (n *Vpc) getDetails(components []interface{}) (lines []Message) { for _, v := range components { - r := v.(map[string]interface{}) - id, _ := r["vpc_id"].(string) - subnet, _ := r["vpc_subnet"].(string) - status, _ := r["status"].(string) - lines = append(lines, Message{Body: " - " + id, Level: ""}) - lines = append(lines, Message{Body: " Subnet : " + subnet, Level: ""}) - lines = append(lines, Message{Body: " Status : " + status, Level: ""}) - if status == "errored" { - err, _ := r["error"].(string) - lines = append(lines, Message{Body: " Error : " + err, Level: "ERROR"}) + for _, l := range n.getSingleDetail(v, "") { + lines = append(lines, l) } } return lines } + +func (n *Vpc) getSingleDetail(v interface{}, prefix string) (lines []Message) { + r := v.(map[string]interface{}) + id, _ := r["vpc_id"].(string) + if prefix != "" { + id = prefix + " " + id + } + subnet, _ := r["vpc_subnet"].(string) + status, _ := r["status"].(string) + lines = append(lines, Message{Body: " - " + id, Level: ""}) + lines = append(lines, Message{Body: " Subnet : " + subnet, Level: ""}) + lines = append(lines, Message{Body: " Status : " + status, Level: ""}) + if status == "errored" { + err, _ := r["error"].(string) + lines = append(lines, Message{Body: " Error : " + err, Level: "ERROR"}) + } + return lines +}