PDA

View Full Version : Any ASP Proz here???


angst
19th June 2002, 20:44
Any ASP Proz here???
I need some help with a new script that I'm working,

SHOUTcast log file Analysis system.
here's a working version
http://dev.zrcweb.com/zrc/test/index_1.asp
and this one is the one that I'm working on,
http://dev.zrcweb.com/zrc/test/index.asp
trying to add some color coding to help make some sence of whats going on in the SC log files,
but having trouble with the IF then statments skipping lines for some reason.

this is the code that I need a little help with:

dim fs2, fs3
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set fs2=Server.CreateObject("Scripting.FileSystemObject")
Set fs3=Server.CreateObject("Scripting.FileSystemObject")
Set f=fs.OpenTextFile(scpath, 1)
Set f2=fs2.OpenTextFile(scpath, 1)
Set f3=fs3.OpenTextFile(scpath, 1)
Response.Write ("<br>")
Response.Write ("<table border=1 cellspacing=1 cellpadding=1><tr><td><font face=arial size=2><b>Line Number</b></td><td><font face=arial size=2><b>Date</b></td><td><font face=arial size=2><b>Time</b></td><td><font face=arial size=2><b>Action Logged</b></font></td></tr>")

dim StrCurrentLine
StrCurrentLine = f.ReadLine
do while f.AtEndOfStream = false
Response.Write("<tr><td><font face=arial size=2>Line:" & f.Line & " </font></td>")

Response.Write("<td><font face=arial size=2>" & mid(f2.ReadLine,2,8) & "</font></td>")
Response.Write("<td><font face=arial size=2>" & mid(f3.ReadLine,11,8) & "</font></td>")
If mid(f.readline,22,6) = "yp_tch" then
Response.Write("<td><font face=arial size=2 color=FF0000>" & mid(f.ReadLine,21) & "</font></td>")
elseif mid(f.readline,22,5) = "dest:" then
Response.Write("<td><font face=arial size=2 color=0000FF>" & mid(f.ReadLine,21) & "</font></td>")
elseif mid(f.readline,22,5) = "file:" then
Response.Write("<td><font face=arial size=2 color=008000>" & mid(f.ReadLine,21) & "</font></td>")
elseif mid(f.readline,25,3) = "add" then
Response.Write("<td><font face=arial size=2 color=800000>" & mid(f.ReadLine,21) & "</font></td>")
elseif mid(f.readline,22,9) = "SHOUTcast" then
Response.Write("<td><font face=arial size=2 color=800080>" & mid(f.ReadLine,21) & "</font></td>")
elseif mid(f.readline,61,3) = "401" then
Response.Write("<td><font face=arial size=2 color=000066>" & mid(f.ReadLine,21) & "</font></td>")
elseif mid(f.readline,61,3) = "403" then
Response.Write("<td><font face=arial size=2 color=000066>" & mid(f.ReadLine,21) & "</font></td>")
else
Response.Write("<td><font face=arial size=2>" & mid(f.ReadLine,21) & "</font></td>")
end if
Response.Write("</tr>")


if any one can help me with this, you can respond here,
icq me at 37664917
or msn me at angstsix@hotmail.com

thanks for your time in advance!

FesterHead
19th June 2002, 21:15
Rather than using the mid function to look for the substring (since the mid you have to specify a start and end) use the InStr function.

With InStr, you just need to specify 2 strings.


If (InStr(f.readline, "yp_tch") > 0) Then
Found
Else
Not Found
End If


