#!/bin/bash
#################################################
#
#      Filename: monitor_file_system_availability.sh
#
#        Author: scott.liu@ucloud.cn
#   Description: ---
#        Create: 2019-03-07 16:59:08
# Last Modified: 2019-08-28 16:57:51(allin.han@ucloud.cn)
#################################################
filesys="$(df -P| grep '^/dev' | egrep -v "^/dev/nbd|^/dev/rbd"| awk '{print $6}'|egrep -v '^/mnt|^/tmp/mnt|^/var/lib/docker')"

temp_file="uagent_file_system_check"

for fsys in $filesys
do
    if [ -n "$fsys" ]; then
        if [[ $fsys == '/' ]]; then
            file_name=$fsys$temp_file
        else
            file_name=$fsys/$temp_file
        fi
        touch $file_name
        if [ $? -ne 0 ];then
            ret[`echo ${#ret[*]}`]={\"value\":1,\"tags\":\"mount=$fsys\"}
	else
            ret[`echo ${#ret[*]}`]={\"value\":0,\"tags\":\"mount=$fsys\"}
        fi

	rm $file_name
    fi
done

if [ ${#ret[@]} -eq 0 ];then
    exit 1
fi
flag=0
for re in ${ret[@]}
do
    if [ $flag -eq 0 ];then
         rets=$re
	 flag=1
    else
         rets=$rets,$re
    fi
done
echo "[$rets]"

exit 0
