2010年7月31日 星期六

monitor your server on cacti through customized script


1: write your own script
return single value: ie: 5.2
return multiple value: ie: arg1:5.0 arg2:5.1
2: cacti -> console -> data input methods
3: cacti -> console -> data templates
4: cacti -> console -> graph templates
5: cacti -> data sources.
last update:|date_time|
<hostname> <ip>

2010年7月20日 星期二

outlook PST file size check

避免user PST過大,提出警告外,並且偵測outlook啟用狀態,強制進行關閉

Const HKEY_CLASS_ROOT = &H80000000
Const OutlookAPPath = "Outlook.Application\CurVer"
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
oReg.GetStringValue HKEY_CLASS_ROOT ,OutlookAPPath ,"",OutlookApplication
If OutlookApplication="" Then
Wscript.Quit
End If

Set objOutlook = CreateObject(OutlookApplication)
Set objNS = objOutlook.GetNamespace("MAPI")
Set defaultFolder = objNS.GetDefaultFolder(5)
DefaultPST = GetPSTPath(defaultFolder.StoreID)

Set objfs = CreateObject("Scripting.FileSystemObject")
For Each objFolder In objNS.Folders
PSTFILE = GetPSTPath(objFolder.StoreID)
If not Trim(PSTFILE) = "" Then
Set objMail = objfs.GetFile(GetPSTPath(objFolder.StoreID))
Set objMail = objfs.GetFile(PSTFILE)
Wscript.Echo objFolder.Name & " " & PSTFILE & " = " & FormatSize(objMail.Size)
Set objMail = Nothing
End If
Next

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colShare = objWMIService.ExecNotificationQuery("Select * From __InstanceCreationEvent Within 60 Where TargetInstance ISA 'Win32_Process' And TargetInstance.Name='cmd.exe'")

Do While True
Set objShare = colShare.NextEvent
Wscript.echo objShare.TargetInstance.Name
objShare.TargetInstance.Terminate
Wscript.Sleep 60
Loop

Function GetPSTPath(input)

For i = 1 To Len(input) Step 2
strSubString = Mid(input,i,2)
If Not strSubString = "00" Then
strPath = strPath & ChrW("&H" & strSubString)
End If
Next

Select Case True
Case InStr(strPath,":\") > 0
GetPSTPath = Mid(strPath,InStr(strPath,":\")-1)
Case InStr(strPath,"\\") > 0
GetPSTPath = Mid(strPath,InStr(strPath,"\\"))
End Select
End Function

Function FormatSize(Size)
Unit = "KB"
If Size/1024 < 1024 Then
Size = Size/1024
Unit = " KB"
Elseif Size/1024/1024 < 1024 Then
Size = Size/1024/1024
Unit = " MB"
Elseif Size/1024/1024/1024 < 1024 Then
Size = Size/1024/1024/1024
Unit = " GB"
End If
If InStr(Size,".") > 0 Then
Size = Left(Size,Instr(Size,".")+2)
End If
FormatSize = Left(Size,20) & Unit
End Function