Skip to content

[FEATURE] Email notification on power events #48

Description

@DemonChicken1111

Sometimes I find myself away from home during power events, and while I do not worry as much since I have battery backups, and WOL running, I do find it useful to know when such events happen so I can figure out what's actually wrong when I have family members asking why the Jellyfin server isn't loading. So I would like to propose a feature which should solve most of that problem.

Feature Overview: On a power event, a wolnut process will trigger an email to be sent via the email package. This will be configurable, like other features and clients are via YAML.

Assumptions: This feature will assume that the entirety of the network stack (at least the important bits) are on battery backup and functioning during a power event.

Proposed Implementation:

A new script named notif.py is created which houses all of the email functions, this can be triggered in the cli.py script after logging events take place. For example, here's a snippet with an added function call (Line 68-73 in cli.py):

# Power Loss Event
 if "OB" in power_status and not on_battery:
     state_tracker.mark_all_online_clients()
     state_tracker.set_ups_on_battery(True, battery_percent)
     on_battery = True
     logger.warning("UPS switched to battery power.")
     mail.send_warning() # Calls email logic and sends specified message

The mail.send_warning() function would trigger the logic to send the message to the configured email address. The configuration file could look something like this:

mail:
     address: "email@example.com"

This might need some tweaking as I haven't looked too deep into what else might be required for reliably getting emails sent via python libraries. Would love some feedback on this, and eventually some help creating tests as I have not done much in the way of creating tests in python. Cheers o/

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions