mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-08-29 15:06:26 +02:00
Huge role refactoring/cleanup. Other commits will propably follow. Because some bugs will exist. Still important for longrun and also for auto docs/help/slideshow generation
This commit is contained in:
24
roles/alert-email/README.md
Normal file
24
roles/alert-email/README.md
Normal file
@@ -0,0 +1,24 @@
|
||||
# Automated Email Alerts for Service Failures
|
||||
|
||||
## Description
|
||||
|
||||
This role installs and configures the necessary components for sending email notifications via systemd when a service fails. It sets up the `alert-email` service and configures email parameters and templates using msmtp.
|
||||
|
||||
## Overview
|
||||
|
||||
Optimized for secure and reliable service failure notifications, this role is an integral part of the overall `alert-core` suite. It ensures that, upon failure of a critical service, an email alert is sent automatically to enable prompt troubleshooting.
|
||||
|
||||
## Purpose
|
||||
|
||||
The primary purpose of this role is to provide a comprehensive solution for automated email notifications in a systemd environment. By integrating with msmtp and customizable templates, it delivers clear and timely alerts about service failures, thereby enhancing system reliability.
|
||||
|
||||
## Features
|
||||
|
||||
- **Service Installation & Configuration:** Installs msmtp and configures the email sending service.
|
||||
- **Customizable Templates:** Supports tailoring email templates for service failure notifications.
|
||||
- **Secure Notifications:** Integrates with systemd to trigger email alerts when services fail.
|
||||
- **Suite Integration:** Part of the `alert-core` suite, offering a unified approach to service failure notifications.
|
||||
|
||||
## Other Resources
|
||||
|
||||
This role was created as part of a conversation with OpenAI's ChatGPT and can be found [here](https://chat.openai.com/share/96e4ca12-0888-41c0-9cfc-29c0180f0dba).
|
4
roles/alert-email/handlers/main.yml
Normal file
4
roles/alert-email/handlers/main.yml
Normal file
@@ -0,0 +1,4 @@
|
||||
- name: "restart alert-email service"
|
||||
systemd:
|
||||
name: alert-email.cymais.service
|
||||
daemon_reload: yes
|
26
roles/alert-email/meta/main.yml
Normal file
26
roles/alert-email/meta/main.yml
Normal file
@@ -0,0 +1,26 @@
|
||||
---
|
||||
galaxy_info:
|
||||
author: "Kevin Veen-Birkenbach"
|
||||
description: "Installs and configures components for sending email notifications. This role is part of the alert-core suite, providing automated alerts when services fail."
|
||||
license: "CyMaIS NonCommercial License (CNCL)"
|
||||
license_url: "https://s.veen.world/cncl"
|
||||
company: |
|
||||
Kevin Veen-Birkenbach
|
||||
Consulting & Coaching Solutions
|
||||
https://www.veen.world
|
||||
min_ansible_version: "2.9"
|
||||
platforms:
|
||||
- name: Archlinux
|
||||
versions:
|
||||
- rolling
|
||||
galaxy_tags:
|
||||
- email
|
||||
- systemd
|
||||
- notifications
|
||||
- automation
|
||||
- msmtp
|
||||
repository: "https://s.veen.world/cymais"
|
||||
issue_tracker_url: "https://s.veen.world/cymaisissues"
|
||||
documentation: "https://s.veen.world/cymais"
|
||||
dependencies:
|
||||
- generic-msmtp
|
24
roles/alert-email/tasks/main.yml
Normal file
24
roles/alert-email/tasks/main.yml
Normal file
@@ -0,0 +1,24 @@
|
||||
- name: "create {{systemd_notifier_email_folder}}"
|
||||
file:
|
||||
path: "{{systemd_notifier_email_folder}}"
|
||||
state: directory
|
||||
mode: 0755
|
||||
when: run_once_systemd_notifier_email is not defined
|
||||
|
||||
- name: configure alert-email.sh
|
||||
template:
|
||||
src: alert-email.sh.j2
|
||||
dest: "{{systemd_notifier_email_folder}}alert-email.sh"
|
||||
when: run_once_systemd_notifier_email is not defined
|
||||
|
||||
- name: configure alert-email.cymais.service
|
||||
template:
|
||||
src: alert-email@.service.j2
|
||||
dest: /etc/systemd/system/alert-email.cymais@.service
|
||||
notify: restart alert-email service
|
||||
when: run_once_systemd_notifier_email is not defined
|
||||
|
||||
- name: run the systemd_notifier_email tasks once
|
||||
set_fact:
|
||||
run_once_systemd_notifier_email: true
|
||||
when: run_once_systemd_notifier_email is not defined
|
15
roles/alert-email/templates/alert-email.sh.j2
Normal file
15
roles/alert-email/templates/alert-email.sh.j2
Normal file
@@ -0,0 +1,15 @@
|
||||
#!/bin/bash
|
||||
|
||||
/usr/bin/sendmail -t <<ERRMAIL
|
||||
To: {{ users.administrator.email }}
|
||||
From: systemd <{{ users['no-reply'].email }}>
|
||||
Subject: $1
|
||||
Content-Transfer-Encoding: 8bit
|
||||
Content-Type: text/plain; charset=UTF-8
|
||||
|
||||
A problem with the service $1 occured:
|
||||
|
||||
$(systemctl status --full "$1" | head -n 30)
|
||||
|
||||
|
||||
ERRMAIL
|
8
roles/alert-email/templates/alert-email@.service.j2
Normal file
8
roles/alert-email/templates/alert-email@.service.j2
Normal file
@@ -0,0 +1,8 @@
|
||||
[Unit]
|
||||
Description=status email for %i to user
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/bin/bash {{systemd_notifier_email_folder}}alert-email.sh %i
|
||||
User=root
|
||||
Group=systemd-journal
|
1
roles/alert-email/vars/main.yml
Normal file
1
roles/alert-email/vars/main.yml
Normal file
@@ -0,0 +1 @@
|
||||
systemd_notifier_email_folder: "{{path_administrator_scripts}}alert-email/"
|
Reference in New Issue
Block a user