• chevron_right

      A nifty push notification system: ntfy

      pubsub.slavino.sk / jpmens.net · Saturday, 29 October, 2022 - 22:00 · 1 minute

    Ever since thinking “that’s quite nifty”, I have the devil of a time spelling ntfy without transposing the ‘t’ and the ‘f’, but it’s called notify so the ‘t’ comes before the ‘f’. :-)

    With ntfy I can send push notifications to a phone or desktop via a simple HTTP-based pub/sub service. Philipp C. Heckel created ntfy and open-sourced its components.

    ntfy is the backend server (written in Golang), Android and iOS apps, and a desktop UI which runs in a Web browser. There’s also a command-line client.

    Messages are published via either HTTP PUT or POST, and something as simple as this suffices to transmit a message. Note that there’s no authentication so use your own server or chose a topic which is hard to guess.

    $curl -d"Hola mundo" ntfy.sh/my-topic
    

    Subscribing via the API is equally easy:

    $curl -s ntfy.sh/admin-alerts/json
    {"id":"AQJQ0ThDMuda","time":1667123190,"event":"open","topic":"admin-alerts"}
    {"id":"7osug0iTf31n","time":1667123207,"event":"message","topic":"admin-alerts","message":"deployment on alice is complete. 🐄","priority":1,"tags":["heavy_check_mark"]}
    {"id":"by9EicvNYMsp","time":1667123235,"event":"keepalive","topic":"admin-alerts"}
    

    All manner of features can be added to a message: priorities, tags, title, attachments, and messages can even contain an action to send a HTTP request from the client when an action button is tapped.

    ntfy on iOS

    Ansible

    I was thinking about Ansible action plugins the other day and decided to implement one which notifies via ntfy . Why an action plugin and not a module? Because I’d expect notification to be emitted from the Ansible controller (also possible with a module delegated to it) so that’s how I did it. (Let me know if you prefer a module; we could do both.)

    -ntfy:msg:"deploymenton{{inventory_hostname}}iscomplete.🐄"

    ansible-ntfy notifies ntfy.sh by default with a topic configured in a play var. Topic, URL, and additional publishing features can be configured in a dict passed as attrs :

    -ntfy:topic:"admin-alerts"url:"https://nfty.sh"msg:"that'sawrap"attrs:tags:[rotating_light,heavy_check_mark]priority:4actions:-action:viewlabel:"OpenMastodon"url:"https://mastodon.social/@jpmens"

    Aside from this Ansible module, there are lots of existing integrations .

    ntfy is nifty. :-)


    Značky: #Network

    • wifi_tethering open_in_new

      This post is public

      jpmens.net /2022/10/30/a-nifty-push-notification-system-ntfy/