Commit bb400f48 by Jocelyn Delalande

monit : Add smart checks to monit

parent 6bd9c9f8
monit_emails: []
monit_email_from: monit@example.com
monit_cycle_duration: 15
monit_cycle_duration: 60
monit_enabled_modules: []
\ No newline at end of file
#!/bin/sh -e
# source https://www.smarthomebeginner.com/monit-monitor-hard-drive-smart-health-and-temperature/
STATUS=`/usr/sbin/smartctl -H /dev/sda | grep overall-health | awk 'match($0,"result:"){print substr($0,RSTART+8,6)}'`
#echo $STATUS
if [ "$STATUS" = "PASSED" ]
then
# 0 implies PASSED
TP=0
else
# 1 implies FAILED
TP=1
fi
#echo $TP # for debug only
# Enable offline data collection (idempotent)
/usr/sbin/smartctl --smart=on --offlineauto=on --saveauto=on /dev/sda > /dev/null 2>&1
exit $TP
#!/bin/sh -e
# source https://www.smarthomebeginner.com/monit-monitor-hard-drive-smart-health-and-temperature/
HDDTP=`/usr/sbin/smartctl -a /dev/sda | grep Temp | awk -F " " '{printf "%d",$10}'`
#echo $HDDTP # for debug only
exit $HDDTP
- name: Install apt package
apt: pkg=monit update_cache=yes cache_valid_time=1800
- import_tasks: smart.yml
- name: Deploy monitrc configuration
template:
src: monitrc.j2
dest: /etc/monit/monitrc
notify: restart monit
- name: Create custom monit scripts dir
file:
path: /etc/monit/scripts
state: directory
- name: Deploy custom monit scripts
copy:
src: "scripts/"
dest: "/etc/monit/scripts/"
mode: 0755
- name: Enable monit modules
template:
src: "custom-modules/{{ item }}.j2"
dest: "/etc/monit/conf.d/{{ item }}"
with_items: "{{ monit_enabled_modules }}"
notify: restart monit
\ No newline at end of file
notify: restart monit
- name: Install apt package
apt: pkg=smartmontools update_cache=yes cache_valid_time=1800
# Temperature
check program HDD-Temp with path "/etc/monit/scripts/sdatemp.sh"
every 5 cycles
if status > 40 for 2 cycles then alert
group health
# SMART Overall Health
check program SSD-Health with path "/etc/monit/scripts/sdahealth.sh"
every 30 cycles
if status != 0 for 2 cycles then alert
group health
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment