From 9a07c4a403cdf758efbaf49ab5d1600bcccff13a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Cidre?= Date: Mon, 22 May 2017 15:31:40 +0200 Subject: [PATCH] Loadbalancers related messages --- c_loadbalancer_backend_address_pool.go | 58 ++++++++++++++++++++++++++ c_loadbalancer_probe.go | 58 ++++++++++++++++++++++++++ c_loadbalancer_rule.go | 58 ++++++++++++++++++++++++++ generic.go | 9 ++++ 4 files changed, 183 insertions(+) create mode 100644 c_loadbalancer_backend_address_pool.go create mode 100644 c_loadbalancer_probe.go create mode 100644 c_loadbalancer_rule.go diff --git a/c_loadbalancer_backend_address_pool.go b/c_loadbalancer_backend_address_pool.go new file mode 100644 index 0000000..821c9c4 --- /dev/null +++ b/c_loadbalancer_backend_address_pool.go @@ -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 +} diff --git a/c_loadbalancer_probe.go b/c_loadbalancer_probe.go new file mode 100644 index 0000000..2ad9541 --- /dev/null +++ b/c_loadbalancer_probe.go @@ -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 +} diff --git a/c_loadbalancer_rule.go b/c_loadbalancer_rule.go new file mode 100644 index 0000000..1c96787 --- /dev/null +++ b/c_loadbalancer_rule.go @@ -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 +} diff --git a/generic.go b/generic.go index 8123030..da7a4a0 100644 --- a/generic.go +++ b/generic.go @@ -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)