场景如下
某厂商邮箱的登录日志为xlsx/csv格式
只有如下四个字段 登录时间,邮箱地址,登录IP,登录方式

(图片可点击放大查看)
想要根据邮箱地址关联出员工姓名,工号等相关
并且GeoIP地址库根据IP地址查询登录IP所在地理位置信息
比如登录的IP地理位置是非国内地址时实现钉钉机器人告警
实现思路及实践参考链接
1、csv是否可以转成sylog格式的日志发到GrayLog
解决办法:nxlog xm_csv功能
方法来源链接地址:
https://nxlog.co/question/6063/nxlog-read-multiple-csv-files-and-send-it-siem
https://gitlab.com/nxlog-public/contrib/-/blob/master/guide_configs/xm_gelf_example_csv-nxlog.conf

(图片可点击放大查看)
2、利用GrayLog的lookup table+pipeline处理功能进行关联查询,实现关联出员工工号,员工姓名等其他字段
解决办法:这个之前有实现过,移植过来即可
3、GrayLog告警+PrometheusAlert告警模板实现钉钉告警时呈现出相关告警字段
解决办法:这个之前有实现过,告警模板修改即可
具体实现的详细步骤如下
1、GrayLog服务器安装nxlog-ce并配置读取csv文件
yum localinstall nxlog-ce-2.11.2190-1_rhel7.x86_64.rpm
cp /etc/nxlog.conf /etc/nxlog.conf_bak
echo > /etc/nxlog.conf
vi /etc/nxlog.conf
修改为如下内容
## This is a sample configuration file. See the nxlog reference manual about the
## configuration options. It should be installed locally under
## /usr/share/doc/nxlog-ce/ and is also available online at
## http://nxlog.org/docs
########################################
# Global directives #
########################################
User nxlog
Group nxlog
LogFile /var/log/nxlog/nxlog.log
LogLevel INFO
########################################
# Modules #
########################################
<Extension _syslog>
Module xm_syslog
</Extension>
<Extension gelf>
Module xm_gelf
</Extension>
<Extension charconv>
Module xm_charconv
AutodetectCharsets gbk,utf-8, euc-jp, utf-16, utf-32, iso8859-2
</Extension>
<Extension csv>
Module xm_csv
Fields $time, $email_address, $loginIP, $method
FieldTypes string, string, string,string
Delimiter ,
</Extension>
<Input file>
Module im_file
File "/home/nxlog/login.csv"
Exec csv->parse_csv();
</Input>
<Output udp>
Module om_udp
Host 192.168.31.230
Port 12201
OutputType GELF_UDP
</Output>
<Route csv_to_gelf>
Path file => udp
</Route>

(图片可点击放大查看)
启动nxlog服务
cd /home/
mkdir nxlog
chown -R nxlog:nxlog nxlog/
cd nxlog
rz上传邮件登录日志的csv文件
chown -R nxlog:nxlog login.csv
chmod 777 login.csv
firewall-cmd --add-port=12201/udp --permanent
firewall-cmd --reload
systemctl restart nxlog
systemctl enable nxlog
如果有报错排查nxlog的运行日志
tail -f /var/log/nxlog/nxlog.log
说明:只有csv文件发生变化时才会产生日志
2、GrayLog配置GELF INPUT用于接收日志

(图片可点击放大查看)

(图片可点击放大查看)
并配置相应的Stream

(图片可点击放大查看)
3、配置LookupTable和Pipeline
LookupTable配置过程及相关csv文件截图如下

(图片可点击放大查看)

(图片可点击放大查看)

(图片可点击放大查看)
pipeline规则语法如下
rule "email2username_lookup_table"
when
// true
has_field("email_address") AND
is_not_null(lookup_value("email2username",to_string($message.email_address)))
then
let email_addresslookup_multivalue = lookup("email2username",to_string($message.email_address));
let email_addressmultivalue = split("#",to_string(email_addresslookup_multivalue.value));
set_field("Employee_Username",to_string(email_addressmultivalue[0]));
//debug($message.Employee_Username);
set_field("Employee_Mobile",to_string(email_addressmultivalue[1]));
//debug($message.Employee_Mobie);
set_field("Employee_alias_emailaddress",to_string(email_addressmultivalue[2]));
//debug($message.Employee_alias_emailaddress);
set_field("Employee_ID",to_string(email_addressmultivalue[3]));
//debug($message.Employee_ID);
end

(图片可点击放大查看)
pipeline的配置,并应用到对应的Stream中

(图片可点击放大查看)
4、日志查询效果如下
可以看到关联查询出来的字段都出来了

(图片可点击放大查看)
5、配置并优化PrometheusAlert告警模板

(图片可点击放大查看)
6、GraylogAlert告警条件配置

(图片可点击放大查看)

(图片可点击放大查看)

(图片可点击放大查看)
7、最终的告警效果如下

(图片可点击放大查看)
8、总结
当然这个只是简单的功能实现的测试过程还有很多细节问题需要考虑
例如由于csv文件是一次性导入,这样会出现瞬间钉钉机器人告警数量过大,触发1分钟20条的阈值,导致告警不再产生的情况
需要用一种方式每几秒读几行csv日志文件的方式避免一次性导入造成日志量过大告警停止的问题
这个应该好实现,后续再优化