Skip to main content

Monitor configurable MQTT topics and forward the messages to ntfy.sh topics.

Project description

NSP Ntfy

GitHub Actions Workflow Status Coveralls Sonar Quality Gate PyPI - Version GitHub License

The Night Sky Pi can be configured to publish messages to a local MQTT broker. The NSP-NTFY module can be configured to listen to these notifactions and publish the notification field to ntfy.sh. This is so push notifications can be recieved on other devices without having to make the broker on the device public with routing.

Prerequisites

Before deploying the nsp-ntfy it's important to ensure that you have the following configured as there are dependencies. However the installation of an MQTT broker is optional I usually have it installed instead of needing to remember to do it when starting up other applications.

Python

nsp-ntfy is written in Python and has been tested with the following Python versions:

  • Python 3.9
  • Python 3.10
  • Python 3.11
  • Python 3.12

The nsp-ntfy.sh runs within a virtual environment based on what's on your system path.

MQTT Broker

Night Sky Pi has the ability to publish events to an MQTT broker. The intent of this is so that other modules can react to the events to complete additional actions. Initially this broker will only run locally therefore only allow clients that reside on the same device as intended. Firstly we need to install MQTT on the Raspberry Pi.

sudo apt update && sudo apt upgrade
sudo apt install -y mosquitto
sudo apt install -y mosquitto-clients # Optional for testing locally
sudo systemctl enable mosquitto.service
sudo reboot # Just something I like to do, this is optional as well

The next step is to configure the nsp-ntfy to use the MQTT broker, as MQTT events are disabled by default. These configuration items are in the nsp configuration not the configuration of the nsp-ntfy module.

"device" : {
    "mqtt" : {
        "enabled": true,
        "host": "127.0.0.1"
    }
}

Running NSP-NTFY

It's recommended that nsp-ntfy is run as a service. This ensures that it doesn't stop of user logging off and on system restarts to do this carry out the following.

# current working directory is the nsp-ntfy repository.
sudo cp nsp.service /etc/systemd/system/nsp-ntfy.service
sudo nano /etc/systemd/system/nsp-ntfy.service

Next step is to update the service definition to the correct paths and running as the correct user.

[Unit]
Description=nsp-ntfy
After=network.target

[Service]
Type=Simple
# update this to be your current user
User=username 
# the location of the nsp-ntfy repository
WorkingDirectory=/home/username/repositories/nsp-ntfy/ 
# update these paths to be the location of the nsp-ntfy.sh 
# update argument to where you previously copied the json configuration.
ExecStart=/home/username/repositories/nsp-ntfy/nsp-ntfy.sh /home/username/nsp-ntfy-config.json /home/username/nsp-config.json 
Restart=on-failure

[Install]
WantedBy=multi-user.target

Next is to enable and start the service.

sudo systemctl daemon-reload
sudo systemctl start nsp-ntfy
sudo systemctl enable nsp-ntfy

Contributing

Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement".

Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nsp_ntfy-2.0.0.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nsp_ntfy-2.0.0-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file nsp_ntfy-2.0.0.tar.gz.

File metadata

  • Download URL: nsp_ntfy-2.0.0.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for nsp_ntfy-2.0.0.tar.gz
Algorithm Hash digest
SHA256 f3915cae8a701396a049423177e402260dd193e74ceb22f1675125305f2284f9
MD5 2c90951bbf4d1d53fa2a35a367989e63
BLAKE2b-256 ffd87dfa7a258026c303f4772eec1ca84b8b927f20362f9ad33d887788cc1adc

See more details on using hashes here.

Provenance

The following attestation bundles were made for nsp_ntfy-2.0.0.tar.gz:

Publisher: publish.yml on joe-mccarthy/nsp-ntfy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nsp_ntfy-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: nsp_ntfy-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for nsp_ntfy-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 58159b57d6d99b311039eed35648e8238d188755eee7062aac32a32c7bfc5d52
MD5 2c4d8b30c9474f8f3e65bca944e631bc
BLAKE2b-256 3dd8507a1e1118351c0d8913ad3ccfa82310e67ca1672e67dd2fefdbf71d92a1

See more details on using hashes here.

Provenance

The following attestation bundles were made for nsp_ntfy-2.0.0-py3-none-any.whl:

Publisher: publish.yml on joe-mccarthy/nsp-ntfy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page