From 993901a670f1a43a266e512891afed61464bd3cf Mon Sep 17 00:00:00 2001 From: Mark Newman Date: Mon, 15 May 2017 13:49:41 +0100 Subject: [PATCH 1/3] Stash changes --- c_sql_firewall_rules.go | 58 +++++++++++++++++++++++++++++++++++++++++ generic.go | 3 +++ 2 files changed, 61 insertions(+) create mode 100644 c_sql_firewall_rules.go diff --git a/c_sql_firewall_rules.go b/c_sql_firewall_rules.go new file mode 100644 index 0000000..85ade68 --- /dev/null +++ b/c_sql_firewall_rules.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" + +// SQLFirewallRule : ... +type SQLFirewallRule struct { +} + +// Handle : ... +func (n *SQLFirewallRule) Handle(subject string, c component, lines []Message) []Message { + parts := strings.Split(subject, ".") + subject = parts[0] + "." + parts[1] + switch subject { + case "sql_server.create": + lines = n.getSingleDetail(c, "Created SQL Server") + case "sql_server.update": + lines = n.getSingleDetail(c, "Updated SQL Server") + case "sql_server.delete": + lines = n.getSingleDetail(c, "Deleted SQL Server") + case "sql_servers.find": + for _, cx := range c.getFoundComponents() { + lines = append(lines, n.getSingleDetail(cx, "Found SQL Server")...) + } + } + return lines +} + +func (n *SQLServer) 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 edd9243..8123030 100644 --- a/generic.go +++ b/generic.go @@ -127,6 +127,9 @@ func genericHandler(msg *nats.Msg) { case "sql_database", "sql_databases": var h SQLDatabase msgLines = h.Handle(msg.Subject, c, msgLines) + case "sql_firewall_rule", "sql_firewall_rules": + var h SQLFirewallRule + msgLines = h.Handle(msg.Subject, c, msgLines) default: log.Println("unsupported: " + msg.Subject) } From ac98f198a7b8b2aa354f03c16a05fb32761d4099 Mon Sep 17 00:00:00 2001 From: Mark Newman Date: Mon, 15 May 2017 17:13:04 +0100 Subject: [PATCH 2/3] Add informational reporting for sql_firewall_rules --- c_sql_firewall_rules.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/c_sql_firewall_rules.go b/c_sql_firewall_rules.go index 85ade68..4dc0a57 100644 --- a/c_sql_firewall_rules.go +++ b/c_sql_firewall_rules.go @@ -15,21 +15,21 @@ func (n *SQLFirewallRule) Handle(subject string, c component, lines []Message) [ parts := strings.Split(subject, ".") subject = parts[0] + "." + parts[1] switch subject { - case "sql_server.create": - lines = n.getSingleDetail(c, "Created SQL Server") - case "sql_server.update": - lines = n.getSingleDetail(c, "Updated SQL Server") - case "sql_server.delete": - lines = n.getSingleDetail(c, "Deleted SQL Server") - case "sql_servers.find": + case "sql_firewall_rule.create": + lines = n.getSingleDetail(c, "Created SQL Firewall Rule") + case "sql_firewall_rule.update": + lines = n.getSingleDetail(c, "Updated SQL Firewall Rule") + case "sql_firewall_rule.delete": + lines = n.getSingleDetail(c, "Deleted SQL Firewall Rule") + case "sql_firewall_rule.find": for _, cx := range c.getFoundComponents() { - lines = append(lines, n.getSingleDetail(cx, "Found SQL Server")...) + lines = append(lines, n.getSingleDetail(cx, "Found SQL Firewall Rule")...) } } return lines } -func (n *SQLServer) getSingleDetail(c component, prefix string) (lines []Message) { +func (n *SQLFirewallRule) getSingleDetail(c component, prefix string) (lines []Message) { name, _ := c["name"].(string) if prefix != "" { name = prefix + " " + name From 39aba54a2856688874d9ccf9d501cf3d17fd81cb Mon Sep 17 00:00:00 2001 From: Mark Newman Date: Mon, 15 May 2017 18:19:20 +0100 Subject: [PATCH 3/3] Fix typo on subject --- c_sql_firewall_rules.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/c_sql_firewall_rules.go b/c_sql_firewall_rules.go index 4dc0a57..b6a95ed 100644 --- a/c_sql_firewall_rules.go +++ b/c_sql_firewall_rules.go @@ -21,7 +21,7 @@ func (n *SQLFirewallRule) Handle(subject string, c component, lines []Message) [ lines = n.getSingleDetail(c, "Updated SQL Firewall Rule") case "sql_firewall_rule.delete": lines = n.getSingleDetail(c, "Deleted SQL Firewall Rule") - case "sql_firewall_rule.find": + case "sql_firewall_rules.find": for _, cx := range c.getFoundComponents() { lines = append(lines, n.getSingleDetail(cx, "Found SQL Firewall Rule")...) }