2 min read

Proxmox Task Notification with Ntfy Integration

Proxmox Task Notification with Ntfy Integration

Introduction

Proxmox Virtual Environment (PVE) is a powerful open-source platform for virtualization that supports container-based and full virtualization. This blog introduces a Python script that monitors Proxmox tasks and sends notifications for completed tasks to an Ntfy server.

Script Overview

The script utilizes the Proxmox API to retrieve information about tasks on a specified Proxmox node. It then checks for completed tasks and sends notifications to an Ntfy server using the requests library. The script includes logic to keep track of processed tasks to avoid sending duplicate notifications.

Prerequisites

  • Python: Ensure that Python is installed on your system. You can download it from python.org.
  • Proxmoxer: Install the Proxmoxer library using the following command:s:
pip install proxmoxer
  • Requests: Install the Requests library for sending HTTP requests:
pip install requests

Script Contents

Running the Script in Screen

screen is a terminal multiplexer that allows you to run processes in the background and reattach to them later.

  • Open a terminal and navigate to the directory containing the script.
  • Start a new screen session:
screen -S proxmox_monitor
  • Inside the screen session, run the script:
python proxmox_notifications.py
  • To detach from the screen session, press Ctrl + A followed by d.
  • To reattach to the session later, use:
screen -r proxmox_monitor

Running the Script with nohup

nohup is a command that runs another command and disconnects it from the terminal, preventing it from being terminated when the terminal is closed.

  • Open a terminal and navigate to the directory containing the script.
  • Run the script with nohup:
nohup python proxmox_notifications.py &
  • The script is now running in the background. You can close the terminal.
  • To check the output or stop the script later, you can use the nohup.out file:
cat nohup.out
  • To stop the script, find its process ID (PID) and use kill:
ps aux | grep proxmox_notifications.py
kill -9 <PID>

These steps allow you to run the script in the background and keep it running even if you close the terminal session. Choose the method that best suits your preferences and requirements.

Conclusion

This script provides a convenient way to receive notifications for completed Proxmox tasks through the Ntfy service. By integrating Proxmox monitoring into your notification workflow, you can stay informed about important events in your virtualized environment.

Feel free to customize the script further based on your specific use case and requirements.

Happy monitoring!