cscli collections install crowdsecurity/unifiA collection to defend Unifi gear against common attacks :
crowdsecurity/unifi-logscrowdsecurity/cef-logscrowdsecurity/unifi-cefcrowdsecurity/dropbear-logscrowdsecurity/ssh-bfcrowdsecurity/iptables-logscrowdsecurity/iptables-scan-multi_portsThis collection supports both standard syslog and CEF (Common Event Format) logs from UniFi devices.
UniFi devices can send logs in CEF format, which provides structured security events with rich metadata.
Configure your UniFi devices to send CEF logs:
Note: While UniFi calls this "CEF format", it actually sends logs with CEF headers but without the full CEF structure. The collection handles this properly.
For CEF format, you need to use rsyslog to receive and process the logs (CrowdSec's built-in syslog acquisition doesn't support CEF format).
Create a configuration file /etc/rsyslog.d/unifi-cef.conf:
1module(load="imudp")23# Only allow your senders (legacy-style; applies to all UDP inputs)4$AllowedSender UDP, 192.168.1.0/24, 192.168.11.1/3256# Templates7template(name="CEF" type="string" string="%msg%\n")8template(name="Syslog" type="string" string="%timegenerated% %hostname% %programname%[%procid%]: %msg%\n")910# Bind the UDP/4242 input to a ruleset so only those messages hit the UniFi actions11input(12 type="imudp"13 name="unifi_in"14 port="4242"15 ruleset="unifi"16)1718ruleset(name="unifi") {19 if $rawmsg startswith "CEF:" then {20 action(type="omfile" file="/var/log/unifi-cef.log" template="CEF")21 } else {22 action(type="omfile" file="/var/log/unifi-syslog.log" template="Syslog")23 }24 stop25}26
Restart rsyslog after configuration:
1sudo systemctl restart rsyslog
Verify UDP port is listening:
1sudo netstat -uln | grep 4242
To prevent log files from growing too large, configure logrotate for both CEF and syslog files. Create /etc/logrotate.d/unifi:
1/var/log/unifi-cef.log /var/log/unifi-syslog.log {2 daily3 rotate 74 compress5 delaycompress6 missingok7 notifempty8 postrotate9 systemctl reload rsyslog >/dev/null 2>&1 || true10 endscript11}
This configuration will:
Test the logrotate configuration:
1sudo logrotate -d /etc/logrotate.d/unifi
And run it manually if needed:
1sudo logrotate -f /etc/logrotate.d/unifi
Example acquisition for CEF logs (recommended for security monitoring):
1---2filenames:3 - /var/log/unifi-cef.log4labels:5 type: cef
Optional: If you also want to monitor non-CEF syslog messages from UniFi devices:
1---2filenames:3 - /var/log/unifi-syslog.log4labels:5 type: unifi
For basic syslog support (non-CEF format), use CrowdSec's built-in syslog acquisition:
1source: syslog2listen_addr: 0.0.0.03listen_port: 42424labels:5 type: unifi
Notes:
unifiThis collection handles multiple types of UniFi events:
All CEF events include rich metadata such as device information, source/destination details, and UniFi-specific context.
After setup, test that logs are being received and properly processed:
1# Send a test CEF message (if using CEF format)2echo "CEF:0|Ubiquiti|UniFi Network|9.4.19|201|Threat Detected and Blocked|7|proto=TCP src=10.0.0.100 spt=52331 dst=192.168.0.233 dpt=443 UNIFIcategory=Security UNIFIsubCategory=Intrusion Prevention UNIFIhost=Express 7 UNIFIdeviceMac=84:78:48:80:0d:86 UNIFIdeviceName=Express 7 UNIFIdeviceModel=UX7 UNIFIdeviceIp=192.168.0.1 UNIFIdeviceVersion=4.3.9 UNIFIrisk=medium UNIFIipsSessionId=54725290909450 UNIFIipsSignature=ET DROP Dshield Block Listed Source group 1 UNIFIipsSignatureId=2402000 UNIFIutcTime=2025-08-30T17:53:21.915Z msg=A network intrusion attempt has been detected and blocked." | nc -u -w1 localhost 424234# Send a test syslog message5echo "test syslog message from unifi device" | nc -u -w1 localhost 424267# Check that messages are being logged8tail -f /var/log/unifi-cef.log9tail -f /var/log/unifi-syslog.log