Skip to content
Snippets Groups Projects
Commit 01aa596e authored by Filip Strömbäck's avatar Filip Strömbäck
Browse files

Added diskwatch script.

parent 4489dc6e
No related branches found
No related tags found
1 merge request!64Added diskwatch script.
Pipeline #163051 passed
#!/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
# 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,
}
}
...@@ -14,6 +14,7 @@ class aes { ...@@ -14,6 +14,7 @@ class aes {
include aes::broker include aes::broker
include aes::auth include aes::auth
include aes::auth_keydb include aes::auth_keydb
include aes::diskwatch
case fact('os.name') { case fact('os.name') {
'RedHat': { 'RedHat': {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment