Solved Need a script to monitor the Folder size and send an alert

Microsoft Windows server 2003 enterprise
September 20, 2012 at 09:00:27
Specs: Windows 2003 or Win2008, 8 Gig
Hi All,

Request you to help me with the script (VB or BATCH) which can monitor the folder size and it can send an alert to an email or can send a SNMP trap to other server.

Regards


See More: Need a script to monitor the Folder size and send an alert

Report •

✔ Best Answer
October 31, 2012 at 18:32:01
Ah yes, the classic "post a question and don't bother following up for a month."

With VBScript, you'll need something third party to get SNMP functionality, so I elected for email.

Const dirPath     = "someDir"
Const alertedPath = "prevRun.txt"
      alertOn     = 3 * 2 ^ 29 '1.5GB
      resetOn     = alertOn * .95 'Approx 77MB
Const emailTo     = "you@some.com"
Const emailFrom   = "me@some.com"
Const emailSbjct  = "Subject"
Const emailMsg    = "Message"
Const SMTPServer  = "smtp.some.com"
Const SMTPPort    = 25
      emailUsr    = emailFrom
Const emailPsswd  = "somePassword"
Const emailSSL    = False


Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists(alertedPath) Then
  alerted =  CBool(Trim(fso.OpenTextFile(alertedPath).ReadLine))
Else
  alerted = False
End If
dirSize = fso.GetFolder(dirPath).Size

If alerted Then 'Email previously sent
  alerted = dirSize > resetOn
ElseIf dirSize >= alertOn Then
  SendEmail
  alerted = True
End If

fso.OpenTextFile(alertedPath, 2, True).WriteLine CInt(alerted)
WScript.Quit 0

Sub SendEmail
  Const cfg = "http://schemas.microsoft.com/cdo/configuration/"
  With CreateObject("CDO.Message")
    .From                                  = emailFrom
    .To                                    = emailTo
    .Subject                               = emailSbjct
    .TextBody                              = emailMsg
    With .Configuration.Fields
      .Item(cfg & "sendusing")             = 2
      .Item(cfg & "smtpserver")            = SMTPServer
      .Item(cfg & "smtpserverport")        = SMTPPort
      .Item(cfg & "smtpconnectiontimeout") = 60
      .Item(cfg & "smtpauthenticate")      = 1
      .Item(cfg & "smtpusessl")            = emailSSL
      .Item(cfg & "sendusername")          = emailUsr
      .Item(cfg & "sendpassword")          = emailPsswd
      .Update
    End With
    .Send
  End With
End Sub

How To Ask Questions The Smart Way



#1
September 20, 2012 at 15:18:42
Your first step should be to determine how you're going to monitor and how often. It's possible to write a script that loops indefinitely, but there will be no notification and no safeguard if the script dies. I suggest running it every X minutes as a scheduled task.

Next, you need to decide on what you want to watch. Above a certain amount? Below? The amount of change? Per hour?

These are important concerns, and should probably be decided on before coding.

How To Ask Questions The Smart Way


Report •

#2
October 23, 2012 at 06:45:52
Hi Razor,

Thanks for the reply.
We need to monitor it on the real time bassis but as you suggested we can schedule it to 5 or 10 mins interval.
And we need to set it 1.5 GB (1536 MB), above that it should trigger the alert to an email or can send a SNMP trap to our monitoring application

Regards.


Report •

#3
October 27, 2012 at 17:40:33
Hi , That folder mantain the 1536mb always? can the script give the warn if just the folder size changes? or only warn if its above?

Report •

Related Solutions

#4
October 31, 2012 at 18:32:01
✔ Best Answer
Ah yes, the classic "post a question and don't bother following up for a month."

With VBScript, you'll need something third party to get SNMP functionality, so I elected for email.

Const dirPath     = "someDir"
Const alertedPath = "prevRun.txt"
      alertOn     = 3 * 2 ^ 29 '1.5GB
      resetOn     = alertOn * .95 'Approx 77MB
Const emailTo     = "you@some.com"
Const emailFrom   = "me@some.com"
Const emailSbjct  = "Subject"
Const emailMsg    = "Message"
Const SMTPServer  = "smtp.some.com"
Const SMTPPort    = 25
      emailUsr    = emailFrom
Const emailPsswd  = "somePassword"
Const emailSSL    = False


Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists(alertedPath) Then
  alerted =  CBool(Trim(fso.OpenTextFile(alertedPath).ReadLine))
Else
  alerted = False
End If
dirSize = fso.GetFolder(dirPath).Size

If alerted Then 'Email previously sent
  alerted = dirSize > resetOn
ElseIf dirSize >= alertOn Then
  SendEmail
  alerted = True
End If

fso.OpenTextFile(alertedPath, 2, True).WriteLine CInt(alerted)
WScript.Quit 0

Sub SendEmail
  Const cfg = "http://schemas.microsoft.com/cdo/configuration/"
  With CreateObject("CDO.Message")
    .From                                  = emailFrom
    .To                                    = emailTo
    .Subject                               = emailSbjct
    .TextBody                              = emailMsg
    With .Configuration.Fields
      .Item(cfg & "sendusing")             = 2
      .Item(cfg & "smtpserver")            = SMTPServer
      .Item(cfg & "smtpserverport")        = SMTPPort
      .Item(cfg & "smtpconnectiontimeout") = 60
      .Item(cfg & "smtpauthenticate")      = 1
      .Item(cfg & "smtpusessl")            = emailSSL
      .Item(cfg & "sendusername")          = emailUsr
      .Item(cfg & "sendpassword")          = emailPsswd
      .Update
    End With
    .Send
  End With
End Sub

How To Ask Questions The Smart Way


Report •

#5
November 1, 2012 at 09:02:51
Ah yes, the classic "post a question and don't bother following up for a month."

Every body do that , that sucks im leaving this forum not even a thank you, this guys give.
Im gone


Report •

#6
November 1, 2012 at 09:20:52
I don't know, given his current rate of posting we should probably wait a month before writing this thread off.

How To Ask Questions The Smart Way


Report •

Ask Question