本次外稽又提到要注意server的HD狀況
如果低於某個臨界值要有告警
寫個批次檔來做 並把資料丟到 log server
要注意的是批次檔的計算有32位元的問題
所以先把後6位砍掉再計算
@echo off
del %tmp%\disk_usage.txt
setlocal enabledelayedexpansion
for /f "tokens=1,2,3" %%A in ('wmic logicaldisk get caption^, size^, freespace ^| findstr /R "^[A-Z]"') do (
set "drive=%%A"
set "totalSize_ori=%%C"
set "freeSpace_ori=%%B"
if defined drive (
rem Remove trailing spaces and convert to numbers
set /a totalSize=!totalSize_ori:~0,-6!
set /a freeSpace=!freeSpace_ori:~0,-6!
rem Check if totalSize is not zero to avoid division by zero
if !totalSize! gtr 0 (
set /a freePercent=freeSpace*100/totalSize
rem echo %COMPUTERNAME% >> %tmp%\disk_usage.txt
echo disk: !drive! >> %tmp%\disk_usage.txt
echo size: !totalSize! MB >> %tmp%\disk_usage.txt
echo %COMPUTERNAME% free_space: !freeSpace! MB >> %tmp%\disk_usage.txt
echo remaining_capacity: !freePercent!%% >> %tmp%\disk_usage.txt
echo -------------------------------- >> %tmp%\disk_usage.txt
)
)
)
endlocal
type %tmp%\disk_usage.txt | nc -w 2 -u 10.0.0.1 514