#68865 - 2002-08-06 06:49 PM
Help with enhancements to Bryces wanreport script
|
ANOA
Fresh Scripter
Registered: 2002-06-12
Posts: 19
Loc: UK
|
I came across this excellent piece of code that was posted by Bryce. I would like to do the following but I am having little success:
1. On the first run store the responses to an ini file. 2. After 5 minutes read and display the historic data stored in (1) above. 3. Overwrite (1) above with the current responses. 4. Repeat.
The trouble I am having is in the timing logic. Any help here would be greatly appreciated.
code:
break on cls ;-------------------------------------------------------------------------------------------------------- ;WanReport.kix ; ; This script will ping a list of ip#'s displaying the status of each connection. ; ; Create a comma delimited file in the following format. ; <Common name>,<ipadress> ; <Common name>,<ipadress> ; <Common name>,<ipadress> ; ... ; ; Example: (the numbers have been changed to protect the innocent, please use FULL IP#'s) ; Arlington Super Store,10.9.x.x ; Arrowhead Crossing,10.9.x.x ; Auburn Hills,10.9.191.x.x ; Baybrook Super Store,10.9.x.x ;-------------------------------------------------------------------------------------------------------- $file = "wanrouters.csv" ;CSV database of ip#'s to scan $sleep_Min = 1 ;Number of minutes between scans $timeOut = "3000" ;The max ping timeout $fast = 95 ;Ping time is MS, used for color codes $slow = 350 ;Ping time is MS, used for color codes
$temp = "%temp%\temp.dat" ;-------------------------------------------------------------------------------------------------------- $sleep_min = $sleep_Min*60
:top $line = 1 $col2 = 10 $col3 = 45
If exist($file) = 1 copy "$file" "%temp%\wanrouters.csv" else ? "Could not find $file. Script ending" exit endif
$nul = open(1,"%temp%\$file",2) $data = readline(1)
at($line,0) 'Press ' color y+/n '"CTRL-C"' color w/n ' to Exit, AUTO repeat set to $sleep_Min seconds' $line = $line + 1
do $Store = substr("$data",1,instr("$data",",")-1) $Store_Router = substr("$data",instr("$data",",")+1,len("$data")) Shell'%comspec% /c ping -n 1 -w $timeout $Store_Router | find "Reply" > "$temp"' $q = open(2,"$temp",2) $reply = readline(2) $q = close(2) if $reply <> "" $reply_time = substr("$reply",instr("$reply","time")+4,instr("$reply","TTL=")-instr("$reply","time")-5) at($line+1,0)" " at($line,0)color g/n "OK" color w/n select case val(substr("$reply_time",2,instr("$reply_time","ms"))) <= $fast color g+/n case val(substr("$reply_time",2,instr("$reply_time","ms"))) <= $slow color y+/n case val(substr("$reply_time",2,instr("$reply_time","ms"))) > $slow color r+/n endselect select case substr("$reply_Time",1,1) = "=" " " substr("$reply_Time",2,len("$reply_Time")-1) color w/n case substr("$reply_Time",1,1) = "<" " $reply_Time" color w/n endselect at($line,$col2)"$store" At($line,$col3)"$Store_Router" $line = $line + 1 else at($line+1,0)" " at($line,0)color r+/n "TIMEOUT!" color w/n at($line,$col2)"$store" at($line,$col3)"$Store_Router" $line = $line + 1 endif $data = readline(1) until @error <> 0 $nul = close(1) del "$temp" ? "Sleeping for " $sleep_min "sec" Sleep $sleep_Min goto top exit
|
|
Top
|
|
|
|
#68867 - 2002-08-06 07:24 PM
Re: Help with enhancements to Bryces wanreport script
|
ANOA
Fresh Scripter
Registered: 2002-06-12
Posts: 19
Loc: UK
|
I am not having a problem with the sleep logic. My problem is with a timing logic to write the results to a file on first run and then read those results in five minutes later to display an extra column as historic data !
|
|
Top
|
|
|
|
#68869 - 2002-08-06 07:40 PM
Re: Help with enhancements to Bryces wanreport script
|
ANOA
Fresh Scripter
Registered: 2002-06-12
Posts: 19
Loc: UK
|
This a misunderstanding somewhere. Here's what I originally posted:
quote:
1. On the first run store the responses to an ini file. 2. After 5 minutes read and display the historic data stored in (1) above. 3. Overwrite (1) above with the current responses. 4. Repeat.
|
|
Top
|
|
|
|
#68871 - 2002-08-06 08:01 PM
Re: Help with enhancements to Bryces wanreport script
|
ANOA
Fresh Scripter
Registered: 2002-06-12
Posts: 19
Loc: UK
|
Yes I want a history report based on different timing parameters from the sleep period. I still want responses every say 60 seconds but it would be great if I had a 5 minutes ago column, 10 minutes ago column etc.
I have tried the following but I am missing something.
code:
break on cls ;-------------------------------------------------------------------------------------------------------- ;WanReport.kix ; ; This script will ping a list of ip#'s displaying the status of each connection. ; ; Create a comma delimited file in the following format. ; <Common name>,<ipadress> ; <Common name>,<ipadress> ; <Common name>,<ipadress> ; ... ; ; Example: (the numbers have been changed to protect the innocent, please use FULL IP#'s) ; Arlington Super Store,10.9.x.x ; Arrowhead Crossing,10.9.x.x ; Auburn Hills,10.9.191.x.x ; Baybrook Super Store,10.9.x.x ;-------------------------------------------------------------------------------------------------------- $file = "wanrouters.csv" ;CSV database of ip#'s to scan $sleep_Min = 5 ;Number of seconds between scans $timeOut = "3000" ;The max ping timeout $fast = 95 ;Ping time is MS, used for color codes $slow = 350 ;Ping time is MS, used for color codes $lasttime1 = 10 ;Historic data for time $lasttime2 = 20 ;Historic data for time
$temp = "%temp%\temp.dat" ;-------------------------------------------------------------------------------------------------------- $sleep_min = $sleep_Min $oldtime=0
:top CLS $line = 1 $col2 = 10 $col3 = 25 $col4 = 40 $col5 = 55
$laststore="15ms"
If exist($file) = 1 copy "$file" "%temp%\wanrouters.csv" else ? "Could not find $file. Script ending" exit endif
$nul = open(1,"%temp%\$file",2) $data = readline(1)
at($line,0) 'Press ' color y+/n '"CTRL-C"' color w/n ' to Exit, AUTO repeat set to $sleep_Min seconds' $line = $line + 1
do $Store = substr("$data",1,instr("$data",",")-1) $Store_Router = substr("$data",instr("$data",",")+1,len("$data")) Shell'%comspec% /c ping -n 1 -w $timeout $Store_Router | find "Reply" > "$temp"' $q = open(2,"$temp",2) $reply = readline(2) $q = close(2) if $reply <> "" $reply_time = substr("$reply",instr("$reply","time")+4,instr("$reply","TTL=")-instr("$reply","time")-5) at($line+1,0)" " at($line,0)color g/n "OK" color w/n select case val(substr("$reply_time",2,instr("$reply_time","ms"))) <= $fast color g+/n case val(substr("$reply_time",2,instr("$reply_time","ms"))) <= $slow color y+/n case val(substr("$reply_time",2,instr("$reply_time","ms"))) > $slow color r+/n endselect select case substr("$reply_Time",1,1) = "=" " " substr("$reply_Time",2,len("$reply_Time")-1) color w/n case substr("$reply_Time",1,1) = "<" " $reply_Time" color w/n endselect if ($stayon1=1) $laststore=ReadProfileString ("D:\laptop\cwie5\kix402\last15min.ini", "15_minutes_ago", "$Store") at($line,$col4)color g+/n "$laststore" color w/n endif if ($stayon2=1) $laststore2=ReadProfileString ("D:\laptop\cwie5\kix402\last30min.ini", "30_minutes_ago", "$Store") at($line,$col5)color g+/n "$laststore2" color w/n endif if (($oldtime=0) or ($oldtime=$lasttime1)) $writeit=WriteProfileString ("D:\laptop\cwie5\kix402\last15min.ini", "15_minutes_ago", "$Store", "$reply_time") endif if ($oldtime=$lasttime2) $writeit=WriteProfileString ("D:\laptop\cwie5\kix402\last30min.ini", "30_minutes_ago", "$Store", "$reply_time") endif at($line,$col2)"$store" At($line,$col3)"$Store_Router" $line = $line + 1 else at($line+1,0)" " if (($oldtime=0) or ($oldtime=$lasttime1)) $writeit=WriteProfileString ("D:\laptop\cwie5\kix402\last15min.ini", "15_minutes_ago", "$Store", "TIMEOUT!") endif if ($oldtime=$lasttime2) $writeit=WriteProfileString ("D:\laptop\cwie5\kix402\last30min.ini", "30_minutes_ago", "$Store", "TIMEOUT!") endif at($line,0)color r+/n "TIMEOUT!" color w/n at($line,$col2)"$store" at($line,$col3)"$Store_Router" $line = $line + 1 endif if ($oldtime=$lasttime1) $stayon1=1 endif if ($oldtime=$lasttime2) $stayon2=1 endif
$data = readline(1) until @error <> 0 $nul = close(1) del "$temp" color w/n ? "Sleeping for " $sleep_min " sec" Sleep $sleep_Min $oldtime=$oldtime+$sleep_Min
?$oldtime get $x goto top exit
|
|
Top
|
|
|
|
#68874 - 2002-08-07 08:45 PM
Re: Help with enhancements to Bryces wanreport script
|
ANOA
Fresh Scripter
Registered: 2002-06-12
Posts: 19
Loc: UK
|
That would be great to do .... but I am still very much in the learning stage with all this great stuff....
Thanks to you all for the great advice ... I'll post what I come up with when I figure it out (Store history of pings and display extra columns with historic data).
|
|
Top
|
|
|
|
#68876 - 2002-08-07 09:04 PM
Re: Help with enhancements to Bryces wanreport script
|
ANOA
Fresh Scripter
Registered: 2002-06-12
Posts: 19
Loc: UK
|
Please show me the way Lonkero
|
|
Top
|
|
|
|
#68880 - 2002-08-08 08:25 PM
Re: Help with enhancements to Bryces wanreport script
|
Bryce
KiX Supporter
   
Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
|
I agree with Jens, it would be easier to write whole new code then try and rework my old script.... (i would have done it already... but I got to busy..... well here are some udf's I wrote.)
The ping(,{ping flags}) UDF will return what you see when you do a
shell 'ping kixtart.org -n 1 | find "TTL"' from a commandline
quote:
C:\wanreport>ping www.kixtart.org -n 1 | find "TTL" Reply from 81.17.37.55: bytes=32 time=218ms TTL=115
$reply = ping("www.kixtart.org")
code:
function Ping($ipaddress, optional $flag) dim $tempfile, $tempdata, $nul $tempfile = "" + @ticks + ".dat"
shell '%comspec% /c ping $ipaddress -n 1 $flag | find "TTL" > $tempfile' $exit=@error if not @error $nul = open(1,$tempfile) $tempdata = readline(1) $nul = close(1) del $tempfile else $tempdata = "Timeout" endif $ping = $tempdata exit($exit) endfunction
the Function Loadfile() will load the contents of the given file into an array
$array = loadfile("computers.csv") for each $thing in $array ? $thing next
code:
function loadfile($file) dim $nul,$count, $line dim $temparray[10]
if exist($file) $nul = open(1,$file) else exit(1) endif
while not @error if $count > ubound($temparray) redim preserve $temparray[ubound($temparray)+10] endif $line = readline(1) if $line <> "" $temparray[$count] = $line $count = $count + 1 endif loop
if $count > 0 redim preserve $temparray[$count-1] else redim perserve $temparray[$count] endif
$nul = close(1)
$loadfile = $temparray endfunction
Bryce
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 1292 anonymous users online.
|
|
|