/
/
/
1#!/bin/bash
2# NAS Health Monitoring Script
3# Generated by Ansible NAS role
4
5LOG_FILE="{{ nas_log_file }}"
6TIMESTAMP=$(date '+%Y-%m-%d %H:%M:%S')
7
8log_message() {
9 echo "[$TIMESTAMP] $1" >> "$LOG_FILE"
10}
11
12# Check RAID status
13{% if nas_raid_enabled | bool %}
14check_raid() {
15 if [ -f /proc/mdstat ]; then
16 if grep -q "U_\|_U" /proc/mdstat; then
17 log_message "WARNING: RAID array degraded!"
18 cat /proc/mdstat >> "$LOG_FILE"
19 fi
20 fi
21}
22{% endif %}
23
24# Check NFS exports
25check_nfs() {
26 if ! systemctl is-active --quiet nfs-kernel-server; then
27 log_message "ERROR: NFS server is not running!"
28 fi
29
30 if ! exportfs -v >/dev/null 2>&1; then
31 log_message "ERROR: NFS exports are not available!"
32 fi
33}
34
35# Check disk space
36check_disk_space() {
37 df -h | awk '$5 > 85 {print $0}' | while read line; do
38 log_message "WARNING: High disk usage: $line"
39 done
40}
41
42# Check network interfaces
43{% if nas_network_bonding_enabled | bool %}
44check_bonding() {
45{% for bond in nas_bond_interfaces %}
46 if [ -f /proc/net/bonding/{{ bond.bond_name }} ]; then
47 if grep -q "MII Status: down" /proc/net/bonding/{{ bond.bond_name }}; then
48 log_message "WARNING: Bond {{ bond.bond_name }} has interfaces down!"
49 fi
50 fi
51{% endfor %}
52}
53{% endif %}
54
55# Main execution
56log_message "Starting NAS health check"
57
58{% if nas_raid_enabled | bool %}
59check_raid
60{% endif %}
61
62check_nfs
63check_disk_space
64
65{% if nas_network_bonding_enabled | bool %}
66check_bonding
67{% endif %}
68
69log_message "NAS health check completed"