Categories
Sponsors
Archive
Blogroll
Badges
Community
|
Sunucu üzerinde kalan disk alanlarını kontrol ettirelim
Posted in Windows Server | No Comment | 2,131 views | 10/04/2009 18:06
Aşağıdaki komutları, vbs dosyası olarak kaydedip, cronjob olarak sunucuya eklerseniz, belirli aralıklarla disklerde kalan boş alanları kontrol edip, belli bir oranın altına indiğinde size mail atarak bilgilendirme yollar.
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
| '##############################################
'#
'# Sunucu icersindeki disk alanlarini kontrol eder,
'# Diskte kalan alan %10 altindaysa mail yollar.
'#
'##############################################
Const LOCAL_HARD_DISK = 3 ' 3 is all local drives.
Const FOR_READING = 1
Const CONVERSION = 1073741824 ' This is total bytes in 1 GB.
strLocal = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\127.0.0.1\root\cimv2")
Set colDisks = objWMIService.ExecQuery _
("SELECT * FROM Win32_LogicalDisk WHERE DriveType = " & LOCAL_HARD_DISK & "")
For Each objDisk In colDisks
intPercentage = objDisk.FreeSpace / objDisk.Size
intTotalSpace = Int(objDisk.Size) / CONVERSION
intFreeSpace = Int(objDisk.FreeSpace) / CONVERSION
intDivideBy = 70 ' Percent to divide total drive space by.
If IntPercentage*100 < intDivideBy Then
strBody = "Rapor Tarihi: " & Now & vbCrLf _
& vbCrLf & "Win01'de disk alani dolmaya basladi." & vbCrLf & "Disk bilgileri asagidadir: " & vbCrLf _
& vbCrLf & "Yerel Disk: " & objDisk.DeviceID & vbCrLf _
& "Toplam Alan: " & FormatNumber(intTotalSpace, 2, False, False, True) & " GB" & vbCrLf _
& "Bos Alan: " & FormatNumber(intFreeSpace, 2, False, False, True) & " GB" & vbCrLf _
& vbCrLf & "Saygilarimizla," & vbCrLf _
& "Radore NOC"
call MAILER(strBody, strBody)
End If
Next
'#####################
'# Mail Gondermece #
'#####################
Sub MAILER(Computer, Body)
Set objEmail = CreateObject("CDO.Message")
objEmail.From = "hddstatus@domain.com"
objEmail.To = "admin@domain.com"
objEmail.Subject = "Win02 Disk Uyarisi"
objEmail.TextBody = Body
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mailserver.domain.com"
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
objEmail.Send
End sub |
'##############################################
'#
'# Sunucu icersindeki disk alanlarini kontrol eder,
'# Diskte kalan alan %10 altindaysa mail yollar.
'#
'##############################################
Const LOCAL_HARD_DISK = 3 ' 3 is all local drives.
Const FOR_READING = 1
Const CONVERSION = 1073741824 ' This is total bytes in 1 GB.
strLocal = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\127.0.0.1\root\cimv2")
Set colDisks = objWMIService.ExecQuery _
("SELECT * FROM Win32_LogicalDisk WHERE DriveType = " & LOCAL_HARD_DISK & "")
For Each objDisk In colDisks
intPercentage = objDisk.FreeSpace / objDisk.Size
intTotalSpace = Int(objDisk.Size) / CONVERSION
intFreeSpace = Int(objDisk.FreeSpace) / CONVERSION
intDivideBy = 70 ' Percent to divide total drive space by.
If IntPercentage*100 < intDivideBy Then
strBody = "Rapor Tarihi: " & Now & vbCrLf _
& vbCrLf & "Win01'de disk alani dolmaya basladi." & vbCrLf & "Disk bilgileri asagidadir: " & vbCrLf _
& vbCrLf & "Yerel Disk: " & objDisk.DeviceID & vbCrLf _
& "Toplam Alan: " & FormatNumber(intTotalSpace, 2, False, False, True) & " GB" & vbCrLf _
& "Bos Alan: " & FormatNumber(intFreeSpace, 2, False, False, True) & " GB" & vbCrLf _
& vbCrLf & "Saygilarimizla," & vbCrLf _
& "Radore NOC"
call MAILER(strBody, strBody)
End If
Next
'#####################
'# Mail Gondermece #
'#####################
Sub MAILER(Computer, Body)
Set objEmail = CreateObject("CDO.Message")
objEmail.From = "hddstatus@domain.com"
objEmail.To = "admin@domain.com"
objEmail.Subject = "Win02 Disk Uyarisi"
objEmail.TextBody = Body
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mailserver.domain.com"
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
objEmail.Send
End sub
Yukardaki kodlar “esnmb” tarafından yayınlanmış olup, aşağıdaki adresten kodlara ulaşabilirsiniz.
Leave a Reply
|