Skip to content

Commit

Permalink
Stash changes
Browse files Browse the repository at this point in the history
  • Loading branch information
g3kk0 committed May 15, 2017
1 parent f5886ba commit 993901a
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
58 changes: 58 additions & 0 deletions c_sql_firewall_rules.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"

// 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
}
3 changes: 3 additions & 0 deletions generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 993901a

Please sign in to comment.