From 993901a670f1a43a266e512891afed61464bd3cf Mon Sep 17 00:00:00 2001 From: Mark Newman Date: Mon, 15 May 2017 13:49:41 +0100 Subject: [PATCH] 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) }