Lotus Domino script snippet check Free Disk Space Agent
Script to determine the free disk space on a Domino server.
Use a profile document that specifies:
Drive letter – cfg_Drive
% free disk space before sending email – cfg_FreePerc
Email Sender – cfg_MailFrom
Email SendTo – cfg_Recipients
Email Subject – cfg_MailSubject
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
Option Public Sub Initialize Dim sn As New NotesSession Dim dbCur As NotesDatabase Dim doc As NotesDocument Dim fso As Variant Dim drv As Variant Dim iPercFree As Integer On Error GoTo ErrorHandler Set dbCur = sn.Currentdatabase Call Logging (dbCur, "# Agent CheckFreeDiskSpace started") Set doc = dbCur.Getprofiledocument("Profile") If Not doc Is Nothing Then Set fso = CreateObject("Scripting.FileSystemObject") 'defined in scrrun.dll, which is located in C:\WINDOWS\system32 Set drv = fso.GetDrive(doc.cfg_Drive(0)) lngTot = drv.TotalSize lngAvailable = drv.AvailableSpace iPercFree = Round((lngAvailable / lngTot * 100), 1) If iPercFree < CInt(doc.cfg_FreePerc(0)) Then 'Create and send a message Dim docMemo As New NotesDocument(dbCur) With docMemo Call .ReplaceItemValue("Form","Memo") Call docMemo.ReplaceItemValue("From",doc.cfg_MailFrom(0)) Call .Replaceitemvalue("SendTo", doc.cfg_Recipients) Call .Replaceitemvalue("Subject", doc.cfg_MailSubject(0)) %REM Call .Replaceitemvalue("Body", doc.cfg_MailSubject(0) + Chr(13) _ + "Total space: " + CStr(lngTot / 1024 / 1024) + " MB" + Chr(13) _ + "Free space: " + CStr(lngAvailable / 1024 / 1024) + " MB" + Chr(13) _ + "Percentage free: " + CStr(iPercFree)) %END REM Dim bodyField As New NotesRichTextItem(docMemo, "Body") With bodyField Call .APPENDTEXT(doc.cfg_MailSubject(0)) Call .ADDNEWLINE(2) Call .APPENDTEXT("Total space: " + CStr(Round(lngTot / 1024 / 1024 / 1024, 2)) + " GB") Call .ADDNEWLINE(1) Call .APPENDTEXT("Free space: " + CStr(Round(lngAvailable / 1024 / 1024 / 1024, 2)) + " GB") Call .ADDNEWLINE(1) Call .APPENDTEXT("Current space available: " + CStr(iPercFree)+ " %") Call .ADDNEWLINE(2) End With End With Call docMemo.Send(False) End If End If Call Logging (dbCur, "# Agent CheckFreeDiskSpace finished") Exit Sub ErrorHandler: Call Logging(dbCur, "Error in CheckFreeDiskSpace") Exit Sub End Sub Sub Logging(dbCur As NotesDatabase, strErrDB As String) Dim docLog As NotesDocument Set docLog = dbCur.CreateDocument docLog.Form = "AgtLog" If Left(strErrDB, 1) <> "#" Then strErrDB = strErrDB & " at line " & Erl() & ": code = " & Err() & ", message= " & Error() End If Print strErrDB docLog.ErrorLog = strErrDB Call docLog.Save(True, False) End Sub |