|
38 | 38 | <h1><img src="static/img/ntfy.png" alt="ntfy"/><br/>ntfy.sh | simple HTTP-based pub-sub</h1>
|
39 | 39 | <p>
|
40 | 40 | <b>Ntfy</b> (pronounce: <i>notify</i>) is a simple HTTP-based <a href="https://en.wikipedia.org/wiki/Publish%E2%80%93subscribe_pattern">pub-sub</a> notification service.
|
41 |
| - It allows you to send notifications <a href="https://play.google.com/store/apps/details?id=io.heckel.ntfy">to your phone</a> or desktop via scripts from any computer, |
| 41 | + It allows you to send notifications <a href="#subscribe-phone">to your phone</a> or desktop via scripts from any computer, |
42 | 42 | entirely <b>without signup or cost</b>. It's also <a href="https://github.com/binwiederhier/ntfy">open source</a> if you want to run your own.
|
43 | 43 | </p>
|
44 | 44 |
|
|
53 | 53 | </div>
|
54 | 54 |
|
55 | 55 | <p>
|
56 |
| - There are many ways to use Ntfy. You can send yourself messages for all sorts of things: When a long process finishes or fails (a backup, a long rsync job, ...), |
| 56 | + There are many ways to use Ntfy. You can send yourself messages for all sorts of things: When a long process finishes or fails, |
57 | 57 | or to notify yourself when somebody logs into your server(s). Or you may want to use it in your own app to distribute messages to subscribed clients.
|
58 |
| - Endless possibilities 😀. Be sure to check out the <a href="https://github.com/binwiederhier/ntfy/tree/main/examples">example on GitHub</a>! |
| 58 | + Endless possibilities 😀. Be sure to check out the <a href="#examples">examples below</a>. |
59 | 59 | </p>
|
60 | 60 |
|
61 | 61 | <h2 id="publish" class="anchor">Publishing messages</h2>
|
|
104 | 104 | <audio id="notifySound" src="static/sound/mixkit-message-pop-alert-2354.mp3"></audio>
|
105 | 105 | </div>
|
106 | 106 |
|
107 |
| - <h3 id="android-app" class="anchor">Subscribe via Android App</h3> |
| 107 | + <h3 id="subscribe-phone" class="anchor">Subscribe from your phone</h3> |
108 | 108 | <p>
|
109 | 109 | You can use the <a href="https://play.google.com/store/apps/details?id=io.heckel.ntfy">Ntfy Android App</a>
|
110 | 110 | to receive notifications directly on your phone. Just like the server, this app is also <a href="https://github.com/binwiederhier/ntfy-android">open source</a>.
|
| 111 | + Since I don't have an iPhone or a Mac, I didn't make an iOS app yet. I'd be awesome if <a href="https://github.com/binwiederhier/ntfy/issues/4">someone else could help out</a>. |
| 112 | + </p> |
| 113 | + <p> |
| 114 | + <a href="https://play.google.com/store/apps/details?id=io.heckel.ntfy"><img src="static/img/badge-googleplay.png"></a> |
| 115 | + <a href="https://github.com/binwiederhier/ntfy/issues/4"><img src="static/img/badge-appstore.png"></a> |
111 | 116 | </p>
|
112 | 117 |
|
113 | 118 | <h3 id="subscribe-api" class="anchor">Subscribe via your app, or via the CLI</h3>
|
114 | 119 | <p class="smallMarginBottom">
|
115 | 120 | Using <a href="https://developer.mozilla.org/en-US/docs/Web/API/EventSource">EventSource</a> in JS, you can consume
|
116 |
| - notifications like this (see <a href="https://github.com/binwiederhier/ntfy/tree/main/examples">full example</a>): |
| 121 | + notifications like this (see <a href="example.html">live example</a>): |
117 | 122 | </p>
|
118 | 123 | <code>
|
119 | 124 | const eventSource = new EventSource('https://ntfy.sh/mytopic/sse');<br/>
|
|
149 | 154 | <code>
|
150 | 155 | $ curl -s ntfy.sh/mytopic/raw<br/>
|
151 | 156 | <br/>
|
152 |
| - This is a notification |
153 |
| - </code> |
154 |
| - <p class="smallMarginBottom"> |
155 |
| - Here's an example of how to use this endpoint to send desktop notifications for every incoming message: |
156 |
| - </p> |
157 |
| - <code> |
158 |
| - while read msg; do<br/> |
159 |
| - [ -n "$msg" ] && notify-send "$msg"<br/> |
160 |
| - done < <(stdbuf -i0 -o0 curl -s ntfy.sh/mytopic/raw) |
| 157 | + This is a notification<br/> |
| 158 | + And another one with a smiley face 😀 |
161 | 159 | </code>
|
162 | 160 |
|
163 | 161 | <h2 id="other-features" class="anchor">Other features</h2>
|
164 |
| - <h3 id="fetching-cached-messages" class="anchor">Fetching cached messages</h3> |
| 162 | + <h3 id="fetching-cached-messages" class="anchor">Fetching cached messages (<tt>since=</tt>)</h3> |
165 | 163 | <p class="smallMarginBottom">
|
166 | 164 | Messages are cached on disk for {{.CacheDuration}} to account for network interruptions of subscribers.
|
167 | 165 | You can read back what you missed by using the <tt>since=</tt> query parameter. It takes either a
|
|
172 | 170 | curl -s "ntfy.sh/mytopic/json?since=10m"
|
173 | 171 | </code>
|
174 | 172 |
|
175 |
| - <h3 id="polling" class="anchor">Fetching cached messages</h3> |
| 173 | + <h3 id="polling" class="anchor">Polling (<tt>poll=1</tt>)</h3> |
176 | 174 | <p class="smallMarginBottom">
|
177 | 175 | You can also just poll for messages if you don't like the long-standing connection using the <tt>poll=1</tt>
|
178 | 176 | query parameter. The connection will end after all available messages have been read. This parameter can be
|
|
182 | 180 | curl -s "ntfy.sh/mytopic/json?poll=1"
|
183 | 181 | </code>
|
184 | 182 |
|
185 |
| - <h3 id="multiple-topics" class="anchor">Subscribing to multiple topics</h3> |
| 183 | + <h3 id="multiple-topics" class="anchor">Subscribing to multiple topics (<tt>topic1,topic2,...</tt>)</h3> |
186 | 184 | <p class="smallMarginBottom">
|
187 | 185 | It's possible to subscribe to multiple topics in one HTTP call by providing a
|
188 | 186 | comma-separated list of topics in the URL. This allows you to reduce the number of connections you have to maintain:
|
|
194 | 192 | {"id":"Cm02DsxUHb","time":1637182643,"event":"message","topic":"mytopic2","message":"for topic 2"}
|
195 | 193 | </code>
|
196 | 194 |
|
| 195 | + <h2 id="examples" class="anchor">Examples</h2> |
| 196 | + <p> |
| 197 | + There are a million ways to use Ntfy, but here are some inspirations. I try to collect |
| 198 | + <a href="https://github.com/binwiederhier/ntfy/tree/main/examples">examples on GitHub</a>, so be sure to check |
| 199 | + those out, too. |
| 200 | + </p> |
| 201 | + |
| 202 | + <h3 id="example-alerts" class="anchor">Example: A long process is done: backups, copying data, pipelines, ...</h3> |
| 203 | + <p class="smallMarginBottom"> |
| 204 | + I started adding notifications pretty much all of my scripts. Typically, I just chain the <tt>curl</tt> call |
| 205 | + directly to the command I'm running. The following example will either send <i>Laptop backup succeeded</i> |
| 206 | + or ⚠️ <i>Laptop backup failed</i> directly to my phone: |
| 207 | + </p> |
| 208 | + <code> |
| 209 | + rsync -a root@laptop /backups/laptop \<br/> |
| 210 | + && zfs snapshot ... \<br/> |
| 211 | + && curl -d "Laptop backup succeeded" ntfy.sh/backups \<br/> |
| 212 | + || echo -en "\u26A0\uFE0F Laptop backup failed" | curl -sT- ntfy.sh/backups |
| 213 | + </code> |
| 214 | + |
| 215 | + <h3 id="example-web" class="anchor">Example: Server-sent messages in your web app</h3> |
| 216 | + <p> |
| 217 | + Just as you can <a href="#subscribe-web">subscribe to topics in this Web UI</a>, you can use Ntfy in your own |
| 218 | + web application. Check out the <a href="example.html">live example</a> or just look the source of this page. |
| 219 | + </p> |
| 220 | + |
| 221 | + <h3 id="example-notify-ssh" class="anchor">Example: Notify on SSH login</h3> |
| 222 | + <p> |
| 223 | + Years ago my home server was broken into. That shook me hard, so every time someone logs into any machine that I |
| 224 | + own, I now message myself. Here's an example of how to use <a href="https://en.wikipedia.org/wiki/Linux_PAM">PAM</a> |
| 225 | + to notify yourself on SSH login. |
| 226 | + </p> |
| 227 | + <p class="smallMarginBottom"> |
| 228 | + <b>/etc/pam.d/sshd</b> (at the end of the file): |
| 229 | + </p> |
| 230 | + <code> |
| 231 | + session optional pam_exec.so /usr/local/bin/ntfy-ssh-login.sh |
| 232 | + </code> |
| 233 | + <p class="smallMarginBottom"> |
| 234 | + <b>/usr/local/bin/ntfy-ssh-login.sh</b>: |
| 235 | + </p> |
| 236 | + <code> |
| 237 | + #!/bin/bash<br/> |
| 238 | + if [ "${PAM_TYPE}" = "open_session" ]; then<br/> |
| 239 | + echo -en "\u26A0\uFE0F SSH login: ${PAM_USER} from ${PAM_RHOST}" | curl -T- ntfy.sh/alerts<br/> |
| 240 | + fi |
| 241 | + </code> |
| 242 | + |
| 243 | + <h3 id="example-collect-data" class="anchor">Example: Collect data from multiple machines</h3> |
| 244 | + <p> |
| 245 | + The other day I was running tasks on 20 servers and I wanted to collect the interim results |
| 246 | + as a CSV in one place. Here's the script I wrote: |
| 247 | + </p> |
| 248 | + <code> |
| 249 | + while read result; do<br/> |
| 250 | + [ -n "$result" ] && echo "result" >> results.csv<br/> |
| 251 | + done < <(stdbuf -i0 -o0 curl -s ntfy.sh/results/raw) |
| 252 | + </code> |
| 253 | + |
197 | 254 | <h2 id="faq" class="anchor">FAQ</h2>
|
198 | 255 | <p>
|
199 | 256 | <b id="isnt-this-like" class="anchor">Isn't this like ...?</b><br/>
|
|
225 | 282 | client network disruptions.
|
226 | 283 | </p>
|
227 | 284 |
|
| 285 | + <p> |
| 286 | + <b id="selfhosted" class="anchor">Can I self-host it?</b><br/> |
| 287 | + Yes. The server (including this Web UI) can be self-hosted, and the Android app supports adding topics from |
| 288 | + your own server as well. There are <a href="https://github.com/binwiederhier/ntfy#installation">install instructions</a> |
| 289 | + on GitHub. |
| 290 | + </p> |
| 291 | + |
228 | 292 | <p>
|
229 | 293 | <b id="why-firebase" class="anchor">Why is Firebase used?</b><br/>
|
230 | 294 | In addition to caching messages locally and delivering them to long-polling subscribers, all messages are also
|
231 | 295 | published to Firebase Cloud Messaging (FCM) (if <tt>FirebaseKeyFile</tt> is set, which it is on ntfy.sh). This
|
232 | 296 | is to facilitate instant notifications on Android.
|
233 | 297 | </p>
|
234 | 298 |
|
235 |
| - <h2 id="#privacy" class="anchor">Privacy policy</h2> |
| 299 | + <p> |
| 300 | + <b id="why-no-ios" class="anchor">Why is there no iOS app (yet)?</b><br/> |
| 301 | + I don't have an iPhone or a Mac, so I didn't make an iOS app yet. I'd be awesome if |
| 302 | + <a href="https://github.com/binwiederhier/ntfy/issues/4">someone else could help out</a>. |
| 303 | + </p> |
| 304 | + |
| 305 | + <h2 id="privacy" class="anchor">Privacy policy</h2> |
236 | 306 | <p>
|
237 | 307 | Neither the server nor the app record any personal information, or share any of the messages and topics with
|
238 | 308 | any outside service. All data is exclusively used to make the service function properly. The one exception
|
|
0 commit comments