Polish and align all scripts; add generic notifier script

This commit is contained in:
Alexander Schäferdiek 2023-01-25 23:27:38 +01:00
parent fbe2eea125
commit e47a2b0145
31 changed files with 474 additions and 185 deletions

View file

@ -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*)

View file

@ -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.

View file

@ -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.\

View file

@ -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.\

View file

@ -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.\

View file

@ -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.

View file

@ -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.\

39
_man/src/notifier.1.md Normal file
View file

@ -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

View file

@ -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

View file

@ -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.\

View file

@ -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.

View file

@ -4,7 +4,7 @@
usage() {
USAGE=$(
cat <<EOF
Usage: check_updates [CONFIG_FILE (absolute path)]
Usage: check_updates
Sends out update notifications. Please see man check_updates.
EOF
@ -32,14 +32,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"
@ -75,7 +69,7 @@ check_required() {
type mailx &> /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

View file

@ -3,7 +3,7 @@
# usage
usage() {
USAGE=$(cat <<EOF
Usage: disk_space_alert [CONFIG_FILE (absolute path)]
Usage: disk_space_alert
Checks available diskspace for configured **mounts** and sends out a mail if certain limits are reached. Please see man disk_space_alert.
EOF
@ -31,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";
@ -57,14 +51,17 @@ check_required() {
type df &> /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')

View file

@ -3,7 +3,7 @@
# usage
usage() {
USAGE=$(cat <<EOF
Usage: docker_check [CONFIG_FILE (absolute path)]
Usage: docker_check
Checks a list of docker containers and notifies if their state is not up and running. Please see man docker_check.
EOF
@ -13,13 +13,6 @@ EOF
set -e;
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=()
# check for config file
apply_config() {
local config=$1;
@ -38,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";
@ -64,7 +51,14 @@ check_required() {
type docker &> /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)

View file

@ -3,9 +3,9 @@
# usage
usage() {
USAGE=$(cat <<EOF
Usage: docker_compose_update [CONFIG_FILE (absolute path)]
Usage: docker_compose_update
An utility to batch update *docker-compose* deployments residing in sub folders. Please see man docker_compose_update.
Utility to batch update docker-compose deployments residing in sub folders of a base directory. Please see man docker_compose_update.
EOF
)
echo "$USAGE";
@ -33,14 +33,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";
@ -72,10 +66,9 @@ check_required() {
}
# check requirements
CONFIG_FILE="$1";
FALLBACK_CONFIG_FILE="${HOME}/.docker_compose_update.conf";
FALLBACK_CONFIG_GLOBAL_FILE="/etc/docker_compose_update.conf";
source_config "${CONFIG_FILE}" "${FALLBACK_CONFIG_FILE}" "${FALLBACK_CONFIG_GLOBAL_FILE}";
source_config "${FALLBACK_CONFIG_FILE}" "${FALLBACK_CONFIG_GLOBAL_FILE}";
apply_defaults;
check_required;

View file

@ -4,8 +4,9 @@ set -e;
usage() {
USAGE=$(cat <<EOF
Usage: dynv6 [CONFIG_FILE (absolute path)]
updates dynv6 (an external service) and notifies about changes of IP addresses. Please see man dynv6.
Usage: dynv6
Updates dynv6 (an external service) and notifies about changes of IP addresses. Please see man dynv6.
EOF
)
echo "$USAGE";
@ -29,14 +30,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";
@ -91,10 +86,9 @@ check_required() {
}
# check requirements
CONFIG_FILE="$1";
FALLBACK_CONFIG_FILE="${HOME}/.dynv6.conf";
FALLBACK_CONFIG_GLOBAL_FILE="/etc/dynv6.conf";
source_config "${CONFIG_FILE}" "${FALLBACK_CONFIG_FILE}" "${FALLBACK_CONFIG_GLOBAL_FILE}";
source_config "${FALLBACK_CONFIG_FILE}" "${FALLBACK_CONFIG_GLOBAL_FILE}";
apply_defaults;
check_required;

View file

@ -3,7 +3,7 @@
# usage
usage() {
USAGE=$(cat <<EOF
Usage: memory_usage_alert [CONFIG_FILE (absolute path)]
Usage: memory_usage_alert
Checks available memory and sends out notification via mail. Please see man memory_usage_alert.
EOF
@ -13,9 +13,6 @@ EOF
set -e;
MEMORY_USAGE_ALERT_MAIL_ADDRESS="";
MEMORY_USAGE_ALERT_THRESHOLD=512;
# check for config file
apply_config() {
local config=$1;
@ -34,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";
@ -60,7 +51,10 @@ check_required() {
type free &> /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)

119
usr/local/bin/notifier Executable file
View file

@ -0,0 +1,119 @@
#!/usr/bin/env bash
# usage
usage() {
USAGE=$(cat <<EOF
Usage: notifier <subject> <content> [<mail address>]
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

View file

@ -3,18 +3,9 @@
# usage
usage() {
USAGE=$(cat <<EOF
Usage: smartctl_tests_long [CONFIG_FILE (absolute path)]
Usage: smartctl_tests_long
If no CONFIG_FILE is given, HOME/.smartctl_tests_long.conf or /etc/smartctl_tests_long.conf is used. This fallback option
has to exist or the script will exit.
Configuration can be done in any file and any pre-defined variable can be overwritten.
The following are at least required for the script to work:
- SMARTCTL_TESTS_LONG_MAIL_ADDRESS="" // mail.rc has to be configured
- 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. Examples can be found in '/usr/share/doc/<scriptname>'.
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)

View file

@ -3,7 +3,7 @@
# usage
usage() {
SYSTEMD_CHECK_USAGE=$(cat <<EOF
Usage: systemd_check.sh [CONFIG_FILE (absolute path)]
Usage: systemd_check.sh
Checks a set of systemd services, targets, mounts of timers, and notifies if their state is not up and running. Please see man systemd_check.
@ -14,13 +14,6 @@ EOF
set -e;
# vars and defaults
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=()
# check for config file
apply_config() {
local config=$1;
@ -39,14 +32,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";
@ -66,7 +53,13 @@ check_required() {
type systemctl &> /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)

View file

@ -3,7 +3,7 @@
# usage
usage() {
USAGE=$(cat <<EOF
Usage: systemd_failure_notify [CONFIG_FILE (absolute path)] <service>
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)

View file

@ -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:

View file

@ -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:

View file

@ -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:

View file

@ -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:

View file

@ -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:

View file

@ -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:

View file

@ -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.

View file

@ -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.

View file

@ -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:

View file

@ -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