I needed to set up email alerts for one of the servers so when disc space dropped below a threshold it would email the team to deal with the issue. I know you can use full monitoring packages for this kind of thing (like Nagios etc) but in this case that kind of monitoring is overkill. I used the bmail.exe command line SMTP mailer from beyondlogic.org but you can use any command line mailer you want really.
First I created a simple .cmd script to send the warning email, making sure to include %1 so as to include any command line arguments produced by perfmon.exe. Apparently if you don’t have any commmand line arguments when you set up alerts the script will not be called:
c:\emailfromcmdbmail.exe -s mail.server.ip -t firstname.lastname@example.org -f email@addresstosendfrom -h -a “Disk Space Warning on server.name.com” -b “Less than 100GB free on server.name.com. Please free space to ensure weekly backups can continue. Free: %1 MB”
The direct path to the executable must be explicitly stated, otherwise it will not be called and no error/warning will be shown.
Now open perfmon.exe, expand “Performance Logs and Alerts” – “Alerts”. Right click and select “New Alert Settings…” and choose a name. The comment can be anything.
Now add a counter. I used “LogicalDisk” – “Free Megabytes” – “C:” to select free space on the C drive. Set “Alert when the value is:” to “Under” and the “Limit:” to whatever free space warning you need. I set the sample interval to 3 hours. Now select run as to be an administrator on the machine and set the password.
Click the action tab and select “Run this program:” and put in the path to your .cmd file, in my case “C:emailfromcmdemailteam.cmd”. Select “Measured value” in “Command Line Arguments…”. Now click OK, you may need to enter the password for the user with permission to run your .cmd.
Done, now your server will email you when drive space gets low.