Skip to main content

SPRbus

version Go Report Card

SPRbus is the event bus used in SPR to send and subscribe to events.

⇨ View the code

Usage

  • db is listening for events and store these in a database
  • packet logs send events when netfilter rules are triggered
  • api for notifications
  • api publish event for access log
  • dns send events on domain lookup or block

Available events

  • auth:success
  • auth:failure
  • dns:block:event
  • dns:blockrebind:event
  • dns:override:event
  • dns:serve:clientip (Ex: 192.168.2.2)
  • dhcp:request
  • dhcp:response
  • dhcp:update
  • device:save
  • device:tags:update
  • device:groups:update
  • log:api
  • log:www:access
  • nft:lan:in
  • nft:lan:out
  • nft:wan:in
  • nft:wan:out
  • nft:drop:private
  • nft:drop:forward
  • nft:drop:input
  • nft:drop:mac
  • wg:update
  • wifi:auth:fail
  • wifi:auth:success
  • wifi:station:disconnect

Example Events

  • wifi:auth:success is published when a device connects
  • device:save is published when a device is updated

View the API documentation for sprbus here

By default log:api, dns:block:event, dns:override:event, dns:serve: events are stored in the database. The log items can be viewed under System -> Logs. If you want to store more events you can add them in the web ui under System -> System Info -> Database.

Command line tools

sprbus

See cmd/main.go

cd cmd/; make
./sprbus --help

remote

export TOKEN="SPR-API-TOKEN"
./sprbus --addr 192.168.2.1

local

./sprbus

example topics

#www and api logs
./sprbus -t log
# device and wifi events
./sprbus -t device,wifi
#network traffic
./sprbus -t nft

network traffic in json, no timeout and pipe to jq

./sprbus -t nft -j --timeout 0 | jq .

publish test event

./sprbus -t test:event -p '{"msg": "testevent1234"}'

sprbus intro example showing how to publish events.

Development

See example/main.go

using default sprbus:

//publish json string
sprbus.PublishString("wifi:station:event", "{\"json\": \"data\"}")

//publish object
sprbus.Publish("www:auth:user:fail", map[string]string{"username": username})

//subscribe
go sprbus.HandleEvent("wifi", func (topic string, json string) {
fmt.Println("wifi event", topic, json)
})

Custom unix socket server and client

See example/main.go for code to setup a custom unix socket server and client