Email alert on disk space overflow for specific partition

Posted on December 30, 2019

0


ENVIRONMENT

OS = Redhat Linux 8.0

Rsyslog Server = rsyslog-8.37.0-9.el8.x86_64

Email Client = mutt-1.10.1-2.el8.x86_64

AGENDA

We need to trigger email alert in case of disk space usage cross a certain storage limit. The said exercise is done on /var disk partition for a centralized rsyslog server .

In said activity we configured mutt email client on operating system with below configurations and make a script which checks the /var partition and execute an email in case find a certain limit exceed on /var partition. The said script can be set in cron job as per the requirement.

  • Please note, The password hash can be generated (to secure the password) after sign in to the gmail ID to protect the password mentioning in script openly. Steps are mentioned below for a reference.
  • Furthermore, A free Gmail SMTP Server is utilized in this activity which required a gmail account.

MUTT EMAIL CLIENT CONFIGURATION

set from = “EMAIL-ID@gmail.com”
set realname = “PASSWORD”
set imap_user = “EMAIL-ID@gmail.com”
set imap_pass = “PASSWORD”
set folder = “imaps://imap.gmail.com:993”
set spoolfile = “imaps://imap.gmail.com/INBOX”
set postponed =”+[Gmail]/Drafts”
set header_cache =~/.mutt/cache/headers
set message_cachedir =~/.mutt/cache/bodies
set certificate_file =~/.mutt/certificates
set smtp_url = “smtps://EMAIL-ID@gmail.com@smtp.gmail.com:465/”
set smtp_pass = “PASSWORD”
set move = no
set imap_keepalive = 900

SCRIPT

#!/bin/bash
CURRENT=$(df / | grep / | awk ‘{ print $5}’ | sed ‘s/%//g’)
THRESHOLD=90

if [ “$CURRENT” -gt “$THRESHOLD” ] ; then
/usr/bin/mutt -s “Disk Space Alert” DestinationEmail@domain.com << EOF
Your /var partition of centralized rsyslogs server remaining free space is critically low. Used: $CURRENT%
EOF
fi

PASSWORD HASH FOR GMAIL PASSWORD

Sign in to Gmail account > Open manage account then locate “sign in to google” area and setup 2-Factor Authentication after this create an app password for your mail client.

 

CRON JOB

In the end make a cron job for script as per your need to run the script so you can aware the status of disk space storage. Below is a example of crontab job for triggering script after 30 minutes which(script) actually check that if space occupied more than 90% in that case the email will be triggered.

*/30 * * * * /mutt.sh

=================

In case you are configuring the Rsyslog server below are some important tips for configuring centralized Log Server with Rsyslog in CentOS8/RHEL 8

IMPORTANT LINKS

Below is the link for Setup a Centralized Log Server with Rsyslog in CentOS/RHEL8 https://www.tecmint.com/create-centralized-log-server-with-rsyslog-in-centos-8/

Following configurations of Rsyslog server where you want every client log directory should separated instead of a single log file of clients on RsysLog server under /var/log

$template RemoteLogs,"/var/log/%HOSTNAME%/%PROGRAMNAME%.log"
*.* ?RemoteLogs
& ~

EMAIL ALERT ON DISK UTILIZATION | MONITOR ALL PARTITIONS

https://zahidhaseeb.wordpress.com/2020/01/07/email-alert-on-disk-utilization-monitor-all-partitions/

ERROR

You will receive this error no authenticators available when send email. Below package installation will fix the issue.

RESOLUTION

yum install cyrus-sasl-plain -y

 

 

 

Posted in: Tech News