Skip to content

Commit

Permalink
Loadbalancers related messages
Browse files Browse the repository at this point in the history
  • Loading branch information
adriacidre committed May 22, 2017
1 parent be8a8e9 commit 9a07c4a
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 0 deletions.
58 changes: 58 additions & 0 deletions c_loadbalancer_backend_address_pool.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/* 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"

// LbBackendAddressPool : ...
type LbBackendAddressPool struct {
}

// Handle : ...
func (n *LbBackendAddressPool) Handle(subject string, c component, lines []Message) []Message {
parts := strings.Split(subject, ".")
subject = parts[0] + "." + parts[1]
switch subject {
case "lb_backend_address_pool.create":
lines = n.getSingleDetail(c, "Created Loadbalancer")
case "lb_backend_address_pool.update":
lines = n.getSingleDetail(c, "Updated Loadbalancer")
case "lb_backend_address_pool.delete":
lines = n.getSingleDetail(c, "Deleted Loadbalancer")
case "lb_backend_address_pools.find":
for _, cx := range c.getFoundComponents() {
lines = append(lines, n.getSingleDetail(cx, "Found Loadbalancer backend address pool")...)
}
}
return lines
}

func (n *LbBackendAddressPool) 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["id"].(string)
if id != "" {
lines = append(lines, Message{Body: " 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
}
58 changes: 58 additions & 0 deletions c_loadbalancer_probe.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/* 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"

// LbProbe : ...
type LbProbe struct {
}

// Handle : ...
func (n *LbProbe) Handle(subject string, c component, lines []Message) []Message {
parts := strings.Split(subject, ".")
subject = parts[0] + "." + parts[1]
switch subject {
case "lb_probe.create":
lines = n.getSingleDetail(c, "Created Loadbalancer")
case "lb_probe.update":
lines = n.getSingleDetail(c, "Updated Loadbalancer")
case "lb_probe.delete":
lines = n.getSingleDetail(c, "Deleted Loadbalancer")
case "lb_probes.find":
for _, cx := range c.getFoundComponents() {
lines = append(lines, n.getSingleDetail(cx, "Found Loadbalancer probe")...)
}
}
return lines
}

func (n *LbProbe) 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["id"].(string)
if id != "" {
lines = append(lines, Message{Body: " 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
}
58 changes: 58 additions & 0 deletions c_loadbalancer_rule.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/* 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"

// LbRule : ...
type LbRule struct {
}

// Handle : ...
func (n *LbRule) Handle(subject string, c component, lines []Message) []Message {
parts := strings.Split(subject, ".")
subject = parts[0] + "." + parts[1]
switch subject {
case "lb_rule.create":
lines = n.getSingleDetail(c, "Created Loadbalancer")
case "lb_rule.update":
lines = n.getSingleDetail(c, "Updated Loadbalancer")
case "lb_rule.delete":
lines = n.getSingleDetail(c, "Deleted Loadbalancer")
case "lb_rules.find":
for _, cx := range c.getFoundComponents() {
lines = append(lines, n.getSingleDetail(cx, "Found Loadbalancer Rule")...)
}
}
return lines
}

func (n *LbRule) 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["id"].(string)
if id != "" {
lines = append(lines, Message{Body: " 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
}
9 changes: 9 additions & 0 deletions generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,15 @@ func genericHandler(msg *nats.Msg) {
case "lb", "lbs":
var h Lb
msgLines = h.Handle(msg.Subject, c, msgLines)
case "lb_rule", "lb_rules":
var h LbRule
msgLines = h.Handle(msg.Subject, c, msgLines)
case "lb_probe", "lb_probes":
var h LbProbe
msgLines = h.Handle(msg.Subject, c, msgLines)
case "lb_backend_address_pool", "lb_backend_address_pools":
var h LbProbe
msgLines = h.Handle(msg.Subject, c, msgLines)
case "sql_server", "sql_servers":
var h SQLServer
msgLines = h.Handle(msg.Subject, c, msgLines)
Expand Down

0 comments on commit 9a07c4a

Please sign in to comment.