Email notification after failed backup

What, you mean NS8 wants configuration to deliver email notifications, but has no mechanism to actually send them?

And personal subscriptions don’t get alerts? We just get pointless alerts about swap being full when there is no swap? Is backup not important for non-business users?

The personal subscription already costs double what it did for NS7, and it seems like it provides less.

I’m not sure I understand the question. An application can obtain SMTP configuration as documented in SMTP smarthost | NS8 dev manual. I’m just wondering if a provided command could help developers avoid writing multiple similar SMTP-client scripts that perform the same function.

This will be fixed during the current milestone, 8.4.

Backup is a fundamental component of the system for every user. Whether a feature is available or not depends on many factors, with complexity being a key one. I don’t want to delve into paid plan tiers, but the point is that Nethesis portals already provide features we haven’t yet implemented in NS8 core—for example, alert logic, email message formatting and queue, and recipient configuration. In my opinion, it’s only a matter of time before NS8 core handles email sending on its own.

1 Like

I’d think it probably would, I’m just surprised that it isn’t already there. I’d have expected that if there are configuration options for one or more[1] alert services, that there’d already be a function like send_alert($severity,$content) in the system.


  1. more than just email would be great–e.g., Slack, Synapse, Telegram, generic web hook ↩︎

2 Likes

Hi David,

has something changed here? The file /run/backup-monitor.dat apparently no longer exists.

Best, Erwin

1 Like

Hi Erwin,

You are right, the monitoring stack has recently undergone a significant change and is now implemented with Prometheus + Alert Manager. Using a widespread monitoring stack should facilitate integration and customization development.

With a Subscription (if monitoring is included), emails are already sent by the Nethesis portal. Without a Subscription, a custom Prometheus configuration is needed, but it is still experimental. Please refer to https://github.com/NethServer/ns8-metrics.

As an alternative to checking /run/backup-monitor.dat, you could also try querying the Prometheus APIs. There’s plenty of documentation available, and it would be a good idea to write a Howto.

Hi David,

thank you very much for your answer. That doesn’t sound so easy at first, I’ll try to read up on it.

Erwin

1 Like

There is no UI to do it yet, however you can already configure alert email notifications with an API call. Refer to the module’s README for details.

For example:

api-cli run module/metrics1/configure-module --data '{"prometheus_path": "", "grafana_path": "", "mail_to": ["me@nethserver.org"], "mail_from": "no-reply@nethserver.org", "mail_template": ""}'
2 Likes

It’s just one command to configure it.
In the future, I think we are going to expose it inside the UI.

You can find a little more info here: Metrics and alerts — NS8 documentation
If you want to dig deeper, take a look at this: GitHub - NethServer/ns8-metrics: NS8 metrics and alerts

Also, if you just want a very simple notification on both success and error, I’ve created a little test script. Put it at /var/lib/nethserver/cluster/events/backup-status-changed/20notify.


#!/bin/bash

# Change the following variables to match your environment
MAIL_FROM="no-reply@nethserver.org"
MAIL_TO="giacomo@nethesis.it"
MAIL_SUBJECT="Backup status changed:"
MAIL_TEMPLATE="The backup status for {BACKUP_NAME} on {MODULE_ID} has changed to {STATUS}. Please check the system for details."

# WARNING - DO NOT EDIT BELOW THIS LINE (unless you know what you're doing)

# Redis command
rdb="redis-cli --raw"

# Read event data from stdin
read -r event_data
if ! echo "$event_data" | jq . >/dev/null 2>&1; then
    echo "Failed to parse JSON input" >&2
    exit 1
fi

# Extract necessary fields from event_data
module_id=$(echo "$event_data" | jq -r '.module_id')
backup_id=$(echo "$event_data" | jq -r '.backup_id')

leader_id=$($rdb hget cluster/environment NODE_ID)
self_id=$NODE_ID

if [[ "$self_id" != "$leader_id" ]]; then
    exit 0 # LEADER ONLY! Do not run this procedure in worker nodes.
fi
backup_name=$($rdb hget "cluster/backup/$backup_id" "name")

errors=$($rdb hget "module/$module_id/backup_status/$backup_id" errors)
if [[ -z "$errors" ]]; then
    echo "INFO: Status unknown, exiting." >&2
    exit 0
fi

if [[ "$errors" == "0" ]]; then
    status="SUCCESS"
else
    status="FAIL"
fi

# Send email
subject="$backup_name ($module_id): $status"
msg="$(echo "$MAIL_TEMPLATE" | sed "s/{BACKUP_NAME}/$backup_name/g; s/{STATUS}/$status/g; s/{MODULE_ID}/$module_id/g")"
echo "$msg" | runagent ns8-sendmail -s "$subject" -f "$MAIL_FROM" "$MAIL_TO"

Then make it executable:

chmod a+x /var/lib/nethserver/cluster/events/backup-status-changed/20notify

Bear in mind: it will send a notification for each instance inside a backup schedule.

If you need to test it, use a command like this:

echo '{"node_id": 1, "module_id": "loki1", "backup_id": 1}' | runagent /var/lib/nethserver/cluster/events/backup-status-changed/20notify 
4 Likes

@davidep @giacomo Many thanks for your support, it was easier than I thought and works perfectly.

Best, Erwin

1 Like

@davidep Hi David,

one more addition to the subscription plan, I use Nethserver exclusively at home for my private use.

An additional subscription plan for private use only, which includes monitoring, would be a good alternative. No tickets would have to be included at all, just unlock these additional functions.

I would support the suggestion here, maybe there will be a solution in the future.
Announcing New NethServer 8 Subscription Plans - #23 by MadPatrick

Best, Erwin

1 Like