-
Notifications
You must be signed in to change notification settings - Fork 3
/
auditing.go
45 lines (41 loc) · 1.23 KB
/
auditing.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package outputs
import (
"fmt"
"os"
"strings"
"time"
"github.com/hexbotio/hex/models"
)
type Auditing struct {
}
func (x Auditing) Write(message models.Message, config models.Config) {
who := " "
if message.Attributes["hex.user"] != "" {
who = who + message.Attributes["hex.user"] + " "
}
if message.Attributes["hex.channel"] != "" {
if strings.HasPrefix(message.Attributes["hex.channel"], "#") {
who = who + message.Attributes["hex.channel"] + " "
} else {
who = who + "DM "
}
}
if message.Attributes["hex.schedule"] != "" {
who = who + message.Attributes["hex.schedule"] + " "
}
if message.Attributes["hex.ipaddress"] != "" {
who = who + message.Attributes["hex.ipaddress"] + " "
}
if message.Attributes["hex.url"] != "" {
who = who + message.Attributes["hex.url"] + " "
}
out := fmt.Sprintf("%s [%s] %s >> %s\n", time.Now().Format(time.RFC3339), who, message.Attributes["hex.input"], message.Attributes["hex.rule.name"])
file, err := os.OpenFile(config.AuditingFile, os.O_APPEND|os.O_WRONLY, 0600)
if err != nil {
config.Logger.Error("Auditing File" + " - " + err.Error())
}
defer file.Close()
if _, err = file.WriteString(out); err != nil {
config.Logger.Error("Writing Audit File" + " - " + err.Error())
}
}