After all Qubes OS and monZphere blogging, let's get closer to original theme of my blog - home monitoring, or monitoring myself.
Zabbix 7.0 API got a nice little history.push method, allowing you to send data to Zabbix over its API. How I'm going to use it? Thanks for asking, I'm going to send the song names of the music I'm listening to. For the sake of simplicity, this entry shows how to send a single value.
Challenges of Apple Music
I'm using Apple Music for my music listening needs. While it allows me to do many things, such as choose my music, play it, pause it, change to next/previous song and adjust the volume, among other innovative features, none of these can be done from the command line. None of these can be done over any API, either, not that I know of.
Did my idea already die? Can I not do this? No, the status is not as bad, as I can use macOS and iOS Shortcuts instead. Yes, it's the same thing I have used before, such as when I integrated Siri with my Zabbix. This time it allows me to call Zabbix history.push.
Without further ado, let's get to business.
Creating new host to Zabbix
I created a new host called nowplaying, and for now gave it this single item: name Song name, type Zabbix trapper*, Key nowplaying.song, type Text, store history for ten years. Done.

*) As I did not give this host any agent interface, I chose type as Zabbix trapper. The history.push itself allows you to send data to other item types, too.
Figuring out the item id
For history.push, you need to figure out where to push the data in your Zabbix so it would go to correct place. As far as I know, there would be two ways:
- Use item id which is a unique numeric ID for the item you just created. This is unique among your Zabbix and cannot collide with the items on other hosts.
- Locate the item by defining both host name and item key name in your JSON payload.
For this demo, I merely clicked on Inspect element on my Safari to find that out and did go with numeric item id.

Creating the Shortcut
Let's run Shortcuts on my Mac and see if we have the shortcut for this.

There it is! Yay! What, you want to see more details? Ok, let's open that up.

I used the Get current song action, which returns all kinds of details about the song. It required me to pick one option at a time, so I did go with the current playing song name. Next, the Get contents of... action sends a POST request to my Zabbix server, using authentication token for authentication. The rest is directly from Zabbix API reference guide.
Let's get to Zabbix
When I run the shortcut, does it work? Of course it does.

Now I can then quickly splat few widgets to new dashboard and get to see what I'm listening to.

The annoying parts
- In theory Shortcuts Get Music action could pass every detail the song as JSON blob, so I could just send that to Zabbix and let low-level discovery to figure out the details I would care about; artist name, song genre, maybe year of publication. As the drag-n-drop semi-programming can be frustrating, I didn't spend too much time with this last night and might revisit the topic later.
- I don't know yet how to run this automatically upon every song change. On iOS, Shortcuts has Automation tab, but unfortunately it does not have any triggers related to Apple Music; one can automate based on time, location, Wi-Fi network, few other choices but that's it. Same goes with macOS Shortcuts, but even worse, I cannot find any automation from its choices.
There's also Automator available on macOS and that's been there at least since around 2012 when I first bought a personal Mac, but I fear it cannot trigger stuff in this manner either. Any ideas and suggestions would be most welcome!

Add new comment