kenstir / hemlock-sendmsg

Command-line utility to send a push notification to the hemlock mobile apps

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

hemlock-sendmsg

hemlock-sendmsg is a small daemon for sending push notifications to the Hemlock mobile apps.

Quick Start

  1. Install hemlock-sendmsg on the machine which runs Evergreen action triggers.
  2. In the Firebase Console, create a service account with the cloudmessaging.messages.create permission, create a service account key, and save it to the hemlock-sendmsg install directory as service-account.json. For detailed instructions, see the Setup Guide to Push Notifications.
  3. Start the server
$ ./hemlock-sendmsg
2024/04/20 13:07:25 initializing firebase with credentials file service-account.json
2024/04/20 13:07:25 listening on localhost:8842

Detailed Usage

Use -addr [host:port] to change the server's address and port.

Use -credentialsFile [path] or the GOOGLE_APPLICATION_CREDENTIALS environment variable to change the location of the service account key.

Sending a Push Notification

POST to /send with parameters:

  • title - the title of the notification
  • body - the body text of the notification
  • token - the FCM registration token
  • debug - if not empty and not "0", log the call to stdout

For example:

$ token="f2uw...Sv2o"
$ curl -F token="$token" -F title="New Message" -F body="DM $(date '+%a %H:%M')" -F debug=1 localhost:8842/send
ok

Will cause hemlock-sendmsg to log something like:

2024/04/29 17:45:21 INFO POST /send result=ok code=200 username="" title="New Message" body="DM Mon 17:45" token=fHC...sQy

Finding a Patron's Push Notification Token

The push notification token is stored after login as a user setting. So to find the push notification token for the 'hemlock' user, you could issue the SQL query:

evergreen=# select s.value from actor.usr_setting s
join actor.usr u on u.id=s.usr
where usrname='hemlock' and s.name='hemlock.push_notification_data';
    value
-------------
"fwql...y-MU"
(1 row)

Collecting Metrics

GET /metrics

The metrics includes golang runtime and some other stats as well as internal stats in Prometheus format. To see just the internal status, grep for "hemlock_", e.g.

$ curl -sS localhost:8842/metrics | grep hemlock_
# HELP hemlock_notifications_sent_total Notifications sent, by result
# TYPE hemlock_notifications_sent_total counter
hemlock_notifications_sent_total{result="EmptyToken"} 1
hemlock_notifications_sent_total{result="ok"} 2

About

Command-line utility to send a push notification to the hemlock mobile apps


Languages

Language:Python 71.1%Language:Go 28.9%Language:Makefile 0.1%