This JSS script will do a scheduled process trigger that emails administrators when the free space on a given drive falls below a certain percentage.
First of all, the script should check the free space of the drive by the code below:
function GetFreeDriveSpace(drive) {
var drives = System.IO.DriveInfo.GetDrives();
for (var i=0; i<drives.Length; i++) {
if (drives[i].Name.ToLower().Substring(0, 1)==drive.toLowerCase()[0])
return drives[i].TotalFreeSpace;
}
throw "Drive not found: " + drive;
}
Then using a similar script to check the total space of the drive:
function GetDriveSpace(drive) {
var drives = System.IO.DriveInfo.GetDrives();
for (var i=0; i<drives.Length; i++) {
if (drives[i].Name.ToLower().Substring(0, 1)==drive.toLowerCase()[0])
return drives[i].TotalSize;
}
throw "Drive not found: " + drive;
}
This script focuses on sending an email to administrators after checking the space of the given drive. So, the script below will help you on it:
//define the minimum percentage of free space to send email
var minPercentFreeSpace = 5;
//to get free Drive space
function GetFreeDriveSpace(drive) {
var drives = System.IO.DriveInfo.GetDrives();
for (var i=0; i<drives.Length; i++) {
if (drives[i].Name.ToLower().Substring(0, 1)==drive.toLowerCase()[0])
return drives[i].TotalFreeSpace;
}
throw "Drive not found: " + drive;
}
//to get total Drive space
function GetDriveSpace(drive) {
var drives = System.IO.DriveInfo.GetDrives();
for (var i=0; i<drives.Length; i++) {
if (drives[i].Name.ToLower().Substring(0, 1)==drive.toLowerCase()[0])
return drives[i].TotalSize;
}
throw "Drive not found: " + drive;
}
mail.smtp.server = "email server";
mail.smtp.port = "email port";
mail.smtp.userName = "my email";
mail.smtp.password = "my password";
mail.smtp.enableSSL = true;
var currentPercentFreeSpace = GetFreeDriveSpace(drive) * 100 / GetDriveSpace(drive);
if (currentPercentFreeSpace < minPercentFreeSpace)
mail.send("my email", "admin email", "Warning: low drive space on server", “Server has only “ + currentPercentFreeSpace + “% free drive space left”);
To enter this script into CompleteFTP, please follow these steps:
Add the script above into the Events panel of the CFTP Manager with a Scheduled event set for every 1 hour.
Apply the changes.
After applying the changes, every hour, it will check your drive, if your free space on a given drive falls below a certain percentage, an email should now be sent to admin in order to notify them about the space deficit.