diff --git a/README.md b/README.md index 049ea2f..b7c1247 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,15 @@ system-helpers - Collection of helper systemd services, systemd timers and shell scripts for common configuration. +It can help you out for small servers where you think a proper monitoring and +alerting system like [Prometheus](https://prometheus.io) and +[AlertManager](https://prometheus.io/docs/alerting/latest/alertmanager/) is too much. + +The **notifier** script can send notifications via mail or [gotify](https://gotify.net). + **system-helpers** collection provides the following helpers +- notifier which sends notifications via mail or gotify (see **see notifier**) - checking if systemd services and timers are running (see **man systemd_check**) - borgmatic backup (see exposed systemd services *borgmatic@* which require a valid *borgmatic.yml* file in */etc/borgmatic* or your **$HOME/.config/borgmatic**) - restic backup (see */usr/share/doc/system-helpers/restic* for an example *mybackup*) diff --git a/_man/src/check_updates.1.md b/_man/src/check_updates.1.md index 423449f..3c632bf 100644 --- a/_man/src/check_updates.1.md +++ b/_man/src/check_updates.1.md @@ -7,13 +7,13 @@ check_updates - Notifies about available updates. Configuration is done in envir It's part of **system-helpers**. # SYNOPSIS -**check_updates** [CONFIG_FILE (absolute path)] +**check_updates** # DESCRIPTION **check_updates** checks for available updates using *checkupdates* and sends out a mail. It comes with systemd services. -If no *CONFIG_FILE* is provided, **check_updates** tries to read from *$HOME/.check_updates.conf* and */etc/check_updates.conf* for configuration. It will exit with a non-zero exit code if it cannot find an proper configuration file. +By default, **check_updates** tries to read from *$HOME/.check_updates.conf* and */etc/check_updates.conf* for configuration. It will exit with a non-zero exit code if it cannot find a proper configuration file. The following are at least required for the script to work:\ - **CHECK_UPDATES_MAIL_ADDRESS=""** which requires *mail.rc* to be configured and '*mailx*' command has be available. diff --git a/_man/src/disk_space_alert.1.md b/_man/src/disk_space_alert.1.md index 63f7af5..4e0efca 100644 --- a/_man/src/disk_space_alert.1.md +++ b/_man/src/disk_space_alert.1.md @@ -7,13 +7,13 @@ disk_space_alert - Checks available disk space and sends out notification via ma It's part of **system-helpers**. # SYNOPSIS -**disk_space_alert** [CONFIG_FILE (absolute path)] +**disk_space_alert** # DESCRIPTION **disk_space_alert** checks available diskspace for configured **mounts** and sends out a mail if certain limits are reached. It comes with systemd services. -If no *CONFIG_FILE* is provided, **disk_space_alert** tries to read from *$HOME/.disk_space_alert.conf* and */etc/disk_space_alert.conf* for configuration. It will exit with a non-zero exit code if it cannot find an proper configuration file. +By default, **disk_space_alert** tries to read from *$HOME/.disk_space_alert.conf* and */etc/disk_space_alert.conf* for configuration. It will exit with a non-zero exit code if it cannot find a proper configuration file. The following are at least required for the script to work:\ - **DISK_SPACE_ALERT_MAIL_ADDRESS=""** which requires *mail.rc* to be configured and '*mailx*' command has be available.\ diff --git a/_man/src/docker_check.1.md b/_man/src/docker_check.1.md index bd2e9c2..97bab8a 100644 --- a/_man/src/docker_check.1.md +++ b/_man/src/docker_check.1.md @@ -7,13 +7,13 @@ docker_check - Checks a set of docker containers and notifies if their state is It's part of **system-helpers**. # SYNOPSIS -**docker_check** [CONFIG_FILE (absolute path)] +**docker_check** # DESCRIPTION **docker_check** checks a list of docker containers and notifies if their state is not up and running. It comes with systemd services. -If no *CONFIG_FILE* is provided, **docker_check** tries to read from *$HOME/.docker_check.conf* and */etc/docker_check.conf* for configuration. It will exit with a non-zero exit code if it cannot find an proper configuration file. +By default, **docker_check** tries to read from *$HOME/.docker_check.conf* and */etc/docker_check.conf* for configuration. It will exit with a non-zero exit code if it cannot find a proper configuration file. The following are at least required for the script to work:\ - **DOCKER_CHECK_MAIL_ADDRESS=""** which requires *mail.rc* to be configured and '*mailx*' command has be available.\ diff --git a/_man/src/docker_compose_update.1.md b/_man/src/docker_compose_update.1.md index bb1181e..0b6b28d 100644 --- a/_man/src/docker_compose_update.1.md +++ b/_man/src/docker_compose_update.1.md @@ -3,17 +3,17 @@ % January 2023 # NAME -docker_compose_update - An utility to batch update *docker-compose* deployments residing in sub folders. Configuration is done in environment files.\ +docker_compose_update - Utility to batch update *docker-compose* deployments residing in sub folders of a base directory. Configuration is done in environment files.\ It's part of **system-helpers**. # SYNOPSIS -**docker_compose_update** [CONFIG_FILE (absolute path)] +**docker_compose_update** # DESCRIPTION **docker_compose_update** is an utility to batch update *docker-compose* deployments residing in sub folders of a **base directory**, e.g */root/deployments/* having different sub folders, each having a *docker-compose* deployment in it. -If no *CONFIG_FILE* is provided, **docker_compose_update** tries to read from *$HOME/.docker_compose_update.conf* and */etc/docker_compose_update.conf* for configuration. It will exit with a non-zero exit code if it cannot find an proper configuration file. +By default, **docker_compose_update** tries to read from *$HOME/.docker_compose_update.conf* and */etc/docker_compose_update.conf* for configuration. It will exit with a non-zero exit code if it cannot find a proper configuration file. The following are at least required for the script to work:\ - **DOCKER_COMPOSE_UPDATE_BASEDIR="/root/deployments"** determines the **base directory** where all *docker-compose* stacks are located in their own sub-folders.\ diff --git a/_man/src/dynv6.1.md b/_man/src/dynv6.1.md index e22fde5..83f432d 100644 --- a/_man/src/dynv6.1.md +++ b/_man/src/dynv6.1.md @@ -7,13 +7,13 @@ dynv6 - Updates dynv6 (an external service) and notifies about changes of IP add It's part of **system-helpers**. # SYNOPSIS -**dynv6** [CONFIG_FILE (absolute path)] +**dynv6** # DESCRIPTION **dynv6** updates dynv6 (an external service) and notifies about changes of IP addresses. It comes with systemd services. -If no *CONFIG_FILE* is provided, **dynv6** tries to read from *$HOME/.dynv6.conf* and */etc/dynv6.conf* for configuration. It will exit with a non-zero exit code if it cannot find an proper configuration file. +By default, **dynv6** tries to read from *$HOME/.dynv6.conf* and */etc/dynv6.conf* for configuration. It will exit with a non-zero exit code if it cannot find a proper configuration file. The following are at least required for the script to work:\ - **DYNV6_MAIL_ENABLED** to enable or disable mail notification. diff --git a/_man/src/memory_usage_alert.1.md b/_man/src/memory_usage_alert.1.md index 6ca1ed8..de4221d 100644 --- a/_man/src/memory_usage_alert.1.md +++ b/_man/src/memory_usage_alert.1.md @@ -7,13 +7,13 @@ memory_usage_alert - Checks available memory and sends out notification via mail It's part of **system-helpers**. # SYNOPSIS -**memory_usage_alert** [CONFIG_FILE (absolute path)] +**memory_usage_alert** # DESCRIPTION **memory_usage_alert** checks available memory and sends out a mail if certain limits are reached. It comes with systemd services. -If no *CONFIG_FILE* is provided, **memory_usage_alert** tries to read from *$HOME/.memory_usage_alert.conf* and */etc/memory_usage_alert.conf* for configuration. It will exit with a non-zero exit code if it cannot find an proper configuration file. +By default, **memory_usage_alert** tries to read from *$HOME/.memory_usage_alert.conf* and */etc/memory_usage_alert.conf* for configuration. It will exit with a non-zero exit code if it cannot find a proper configuration file. The following are at least required for the script to work:\ - **MEMORY_USAGE_ALERT_MAIL_ADDRESS=""** which requires *mail.rc* to be configured and '*mailx*' command has be available.\ diff --git a/_man/src/notifier.1.md b/_man/src/notifier.1.md new file mode 100644 index 0000000..74b8e09 --- /dev/null +++ b/_man/src/notifier.1.md @@ -0,0 +1,39 @@ +% notifier(1) notifier +% Alexander Schäferdiek +% January 2023 + +# NAME +notifier - Notifies via mail or gotify. Configuration is done in environment files.\ +It's part of **system-helpers**. + +# SYNOPSIS +**notifier** TITLE MESSAGE [MAIL_ADDRESS] + +# DESCRIPTION + +**notifier** executes *mailx* or *gotify* to send out notifications. It is used in other **system-helpers** by default. + +By default, **notifier** tries to read from *$HOME/.notifier.conf* and */etc/notifier.conf* for configuration. It will exit with a non-zero exit code if it cannot find a proper configuration file. + +The following configuration values can be set, defaults are shown as well:\ + +- **NOTIFIER_MAIL_ENABLED="true"** which enables or disables notification via mail to *NOTIFIER_MAIL_ADDRESS*. +- **NOTIFIER_MAIL_ADDRESS=""** which requires *mail.rc* to be configured and '*mailx*' command has be available¸ +- **NOTIFIER_GOTIFY_ENABLED="false"** which 'gotify' command has be available and needs to be properly configured by having a cli.json file + +You can copy this script to */usr/local/bin* and use create a custom **CONFIG_FILE** as user. + +# EXAMPLE + +Create a *$HOME/.notifier.conf* and add *NOTIFIER_MAIL_ADDRESS="alias@domain.tld"*. Notifications will be delivered to alias@domain.tld. Examples can be found in */usr/share/doc/notifier*. + +# EXIT VALUES +**0** +: Success + +**1** +: Error + +# SEE ALSO + +system-helpers \ No newline at end of file diff --git a/_man/src/smart_tests_long.1.md b/_man/src/smart_tests_long.1.md new file mode 100644 index 0000000..6187c20 --- /dev/null +++ b/_man/src/smart_tests_long.1.md @@ -0,0 +1,33 @@ +% smart_tests_long(1) smart_tests_long +% Alexander Schäferdiek +% January 2023 + +# NAME +smart_tests_long - Schedules smartd long tests. Configuration is done in environment files.\ +It's part of **system-helpers**. + +# SYNOPSIS +**smart_tests_long** + +# DESCRIPTION + +**smart_tests_long** checks for available updates using *smartctl* and sends out a mail. It comes with systemd services. + +By default, **smart_tests_long** tries to read from *$HOME/.smartctl_tests_long.conf* and */etc/smartctl_tests_long.conf* for configuration. It will exit with a non-zero exit code if it cannot find a proper configuration file. + +The following are at least required for the script to work:\ +- **SMARTCTL_TESTS_LONG_MAIL_ADDRESS=""** which requires *mail.rc* to be configured and '*mailx*' command has be available. +- **SMARTCTL_TESTS_LONG_DEVICES=(sda)** array of block devices (not partitions!) to check. + +You can copy this script to */usr/local/bin* and use create a custom **CONFIG_FILE** as user. + +# EXAMPLE + +Create a *$HOME/.smartctl_tests_long.conf* and add *SMARTCTL_TESTS_LONG_MAIL_ADDRESS="alias@domain.tld"*. Notifications will be delivered to alias@domain.tld for default block device **sda**. Examples can be found in */usr/share/doc/smart_tests_long*. + +# EXIT VALUES +**0** +: Success + +**1** +: Error \ No newline at end of file diff --git a/_man/src/systemd_check.1.md b/_man/src/systemd_check.1.md index c362ef3..56434ce 100644 --- a/_man/src/systemd_check.1.md +++ b/_man/src/systemd_check.1.md @@ -7,13 +7,13 @@ systemd_check - Checks a set of systemd services, targets, mounts of timers, and It's part of **system-helpers**. # SYNOPSIS -**systemd_check** [CONFIG_FILE (absolute path)] +**systemd_check** # DESCRIPTION **systemd_check** checks a set of systemd services, targets, mounts of timers, and notifies if their state is not up and running. It comes with systemd services. -If no *CONFIG_FILE* is provided, **systemd_check** tries to read from *$HOME/.systemd_check.conf* and */etc/systemd_check.conf* for configuration. It will exit with a non-zero exit code if it cannot find an proper configuration file. +By default, **systemd_check** tries to read from *$HOME/.systemd_check.conf* and */etc/systemd_check.conf* for configuration. It will exit with a non-zero exit code if it cannot find a proper configuration file. The following are at least required for the script to work:\ - **SYSTEMD_CHECK_LIST_FILE="$HOME/.systemd_check.list"** which lists to be checked systemd services, timers or targets separated by lines.\ diff --git a/_man/src/systemd_failure_notify.1.md b/_man/src/systemd_failure_notify.1.md index 6cc4776..59e25df 100644 --- a/_man/src/systemd_failure_notify.1.md +++ b/_man/src/systemd_failure_notify.1.md @@ -7,20 +7,20 @@ systemd_failure_notify - Notifies via mail or gotify when a service has failed. It's part of **system-helpers**. # SYNOPSIS -**systemd_failure_notify** [CONFIG_FILE (absolute path)] [service name] +**systemd_failure_notify** [SERVICE] # DESCRIPTION **systemd_failure_notify** executes *mailx* or *gotify* to send out notifications. It comes with systemd services. Use the provided systemd service in the **OnFailure** directive with *OnFailure=systemd_failure_notify@%n.service*. -If no *CONFIG_FILE* is provided, **systemd_failure_notify** tries to read from *$HOME/.systemd_failure_notify.conf* and */etc/systemd_failure_notify.conf* for configuration. It will exit with a non-zero exit code if it cannot find an proper configuration file. +By default, **systemd_failure_notify** tries to read from *$HOME/.systemd_failure_notify.conf* and */etc/systemd_failure_notify.conf* for configuration. It will exit with a non-zero exit code if it cannot find a proper configuration file. The following are at least required for the script to work:\ - **SYSTEMD_FAILURE_NOTIFY_MAIL_ADDRESS=""** which requires *mail.rc* to be configured and '*mailx*' command has be available¸ -By default, **SYSTEMD_FAILURE_NOTIFY_MAIL_ENABLED** is set to **true**. Set it to **false** to use *gotify* only.¸ +By default, **SYSTEMD_FAILURE_NOTIFY_MAIL_ENABLED** is set to **true**. Set it to **false** to use *gotify* only.\ -The following are optional and integrate gotify-cli to send notifications, it defaults to false: +The following are optional and integrate gotify-cli to send notifications, it defaults to false:\ - **SYSTEMD_FAILURE_NOTIFY_GOTIFY_ENABLED="true"** uses *gotify* command which has be available and needs to be properly configured by having a cli.json file. You can copy this script to */usr/local/bin* and use create a custom **CONFIG_FILE** as user. diff --git a/usr/local/bin/check_updates b/usr/local/bin/check_updates index e96a949..7e99771 100755 --- a/usr/local/bin/check_updates +++ b/usr/local/bin/check_updates @@ -4,7 +4,7 @@ usage() { USAGE=$( cat < /dev/null || { echo "Requiring 'mailx' but it's not installed"; exit 1; } } -source_config "$1" "$HOME/.check_updates.conf" "/etc/check_updates.conf" +source_config "$HOME/.check_updates.conf" "/etc/check_updates.conf" apply_defaults check_required diff --git a/usr/local/bin/disk_space_alert b/usr/local/bin/disk_space_alert index f4e6d93..de47a89 100755 --- a/usr/local/bin/disk_space_alert +++ b/usr/local/bin/disk_space_alert @@ -3,7 +3,7 @@ # usage usage() { USAGE=$(cat < /dev/null || { echo "Requiring 'df' but it's not installed"; exit 1; } } -source_config "$1" "$HOME/.disk_space_alert.conf" "/etc/disk_space_alert.conf" -check_required - -HOSTNAME=$(hostname) +# apply defaults DISK_SPACE_ALERT_MAIL_ADDRESS=""; DISK_SPACE_ALERT_THRESHOLD=93 DISK_SPACE_ALERT_MOUNTPOINTS=("/") +source_config "$HOME/.disk_space_alert.conf" "/etc/disk_space_alert.conf" +check_required + +# do not touch below +HOSTNAME=$(hostname) + for point in "${DISK_SPACE_ALERT_MOUNTPOINTS[@]}" do CURRENT=$(df "$point" | grep "$point" | awk '{ print $5}' | sed 's/%//g') diff --git a/usr/local/bin/docker_check b/usr/local/bin/docker_check index 08032ce..edd5399 100755 --- a/usr/local/bin/docker_check +++ b/usr/local/bin/docker_check @@ -3,7 +3,7 @@ # usage usage() { USAGE=$(cat < /dev/null || { echo "Requiring 'docker' but it's not installed"; exit 1; } } -source_config "$1" "$HOME/.docker_check.conf" "/etc/docker_check.conf" +DOCKER_CHECK_LIST_FILE="$HOME/.docker_check.list" +DOCKER_CHECK_GLOBAL_LIST_FILE="/etc/docker_check.list" +DOCKER_CHECK_NOTIFY_LEVELS=("UNKNOWN" "WARNING" "CRITICAL") +DOCKER_CHECK_MAIL_ENABLED=false +DOCKER_CHECK_MAIL_ADDRESS="" +CONTAINERS=() + +source_config "$HOME/.docker_check.conf" "/etc/docker_check.conf" check_required HOSTNAME=$(hostname) diff --git a/usr/local/bin/docker_compose_update b/usr/local/bin/docker_compose_update index d9bf3df..66a0554 100755 --- a/usr/local/bin/docker_compose_update +++ b/usr/local/bin/docker_compose_update @@ -3,9 +3,9 @@ # usage usage() { USAGE=$(cat < /dev/null || { echo "Requiring 'free' but it's not installed"; exit 1; } } -source_config "$1" "$HOME/.memory_usage_alert.conf" "/etc/memory_usage_alert.conf" +MEMORY_USAGE_ALERT_MAIL_ADDRESS=""; +MEMORY_USAGE_ALERT_THRESHOLD=512; + +source_config "$HOME/.memory_usage_alert.conf" "/etc/memory_usage_alert.conf" check_required HOSTNAME=$(hostname) diff --git a/usr/local/bin/notifier b/usr/local/bin/notifier new file mode 100755 index 0000000..bbc1845 --- /dev/null +++ b/usr/local/bin/notifier @@ -0,0 +1,119 @@ +#!/usr/bin/env bash + +# usage +usage() { +USAGE=$(cat < [] + +Sends out notifications. Please see man notifier. +EOF +) + echo "$USAGE"; +} + +set -e; + +NOTIFIER_SUBJECT=$1 +if [ -z "$NOTIFIER_SUBJECT" ]; then + echo "No subject given"; + echo ""; + usage; + exit 1; +fi + +NOTIFIER_CONTENT=$2 +if [ -z "$NOTIFIER_CONTENT" ]; then + echo "No content given"; + echo ""; + usage; + exit 1; +fi + +NOTIFIER_MAIL_ENABLED="true"; +NOTIFIER_GOTIFY_ENABLED="false"; +NOTIFIER_MAIL_ADDRESS=$3; + +# check for config file +apply_config() { + local config=$1; + + if [[ ! -f "$config" ]]; then + echo "No config file specified"; + echo ""; + usage; + exit 1; + fi + + set -a; + # shellcheck disable=SC1090 + source "$config"; + set +a; +} + +check_requirements() { + local mailEnabled=$1; + local gotifyEnabled=$2; + local mailAddress=$3; + + if [[ "${mailEnabled}" == "false" && "${gotifyEnabled}" == "false" ]]; then + echo "Mail and gotify cannot be disabled simultanously"; + echo ""; + usage; + exit 1; + fi + + if [[ "${mailEnabled}" == "true" ]]; then + type mailx &> /dev/null || { echo "Requiring 'mailx' but it's not installed"; exit 1; } + + if [ -z "${mailAddress}" ]; then + echo "No mail address given"; + echo ""; + usage; + exit 1; + fi + fi + + if [[ "${gotifyEnabled}" == "true" ]]; then + type gotify &> /dev/null || { echo "Requiring 'gotify' but it's not installed"; exit 1; } + fi +} + +source_config() { + local configFallback=$1; + local configGlobalFallback=$2; + + if [[ -f "$configFallback" ]]; then + apply_config "$configFallback"; + return; + fi + + if [[ -f "$configGlobalFallback" ]]; then + apply_config "$configGlobalFallback"; + return; + fi +} +source_config "$HOME/.notifier.conf" "/etc/notifier.conf" +check_requirements "${NOTIFIER_MAIL_ENABLED}" "${NOTIFIER_GOTIFY_ENABLED}" "${NOTIFIER_MAIL_ADDRESS}" + +SUBJECT="${NOTIFIER_SUBJECT}" +MESSAGE="${NOTIFIER_CONTENT}" + +if [[ "${NOTIFIER_MAIL_ENABLED}" == "true" ]]; then + echo "$MESSAGE"|mailx -Ssendwait -s "$SUBJECT" "$NOTIFIER_MAIL_ADDRESS"; + echo "Sent notifiction via mail" +else + echo "Sending notifictions via mail is disabled" +fi + +if [[ "${NOTIFIER_GOTIFY_ENABLED}" == "true" ]]; then + + if [[ ! -f "${HOME}/.config/gotify/cli.json" && ! -f "${HOME}/gotify/cli.json" && ! -f "./cli.json" && ! -f "/etc/gotify/cli.json" ]]; then + echo "Cannot find a valid cli.json, please run 'gotify init' before using this" + exit 1; + fi + + echo "$MESSAGE"|gotify push --quiet --title "${SUBJECT}"; + echo "Sent message via gotify" +else + echo "Sending notifictions via gotify is disabled" +fi \ No newline at end of file diff --git a/usr/local/bin/smartctl_tests_long b/usr/local/bin/smartctl_tests_long index 198ff1c..0e31c2a 100755 --- a/usr/local/bin/smartctl_tests_long +++ b/usr/local/bin/smartctl_tests_long @@ -3,18 +3,9 @@ # usage usage() { USAGE=$(cat <'. +Schedules smartd long tests. Please see man smartctl_tests_long. EOF ) echo "$USAGE"; @@ -22,9 +13,6 @@ EOF set -e; -SMARTCTL_TESTS_LONG_MAIL_ADDRESS=""; -SMARTCTL_TESTS_LONG_DEVICES=(sda) - # check for config file apply_config() { local config=$1; @@ -43,14 +31,8 @@ apply_config() { } source_config() { - local config=$1; - local configFallback=$2; - local configGlobalFallback=$3; - - if [[ -f "$config" ]]; then - apply_config "$config"; - return; - fi + local configFallback=$1; + local configGlobalFallback=$2; if [[ -f "$configFallback" ]]; then apply_config "$configFallback"; @@ -69,7 +51,11 @@ check_required() { type smartctl &> /dev/null || { echo "Requiring 'smartctl' but it's not installed"; exit 1; } } -source_config "$1" "$HOME/.smartctl_tests_long.conf" "/etc/smartctl_tests_long.conf" +SMARTCTL_TESTS_LONG_MAIL_ADDRESS=""; +SMARTCTL_TESTS_LONG_DEVICES=(sda) + +source_config "$HOME/.smartctl_tests_long.conf" "/etc/smartctl_tests_long.conf" +check_required HOSTNAME=$(hostname) diff --git a/usr/local/bin/systemd_check b/usr/local/bin/systemd_check index 694c9fc..7ce9ae4 100755 --- a/usr/local/bin/systemd_check +++ b/usr/local/bin/systemd_check @@ -3,7 +3,7 @@ # usage usage() { SYSTEMD_CHECK_USAGE=$(cat < /dev/null || { echo "Requiring 'systemctl' but it's not installed"; exit 1; } } -source_config "$1" "$HOME/.systemd_check.conf" "/etc/systemd_check.conf" +SYSTEMD_CHECK_LIST_FILE="$HOME/.systemd_check.list" +SYSTEMD_CHECK_GLOBAL_LIST_FILE="/etc/systemd_check.list" +SYSTEMD_CHECK_MAIL_ENABLED=fase +SYSTEMD_CHECK_MAIL_ADDRESS="" +SYSTEMD_CHECK_SERVICES=() + +source_config "$HOME/.systemd_check.conf" "/etc/systemd_check.conf" check_required SYSTEMD_CHECK_HOSTNAME=$(hostname) diff --git a/usr/local/bin/systemd_failure_notify b/usr/local/bin/systemd_failure_notify index 5020c1d..fcd1e01 100755 --- a/usr/local/bin/systemd_failure_notify +++ b/usr/local/bin/systemd_failure_notify @@ -3,7 +3,7 @@ # usage usage() { USAGE=$(cat < +Usage: systemd_failure_notify [SERVICE] Sends out notifications for failed services. Please see man systemd_failure_notify. EOF @@ -59,14 +59,8 @@ check_requirements() { } source_config() { - local config=$1; - local configFallback=$2; - local configGlobalFallback=$3; - - if [[ -f "$config" ]]; then - apply_config "$config"; - return; - fi + local configFallback=$1; + local configGlobalFallback=$2; if [[ -f "$configFallback" ]]; then apply_config "$configFallback"; @@ -78,7 +72,7 @@ source_config() { return; fi } -source_config "$2" "$HOME/.systemd_failure_notify.conf" "/etc/systemd_failure_notify.conf" +source_config "$HOME/.systemd_failure_notify.conf" "/etc/systemd_failure_notify.conf" check_requirements "$SYSTEMD_FAILURE_NOTIFY_MAIL_ENABLED" "$SYSTEMD_FAILURE_NOTIFY_GOTIFY_ENABLED" SYSTEMD_FAILURE_NOTIFY_HOSTNAME=$(hostname) diff --git a/usr/share/man/man1/check_updates.1 b/usr/share/man/man1/check_updates.1 index e76742d..69e2e28 100644 --- a/usr/share/man/man1/check_updates.1 +++ b/usr/share/man/man1/check_updates.1 @@ -26,17 +26,17 @@ Configuration is done in environment files. It\[cq]s part of \f[B]system-helpers\f[R]. .SH SYNOPSIS .PP -\f[B]check_updates\f[R] [CONFIG_FILE (absolute path)] +\f[B]check_updates\f[R] .SH DESCRIPTION .PP \f[B]check_updates\f[R] checks for available updates using \f[I]checkupdates\f[R] and sends out a mail. It comes with systemd services. .PP -If no \f[I]CONFIG_FILE\f[R] is provided, \f[B]check_updates\f[R] tries -to read from \f[I]$HOME/.check_updates.conf\f[R] and +By default, \f[B]check_updates\f[R] tries to read from +\f[I]$HOME/.check_updates.conf\f[R] and \f[I]/etc/check_updates.conf\f[R] for configuration. -It will exit with a non-zero exit code if it cannot find an proper +It will exit with a non-zero exit code if it cannot find a proper configuration file. .PP The following are at least required for the script to work: diff --git a/usr/share/man/man1/disk_space_alert.1 b/usr/share/man/man1/disk_space_alert.1 index 174453a..7343194 100644 --- a/usr/share/man/man1/disk_space_alert.1 +++ b/usr/share/man/man1/disk_space_alert.1 @@ -27,17 +27,17 @@ Configuration is done in environment files. It\[cq]s part of \f[B]system-helpers\f[R]. .SH SYNOPSIS .PP -\f[B]disk_space_alert\f[R] [CONFIG_FILE (absolute path)] +\f[B]disk_space_alert\f[R] .SH DESCRIPTION .PP \f[B]disk_space_alert\f[R] checks available diskspace for configured \f[B]mounts\f[R] and sends out a mail if certain limits are reached. It comes with systemd services. .PP -If no \f[I]CONFIG_FILE\f[R] is provided, \f[B]disk_space_alert\f[R] -tries to read from \f[I]$HOME/.disk_space_alert.conf\f[R] and +By default, \f[B]disk_space_alert\f[R] tries to read from +\f[I]$HOME/.disk_space_alert.conf\f[R] and \f[I]/etc/disk_space_alert.conf\f[R] for configuration. -It will exit with a non-zero exit code if it cannot find an proper +It will exit with a non-zero exit code if it cannot find a proper configuration file. .PP The following are at least required for the script to work: diff --git a/usr/share/man/man1/docker_check.1 b/usr/share/man/man1/docker_check.1 index 74b2ecf..57f50c0 100644 --- a/usr/share/man/man1/docker_check.1 +++ b/usr/share/man/man1/docker_check.1 @@ -27,17 +27,17 @@ Configuration is done in environment files. It\[cq]s part of \f[B]system-helpers\f[R]. .SH SYNOPSIS .PP -\f[B]docker_check\f[R] [CONFIG_FILE (absolute path)] +\f[B]docker_check\f[R] .SH DESCRIPTION .PP \f[B]docker_check\f[R] checks a list of docker containers and notifies if their state is not up and running. It comes with systemd services. .PP -If no \f[I]CONFIG_FILE\f[R] is provided, \f[B]docker_check\f[R] tries to -read from \f[I]$HOME/.docker_check.conf\f[R] and -\f[I]/etc/docker_check.conf\f[R] for configuration. -It will exit with a non-zero exit code if it cannot find an proper +By default, \f[B]docker_check\f[R] tries to read from +\f[I]$HOME/.docker_check.conf\f[R] and \f[I]/etc/docker_check.conf\f[R] +for configuration. +It will exit with a non-zero exit code if it cannot find a proper configuration file. .PP The following are at least required for the script to work: diff --git a/usr/share/man/man1/docker_compose_update.1 b/usr/share/man/man1/docker_compose_update.1 index 82dbed9..280b080 100644 --- a/usr/share/man/man1/docker_compose_update.1 +++ b/usr/share/man/man1/docker_compose_update.1 @@ -18,8 +18,8 @@ .hy .SH NAME .PP -docker_compose_update - An utility to batch update -\f[I]docker-compose\f[R] deployments residing in sub folders. +docker_compose_update - Utility to batch update \f[I]docker-compose\f[R] +deployments residing in sub folders of a base directory. Configuration is done in environment files. .PD 0 .P @@ -27,7 +27,7 @@ Configuration is done in environment files. It\[cq]s part of \f[B]system-helpers\f[R]. .SH SYNOPSIS .PP -\f[B]docker_compose_update\f[R] [CONFIG_FILE (absolute path)] +\f[B]docker_compose_update\f[R] .SH DESCRIPTION .PP \f[B]docker_compose_update\f[R] is an utility to batch update @@ -36,10 +36,10 @@ It\[cq]s part of \f[B]system-helpers\f[R]. different sub folders, each having a \f[I]docker-compose\f[R] deployment in it. .PP -If no \f[I]CONFIG_FILE\f[R] is provided, \f[B]docker_compose_update\f[R] -tries to read from \f[I]$HOME/.docker_compose_update.conf\f[R] and +By default, \f[B]docker_compose_update\f[R] tries to read from +\f[I]$HOME/.docker_compose_update.conf\f[R] and \f[I]/etc/docker_compose_update.conf\f[R] for configuration. -It will exit with a non-zero exit code if it cannot find an proper +It will exit with a non-zero exit code if it cannot find a proper configuration file. .PP The following are at least required for the script to work: diff --git a/usr/share/man/man1/dynv6.1 b/usr/share/man/man1/dynv6.1 index a06e3c4..cc1978e 100644 --- a/usr/share/man/man1/dynv6.1 +++ b/usr/share/man/man1/dynv6.1 @@ -27,17 +27,17 @@ Configuration is done in environment files. It\[cq]s part of \f[B]system-helpers\f[R]. .SH SYNOPSIS .PP -\f[B]dynv6\f[R] [CONFIG_FILE (absolute path)] +\f[B]dynv6\f[R] .SH DESCRIPTION .PP \f[B]dynv6\f[R] updates dynv6 (an external service) and notifies about changes of IP addresses. It comes with systemd services. .PP -If no \f[I]CONFIG_FILE\f[R] is provided, \f[B]dynv6\f[R] tries to read -from \f[I]$HOME/.dynv6.conf\f[R] and \f[I]/etc/dynv6.conf\f[R] for +By default, \f[B]dynv6\f[R] tries to read from +\f[I]$HOME/.dynv6.conf\f[R] and \f[I]/etc/dynv6.conf\f[R] for configuration. -It will exit with a non-zero exit code if it cannot find an proper +It will exit with a non-zero exit code if it cannot find a proper configuration file. .PP The following are at least required for the script to work: diff --git a/usr/share/man/man1/memory_usage_alert.1 b/usr/share/man/man1/memory_usage_alert.1 index f087a41..0be51d9 100644 --- a/usr/share/man/man1/memory_usage_alert.1 +++ b/usr/share/man/man1/memory_usage_alert.1 @@ -27,17 +27,17 @@ Configuration is done in environment files. It\[cq]s part of \f[B]system-helpers\f[R]. .SH SYNOPSIS .PP -\f[B]memory_usage_alert\f[R] [CONFIG_FILE (absolute path)] +\f[B]memory_usage_alert\f[R] .SH DESCRIPTION .PP \f[B]memory_usage_alert\f[R] checks available memory and sends out a mail if certain limits are reached. It comes with systemd services. .PP -If no \f[I]CONFIG_FILE\f[R] is provided, \f[B]memory_usage_alert\f[R] -tries to read from \f[I]$HOME/.memory_usage_alert.conf\f[R] and +By default, \f[B]memory_usage_alert\f[R] tries to read from +\f[I]$HOME/.memory_usage_alert.conf\f[R] and \f[I]/etc/memory_usage_alert.conf\f[R] for configuration. -It will exit with a non-zero exit code if it cannot find an proper +It will exit with a non-zero exit code if it cannot find a proper configuration file. .PP The following are at least required for the script to work: diff --git a/usr/share/man/man1/notifier.1 b/usr/share/man/man1/notifier.1 new file mode 100644 index 0000000..7cf6e5d --- /dev/null +++ b/usr/share/man/man1/notifier.1 @@ -0,0 +1,78 @@ +.\" Automatically generated by Pandoc 2.19.2 +.\" +.\" Define V font for inline verbatim, using C font in formats +.\" that render this, and otherwise B font. +.ie "\f[CB]x\f[]"x" \{\ +. ftr V B +. ftr VI BI +. ftr VB B +. ftr VBI BI +.\} +.el \{\ +. ftr V CR +. ftr VI CI +. ftr VB CB +. ftr VBI CBI +.\} +.TH "notifier" "1" "January 2023" "notifier" "" +.hy +.SH NAME +.PP +notifier - Notifies via mail or gotify. +Configuration is done in environment files. +.PD 0 +.P +.PD +It\[cq]s part of \f[B]system-helpers\f[R]. +.SH SYNOPSIS +.PP +\f[B]notifier\f[R] TITLE MESSAGE [MAIL_ADDRESS] +.SH DESCRIPTION +.PP +\f[B]notifier\f[R] executes \f[I]mailx\f[R] or \f[I]gotify\f[R] to send +out notifications. +It is used in other \f[B]system-helpers\f[R] by default. +.PP +By default, \f[B]notifier\f[R] tries to read from +\f[I]$HOME/.notifier.conf\f[R] and \f[I]/etc/notifier.conf\f[R] for +configuration. +It will exit with a non-zero exit code if it cannot find a proper +configuration file. +.PP +The following configuration values can be set, defaults are shown as +well: +.PD 0 +.P +.PD +.IP \[bu] 2 +\f[B]NOTIFIER_MAIL_ENABLED=\[lq]true\[rq]\f[R] which enables or disables +notification via mail to \f[I]NOTIFIER_MAIL_ADDRESS\f[R]. +.IP \[bu] 2 +\f[B]NOTIFIER_MAIL_ADDRESS=\[lq]\[lq]\f[R] which requires +\f[I]mail.rc\f[R] to be configured and `\f[I]mailx\f[R]' command has be +available\[ac] +.IP \[bu] 2 +\f[B]NOTIFIER_GOTIFY_ENABLED=\[lq]false\[rq]\f[R] which `gotify' command +has be available and needs to be properly configured by having a +cli.json file +.PP +You can copy this script to \f[I]/usr/local/bin\f[R] and use create a +custom \f[B]CONFIG_FILE\f[R] as user. +.SH EXAMPLE +.PP +Create a \f[I]$HOME/.notifier.conf\f[R] and add +\f[I]NOTIFIER_MAIL_ADDRESS=\[lq]alias\[at]domain.tld\[rq]\f[R]. +Notifications will be delivered to alias\[at]domain.tld. +Examples can be found in \f[I]/usr/share/doc/notifier\f[R]. +.SH EXIT VALUES +.TP +\f[B]0\f[R] +Success +.TP +\f[B]1\f[R] +Error +.SH SEE ALSO +.PP +system-helpers +.SH AUTHORS +Alexander Sch\[:a]ferdiek. diff --git a/usr/share/man/man1/smart_tests_long.1 b/usr/share/man/man1/smart_tests_long.1 new file mode 100644 index 0000000..ed2850f --- /dev/null +++ b/usr/share/man/man1/smart_tests_long.1 @@ -0,0 +1,70 @@ +.\" Automatically generated by Pandoc 2.19.2 +.\" +.\" Define V font for inline verbatim, using C font in formats +.\" that render this, and otherwise B font. +.ie "\f[CB]x\f[]"x" \{\ +. ftr V B +. ftr VI BI +. ftr VB B +. ftr VBI BI +.\} +.el \{\ +. ftr V CR +. ftr VI CI +. ftr VB CB +. ftr VBI CBI +.\} +.TH "smart_tests_long" "1" "January 2023" "smart_tests_long" "" +.hy +.SH NAME +.PP +smart_tests_long - Schedules smartd long tests. +Configuration is done in environment files. +.PD 0 +.P +.PD +It\[cq]s part of \f[B]system-helpers\f[R]. +.SH SYNOPSIS +.PP +\f[B]smart_tests_long\f[R] +.SH DESCRIPTION +.PP +\f[B]smart_tests_long\f[R] checks for available updates using +\f[I]smartctl\f[R] and sends out a mail. +It comes with systemd services. +.PP +By default, \f[B]smart_tests_long\f[R] tries to read from +\f[I]$HOME/.smartctl_tests_long.conf\f[R] and +\f[I]/etc/smartctl_tests_long.conf\f[R] for configuration. +It will exit with a non-zero exit code if it cannot find a proper +configuration file. +.PP +The following are at least required for the script to work: +.PD 0 +.P +.PD +- \f[B]SMARTCTL_TESTS_LONG_MAIL_ADDRESS=\[lq]\[lq]\f[R] which requires +\f[I]mail.rc\f[R] to be configured and `\f[I]mailx\f[R]' command has be +available. +- \f[B]SMARTCTL_TESTS_LONG_DEVICES=(sda)\f[R] array of block devices +(not partitions!) +to check. +.PP +You can copy this script to \f[I]/usr/local/bin\f[R] and use create a +custom \f[B]CONFIG_FILE\f[R] as user. +.SH EXAMPLE +.PP +Create a \f[I]$HOME/.smartctl_tests_long.conf\f[R] and add +\f[I]SMARTCTL_TESTS_LONG_MAIL_ADDRESS=\[lq]alias\[at]domain.tld\[rq]\f[R]. +Notifications will be delivered to alias\[at]domain.tld for default +block device \f[B]sda\f[R]. +Examples can be found in \f[I]/usr/share/doc/smart_tests_long\f[R]. +.SH EXIT VALUES +.TP +\f[B]0\f[R] +Success +.TP +\f[B]1\f[R] +Error +.SH AUTHORS +Alexander Sch\[:a]ferdiek. diff --git a/usr/share/man/man1/systemd_check.1 b/usr/share/man/man1/systemd_check.1 index 05bdc5e..03cca53 100644 --- a/usr/share/man/man1/systemd_check.1 +++ b/usr/share/man/man1/systemd_check.1 @@ -27,17 +27,17 @@ Configuration is done in environment files. It\[cq]s part of \f[B]system-helpers\f[R]. .SH SYNOPSIS .PP -\f[B]systemd_check\f[R] [CONFIG_FILE (absolute path)] +\f[B]systemd_check\f[R] .SH DESCRIPTION .PP \f[B]systemd_check\f[R] checks a set of systemd services, targets, mounts of timers, and notifies if their state is not up and running. It comes with systemd services. .PP -If no \f[I]CONFIG_FILE\f[R] is provided, \f[B]systemd_check\f[R] tries -to read from \f[I]$HOME/.systemd_check.conf\f[R] and +By default, \f[B]systemd_check\f[R] tries to read from +\f[I]$HOME/.systemd_check.conf\f[R] and \f[I]/etc/systemd_check.conf\f[R] for configuration. -It will exit with a non-zero exit code if it cannot find an proper +It will exit with a non-zero exit code if it cannot find a proper configuration file. .PP The following are at least required for the script to work: diff --git a/usr/share/man/man1/systemd_failure_notify.1 b/usr/share/man/man1/systemd_failure_notify.1 index f491d57..997bcdb 100644 --- a/usr/share/man/man1/systemd_failure_notify.1 +++ b/usr/share/man/man1/systemd_failure_notify.1 @@ -27,8 +27,7 @@ Configuration is done in environment files. It\[cq]s part of \f[B]system-helpers\f[R]. .SH SYNOPSIS .PP -\f[B]systemd_failure_notify\f[R] [CONFIG_FILE (absolute path)] [service -name] +\f[B]systemd_failure_notify\f[R] [SERVICE] .SH DESCRIPTION .PP \f[B]systemd_failure_notify\f[R] executes \f[I]mailx\f[R] or @@ -37,11 +36,10 @@ It comes with systemd services. Use the provided systemd service in the \f[B]OnFailure\f[R] directive with \f[I]OnFailure=systemd_failure_notify\[at]%n.service\f[R]. .PP -If no \f[I]CONFIG_FILE\f[R] is provided, -\f[B]systemd_failure_notify\f[R] tries to read from +By default, \f[B]systemd_failure_notify\f[R] tries to read from \f[I]$HOME/.systemd_failure_notify.conf\f[R] and \f[I]/etc/systemd_failure_notify.conf\f[R] for configuration. -It will exit with a non-zero exit code if it cannot find an proper +It will exit with a non-zero exit code if it cannot find a proper configuration file. .PP The following are at least required for the script to work: @@ -54,11 +52,17 @@ command has be available\[ac] .PP By default, \f[B]SYSTEMD_FAILURE_NOTIFY_MAIL_ENABLED\f[R] is set to \f[B]true\f[R]. -Set it to \f[B]false\f[R] to use \f[I]gotify\f[R] only.\[ac] +Set it to \f[B]false\f[R] to use \f[I]gotify\f[R] only. +.PD 0 +.P +.PD .PP The following are optional and integrate gotify-cli to send -notifications, it defaults to false: - -\f[B]SYSTEMD_FAILURE_NOTIFY_GOTIFY_ENABLED=\[lq]true\[rq]\f[R] uses +notifications, it defaults to false: +.PD 0 +.P +.PD +- \f[B]SYSTEMD_FAILURE_NOTIFY_GOTIFY_ENABLED=\[lq]true\[rq]\f[R] uses \f[I]gotify\f[R] command which has be available and needs to be properly configured by having a cli.json file. .PP