Lotus Domino script snippet: Drive free space notification
Send email notification when the available free space of a specified drive falls below a certain percentage
Create profile document with following fields:
cfg_Drive (Text, Drive letter)
cfg_FreePerc (Number, Percentage)
cfg_MailFrom (Text, Email Sender)
cfg_Recipients (Names, Send email to)
cfg_MailSubject (Text Mail subject)
Add following code to an agent:
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 |
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 Set doc = dbCur.Getprofiledocument("Profile") If Not doc Is Nothing Then Set fso = CreateObject("Scripting.FileSystemObject") 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 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)) 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 Exit Sub ErrorHandler: Print "Error (your error code here)" Exit sub End Sub |