import java.util.Date;
import lotus.domino.*;
import org.apache.commons.io.FileSystemUtils;
public class FreeDiskSpace extends AgentBase {
public void NotesMain() {
Notification n = null;
Database db = null;
Document log = null;
try {
Session session = getSession();
n = Notification.getInstance(session);
AgentContext agentContext = session.getAgentContext();
db = agentContext.getCurrentDatabase();
log = db.createDocument();
DateTime time = session.createDateTime("Today");
time.setNow();
String body = "";
Name sn = null;
long fs = FileSystemUtils.freeSpaceKb("/data") / 1024;
log.appendItemValue("Form", "Log");
sn = session.createName( session.getServerName() );
log.appendItemValue("ServerName", session.getServerName());
log.appendItemValue("FreeSpace", fs);
log.appendItemValue("LogDate", time);
log.save();
body += "Server name: " + session.getServerName() + "<br>";
body += "Free disk space (/data): " + fs + " Mb";
n.setRecipients(Notification.ADMINS);
n.sendMemo(body, "Free disk space: " + sn.getCommon() + " = "+fs + " Kb");
} catch (Exception e) {
try {
log.recycle();
db.recycle();
} catch (NotesException e1) {
e1.printStackTrace();
}
n.sendMemo(e);
e.printStackTrace();
} finally {
try {
log.recycle();
db.recycle();
} catch (NotesException e) {
e.printStackTrace();
}
}
}
}