Hello,
I ran the following configuration:
logging {
level = "info"
format = "logfmt"
}
loki.source.windowsevent "windows_event_logs" {
eventlog_name = "Security"
xpath_query = "*[System[(EventID=4660 or EventID=4663)]]"
poll_interval = "0s"
use_incoming_timestamp = true
forward_to = [loki.relabel.windows_event_logs.receiver]
labels = {
job = "windows_event_logs",
}
legacy_bookmark_path = "./bookmark.xml"
}
loki.relabel "windows_event_logs" {
forward_to = [loki.process.windows_event_logs.receiver]
rule {
source_labels = ["__name__"]
target_label = "__name__"
}
}
loki.process "windows_event_logs" {
forward_to = [loki.echo.debug.receiver]
stage.regex {
expression = ".*EventID=\"(4660|4663)\".*SubjectUserName=\"(?P<username>[^\"]+)\".*ObjectName=\"(?P<file>[^\"]+)\".*ObjectType=\"(?P<folder>[^\"]+)\".*Computer=\"(?P<hostname>[^\"]+)\".*IpAddress=\"(?P<ip_address>[^\"]+)\".*TimeCreated=\"(?P<timestamp>[^\"]+)\".*"
}
stage.labels {
values = {
file = "file",
folder = "folder",
hostname = "hostname",
ip_address = "ip_address",
timestamp = "timestamp",
username = "username",
}
}
stage.timestamp {
source = "timestamp"
format = "RFC3339"
}
}
loki.echo "debug" { }
loki.write "default" {
endpoint {
url = "http://192.168.1.2:3100/loki/api/v1/push"
}
external_labels = {}
}
When I looked at the Windows Event Viewer, the following reports were generated:
ts=2025-02-15T05:55:03.0552645Z level=info component_path=/ component_id=loki.echo.debug receiver=loki.echo.debug entry="{\"source\":\"Microsoft-Windows-Security-Auditing\",\"channel\":\"Security\",\"computer\":\"DESKTOP-1PNH21K\",\"event_id\":4663,\"version\":1,\"task\":12800,\"levelText\":\"Information\",\"taskText\":\"File System\",\"opCodeText\":\"Info\",\"keywords\":\"Audit Success\",\"timeCreated\":\"2025-02-11T10:45:37.6576565Z\",\"eventRecordID\":124091,\"execution\":{\"processId\":4,\"threadId\":868,\"processName\":\"System\"},\"event_data\":\"\\u003cData Name='SubjectUserSid'\\u003eS-1-5-21-2104788189-4142446361-3889847816-1001\\u003c/Data\\u003e\\u003cData Name='SubjectUserName'\\u003eGrafana\\u003c/Data\\u003e\\u003cData Name='SubjectDomainName'\\u003eDESKTOP-1PNH21K\\u003c/Data\\u003e\\u003cData Name='SubjectLogonId'\\u003e0x3e091\\u003c/Data\\u003e\\u003cData Name='ObjectServer'\\u003eSecurity\\u003c/Data\\u003e\\u003cData Name='ObjectType'\\u003eFile\\u003c/Data\\u003e\\u003cData Name='ObjectName'\\u003eC:\\\\Users\\\\Grafana\\\\Desktop\\\\Test\\u003c/Data\\u003e\\u003cData Name='HandleId'\\u003e0x1bbc\\u003c/Data\\u003e\\u003cData Name='AccessList'\\u003eCountry/region code\\r\\n\\t\\t\\t\\t\\u003c/Data\\u003e\\u003cData Name='AccessMask'\\u003e0x1\\u003c/Data\\u003e\\u003cData Name='ProcessId'\\u003e0x404\\u003c/Data\\u003e\\u003cData Name='ProcessName'\\u003eC:\\\\Windows\\\\explorer.exe\\u003c/Data\\u003e\\u003cData Name='ResourceAttributes'\\u003eS:AI\\u003c/Data\\u003e\",\"message\":\"An attempt was made to access an object.\\r\\n\\r\\nSubject:\\r\\n\\tSecurity ID:\\t\\tS-1-5-21-2104788189-4142446361-3889847816-1001\\r\\n\\tAccount Name:\\t\\tGrafana\\r\\n\\tAccount Domain:\\t\\tDESKTOP-1PNH21K\\r\\n\\tLogon ID:\\t\\t0x3E091\\r\\n\\r\\nObject:\\r\\n\\tObject Server:\\t\\tSecurity\\r\\n\\tObject Type:\\t\\tFile\\r\\n\\tObject Name:\\t\\tC:\\\\Users\\\\Grafana\\\\Desktop\\\\Test\\r\\n\\tHandle ID:\\t\\t0x1bbc\\r\\n\\tResource Attributes:\\tS:AI\\r\\n\\r\\nProcess Information:\\r\\n\\tProcess ID:\\t\\t0x404\\r\\n\\tProcess Name:\\t\\tC:\\\\Windows\\\\explorer.exe\\r\\n\\r\\nAccess Request Information:\\r\\n\\tAccesses:\\t\\tReadData (or ListDirectory)\\r\\n\\t\\t\\t\\t\\r\\n\\tAccess Mask:\\t\\t0x1\"}" labels="{channel=\"Security\", computer=\"DESKTOP-1PNH21K\", job=\"windows_event_logs\"}"
ts=2025-02-15T05:56:10.9457659Z level=info component_path=/ component_id=loki.echo.debug receiver=loki.echo.debug entry="{\"source\":\"Microsoft-Windows-Security-Auditing\",\"channel\":\"Security\",\"computer\":\"DESKTOP-1PNH21K\",\"event_id\":4660,\"task\":12800,\"levelText\":\"Information\",\"taskText\":\"File System\",\"opCodeText\":\"Info\",\"keywords\":\"Audit Success\",\"timeCreated\":\"2025-02-15T05:56:08.5085280Z\",\"eventRecordID\":129178,\"execution\":{\"processId\":4,\"threadId\":304,\"processName\":\"System\"},\"event_data\":\"\\u003cData Name='SubjectUserSid'\\u003eS-1-5-21-2104788189-4142446361-3889847816-1001\\u003c/Data\\u003e\\u003cData Name='SubjectUserName'\\u003eGrafana\\u003c/Data\\u003e\\u003cData Name='SubjectDomainName'\\u003eDESKTOP-1PNH21K\\u003c/Data\\u003e\\u003cData Name='SubjectLogonId'\\u003e0x32891\\u003c/Data\\u003e\\u003cData Name='ObjectServer'\\u003eSecurity\\u003c/Data\\u003e\\u003cData Name='HandleId'\\u003e0x2720\\u003c/Data\\u003e\\u003cData Name='ProcessId'\\u003e0x12ac\\u003c/Data\\u003e\\u003cData Name='ProcessName'\\u003eC:\\\\Windows\\\\explorer.exe\\u003c/Data\\u003e\\u003cData Name='TransactionId'\\u003e{00000000-0000-0000-0000-000000000000}\\u003c/Data\\u003e\",\"message\":\"An object was deleted.\\r\\n\\r\\nSubject:\\r\\n\\tSecurity ID:\\t\\tS-1-5-21-2104788189-4142446361-3889847816-1001\\r\\n\\tAccount Name:\\t\\tGrafana\\r\\n\\tAccount Domain:\\t\\tDESKTOP-1PNH21K\\r\\n\\tLogon ID:\\t\\t0x32891\\r\\n\\r\\nObject:\\r\\n\\tObject Server:\\tSecurity\\r\\n\\tHandle ID:\\t0x2720\\r\\n\\r\\nProcess Information:\\r\\n\\tProcess ID:\\t0x12ac\\r\\n\\tProcess Name:\\tC:\\\\Windows\\\\explorer.exe\\r\\n\\tTransaction ID:\\t{00000000-0000-0000-0000-000000000000}\"}" labels="{channel=\"Security\", computer=\"DESKTOP-1PNH21K\", job=\"windows_event_logs\"}"
But the problem is that the Grafana server is not receiving any reports:
# tcpdump -vvv -i any src 192.168.1.3 and port 3100
tcpdump: data link type LINUX_SLL2
tcpdump: listening on any, link-type LINUX_SLL2 (Linux cooked v2), snapshot length 262144 bytes
This is because of the line xpath_query = "*[System[(EventID=4660 or EventID=4663)]]"
.