Skip to content

Commit a3529a4

Browse files
authored
Merge pull request #18 from hazcod/work/commandbot
Tag fix & log optimisations
2 parents 7711901 + 98213a3 commit a3529a4

File tree

2 files changed

+39
-13
lines changed

2 files changed

+39
-13
lines changed

cmd/main.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ func main() {
2525
configPath := flag.String("config", "", "Path to your config file.")
2626
logLevelStr := flag.String("log", "info", "Log level.")
2727
dryMode := flag.Bool("dry", false, "whether we run in dry-run mode and send nothing to the users.")
28+
noReport := flag.Bool("noreport", false, "disable sending an overview to the security user.")
2829
flag.Parse()
2930

3031
logLevel, err := logrus.ParseLevel(*logLevelStr)
@@ -76,7 +77,7 @@ func main() {
7677
}
7778
}
7879

79-
if securityUserID == "" {
80+
if securityUserID == "" && !*noReport {
8081
logrus.WithField("fallback_user", config.Slack.SecurityUser).
8182
Fatal("could not find fallback user on Slack")
8283
}
@@ -92,11 +93,6 @@ func main() {
9293
continue
9394
}
9495

95-
if config.Slack.SkipOnHoliday && strings.EqualFold(slackUser.Profile.StatusText, slackStatusHoliday) {
96-
logrus.WithField("slack_name", slackUser.Name).Warn("skipping user since he/she is on holiday")
97-
continue
98-
}
99-
10096
userFalconMsg := falconMessages[userEmail]
10197

10298
userWS1Msg := ws1Messages[userEmail]
@@ -105,7 +101,12 @@ func main() {
105101
continue
106102
}
107103

108-
logrus.WithField("falcon", userFalconMsg).WithField("ws1", userWS1Msg).WithField("email", userEmail).
104+
if config.Slack.SkipOnHoliday && strings.EqualFold(slackUser.Profile.StatusText, slackStatusHoliday) {
105+
logrus.WithField("slack_name", slackUser.Name).Warn("skipping user since he/she is on holiday")
106+
continue
107+
}
108+
109+
logrus.WithField("falcon", len(userFalconMsg.Devices)).WithField("ws1", len(userWS1Msg.Devices)).WithField("email", userEmail).
109110
Debug("found messages")
110111

111112
slackMessage, err := user.BuildUserOverviewMessage(logrus.StandardLogger(), config, slackUser, falconMessages[userEmail], ws1Messages[userEmail])
@@ -134,6 +135,11 @@ func main() {
134135
logrus.WithField("user", userEmail).Info("sent notice on Slack")
135136
}
136137

138+
if *noReport {
139+
logrus.Info("exiting since security overview is disabled")
140+
os.Exit(0)
141+
}
142+
137143
if config.Templates.SecurityOverviewMessage == "" {
138144
logrus.Warn("not sending a security overview since template is empty")
139145
os.Exit(0)

pkg/falcon/extractor.go

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,25 @@ func findEmailTag(tags []string, emailDomains []string) (email string, err error
9797
return email, nil
9898
}
9999

100+
func appendUnique(main, adder []string) []string {
101+
for i := range adder {
102+
found := false
103+
104+
for j := range main {
105+
if strings.EqualFold(adder[i], main[j]) {
106+
found = true
107+
break
108+
}
109+
}
110+
111+
if found { continue }
112+
113+
main = append(main, adder[i])
114+
}
115+
116+
return main
117+
}
118+
100119
func GetMessages(config *config.Config, ctx context.Context) (results map[string]FalconResult, err error) {
101120
falconAPIMaxRecords := int64(400)
102121

@@ -181,7 +200,9 @@ func GetMessages(config *config.Config, ctx context.Context) (results map[string
181200

182201
for _, sev := range config.Falcon.SkipSeverities {
183202
if strings.EqualFold(sev, vulnSev) {
184-
logrus.WithField("severity", *vuln.Cve.Severity).Debug("skipping vulnerability")
203+
logrus.WithField("host", *vuln.HostInfo.Hostname).WithField("cve_score", *vuln.Cve.BaseScore).
204+
WithField("severity", *vuln.Cve.Severity).WithField("cve", *vuln.Cve.ID).
205+
Debug("skipping vulnerability")
185206
skip = true
186207
break
187208
}
@@ -190,7 +211,8 @@ func GetMessages(config *config.Config, ctx context.Context) (results map[string
190211
if skip { continue }
191212
}
192213

193-
logrus.WithField("cve_score", *vuln.Cve.BaseScore).WithField("severity", *vuln.Cve.Severity).
214+
logrus.WithField("host", *vuln.HostInfo.Hostname).WithField("cve_score", *vuln.Cve.BaseScore).
215+
WithField("severity", *vuln.Cve.Severity).WithField("cve", *vuln.Cve.ID).
194216
Debug("adding vulnerability")
195217

196218
deviceFinding := UserDeviceFinding{
@@ -235,7 +257,7 @@ func GetMessages(config *config.Config, ctx context.Context) (results map[string
235257
device.Findings = append(device.Findings, deviceFinding)
236258
}
237259

238-
device.Tags = append(device.Tags, vuln.HostInfo.Tags...)
260+
device.Tags = appendUnique(device.Tags, vuln.HostInfo.Tags)
239261

240262
devices[uniqueDeviceID] = device
241263

@@ -260,7 +282,7 @@ func GetMessages(config *config.Config, ctx context.Context) (results map[string
260282
WithField("tags", device.Tags).
261283
WithField("prefix", tagEmailPrefix).
262284
WithField("device", device.MachineName).
263-
Warn("could extract user email tag, using fallback Slack user")
285+
Warn("could not extract Falcon email tag from host, using fallback")
264286

265287
userEmail = config.Slack.SecurityUser
266288
}
@@ -278,7 +300,5 @@ func GetMessages(config *config.Config, ctx context.Context) (results map[string
278300
results[userEmail] = user
279301
}
280302

281-
logrus.Debugf("%+v", results)
282-
283303
return results, nil
284304
}

0 commit comments

Comments
 (0)