forked from falcosecurity/falcosidekick
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
735 lines (661 loc) · 25.3 KB
/
main.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
package main
import (
"context"
"fmt"
"log"
"net/http"
"os"
"regexp"
"strings"
"time"
"github.com/DataDog/datadog-go/statsd"
"github.com/embano1/memlog"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/falcosecurity/falcosidekick/outputs"
"github.com/falcosecurity/falcosidekick/types"
)
// Globale variables
var (
nullClient *outputs.Client
slackClient *outputs.Client
cliqClient *outputs.Client
rocketchatClient *outputs.Client
mattermostClient *outputs.Client
teamsClient *outputs.Client
datadogClient *outputs.Client
discordClient *outputs.Client
alertmanagerClient *outputs.Client
elasticsearchClient *outputs.Client
influxdbClient *outputs.Client
lokiClient *outputs.Client
natsClient *outputs.Client
stanClient *outputs.Client
awsClient *outputs.Client
smtpClient *outputs.Client
opsgenieClient *outputs.Client
webhookClient *outputs.Client
noderedClient *outputs.Client
cloudeventsClient *outputs.Client
azureClient *outputs.Client
gcpClient *outputs.Client
googleChatClient *outputs.Client
kafkaClient *outputs.Client
kafkaRestClient *outputs.Client
pagerdutyClient *outputs.Client
gcpCloudRunClient *outputs.Client
kubelessClient *outputs.Client
openfaasClient *outputs.Client
tektonClient *outputs.Client
webUIClient *outputs.Client
policyReportClient *outputs.Client
rabbitmqClient *outputs.Client
wavefrontClient *outputs.Client
fissionClient *outputs.Client
grafanaClient *outputs.Client
grafanaOnCallClient *outputs.Client
yandexClient *outputs.Client
syslogClient *outputs.Client
mqttClient *outputs.Client
zincsearchClient *outputs.Client
gotifyClient *outputs.Client
spyderbatClient *outputs.Client
timescaleDBClient *outputs.Client
redisClient *outputs.Client
telegramClient *outputs.Client
n8nClient *outputs.Client
statsdClient, dogstatsdClient *statsd.Client
config *types.Configuration
stats *types.Statistics
promStats *types.PromStatistics
regPromLabels *regexp.Regexp
)
func init() {
// detect unit testing and skip init.
// see: https://github.com/alecthomas/kingpin/issues/187
testing := (strings.HasSuffix(os.Args[0], ".test") ||
strings.HasSuffix(os.Args[0], "__debug_bin"))
if testing {
return
}
regPromLabels, _ = regexp.Compile("^[a-zA-Z_:][a-zA-Z0-9_:]*$")
config = getConfig()
stats = getInitStats()
promStats = getInitPromStats(config)
nullClient = &outputs.Client{
OutputType: "null",
Config: config,
Stats: stats,
PromStats: promStats,
StatsdClient: statsdClient,
DogstatsdClient: dogstatsdClient,
}
if config.Statsd.Forwarder != "" {
var err error
statsdClient, err = outputs.NewStatsdClient("StatsD", config, stats)
if err != nil {
config.Statsd.Forwarder = ""
} else {
outputs.EnabledOutputs = append(outputs.EnabledOutputs, "StatsD")
nullClient.DogstatsdClient = statsdClient
}
}
if config.Dogstatsd.Forwarder != "" {
var err error
dogstatsdClient, err = outputs.NewStatsdClient("DogStatsD", config, stats)
if err != nil {
config.Statsd.Forwarder = ""
} else {
outputs.EnabledOutputs = append(outputs.EnabledOutputs, "DogStatsD")
nullClient.DogstatsdClient = dogstatsdClient
}
}
if config.Slack.WebhookURL != "" {
var err error
slackClient, err = outputs.NewClient("Slack", config.Slack.WebhookURL, config.Slack.MutualTLS, config.Slack.CheckCert, config, stats, promStats, statsdClient, dogstatsdClient)
if err != nil {
config.Slack.WebhookURL = ""
} else {
outputs.EnabledOutputs = append(outputs.EnabledOutputs, "Slack")
}
}
if config.Cliq.WebhookURL != "" {
var err error
cliqClient, err = outputs.NewClient("Cliq", config.Cliq.WebhookURL, config.Cliq.MutualTLS, config.Cliq.CheckCert, config, stats, promStats, statsdClient, dogstatsdClient)
if err != nil {
config.Cliq.WebhookURL = ""
} else {
outputs.EnabledOutputs = append(outputs.EnabledOutputs, "Cliq")
}
}
if config.Rocketchat.WebhookURL != "" {
var err error
rocketchatClient, err = outputs.NewClient("Rocketchat", config.Rocketchat.WebhookURL, config.Rocketchat.MutualTLS, config.Rocketchat.CheckCert, config, stats, promStats, statsdClient, dogstatsdClient)
if err != nil {
config.Rocketchat.WebhookURL = ""
} else {
outputs.EnabledOutputs = append(outputs.EnabledOutputs, "Rocketchat")
}
}
if config.Mattermost.WebhookURL != "" {
var err error
mattermostClient, err = outputs.NewClient("Mattermost", config.Mattermost.WebhookURL, config.Mattermost.MutualTLS, config.Mattermost.CheckCert, config, stats, promStats, statsdClient, dogstatsdClient)
if err != nil {
config.Mattermost.WebhookURL = ""
} else {
outputs.EnabledOutputs = append(outputs.EnabledOutputs, "Mattermost")
}
}
if config.Teams.WebhookURL != "" {
var err error
teamsClient, err = outputs.NewClient("Teams", config.Teams.WebhookURL, config.Teams.MutualTLS, config.Teams.CheckCert, config, stats, promStats, statsdClient, dogstatsdClient)
if err != nil {
config.Teams.WebhookURL = ""
} else {
outputs.EnabledOutputs = append(outputs.EnabledOutputs, "Teams")
}
}
if config.Datadog.APIKey != "" {
var err error
datadogClient, err = outputs.NewClient("Datadog", config.Datadog.Host+outputs.DatadogPath+"?api_key="+config.Datadog.APIKey, config.Datadog.MutualTLS, config.Datadog.CheckCert, config, stats, promStats, statsdClient, dogstatsdClient)
if err != nil {
config.Datadog.APIKey = ""
} else {
outputs.EnabledOutputs = append(outputs.EnabledOutputs, "Datadog")
}
}
if config.Discord.WebhookURL != "" {
var err error
discordClient, err = outputs.NewClient("Discord", config.Discord.WebhookURL, config.Discord.MutualTLS, config.Discord.CheckCert, config, stats, promStats, statsdClient, dogstatsdClient)
if err != nil {
config.Discord.WebhookURL = ""
} else {
outputs.EnabledOutputs = append(outputs.EnabledOutputs, "Discord")
}
}
if config.Alertmanager.HostPort != "" {
var err error
alertmanagerClient, err = outputs.NewClient("AlertManager", config.Alertmanager.HostPort+config.Alertmanager.Endpoint, config.Alertmanager.MutualTLS, config.Alertmanager.CheckCert, config, stats, promStats, statsdClient, dogstatsdClient)
if err != nil {
config.Alertmanager.HostPort = ""
} else {
outputs.EnabledOutputs = append(outputs.EnabledOutputs, "AlertManager")
}
}
if config.Elasticsearch.HostPort != "" {
var err error
elasticsearchClient, err = outputs.NewClient("Elasticsearch", config.Elasticsearch.HostPort+"/"+config.Elasticsearch.Index+"/"+config.Elasticsearch.Type, config.Elasticsearch.MutualTLS, config.Elasticsearch.CheckCert, config, stats, promStats, statsdClient, dogstatsdClient)
if err != nil {
config.Elasticsearch.HostPort = ""
} else {
outputs.EnabledOutputs = append(outputs.EnabledOutputs, "Elasticsearch")
}
}
if config.Loki.HostPort != "" {
var err error
lokiClient, err = outputs.NewClient("Loki", config.Loki.HostPort+config.Loki.Endpoint, config.Loki.MutualTLS, config.Loki.CheckCert, config, stats, promStats, statsdClient, dogstatsdClient)
if err != nil {
config.Loki.HostPort = ""
} else {
outputs.EnabledOutputs = append(outputs.EnabledOutputs, "Loki")
}
}
if config.Nats.HostPort != "" {
var err error
natsClient, err = outputs.NewClient("NATS", config.Nats.HostPort, config.Nats.MutualTLS, config.Nats.CheckCert, config, stats, promStats, statsdClient, dogstatsdClient)
if err != nil {
config.Nats.HostPort = ""
} else {
outputs.EnabledOutputs = append(outputs.EnabledOutputs, "NATS")
}
}
if config.Stan.HostPort != "" && config.Stan.ClusterID != "" && config.Stan.ClientID != "" {
var err error
stanClient, err = outputs.NewClient("STAN", config.Stan.HostPort, config.Stan.MutualTLS, config.Stan.CheckCert, config, stats, promStats, statsdClient, dogstatsdClient)
if err != nil {
config.Stan.HostPort = ""
config.Stan.ClusterID = ""
config.Stan.ClientID = ""
} else {
outputs.EnabledOutputs = append(outputs.EnabledOutputs, "STAN")
}
}
if config.Influxdb.HostPort != "" {
var url string = config.Influxdb.HostPort
if config.Influxdb.Organization != "" && config.Influxdb.Bucket != "" {
url += "/api/v2/write?org=" + config.Influxdb.Organization + "&bucket=" + config.Influxdb.Bucket
} else if config.Influxdb.Database != "" {
url += "/write?db=" + config.Influxdb.Database
}
if config.Influxdb.User != "" && config.Influxdb.Password != "" && config.Influxdb.Token == "" {
url += "&u=" + config.Influxdb.User + "&p=" + config.Influxdb.Password
}
if config.Influxdb.Precision != "" {
url += "&precision=" + config.Influxdb.Precision
}
var err error
influxdbClient, err = outputs.NewClient("Influxdb", url, config.Influxdb.MutualTLS, config.Influxdb.CheckCert, config, stats, promStats, statsdClient, dogstatsdClient)
if err != nil {
config.Influxdb.HostPort = ""
} else {
outputs.EnabledOutputs = append(outputs.EnabledOutputs, "Influxdb")
}
}
if config.AWS.Lambda.FunctionName != "" || config.AWS.SQS.URL != "" ||
config.AWS.SNS.TopicArn != "" || config.AWS.CloudWatchLogs.LogGroup != "" || config.AWS.S3.Bucket != "" ||
config.AWS.Kinesis.StreamName != "" || (config.AWS.SecurityLake.Bucket != "" && config.AWS.SecurityLake.Region != "" && config.AWS.SecurityLake.AccountID != "") {
var err error
awsClient, err = outputs.NewAWSClient(config, stats, promStats, statsdClient, dogstatsdClient)
if err != nil {
config.AWS.AccessKeyID = ""
config.AWS.SecretAccessKey = ""
config.AWS.Region = ""
config.AWS.Lambda.FunctionName = ""
config.AWS.SQS.URL = ""
config.AWS.S3.Bucket = ""
config.AWS.SNS.TopicArn = ""
config.AWS.CloudWatchLogs.LogGroup = ""
config.AWS.CloudWatchLogs.LogStream = ""
config.AWS.Kinesis.StreamName = ""
config.AWS.SecurityLake.Region = ""
config.AWS.SecurityLake.Bucket = ""
config.AWS.SecurityLake.AccountID = ""
} else {
if config.AWS.Lambda.FunctionName != "" {
outputs.EnabledOutputs = append(outputs.EnabledOutputs, "AWSLambda")
}
if config.AWS.SQS.URL != "" {
outputs.EnabledOutputs = append(outputs.EnabledOutputs, "AWSSQS")
}
if config.AWS.SNS.TopicArn != "" {
outputs.EnabledOutputs = append(outputs.EnabledOutputs, "AWSSNS")
}
if config.AWS.CloudWatchLogs.LogGroup != "" {
outputs.EnabledOutputs = append(outputs.EnabledOutputs, "AWSCloudWatchLogs")
}
if config.AWS.S3.Bucket != "" {
outputs.EnabledOutputs = append(outputs.EnabledOutputs, "AWSS3")
}
if config.AWS.Kinesis.StreamName != "" {
outputs.EnabledOutputs = append(outputs.EnabledOutputs, "AWSKinesis")
}
if config.AWS.SecurityLake.Bucket != "" && config.AWS.SecurityLake.Region != "" && config.AWS.SecurityLake.AccountID != "" && config.AWS.SecurityLake.Prefix != "" {
config.AWS.SecurityLake.Ctx = context.Background()
config.AWS.SecurityLake.ReadOffset, config.AWS.SecurityLake.WriteOffset = new(memlog.Offset), new(memlog.Offset)
config.AWS.SecurityLake.Memlog, err = memlog.New(config.AWS.SecurityLake.Ctx, memlog.WithMaxSegmentSize(10000))
if config.AWS.SecurityLake.Interval < 5 {
config.AWS.SecurityLake.Interval = 5
}
go awsClient.StartSecurityLakeWorker()
if err != nil {
config.AWS.SecurityLake.Region = ""
config.AWS.SecurityLake.Bucket = ""
config.AWS.SecurityLake.AccountID = ""
config.AWS.SecurityLake.Prefix = ""
} else {
outputs.EnabledOutputs = append(outputs.EnabledOutputs, "AWSSecurityLake")
}
}
}
}
if config.SMTP.HostPort != "" && config.SMTP.From != "" && config.SMTP.To != "" {
var err error
smtpClient, err = outputs.NewSMTPClient(config, stats, promStats, statsdClient, dogstatsdClient)
if err != nil {
config.SMTP.HostPort = ""
} else {
outputs.EnabledOutputs = append(outputs.EnabledOutputs, "SMTP")
}
}
if config.Opsgenie.APIKey != "" {
var err error
url := "https://api.opsgenie.com/v2/alerts"
if strings.ToLower(config.Opsgenie.Region) == "eu" {
url = "https://api.eu.opsgenie.com/v2/alerts"
}
opsgenieClient, err = outputs.NewClient("Opsgenie", url, config.Opsgenie.MutualTLS, config.Opsgenie.CheckCert, config, stats, promStats, statsdClient, dogstatsdClient)
if err != nil {
config.Opsgenie.APIKey = ""
} else {
outputs.EnabledOutputs = append(outputs.EnabledOutputs, "Opsgenie")
}
}
if config.Webhook.Address != "" {
var err error
webhookClient, err = outputs.NewClient("Webhook", config.Webhook.Address, config.Webhook.MutualTLS, config.Webhook.CheckCert, config, stats, promStats, statsdClient, dogstatsdClient)
if err != nil {
config.Webhook.Address = ""
} else {
outputs.EnabledOutputs = append(outputs.EnabledOutputs, "Webhook")
}
}
if config.NodeRed.Address != "" {
var err error
noderedClient, err = outputs.NewClient("NodeRed", config.NodeRed.Address, false, config.NodeRed.CheckCert, config, stats, promStats, statsdClient, dogstatsdClient)
if err != nil {
config.NodeRed.Address = ""
} else {
outputs.EnabledOutputs = append(outputs.EnabledOutputs, "NodeRed")
}
}
if config.CloudEvents.Address != "" {
var err error
cloudeventsClient, err = outputs.NewClient("CloudEvents", config.CloudEvents.Address, config.CloudEvents.MutualTLS, config.CloudEvents.CheckCert, config, stats, promStats, statsdClient, dogstatsdClient)
if err != nil {
config.CloudEvents.Address = ""
} else {
outputs.EnabledOutputs = append(outputs.EnabledOutputs, "CloudEvents")
}
}
if config.Azure.EventHub.Name != "" {
var err error
azureClient, err = outputs.NewEventHubClient(config, stats, promStats, statsdClient, dogstatsdClient)
if err != nil {
config.Azure.EventHub.Name = ""
config.Azure.EventHub.Namespace = ""
} else {
if config.Azure.EventHub.Name != "" {
outputs.EnabledOutputs = append(outputs.EnabledOutputs, "EventHub")
}
}
}
if (config.GCP.PubSub.ProjectID != "" && config.GCP.PubSub.Topic != "") || config.GCP.Storage.Bucket != "" || config.GCP.CloudFunctions.Name != "" {
var err error
gcpClient, err = outputs.NewGCPClient(config, stats, promStats, statsdClient, dogstatsdClient)
if err != nil {
config.GCP.PubSub.ProjectID = ""
config.GCP.PubSub.Topic = ""
config.GCP.Storage.Bucket = ""
config.GCP.CloudFunctions.Name = ""
} else {
if config.GCP.PubSub.Topic != "" && config.GCP.PubSub.ProjectID != "" {
outputs.EnabledOutputs = append(outputs.EnabledOutputs, "GCPPubSub")
}
if config.GCP.Storage.Bucket != "" {
outputs.EnabledOutputs = append(outputs.EnabledOutputs, "GCPStorage")
}
if config.GCP.CloudFunctions.Name != "" {
outputs.EnabledOutputs = append(outputs.EnabledOutputs, "GCPCloudFunctions")
}
}
}
if config.GCP.CloudRun.Endpoint != "" && config.GCP.CloudRun.JWT != "" {
var err error
var outputName = "GCPCloudRun"
gcpCloudRunClient, err = outputs.NewClient(outputName, config.GCP.CloudRun.Endpoint, false, false, config, stats, promStats, statsdClient, dogstatsdClient)
if err != nil {
config.GCP.CloudRun.Endpoint = ""
} else {
outputs.EnabledOutputs = append(outputs.EnabledOutputs, outputName)
}
}
if config.Googlechat.WebhookURL != "" {
var err error
googleChatClient, err = outputs.NewClient("Googlechat", config.Googlechat.WebhookURL, config.Googlechat.MutualTLS, config.Googlechat.CheckCert, config, stats, promStats, statsdClient, dogstatsdClient)
if err != nil {
config.Googlechat.WebhookURL = ""
} else {
outputs.EnabledOutputs = append(outputs.EnabledOutputs, "GoogleChat")
}
}
if config.Kafka.HostPort != "" && config.Kafka.Topic != "" {
var err error
kafkaClient, err = outputs.NewKafkaClient(config, stats, promStats, statsdClient, dogstatsdClient)
if err != nil {
config.Kafka.HostPort = ""
} else {
outputs.EnabledOutputs = append(outputs.EnabledOutputs, "Kafka")
}
}
if config.KafkaRest.Address != "" {
var err error
kafkaRestClient, err = outputs.NewClient("KafkaRest", config.KafkaRest.Address, config.KafkaRest.MutualTLS, config.KafkaRest.CheckCert, config, stats, promStats, statsdClient, dogstatsdClient)
if err != nil {
config.KafkaRest.Address = ""
} else {
outputs.EnabledOutputs = append(outputs.EnabledOutputs, "KafkaRest")
}
}
if config.Pagerduty.RoutingKey != "" {
var err error
var url = "https://events.pagerduty.com/v2/enqueue"
var outputName = "Pagerduty"
pagerdutyClient, err = outputs.NewClient(outputName, url, config.Pagerduty.MutualTLS, config.Pagerduty.CheckCert, config, stats, promStats, statsdClient, dogstatsdClient)
if err != nil {
config.Pagerduty.RoutingKey = ""
} else {
outputs.EnabledOutputs = append(outputs.EnabledOutputs, outputName)
}
}
if config.Kubeless.Namespace != "" && config.Kubeless.Function != "" {
var err error
kubelessClient, err = outputs.NewKubelessClient(config, stats, promStats, statsdClient, dogstatsdClient)
if err != nil {
log.Printf("[ERROR] : Kubeless - %v\n", err)
config.Kubeless.Namespace = ""
config.Kubeless.Function = ""
} else {
outputs.EnabledOutputs = append(outputs.EnabledOutputs, "Kubeless")
}
}
if config.WebUI.URL != "" {
var err error
webUIClient, err = outputs.NewClient("WebUI", config.WebUI.URL, config.WebUI.MutualTLS, config.WebUI.CheckCert, config, stats, promStats, statsdClient, dogstatsdClient)
if err != nil {
config.WebUI.URL = ""
} else {
outputs.EnabledOutputs = append(outputs.EnabledOutputs, "WebUI")
}
}
if config.PolicyReport.Enabled {
var err error
policyReportClient, err = outputs.NewPolicyReportClient(config, stats, promStats, statsdClient, dogstatsdClient)
if err != nil {
config.PolicyReport.Enabled = false
} else {
outputs.EnabledOutputs = append(outputs.EnabledOutputs, "PolicyReport")
}
}
if config.Openfaas.FunctionName != "" {
var err error
openfaasClient, err = outputs.NewOpenfaasClient(config, stats, promStats, statsdClient, dogstatsdClient)
if err != nil {
log.Printf("[ERROR] : OpenFaaS - %v\n", err)
} else {
outputs.EnabledOutputs = append(outputs.EnabledOutputs, "OpenFaaS")
}
}
if config.Tekton.EventListener != "" {
var err error
tektonClient, err = outputs.NewClient("Tekton", config.Tekton.EventListener, false, config.Tekton.CheckCert, config, stats, promStats, statsdClient, dogstatsdClient)
if err != nil {
log.Printf("[ERROR] : Tekton - %v\n", err)
} else {
outputs.EnabledOutputs = append(outputs.EnabledOutputs, "Tekton")
}
}
if config.Rabbitmq.URL != "" && config.Rabbitmq.Queue != "" {
var err error
rabbitmqClient, err = outputs.NewRabbitmqClient(config, stats, promStats, statsdClient, dogstatsdClient)
if err != nil {
config.Rabbitmq.URL = ""
} else {
outputs.EnabledOutputs = append(outputs.EnabledOutputs, "RabbitMQ")
}
}
if config.Wavefront.EndpointType != "" && config.Wavefront.EndpointHost != "" {
var err error
wavefrontClient, err = outputs.NewWavefrontClient(config, stats, promStats, statsdClient, dogstatsdClient)
if err != nil {
log.Printf("[ERROR] : Wavefront - %v\n", err)
config.Wavefront.EndpointHost = ""
} else {
outputs.EnabledOutputs = append(outputs.EnabledOutputs, "Wavefront")
}
}
if config.Fission.Function != "" {
var err error
fissionClient, err = outputs.NewFissionClient(config, stats, promStats, statsdClient, dogstatsdClient)
if err != nil {
log.Printf("[ERROR] : Fission - %v\n", err)
} else {
outputs.EnabledOutputs = append(outputs.EnabledOutputs, outputs.Fission)
}
}
if config.Grafana.HostPort != "" && config.Grafana.APIKey != "" {
var err error
var outputName = "Grafana"
grafanaClient, err = outputs.NewClient(outputName, config.Grafana.HostPort+"/api/annotations", config.Grafana.MutualTLS, config.Grafana.CheckCert, config, stats, promStats, statsdClient, dogstatsdClient)
if err != nil {
config.Grafana.HostPort = ""
config.Grafana.APIKey = ""
} else {
outputs.EnabledOutputs = append(outputs.EnabledOutputs, outputName)
}
}
if config.GrafanaOnCall.WebhookURL != "" {
var err error
var outputName = "GrafanaOnCall"
grafanaOnCallClient, err = outputs.NewClient(outputName, config.GrafanaOnCall.WebhookURL, config.GrafanaOnCall.MutualTLS, config.GrafanaOnCall.CheckCert, config, stats, promStats, statsdClient, dogstatsdClient)
if err != nil {
config.GrafanaOnCall.WebhookURL = ""
} else {
outputs.EnabledOutputs = append(outputs.EnabledOutputs, outputName)
}
}
if config.Yandex.S3.Bucket != "" {
var err error
yandexClient, err = outputs.NewYandexClient(config, stats, promStats, statsdClient, dogstatsdClient)
if err != nil {
config.Yandex.S3.Bucket = ""
log.Printf("[ERROR] : Yandex - %v\n", err)
} else {
if config.Yandex.S3.Bucket != "" {
outputs.EnabledOutputs = append(outputs.EnabledOutputs, "YandexS3")
}
}
}
if config.Yandex.DataStreams.StreamName != "" {
var err error
yandexClient, err = outputs.NewYandexClient(config, stats, promStats, statsdClient, dogstatsdClient)
if err != nil {
config.Yandex.DataStreams.StreamName = ""
log.Printf("[ERROR] : Yandex - %v\n", err)
} else {
if config.Yandex.DataStreams.StreamName != "" {
outputs.EnabledOutputs = append(outputs.EnabledOutputs, "YandexDataStreams")
}
}
}
if config.Syslog.Host != "" {
var err error
syslogClient, err = outputs.NewSyslogClient(config, stats, promStats, statsdClient, dogstatsdClient)
if err != nil {
config.Syslog.Host = ""
log.Printf("[ERROR] : Syslog - %v\n", err)
} else {
outputs.EnabledOutputs = append(outputs.EnabledOutputs, "Syslog")
}
}
if config.MQTT.Broker != "" {
var err error
mqttClient, err = outputs.NewMQTTClient(config, stats, promStats, statsdClient, dogstatsdClient)
if err != nil {
config.MQTT.Broker = ""
log.Printf("[ERROR] : MQTT - %v\n", err)
} else {
outputs.EnabledOutputs = append(outputs.EnabledOutputs, "MQTT")
}
}
if config.Zincsearch.HostPort != "" {
var err error
zincsearchClient, err = outputs.NewClient("Zincsearch", config.Zincsearch.HostPort+"/api/"+config.Zincsearch.Index+"/_doc", false, config.Zincsearch.CheckCert, config, stats, promStats, statsdClient, dogstatsdClient)
if err != nil {
config.Zincsearch.HostPort = ""
} else {
outputs.EnabledOutputs = append(outputs.EnabledOutputs, "Zincsearch")
}
}
if config.Gotify.HostPort != "" {
var err error
gotifyClient, err = outputs.NewClient("Gotify", config.Gotify.HostPort+"/message", false, config.Gotify.CheckCert, config, stats, promStats, statsdClient, dogstatsdClient)
if err != nil {
config.Gotify.HostPort = ""
} else {
outputs.EnabledOutputs = append(outputs.EnabledOutputs, "Gotify")
}
}
if config.Spyderbat.OrgUID != "" {
var err error
spyderbatClient, err = outputs.NewSpyderbatClient(config, stats, promStats, statsdClient, dogstatsdClient)
if err != nil {
config.Spyderbat.OrgUID = ""
log.Printf("[ERROR] : Spyderbat - %v\n", err)
} else {
outputs.EnabledOutputs = append(outputs.EnabledOutputs, "Spyderbat")
}
}
if config.TimescaleDB.Host != "" {
var err error
timescaleDBClient, err = outputs.NewTimescaleDBClient(config, stats, promStats, statsdClient, dogstatsdClient)
if err != nil {
config.TimescaleDB.Host = ""
log.Printf("[ERROR] : TimescaleDB - %v\n", err)
} else {
outputs.EnabledOutputs = append(outputs.EnabledOutputs, "TimescaleDB")
}
}
if config.Redis.Address != "" {
var err error
redisClient, err = outputs.NewRedisClient(config, stats, promStats, statsdClient, dogstatsdClient)
if err != nil {
config.Redis.Address = ""
} else {
outputs.EnabledOutputs = append(outputs.EnabledOutputs, "Redis")
}
}
if config.Telegram.ChatID != "" && config.Telegram.Token != "" {
var err error
var urlFormat = "https://api.telegram.org/bot%s/sendMessage"
telegramClient, err = outputs.NewClient("Telegram", fmt.Sprintf(urlFormat, config.Telegram.Token), false, config.Telegram.CheckCert, config, stats, promStats, statsdClient, dogstatsdClient)
if err != nil {
config.Telegram.ChatID = ""
config.Telegram.Token = ""
log.Printf("[ERROR] : Telegram - %v\n", err)
} else {
outputs.EnabledOutputs = append(outputs.EnabledOutputs, "Telegram")
}
}
if config.N8N.Address != "" {
var err error
n8nClient, err = outputs.NewClient("n8n", config.N8N.Address, false, config.N8N.CheckCert, config, stats, promStats, statsdClient, dogstatsdClient)
if err != nil {
config.N8N.Address = ""
} else {
outputs.EnabledOutputs = append(outputs.EnabledOutputs, "n8n")
}
}
log.Printf("[INFO] : Falco Sidekick version: %s\n", GetVersionInfo().GitVersion)
log.Printf("[INFO] : Enabled Outputs : %s\n", outputs.EnabledOutputs)
}
func main() {
http.HandleFunc("/", mainHandler)
http.HandleFunc("/ping", pingHandler)
http.HandleFunc("/healthz", healthHandler)
http.HandleFunc("/test", testHandler)
http.Handle("/metrics", promhttp.Handler())
log.Printf("[INFO] : Falco Sidekick is up and listening on %s:%d", config.ListenAddress, config.ListenPort)
if config.Debug {
log.Printf("[INFO] : Debug mode : %v", config.Debug)
}
server := &http.Server{
Addr: fmt.Sprintf("%s:%d", config.ListenAddress, config.ListenPort),
// Timeouts
ReadTimeout: 60 * time.Second,
ReadHeaderTimeout: 60 * time.Second,
WriteTimeout: 60 * time.Second,
IdleTimeout: 60 * time.Second,
}
if err := server.ListenAndServe(); err != nil {
log.Fatalf("[ERROR] : %v", err.Error())
}
}