diff --git a/files/check_disk_usage.sh b/files/check_disk_usage.sh new file mode 100644 index 0000000000000000000000000000000000000000..fef1d74b8433f16b378687750d443bc876df486d --- /dev/null +++ b/files/check_disk_usage.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +WARNINGS=$(df -l --output=source,fstype,pcent,target | tail --lines=+2 | while read source fstype usage mountpoint +do + # Only filesystems that originate from some kind of device + if [[ "$source" != /* ]] + then + continue + fi + + # Remove trailing percentage sign. + usage=${usage%%%} + + # Warn if usage is above 90% + if [[ ${usage} -gt 89 ]] + then + echo "${source} (mounted on ${mountpoint}) is ${usage}% full" + fi +done) + +if [[ "$WARNINGS" != "" ]] +then + echo "WARNINGS" + + ( + echo -n "From: noreply@" + cat /etc/hostname + for r in $WARNING_RECIPIENTS + do + echo "To: ${r}" + done + echo "Subject: Disk usage warning" + echo + echo "The following disks are almost full:" + echo "$WARNINGS" + ) | sendmail -t +fi diff --git a/manifests/diskwatch.pp b/manifests/diskwatch.pp new file mode 100644 index 0000000000000000000000000000000000000000..998d8b3c14990f89a4ee6a40cc77e18ed1ee4865 --- /dev/null +++ b/manifests/diskwatch.pp @@ -0,0 +1,49 @@ +# Watch for low disk space +class aes::diskwatch { + # Who should receive warnings? (space separated) + $recipients = 'filip.stromback@liu.se klas.arvidsson@liu.se' + + # Directory for the scripts. + file { '/opt/upp' : + ensure => directory, + owner => root, + group => root, + mode => '0755', + } + + # The script itself. + file { '/opt/upp/check_disk_usage.sh' : + ensure => file, + owner => root, + group => root, + mode => '0744', + source => "puppet:///modules/${module_name}/check_disk_usage.sh", + } + + # We need a service. + systemd::manage_unit { 'diskwatch.service' : + unit_entry => { + 'Description' => 'Watch for high disk usage', + }, + service_entry => { + 'Type' => 'oneshot', + 'ExecStart' => '/opt/upp/check_disk_usage.sh', + 'Environment' => "\"WARNING_RECIPIENTS=${recipients}\"", + }, + } + + # And a timer. + systemd::manage_unit { 'diskwatch.timer' : + unit_entry => { + 'Description' => 'Check disk usage daily', + }, + timer_entry => { + 'OnCalendar' => '*-*-* 07:00:00', + }, + install_entry => { + 'WantedBy' => 'timers.target', + }, + enable => true, + active => true, + } +} diff --git a/manifests/init.pp b/manifests/init.pp index f09f644a2fbf3b575bede5e694b7157f48799b9f..f63711ec327a32ac810a834649218f11d4749469 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -14,6 +14,7 @@ class aes { include aes::broker include aes::auth include aes::auth_keydb + include aes::diskwatch case fact('os.name') { 'RedHat': {