Skip to content

Commit

Permalink
Merge pull request #21 from ernestio/rds
Browse files Browse the repository at this point in the history
monitoring rds instance and cluster messages
  • Loading branch information
adriacidre authored Nov 30, 2016
2 parents 80b7e04 + 9b8d1a5 commit eaab3f8
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 0 deletions.
57 changes: 57 additions & 0 deletions c_rds_cluster.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/* 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

type RDSCluster struct {
}

func (n *RDSCluster) Handle(subject string, components []interface{}, lines []Message) []Message {
switch subject {
case "rds_clusters.create":
lines = append(lines, Message{Body: "Creating rds clusters:", Level: "INFO"})
case "rds_clusters.create.done":
lines = n.getDetails(components)
return append(lines, Message{Body: "RDS clusters created", Level: "INFO"})
case "rds_clusters.create.error":
lines = n.getDetails(components)
return append(lines, Message{Body: "RDS clusters creation failed", Level: "INFO"})
case "rds_clusters.update":
lines = append(lines, Message{Body: "Updating rds clusters:", Level: "INFO"})
case "rds_clusters.update.done":
lines = n.getDetails(components)
return append(lines, Message{Body: "RDS clusters modified", Level: "INFO"})
case "rds_clusters.update.error":
lines = n.getDetails(components)
return append(lines, Message{Body: "RDS clusters modification failed", Level: "INFO"})
case "rds_clusters.delete":
return append(lines, Message{Body: "Deleting rds clusters:", Level: "INFO"})
case "rds_clusters.delete.done":
lines = n.getDetails(components)
return append(lines, Message{Body: "RDS clusters deleted", Level: "INFO"})
case "rds_clusters.delete.error":
lines = n.getDetails(components)
return append(lines, Message{Body: "RDS clusters deletion failed", Level: "INFO"})
}
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"})
}
}

return lines
}
59 changes: 59 additions & 0 deletions c_rds_instance.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/* 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

type RDSInstance struct {
}

func (n *RDSInstance) Handle(subject string, components []interface{}, lines []Message) []Message {
switch subject {
case "rds_instances.create":
lines = append(lines, Message{Body: "Creating rds instances:", Level: "INFO"})
case "rds_instances.create.done":
lines = n.getDetails(components)
return append(lines, Message{Body: "RDS instances created", Level: "INFO"})
case "rds_instances.create.error":
lines = n.getDetails(components)
return append(lines, Message{Body: "RDS instances creation failed", Level: "INFO"})
case "rds_instances.update":
lines = append(lines, Message{Body: "Updating rds instances:", Level: "INFO"})
case "rds_instances.update.done":
lines = n.getDetails(components)
return append(lines, Message{Body: "RDS instances modified", Level: "INFO"})
case "rds_instances.update.error":
lines = n.getDetails(components)
return append(lines, Message{Body: "RDS instances modification failed", Level: "INFO"})
case "rds_instances.delete":
return append(lines, Message{Body: "Deleting rds instances:", Level: "INFO"})
case "rds_instances.delete.done":
lines = n.getDetails(components)
return append(lines, Message{Body: "RDS instances deleted", Level: "INFO"})
case "rds_instances.delete.error":
lines = n.getDetails(components)
return append(lines, Message{Body: "RDS instances deletion failed", Level: "INFO"})
}
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"})
}
}

return lines
}
6 changes: 6 additions & 0 deletions generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ func genericHandler(msg *nats.Msg) {
case "s3s":
var n S3Bucket
msgLines = n.Handle(msg.Subject, input.Components, msgLines)
case "rds_clusters":
var n RDSCluster
msgLines = n.Handle(msg.Subject, input.Components, msgLines)
case "rds_instances":
var n RDSInstance
msgLines = n.Handle(msg.Subject, input.Components, msgLines)
default:
switch msg.Subject {
case "executions.create.done":
Expand Down

0 comments on commit eaab3f8

Please sign in to comment.