See...
Mid Function (http://www.asp-help.com/getstarted/ms/vbscript/128.asp)
InStr Function (http://www.asp-help.com/getstarted/ms/vbscript/95.asp)

2surreal
19th June 2002, 21:47
I was thinking maybe you could use a Dictionary Object & loop thru rather than all those IF's:

<%Dim oDict
Set oDict=CreateObject("Scripting.Dictionary")
oDict.Add "yp_tch","FF0000"
..
.. add all the other string, color combinations here
..
%>

then to loop thru

<%
' --- loop thru the possible strings
For Each key in oDict

' --- write the color value in if that string is there
If (InStr(f.readline, key) > 0) Then
Response.Write("<td><font face=arial size=2 color=" & oDict.Item(key)& ">" & mid(f.ReadLine,21) & "</font></td>")
End If

Next
%>

This way you can add extra strings / colors to the Dictionary without adding new IF statements...

I think the above should work... more on Dictionary Objects at:
http://www.learnasp.com/learn/dictionary.asp

hope that helps

angst
20th June 2002, 15:03
ok, I've tried both methods suggested above, both of them didn't work,

runing here: http://dev.zrcweb.com/zrc/test/index_1.asp

here's the first one with the example code 1
--------------------------------------------

<%
'Server.ScriptTimeout = "240"
dim scpath

'////////Configure Path to Shoutcast Log file, this is the default: c:/Program Files/SHOUTcast/sc_serv.log
scpath = "c:/Program Files/SHOUTcast/sc_serv.log"
'////////End Config/////////////
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set f=fs.OpenTextFile(scpath, 1)

iLineCount = 0
iLineCount2 = 0
iLineCount3 = 0
iLineCount4 = 0
iLineCount5 = 0
iLineCount_Special = 0
iLineCount_Special2 = 0
iLineCount_Special3 = 0
iLineCount_Special4 = 0
iLineCount_Special5 = 0

Do Until f.AtEndOfStream
f.Skip(21)
sLine = f.ReadLine
iLineCount = iLineCount + 1
iLineCount2 = iLineCount2 + 1
iLineCount3 = iLineCount3 + 1
iLineCount4 = iLineCount4 + 1
iLineCount5 = iLineCount5 + 1

If Left(sLine, 4) = "dest" Then
iLineCount_Special = iLineCount_Special + 1
'response.write f.ReadLine & "<br>"

End If

If Left(sLine, 5) = "file:" Then
iLineCount_Special2 = iLineCount_Special2 + 1

End If

If Left(sLine, 6) = "yp_add" Then
iLineCount_Special3 = iLineCount_Special3 + 1

End If

If Left(sLine, 6) = "yp_tch" Then
iLineCount_Special4 = iLineCount_Special4 + 1

End If

If Left(sLine, 9) = "SHOUTcast" Then
iLineCount_Special5 = iLineCount_Special5 + 1

End If

Loop

Response.Write ("<br>")
Response.Write ("<font face=arial size=1>" & iLineCount & " total SC log file entries.<br /></font>")
Response.Write ("<font face=arial size=1 color=0000FF>" & iLineCount_Special & " total stream requests.<br /></font>")
Response.Write ("<font face=arial size=1 color=008000>" & iLineCount_Special2 & " total ondemand file requests.<br /></font>")
Response.Write ("<font face=arial size=1 color=800000>" & iLineCount_Special3 & " total YP Add requests.<br /></font>")
Response.Write ("<font face=arial size=1 color=FF0000>" & iLineCount_Special4 & " total YP Touch requests.<br /></font>")
Response.Write ("<font face=arial size=1 color=800080>" & iLineCount_Special5 & " total Times SHOUTcast has been restated.<br /></font>")

Set f=Nothing
Set fs=Nothing
'////////////////////////////////////////////////////////////////////////

Set fs2=Server.CreateObject("Scripting.FileSystemObject")
Set f2=fs2.OpenTextFile(scpath, 1)

iLineCount_Special6 = 0
iLineCount_Special7 = 0

Do Until f2.AtEndOfStream
f2.Skip(60)
sLine = f2.ReadLine

If Left(sLine, 3) = "403" Then
iLineCount_Special6 = iLineCount_Special6 + 1
End If

If Left(sLine, 3) = "401" Then
iLineCount_Special7 = iLineCount_Special7 + 1
End If
Loop

Response.Write ("<font face=arial size=1 color=000066>" & iLineCount_Special6 & " total Times ICY 403 Service Forbidden Errors.<br></font>")
Response.Write ("<font face=arial size=1 color=000066>" & iLineCount_Special7 & " total Times ICY 401 Service Unavailable Errors.<br></font>")
'////////////////////////////////////////////////////////////////////////
dim fs2, fs3, f4, f5, f6, f7, f8, f9, f10
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set fs2=Server.CreateObject("Scripting.FileSystemObject")
Set fs3=Server.CreateObject("Scripting.FileSystemObject")

Set f=fs.OpenTextFile(scpath,1)
Set f2=fs2.OpenTextFile(scpath,1)
Set f3=fs3.OpenTextFile(scpath,1)
Set f4=fs3.OpenTextFile(scpath)
Set f5=fs3.OpenTextFile(scpath)
Set f6=fs3.OpenTextFile(scpath)
Set f7=fs3.OpenTextFile(scpath)
Set f8=fs3.OpenTextFile(scpath)
Set f9=fs3.OpenTextFile(scpath)
Set f10=fs3.OpenTextFile(scpath)


Response.Write ("<br>")
Response.Write ("<table border=1 cellspacing=1 cellpadding=1><tr><td><font face=arial size=2><b>Line Number</b></td><td><font face=arial size=2><b>Date</b></td><td><font face=arial size=2><b>Time</b></td><td><font face=arial size=2><b>Action Logged</b></font></td></tr>")

do while f.AtEndOfStream = false
Response.Write("<tr><td><font face=arial size=2>Line:" & f.Line & " </font></td>")

Response.Write("<td><font face=arial size=2>" & mid(f2.ReadLine,2,8) & "</font></td>")
Response.Write("<td><font face=arial size=2>" & mid(f3.ReadLine,11,8) & "</font></td>")

If (InStr(f4.readline, "dest") >0) then
Response.Write("<td><font face=arial size=2 color=0000FF>" & mid(f.ReadLine,21) & "</font></td>")
elseif(InStr(f5.readline, "file: ") >0) then
Response.Write("<td><font face=arial size=2 color=008000>" & mid(f.ReadLine,21) & "</font></td>")
elseif(InStr(f6.readline, "yp_add") >0) then
Response.Write("<td><font face=arial size=2 color=800000>" & mid(f.ReadLine,21) & "</font></td>")
elseif(InStr(f7.readline, "yp_tch") >0) then
Response.Write("<td><font face=arial size=2 color=ff0000>" & mid(f.ReadLine,21) & "</font></td>")
elseif(InStr(f8.readline, "SHOUTcast") >0) then
Response.Write("<td><font face=arial size=2 color=800080>" & mid(f.ReadLine,21) & "</font></td>")
elseif(InStr(f9.readline, "Forbidden") >0) then
Response.Write("<td><font face=arial size=2 color=000066>" & mid(f.ReadLine,21) & "</font></td>")
elseif(InStr(f10.readline, "Unavailable") >0) then
Response.Write("<td><font face=arial size=2 color=000066>" & mid(f.ReadLine,21) & "</font></td>")
else
Response.Write("<td><font face=arial size=2>" & mid(f.ReadLine,21) & "</font></td>")
end if
Response.Write("</td></tr>")

loop

f.Close

Set f=Nothing
Set fs=Nothing
%>
</table>

-----------------------------------------------------


runing here: http://dev.zrcweb.com/zrc/test/index_2.asp

here's the second one with the example code 2 using oDict

----------------------------------------------------


<%
'Server.ScriptTimeout = "240"
dim scpath

'////////Configure Path to Shoutcast Log file, this is the default: c:/Program Files/SHOUTcast/sc_serv.log
scpath = "c:/Program Files/SHOUTcast/sc_serv.log"
'////////End Config/////////////
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set f=fs.OpenTextFile(scpath, 1)

iLineCount = 0
iLineCount2 = 0
iLineCount3 = 0
iLineCount4 = 0
iLineCount5 = 0
iLineCount_Special = 0
iLineCount_Special2 = 0
iLineCount_Special3 = 0
iLineCount_Special4 = 0
iLineCount_Special5 = 0

Do Until f.AtEndOfStream
f.Skip(21)
sLine = f.ReadLine
iLineCount = iLineCount + 1
iLineCount2 = iLineCount2 + 1
iLineCount3 = iLineCount3 + 1
iLineCount4 = iLineCount4 + 1
iLineCount5 = iLineCount5 + 1

If Left(sLine, 4) = "dest" Then
iLineCount_Special = iLineCount_Special + 1
'response.write f.ReadLine & "<br>"

End If

If Left(sLine, 5) = "file:" Then
iLineCount_Special2 = iLineCount_Special2 + 1

End If

If Left(sLine, 6) = "yp_add" Then
iLineCount_Special3 = iLineCount_Special3 + 1

End If

If Left(sLine, 6) = "yp_tch" Then
iLineCount_Special4 = iLineCount_Special4 + 1

End If

If Left(sLine, 9) = "SHOUTcast" Then
iLineCount_Special5 = iLineCount_Special5 + 1

End If

Loop

Response.Write ("<br>")
Response.Write ("<font face=arial size=1>" & iLineCount & " total SC log file entries.<br /></font>")
Response.Write ("<font face=arial size=1 color=0000FF>" & iLineCount_Special & " total stream requests.<br /></font>")
Response.Write ("<font face=arial size=1 color=008000>" & iLineCount_Special2 & " total ondemand file requests.<br /></font>")
Response.Write ("<font face=arial size=1 color=800000>" & iLineCount_Special3 & " total YP Add requests.<br /></font>")
Response.Write ("<font face=arial size=1 color=FF0000>" & iLineCount_Special4 & " total YP Touch requests.<br /></font>")
Response.Write ("<font face=arial size=1 color=800080>" & iLineCount_Special5 & " total Times SHOUTcast has been restated.<br /></font>")

Set f=Nothing
Set fs=Nothing
'////////////////////////////////////////////////////////////////////////

Set fs2=Server.CreateObject("Scripting.FileSystemObject")
Set f2=fs2.OpenTextFile(scpath, 1)

iLineCount_Special6 = 0
iLineCount_Special7 = 0

Do Until f2.AtEndOfStream
f2.Skip(60)
sLine = f2.ReadLine

If Left(sLine, 3) = "403" Then
iLineCount_Special6 = iLineCount_Special6 + 1
End If

If Left(sLine, 3) = "401" Then
iLineCount_Special7 = iLineCount_Special7 + 1
End If
Loop

Response.Write ("<font face=arial size=1 color=000066>" & iLineCount_Special6 & " total Times ICY 403 Service Forbidden Errors.<br></font>")
Response.Write ("<font face=arial size=1 color=000066>" & iLineCount_Special7 & " total Times ICY 401 Service Unavailable Errors.<br></font>")
'////////////////////////////////////////////////////////////////////////
dim fs2, fs3
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set fs2=Server.CreateObject("Scripting.FileSystemObject")
Set fs3=Server.CreateObject("Scripting.FileSystemObject")

Set f=fs.OpenTextFile(scpath,1)
Set f2=fs2.OpenTextFile(scpath,1)
Set f3=fs3.OpenTextFile(scpath,1)

Response.Write ("<br>")
Response.Write ("<table border=1 cellspacing=1 cellpadding=1><tr><td><font face=arial size=2><b>Line Number</b></td><td><font face=arial size=2><b>Date</b></td><td><font face=arial size=2><b>Time</b></td><td><font face=arial size=2><b>Action Logged</b></font></td></tr>")

do while f.AtEndOfStream = false
Response.Write("<tr><td><font face=arial size=2>Line:" & f.Line & " </font></td>")

Response.Write("<td><font face=arial size=2>" & mid(f2.ReadLine,2,8) & "</font></td>")
Response.Write("<td><font face=arial size=2>" & mid(f3.ReadLine,11,8) & "</font></td>")

loop

Dim oDict
Set oDict=CreateObject("Scripting.Dictionary")
oDict.Add "Dest","0000FF"
oDict.Add "file:","008000"
oDict.Add "yp_add","800000"
oDict.Add "yp_tch","FF0000"
oDict.Add "SHOUTcast","800080"

For Each Key in oDict

If(InStr(f.ReadLine, key)>0) Then
Response.Write("<td><font face=arial size=2 color=" & oDict.Item(key) & ">" & mid(f.ReadLine,21) & "</font></td>")
Else
Response.Write("<td><font face=arial size=2>" & mid(f.ReadLine,21) & "</font></td>")
End If
Response.Write("</td></tr>")


Next
f.Close

Set f=Nothing
Set fs=Nothing
%>
</table>


-----------------------------------------------------

the Dictionary one seems like a good idea, and I have read about it a bit, but can't get it working, and the first example using just InStr function, is very flacky, doesn't work with every line, and colors some of the wrong lines.

can any one maybe show me what I'm doing wrong here??
Thanks again for your time!

2surreal
20th June 2002, 16:04
... can't see it at the moment (only had a quick glance) but I would put the first bit of the dictionary (the dim & settng the values) at the top so it doesn't get set at every itteration of the loop...

Will have a closer look later if I get a mo...

angst
20th June 2002, 16:13
ok, thanks I'll try give that a try,

2surreal
20th June 2002, 18:00
doesn't seem that the dictionary iteration is within the loop where it reads each line. surely the idea is that you read a line, check it against the values in the dictionary to see if the string matches so you can colour it, then check the next line, repeat until end of file.

At the moment the last "loop" is above the dictionary bit so the only thing being checked would be the last line...

post back if that's not it - I may be following the flow incorrectly. It may help you if you indent various chunks (even temporarily) so you can see where the loops start, finish & overlap.

Hope that helps...

angst
20th June 2002, 18:16
could you maybe give me an example using my code?
I've never used this Dictionary Function before, and I'm still kinda new to ASP.

angst
20th June 2002, 18:37
ok,, I tryed what you said, and still nothing, the script isn't crashing now, but it's not doing the color coding either,,

here's the script again, and I formated it a bit more,
url: http://207.54.121.8/zrc/test/index_2.asp
----------------------------------------------------
<%
'Server.ScriptTimeout = "240"
dim scpath

'////////Configure Path to Shoutcast Log file, this is the default: c:/Program Files/SHOUTcast/sc_serv.log
scpath = "c:/Program Files/SHOUTcast/sc_serv.log"
'////////End Config///////////
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set f=fs.OpenTextFile(scpath, 1)

iLineCount = 0
iLineCount2 = 0
iLineCount3 = 0
iLineCount4 = 0
iLineCount5 = 0
iLineCount_Special = 0
iLineCount_Special2 = 0
iLineCount_Special3 = 0
iLineCount_Special4 = 0
iLineCount_Special5 = 0

Do Until f.AtEndOfStream
f.Skip(21)
sLine = f.ReadLine
iLineCount = iLineCount + 1
iLineCount2 = iLineCount2 + 1
iLineCount3 = iLineCount3 + 1
iLineCount4 = iLineCount4 + 1
iLineCount5 = iLineCount5 + 1

If Left(sLine, 4) = "dest" Then
iLineCount_Special = iLineCount_Special + 1
'response.write f.ReadLine & "<br>"

End If

If Left(sLine, 5) = "file:" Then
iLineCount_Special2 = iLineCount_Special2 + 1

End If

If Left(sLine, 6) = "yp_add" Then
iLineCount_Special3 = iLineCount_Special3 + 1

End If

If Left(sLine, 6) = "yp_tch" Then
iLineCount_Special4 = iLineCount_Special4 + 1

End If

If Left(sLine, 9) = "SHOUTcast" Then
iLineCount_Special5 = iLineCount_Special5 + 1

End If

Loop

Response.Write ("<br>")
Response.Write ("<font face=arial size=1>" & iLineCount & " total SC log file entries.<br /></font>")
Response.Write ("<font face=arial size=1 color=0000FF>" & iLineCount_Special & " total stream requests.<br /></font>")
Response.Write ("<font face=arial size=1 color=008000>" & iLineCount_Special2 & " total ondemand file requests.<br /></font>")
Response.Write ("<font face=arial size=1 color=800000>" & iLineCount_Special3 & " total YP Add requests.<br /></font>")
Response.Write ("<font face=arial size=1 color=FF0000>" & iLineCount_Special4 & " total YP Touch requests.<br /></font>")
Response.Write ("<font face=arial size=1 color=800080>" & iLineCount_Special5 & " total Times SHOUTcast has been restated.<br /></font>")

Set f=Nothing
Set fs=Nothing
'////////////////////////////////////////////////////////////////////////

Set fs2=Server.CreateObject("Scripting.FileSystemObject")
Set f2=fs2.OpenTextFile(scpath, 1)

iLineCount_Special6 = 0
iLineCount_Special7 = 0

Do Until f2.AtEndOfStream
f2.Skip(60)
sLine = f2.ReadLine

If Left(sLine, 3) = "403" Then
iLineCount_Special6 = iLineCount_Special6 + 1
End If

If Left(sLine, 3) = "401" Then
iLineCount_Special7 = iLineCount_Special7 + 1
End If
Loop

Response.Write ("<font face=arial size=1 color=000066>" & iLineCount_Special6 & " total Times ICY 403 Service Forbidden Errors.<br></font>")
Response.Write ("<font face=arial size=1 color=000066>" & iLineCount_Special7 & " total Times ICY 401 Service Unavailable Errors.<br></font>")
'////////////////////////////////////////////////////////////////////////
dim fs2, fs3
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set fs2=Server.CreateObject("Scripting.FileSystemObject")
Set fs3=Server.CreateObject("Scripting.FileSystemObject")

Set f=fs.OpenTextFile(scpath,1)
Set f2=fs2.OpenTextFile(scpath,1)
Set f3=fs3.OpenTextFile(scpath,1)
Set f4=fs3.OpenTextFile(scpath)


Dim oDict
Set oDict=CreateObject("Scripting.Dictionary")
oDict.Add "Dest","0000FF"
oDict.Add "file:","008000"
oDict.Add "yp_add","800000"
oDict.Add "yp_tch","FF0000"
oDict.Add "SHOUTcast","800080"


Response.Write ("<br>")
Response.Write ("<table border=1 cellspacing=1 cellpadding=1><tr><td><font face=arial size=2><b>Line Number</b></td><td><font face=arial size=2><b>Date</b></td><td><font face=arial size=2><b>Time</b></td><td><font face=arial size=2><b>Action Logged</b></font></td></tr>")

For Each Key in oDict
do while f.AtEndOfStream = false

Response.Write("<tr><td><font face=arial size=2>Line:" & f.Line & " </font></td>")

Response.Write("<td><font face=arial size=2>" & mid(f2.ReadLine,2,8) & "</font></td>")
Response.Write("<td><font face=arial size=2>" & mid(f3.ReadLine,11,8) & "</font></td>")



If(InStr(f4.ReadLine, key)>0) Then
Response.Write("<td><font face=arial size=2 color=" & oDict.Item(key) & ">" & mid(f.ReadLine,21) & "</font></td>")
Else
Response.Write("<td><font face=arial size=2>" & mid(f.ReadLine,21) & "</font></td>")
End If
Response.Write("</td></tr>")

loop

Next
f.Close

Set f=Nothing
Set fs=Nothing
%>
</table>

2surreal
20th June 2002, 19:48
I've replied via email as this was getting a bit long winded for a forum...