Unifi network devices generate valuable logs that can help you troubleshoot network issues and monitor your devices. By sending these syslog messages to Loki using Grafana Alloy, you can centralize your network logs alongside your application logs for unified observability.
This guide we will only focus on device logs. Securtiy and firewall logs are out of scope.
Prerequisites
- Grafana Alloy installed (or can be deployed via Docker)
- Grafana and Loki instance running (see my Log Monitoring with Loki & Promtail post)
- Unifi Controller with network devices configured
Why Grafana Alloy?
Grafana Alloy is the next-generation telemetry collector that replaces Promtail. It supports multiple data formats including logs, metrics, traces, and profiles. For syslog collection, Alloy provides:
- Native syslog receiver (no need for external syslog daemons)
- Powerful log processing and relabeling capabilities
- Lower resource usage compared to traditional collectors
- Unified configuration for all telemetry types
Setup Grafana Alloy
First, create a folder to hold the Docker Compose file and Alloy configuration:
1mkdir alloyCreate the Docker Compose file:
1nano alloy/docker-compose.ymlPaste the following content:
1services:
2 alloy:
3 image: grafana/alloy:latest
4 container_name: alloy
5 restart: unless-stopped
6 environment:
7 - TZ=Europe/Amsterdam
8 ports:
9 - "12345:12345"
10 - "514:514/udp" # Syslog UDP
11 volumes:
12 - ./config.alloy:/etc/alloy/config.alloy:ro
13 - alloy-data:/var/lib/alloy/data
14 command:
15 - run
16 - --server.http.listen-addr=0.0.0.0:12345
17 - --storage.path=/var/lib/alloy/data
18 - /etc/alloy/config.alloy
19 networks:
20 - backend
21
22networks:
23 backend:
24 name: backend
25
26volumes:
27 alloy-data:
28 name: alloy-dataConfigure Alloy for Syslog
Create the Alloy configuration file:
1nano alloy/config.alloyPaste the following configuration:
1/* UniFi Syslog (RFC3164) - Relabel rules to capture syslog metadata */
2loki.relabel "unifi_syslog" {
3 forward_to = []
4
5 // Copy severity first (for error, debug, or unknown values)
6 rule {
7 source_labels = ["__syslog_message_severity"]
8 target_label = "detected_level"
9 }
10 // Then normalize specific values (these overwrite the above)
11 rule {
12 source_labels = ["__syslog_message_severity"]
13 regex = "(?i)(emergency|alert|critical)"
14 target_label = "detected_level"
15 replacement = "critical"
16 }
17 rule {
18 source_labels = ["__syslog_message_severity"]
19 regex = "(?i)(warning)"
20 target_label = "detected_level"
21 replacement = "warn"
22 }
23 rule {
24 source_labels = ["__syslog_message_severity"]
25 regex = "(?i)(notice|informational)"
26 target_label = "detected_level"
27 replacement = "info"
28 }
29
30 // Map hostname from syslog header
31 rule {
32 source_labels = ["__syslog_message_hostname"]
33 target_label = "host"
34 }
35
36 // Map app name from syslog header
37 rule {
38 source_labels = ["__syslog_message_app_name"]
39 target_label = "app"
40 }
41}
42
43loki.source.syslog "unifi" {
44 listener {
45 address = "0.0.0.0:514"
46 protocol = "udp"
47 syslog_format = "rfc3164"
48 use_incoming_timestamp = false
49 labels = {
50 job = "unifi",
51 }
52 }
53
54 relabel_rules = loki.relabel.unifi_syslog.rules
55 forward_to = [loki.process.unifi.receiver]
56}
57
58loki.process "unifi" {
59 // Extract app and message from UniFi syslog content
60 // Format 1 (AP/Switch): "mac,device-firmware: process[pid]: message"
61 // Example: "6c63f8863465,U7-Pro-Wall-8.3.2+18064: hostapd[5343]: wifi1ap6: STA ..."
62 // Format 2 (Gateway): "hostname process[pid]: message"
63 // Example: "UCG-Fiber bash[2616997]: HISTORY: ..."
64 stage.regex {
65 expression = "^(?:[\\w,\\-\\.\\+]+:\\s+|[\\w\\-]+\\s+)?(?P<app>[\\w\\-]+)(?:\\[\\d+\\])?:\\s*(?P<message>.*)$"
66 }
67
68 // Set app label from regex
69 stage.labels {
70 values = {
71 app = "",
72 }
73 }
74
75 // Output just the message content
76 stage.output {
77 source = "message"
78 }
79
80 forward_to = [loki.write.default.receiver]
81}
82
83// Loki write endpoint
84loki.write "default" {
85 endpoint {
86 url = "http://loki:3100/loki/api/v1/push"
87 }
88}Configuration Breakdown
This configuration includes three main components that work together to collect, process, and forward Unifi syslog messages to Loki.
1. Relabel Rules (loki.relabel "unifi_syslog")
The relabel component extracts and normalizes metadata from the syslog headers:
Severity Normalization:
- Converts syslog severity levels (emergency, alert, critical etc) to standardized labels
- Creates a
detected_levellabel for filtering logs by severity in Grafana
Metadata Extraction:
host: Captures the hostname of the device sending logs (e.g., “UCG-Fiber”, “U7-Pro-Wall”)app: Extracts the application or process name from the syslog header
These labels make it easy to filter logs by device or severity without parsing the log content.
2. Syslog Listener (loki.source.syslog "unifi")
The syslog source receives incoming log messages:
Listener Configuration:
address: Binds to all interfaces on port 514 (standard syslog port)protocol: Uses UDP, the most common syslog transport protocolsyslog_format: Parses RFC3164 format, which Unifi devices useuse_incoming_timestamp: Set to false to use Alloy’s timestamp instead of the device timestamp
Static Labels:
job="unifi": Identifies all logs from this source as Unifi logsplatform="network": Categorizes these as network infrastructure logs
Pipeline:
- Applies the relabel rules defined above
- Forwards logs to the processing stage
3. Log Processing (loki.process "unifi")
This component parses and cleans Unifi-specific log formats:
Regex Extraction: Unifi devices use different log formats depending on the device type:
- Access Points/Switches: Include MAC address and firmware version
- Example:
6c63f8863465,U7-Pro-Wall-8.3.2+18064: hostapd[5343]: wifi1ap6: STA connected
- Example:
- Gateways: Use hostname and process name
- Example:
UCG-Fiber bash[2616997]: HISTORY: command executed
- Example:
The regex pattern captures:
app: The process or service name (hostapd, bash, kernel, etc.)message: The actual log message content
Output Stage:
- Extracts just the message content, removing metadata already captured as labels
- Results in cleaner, more readable logs in Grafana
4. Loki Write (loki.write "default")
The final component sends processed logs to Loki:
endpoint.url: The Loki push API endpoint- Uses the Docker network name
lokito connect to Loki running in the same Docker network - Handles batching and retries automatically
Start Alloy
Deploy the Alloy container:
1docker compose -f alloy/docker-compose.yml up -dVerify Alloy is running and check the logs:
1docker logs alloyYou should see messages indicating that Alloy has started and the syslog listener is active.
Configure Unifi Devices
Now configure your Unifi Controller to send syslog messages to Alloy.
Using Unifi Controller
- Open your Unifi Controller
- Navigate to Settings > Cyber Secure
- Go to to Traffic Logging
- Set Activity Logging (Syslog) to SIEM Server
- Set the IP Address to your Alloy server IP (e.g.,
192.168.1.100) - Set the Port to
514 - Click Apply Changes
Verify Log Collection
After configuring your Unifi devices, logs should start flowing to Loki within seconds.
Check in Grafana
- Open Grafana and navigate to Explore
- Select Loki as the datasource
- Run a query to see Unifi logs:
{job="unifi"}You should see syslog messages from your Unifi devices, including authentication events, DHCP assignments, wireless connections, and security events.
Example Queries
With the labels and processing configured above, you can create powerful queries to analyze your network logs.
Basic Queries
All Unifi logs:
{job="unifi"}Logs from a specific device:
{job="unifi", host="UCG-Fiber"}Logs from a specific application:
{job="unifi", app="hostapd"}Summary
With Grafana Alloy configured to receive Unifi syslog messages, you now have centralized network logging alongside your application logs in Loki. This unified observability platform makes it easier to correlate network events with application behavior, troubleshoot issues, and maintain security.
The modern Alloy architecture provides better performance and more flexible log processing compared to traditional syslog daemons, while integrating seamlessly with the Grafana ecosystem.
