We’re going to go full-MacGyver for part of this, since Sonos does not offer a nice API. The diagnostics that Sonos devices serve up on the http://<sonos player IP>:1400/support/review interface (I’ll not actually call it an API, since it isn’t really) are XML-wrapped plaintext. So whilst XML may actually be nicer than YAML to work with (who knew), plain text is not so nice to work with. Fancy parsing this for key/value pairs? It’s going to be all hand-crafted code needed:

Mode: INFRA (sonosnet) Operating on channel 2437 Home channel is 2437 HT Channel is 0 RF Chains: RX:4 TX:4 RF Chainmask: RX:0x0F TX:0x0F Max Spatial Streams: RX:4 TX:4 Noise Floor: 0 dBm (chain 0 ctl) Noise Floor: 0 dBm (chain 1 ctl) Noise Floor: 0 dBm (chain 2 ctl) Noise Floor: 0 dBm (chain 3 ctl) PHY errors since last reading/reset: 3882

To pull the data from Sonos you just need to hit one of the devices, since it serves up the stats for all the others too. I’m using xq here which is an XML version of the superb jq tool (which is for JSON). It means that I can stream data from curl into xq and parse the document structure for fields and values that I want, as well as starting to manipulate the data into more of a structure for processing (such as splitting the status data shown above into an array).

Once it’s parsed the data it pipes it into kafkacat which writes it to a Kafka topic, as well as echo’ing it to the terminal.