
Lookup tables là một công cụ trên Graylog cho phép tra cứu/ánh xạ/sửa đổi giá trị trường message thành giá trị mới và ghi chúng vào một trường mới hoặc ghi đè lên trường cũ. Trong hướng dẫn này tôi sẽ sử dụng nó đề map những user ssh với tên đầy đủ của người dùng tương ứng.
Chuẩn bị
Graylog cần thu thập log ssh từ các client gửi về.
Sử dụng các công cụ để lấy được user ssh đến từ một bản tin SSH.
Cấu hình
Tách user từ bản tin ssh
Có nhiều cách để tách được user từ bản tin SSH thành một trường mới. Ở đây tôi dùng grok pattern.
Xác định bản tin log có chứa user

Chọn grok pattern

Tách message thành các trường
Bạn có thể sử dụng pattern phù hợp hoặc sử dụng như của tôi cho pattern ở khung dưới đây.
%{WORD} %{INT} %{TIME} %{WORD:servername} %{WORD:app_name}\[%{INT}\]\: %{WORD: action_ssh} password for %{WORD:user_ssh} from %{IPV4:ip_ssh}

Click Try against example
để xem thử kết quả

User ssh đã được tách thành trường user_ssh
Ta thấy đã có trường user ssh
trong bản tin log ssh

Tạo lookup tables

Tạo data adapter
Data adapter được sử dụng để thực hiện tra cứu kết qủa cho một giá trị. Nó có thể đọc từ file CSV, kết nối với cơ sở dữ liệu hoặc thực hiện các request HTTP để nhận kết quả tra cứu.
Click Data Adapter
-> Create data adapter

Chọn CSV File
cho Data Adapter Type

Điền các thông tin

Click Create Adapter

Ta thấy có lỗi vì ta chưa tạo file CSV. Ta sẽ tạo file này ở bước sau
Tạo caches

Chọn Cache Type

Config cache


Tạo lookup tables

Khai báo thông tin. Data Adapter
và Cache
chọn giá trị vừa tạo ở bước trước.


Ta thấy vẫn có lỗi vì vẫn bị thiếu file CSV. Bây giờ chúng ta sẽ tiến hành tạo file này.
Tạo file CSV
Truy cập vào Graylog server để tạo file CSV
vi /etc/graylog/lookup-table.csv
Thêm nội dung thích hợp. File ví dụ của tôi có nội dung như sau
[root@graylog ~]# cat /etc/graylog/lookup-table.csv
"user_ssh","full_name"
"root","Quan tri vien"
"anv","Nguyen Van A"
"bnv","Nguyen Van B"
Dòng đầu tiên khai báo Key
và Value
như khai báo Adapter
Tạo extractor
Quay trở lại bản tin SSH để tạo extractor


Cấu hình extractor

Trong đó:
Lookup Table
là lookup table ta tạo ở trênStore as field
là tên của trường ta muốn lưu giá trị mới
Ta thấy extractor vừa tạo

Kiểm tra bản tin SSH ta đã thấy có trường full_name_login_ssh

Leave a Reply