mirror of
https://gitee.com/samwaf/SamWaf.git
synced 2026-10-31 02:01:44 +08:00
31 lines
1.0 KiB
Go
31 lines
1.0 KiB
Go
package wafnotify
|
|
|
|
import (
|
|
"SamWaf/wafnotify/kafka"
|
|
"SamWaf/wafnotify/logfilewriter"
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
func InitNotifyKafkaEngine(enable int64, url string, topic string) *WafNotifyService {
|
|
|
|
brokers := strings.Split(url, ",") // Kafka brokers
|
|
notifier, err := kafka.NewKafkaNotifier(brokers, topic, enable)
|
|
if err != nil {
|
|
fmt.Printf("Failed to create notifier: %v\n", err)
|
|
return NewWafNotifyService(notifier, enable)
|
|
}
|
|
// 创建日志服务并注入 notifier
|
|
return NewWafNotifyService(notifier, enable)
|
|
}
|
|
|
|
// InitLogFileWriterEngine 初始化日志文件写入引擎
|
|
func InitLogFileWriterEngine(enable int64, filePath, format, customTpl string, maxSize int64, maxBackups int, maxDays int, compress bool) *WafNotifyService {
|
|
notifier, err := logfilewriter.NewLogFileWriter(filePath, format, customTpl, maxSize, maxBackups, maxDays, compress)
|
|
if err != nil {
|
|
fmt.Printf("Failed to create log file writer: %v\n", err)
|
|
return NewWafNotifyService(notifier, enable)
|
|
}
|
|
return NewWafNotifyService(notifier, enable)
|
|
}
|