Tuesday, October 18, 2016

vCSA (vCenter Server Appliance) - Disk space monitoring



http://www.kanap.net/2014/11/vcsa-vcenter-server-appliance-part-3-advanced-customizing/

#!/bin/bash
 
# Please provide email for alert messages
email='my-email-recipient@mycompany.com'
# Please provide percentage threshold for PostgreSQL used disk space
thresh=80
 
# check that we're using PostgreSQL database
db_type=`cat /etc/odbc.ini | grep DB_TYPE | awk -F= '{print $2}' | tr -d ' '`
if [ "$db_type" != "PostgreSQL" ]; then
   exit
fi
 
if [ -z "$email" ]; then
   if [ ! -f /etc/vmware-vpx/root.email ]; then
      exit
   fi
   email=$(head -n 1 /etc/vmware-vpx/root.email)
fi
# identify PostgreSQL mount point
mount_point=`cat /etc/vmware-vpx/embedded_db.cfg | grep EMB_DB_STORAGE | awk -F"'" '{print $2}'`
# collect disk usage for the mount point
df_out=`df $mount_point | tail -n 1 | awk '{print strtonum($5)}'`
 
if [ $df_out -gt $thresh ]; then
   cat << HEREDOC | sendmail -t
To: $email
Subject: Storage Alert for MyvCSA - disk full!
From: vCenter Server Appliance disk usage <myvCSA_noreply@mycompany.com>
 
Hello!
 
Threshold of $thresh% for $mount_point is exceeded: $df_out%.
Consider extending your disk storage for $mount_point mount. Please refer to http://kb.vmware.com/kb/2056764 how to do that.
 
Regards,
my-vCSA's-name
HEREDOC
fi