很喜歡這里的學習氣氛,也很佩服兩位版主的技術水平,希望能夠在這里與大家多多交流。 作為見面禮吧,把前一陣子寫的一個生成ISA 2004 Web 流量報告的腳本與大家分享。說明下,該校本是首發而且僅發在這里,我沒有在菊花里面或任何地方發過。大家可以隨意更改腳本以便適合你的要求,轉載請保留作者信息謝謝。
我的很多客戶希望能夠每天或每周得到一份員工瀏覽Web情況的報告,例如所訪問的站點以及流量等等,他們都使用ISA2004作為web proxy。由于ISA2004自帶的report不能滿足他們的要求,所以我寫了這個腳本,用來生成報告。使用前請先閱讀readme.txt 復制代碼 代碼如下: 'ISA 2004 Web Log Query Tool 'Created by mwpq 'Version 1.0 'Date 2007.9.18
On Error Resume Next
Dim startdate, enddate Dim topweb, topuser,usertop, usertopweb
'Configuration part of the script '================================================================== startdate = 1 ' the newest log files to be queried. 1 means one day ago interday = 7 ' the oldest log files is startdate + interday ' For example startdate =1, interday =7 means script will query log files between 8 days ago and yesterday's.
topweb="Top 20" ' List Top 20 Websites visited. Just change 20 to other No to get what you want like "top 21" will list top 21 websites. topuser="Top 10" ' List Top 10 users and their total usage. Usertop = "Top 20" ' List Top 20 Users with their top websites, depend on uesrtopweb. set to "" to list all users web usage usertopweb = "Top 10" sMailTo = "mwpq@yahoo.com" 'Send email repor to sMailFrom = "admin@yourdomain.com 'Email comes from sMailSub = "ISA Web Traffic Report" 'Email Title sSMTPServer = "youremailserver" 'Email server strMessage = "Please see attachment for the ISA Web Traffic Report." 'Email txt body. satt = "C:/Program Files/Microsoft ISA Server/ISALogs/report.htm" 'Email attachment path. The report.htm will be created under ISA's log folder.
'Create the html reprot and write the html header '================================================================================================================= Const BEGIN_TABLE = " TABLE width=100% BORDER=0 CELLSPACING=1 CELLPADDING=2 " Const END_TABLE = " /TABLE " Const ForReading = 1 Const ForWriting = 2 Const ForAppending = 8 Set oFSO = CreateObject("Scripting.FileSystemObject") If oFSO.FileExists("./report.htm") Then oFSO.Deletefile("./report.htm") End If If oFSO.FileExists("./tempsum.w3c") Then oFSO.Deletefile("./tempsum.w3c") End If Set oFile = oFSO.OpenTextFile("./report.htm", ForWriting, True, true)
oFile.writeline " p class = Title ISA Web Traffic Report - From "&date-startdate-interday&" to "&date-startdate oFile.writeline " p " '================================================================================================================= 'End of create html report header part
'build the log file name list spath = ""
while interday = 0
dtmDate = date - startdate - interday
'Convert the current Date to UTC '================================================================================================================= strDay = Day(dtmDate) If Len(strDay) 2 Then strDay = "0" & strDay End If strMonth = Month(dtmDate) If Len(strMonth) 2 Then strMonth = "0" & strMonth End If strYear = Year(dtmDate)
if interday - startday 0 then spath = spath&", " end if
interday = interday - 1 wend
'Create a temp sumary file set objLogParser = CreateObject("MSUtil.LogQuery") Set objInputFormat = _ CreateObject("MSUtil.LogQuery.W3CInputFormat") SET w3cOutputFormat = WScript.CreateObject("MSUtil.LogQuery.W3COutputFormat") w3cOutputFormat.filemode = 1 ' Set file to overwrite mode strQuery = "SELECT cs-username, r-host, Sum(add(cs-bytes,sc-bytes)) as SRdata into 'tempsum.w3c' FROM "&spath&" where sc-Network = 'External' group by cs-username,r-host order by SRdata DESC" objLogParser.Executebatch strQuery, objInputFormat,w3cOutputFormat
'check tempsum.w3c existed Set oFSO1 = CreateObject("Scripting.FileSystemObject") If oFSO1.FileExists("./tempsum.w3c") Then oFSO1 = nothing else oFSO1=nothing wscript.echo "Sorry cannot find some of the log files to query! Script Quit." wscript.quit End If
set objLogParser10 = CreateObject("MSUtil.LogQuery") Set objInputFormat10 = _ CreateObject("MSUtil.LogQuery.W3CInputFormat") 'objInputFormat.recurse = 2
strQuery10 = "SELECT "&topweb&" r-host, sum(SRdata) as TSRData FROM 'tempsum.w3c' group by r-host order by TSRdata DESC" Set objRecordSet10 = objLogParser10.Execute(strQuery10, objInputFormat10) Do While Not objRecordSet10.AtEnd Set objRecord10 = objRecordSet10.GetRecord
if fl = 0 then
mWBRow mWDetail2 objRecord10.GetValue("r-host") mwDetail2 FormatNumber(objRecord10.GetValue("TSRdata")/1048576,2) mWERow fl=1 else mWBRow mWDetail1 objRecord10.GetValue("r-host") mwDetail1 FormatNumber(objRecord10.GetValue("TSRdata")/1048576,2) mWERow fl=0 end if
set objLogParser11 = CreateObject("MSUtil.LogQuery") Set objInputFormat11 = _ CreateObject("MSUtil.LogQuery.W3CInputFormat") 'objInputFormat.recurse = 2
strQuery11 = "SELECT "&topuser&" cs-username, Sum(SRdata) as TSRdata FROM 'tempsum.w3c' group by cs-username order by TSRdata DESC" Set objRecordSet11 = objLogParser11.Execute(strQuery11, objInputFormat11) Do While Not objRecordSet11.AtEnd Set objRecord11 = objRecordSet11.GetRecord
if fl=0 then mWBRow mWDetail2 objRecord11.GetValue("cs-username") mwDetail2 FormatNumber(objRecord11.GetValue("TSRdata")/1048576,2) mWERow fl =1 else mWBRow mWDetail1 objRecord11.GetValue("cs-username") mwDetail1 FormatNumber(objRecord11.GetValue("TSRdata")/1048576,2) mWERow fl =0 end if 'wscript.echo "uri"& objRecord2.GetValue("r-host") & "---" & objRecord2.GetValue("SRdata")
set objLogParser2 = CreateObject("MSUtil.LogQuery") Set objInputFormat2 = _ CreateObject("MSUtil.LogQuery.W3CInputFormat") 'objInputFormat.recurse = 2 fl=0 strQuery2 = "SELECT "&usertopweb&" r-host, SRdata FROM 'tempsum.w3c' where cs-username =" &stt&" group by r-host,SRdata" Set objRecordSet2 = objLogParser2.Execute(strQuery2, objInputFormat2) Do While Not objRecordSet2.AtEnd Set objRecord2 = objRecordSet2.GetRecord if fl=0 then mWBRow mWDetail2 objRecord2.GetValue("r-host") mwDetail2 FormatNumber(objRecord2.GetValue("SRdata")/1048576,2)
'================================================================================================================= 'End of create html method
'Send email
Dim iMsg, iConf, Flds
'// Create the CDO connections. Set iMsg = CreateObject("CDO.Message") Set iConf = CreateObject("CDO.Configuration") Set Flds = iConf.Fields
'// SMTP server configuration. With Flds .Item(cdoSendUsingMethod) = cdoSendUsingPort
'// Set the SMTP server address here. .Item(cdoSMTPServer) = sSMTPServer .Update End With
'// Set the message properties. With iMsg Set .Configuration = iConf .To = sMailTo .From = sMailFrom .Subject = sMailSub .TextBody = strMessage End With
'iMsg.HTMLBody = sMailMessage '// Send the message.
iMsg.AddAttachment satt
iMsg.Send ' send the message. Set iMsg = Nothing Set iConf = Nothing