<html xmlns="http://www.w3.org/TR/REC-html40">
<head>
  <HEAD>
    <META HTTP-EQUIV="Expires" CONTENT="0">
    <TITLE> "TN4010 Rmon Statistics"</TITLE>
    <HTA:APPLICATION ID="oTNControlHta"
     APPLICATIONNAME="TN4010 Rmon Statistics"
     __BORDER="dialog"
     BORDERSTYLE="normal"
     CAPTION="yes"
     SINGLEINSTANCE ="yes"
     MAXIMIZEBUTTON="yes"
     MINIMIZEBUTTON="yes"
     SHOWINTASKBAR="yes"
     SCROLL="yes"
     SYSMENU="yes"
     VERSION="1.2"
     CONTEXTMENU="NO"
     _WINDOWSTATE="maximize"/>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<script language="VBScript">

On Error Resume Next
Dim Locator
Dim Service
Dim Collection
Dim InstancePaths()
Dim InstanceCount
Dim CurrentInstanceIndex
Dim HostName

sub DoInit
	Set Locator = CreateObject("WbemScripting.SWbemLocator")
	Set Service = Locator.ConnectServer(, "root\wmi")
	Service.Security_.ImpersonationLevel=3
	HostName=""
	LoadDeviceList
	ReloadInstance
end sub

<!--
sub SelectHost
	dim objShell
	dim ssfWINDOWS
	dim objFolder
	dim s
	ssfNETWORK = 18
	BIF_BROWSEFORCOMPUTER = 4096
	set objShell = CreateObject("Shell.Application")
	set objFolder = objShell.BrowseForFolder(0, "Select remote host", BIF_BROWSEFORCOMPUTER, ssfNETWORK)

	if (objFolder is nothing) then
		exit sub
	end if

	HostName=objFolder.Title
	Set Service = Locator.ConnectServer(HostName, "root\wmi")
	Service.Security_.ImpersonationLevel=3
	LoadDeviceList
	ReloadInstance
end sub
-->

sub LoadDeviceList
	On Error Resume Next
	dim i,s,ss
	Set Collection = Service.InstancesOf ("THTINdis_AllStat")
	InstanceCount = 0
	Err.Clear
	for each Instance in Collection
		if Err.Number = 0 Then
			InstanceCount = InstanceCount + 1
			ReDim Preserve InstancePaths(InstanceCount)
			Set ObjectPath = Instance.Path_
			InstancePaths(InstanceCount) = ObjectPath.Path
		End If
	next 'Instance

	if InstanceCount = 0 Then
		s=HostName & "   No instances available for this class - Make sure you are running As Administrator"
		idAdapterControl.style.display="none"
	Else
		CurrentInstanceIndex = 1
		s=""
		for i=1 to InstanceCount step 1
			ss=InstancePaths(i)
			ss=Split(ss,"InstanceName=")
			s= s & "<OPTION> " & ss(1)
		next
		s=HostName & "  <SELECT onchange='ChangeAdapter()' ID=idAdaptersList>" & s & "</SELECT> Total:" & InstanceCount
		idAdapterControl.style.display=""
	End if
	idAdaptersListSpan.innerHTML=s

end sub

sub ChangeAdapter()
	CurrentInstanceIndex=idAdaptersList.selectedIndex+1
	call ReloadInstance
end sub  

Sub ReloadInstance
	On Error Resume Next
	Dim ss
	if InstanceCount = 0 Then
		idAdapterControlHeader.innerHTML="No Instances Available"
	Else
		Err.Clear
		Set Instance = Service.Get(InstancePaths(CurrentInstanceIndex))
		if Err.Number = 0 Then
			ss=Split(InstancePaths(CurrentInstanceIndex),"InstanceName=")
			idAdapterControlHeader.innerHTML=ss(1)
			ss=GetRmonStats(Instance)
			UpdateStatus(ss)
		Else
			MsgBox Err.Description, ,CurrentObjectPath
		End If
	End If

End Sub

function GetRmonStats(Adapter)
	reg_names_list=Array( "etherStatsDropEvents", "etherStatsMulticastPkts", "etherStatsOctets", "etherStatsPkts", "etherStatsBroadcastPkts", "etherStatsCRCAlignErrors", "etherStatsUndersizePkts", "etherStatsFragments", "etherStatsOversizePkts", "etherStatsJabbers", "etherStatsPkts64Octets", "etherStatsPkts65to127Octets", "etherStatsPkts128to255Octets", "etherStatsPkts256to511Octets", "etherStatsPkts512to1023Octets", "etherStatsPkts1024to1518Octets", "etherStatsPkts1519toX")
	dim reg_values_list(20)

	Set Service = GetObject("winmgmts:{impersonationLevel=impersonate}!root/wmi")

	log_str= "<UL>" & vbcrlf & "<h3>" & "Collected on " & Date & ", " & Time & "</h3>" & vbcrlf
	log_str = log_str & "<table class=MsoTableGrid border=1 cellspacing=0 cellpadding=0 style='border-collapse:collapse;border:none'>" & vbcrlf

	reg_values_list( 0) = ReadTNReg(Service,Adapter.instanceName,&h6120) + ReadTNReg(Service,Adapter.instanceName,&h7250) + (ReadTNReg(Service,Adapter.instanceName,&h7258) * 0)
	reg_values_list( 1) = ReadTNReg(Service,Adapter.instanceName,&h60E8) + ReadTNReg(Service,Adapter.instanceName,&h60A8)
	reg_values_list( 2) = ReadTNReg(Service,Adapter.instanceName,&h6128)
	reg_values_list( 3) = ReadTNReg(Service,Adapter.instanceName,&h6130)
	reg_values_list( 4) = ReadTNReg(Service,Adapter.instanceName,&h60F0)
	reg_values_list( 5) = ReadTNReg(Service,Adapter.instanceName,&h6090)
	reg_values_list( 6) = ReadTNReg(Service,Adapter.instanceName,&h6138)
	reg_values_list( 7) = ReadTNReg(Service,Adapter.instanceName,&h6188)
	reg_values_list( 8) = ReadTNReg(Service,Adapter.instanceName,&h6178)
	reg_values_list( 9) = ReadTNReg(Service,Adapter.instanceName,&h6180)
	reg_values_list(10) = ReadTNReg(Service,Adapter.instanceName,&h6140)
	reg_values_list(11) = ReadTNReg(Service,Adapter.instanceName,&h6148)
	reg_values_list(12) = ReadTNReg(Service,Adapter.instanceName,&h6150)
	reg_values_list(13) = ReadTNReg(Service,Adapter.instanceName,&h6158)
	reg_values_list(14) = ReadTNReg(Service,Adapter.instanceName,&h6160)
	reg_values_list(15) = ReadTNReg(Service,Adapter.instanceName,&h6168)
	reg_values_list(16) = ReadTNReg(Service,Adapter.instanceName,&h6170)

	for i=0 to UBound(reg_names_list) step 1
		ss = "<tr>" & vbcrlf
		ss = ss & "<td width=295 valign=top style='width:221.4pt;border:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt'>" & vbcrlf
		ss = ss & "<p class=MsoNormal dir=LTR style='margin-bottom:0cm;margin-bottom:.0001pt;text-align:left;line-height:normal;direction:ltr;unicode-bidi:embed'><b>" & reg_names_list(i) & "</b></p>" & vbcrlf
		ss = ss & "</td>" & vbcrlf
		ss = ss & "<td width=295 valign=top style='width:221.4pt;border:solid windowtext 1.0pt;border-left:none;padding:0cm 5.4pt 0cm 5.4pt'>" & vbcrlf
		ss = ss & "<p class=MsoNormal dir=LTR style='margin-bottom:0cm;margin-bottom:.0001pt;text-align:left;line-height:normal;direction:ltr;unicode-bidi:embed'><b>" & reg_values_list(i) & "</b></p>" & vbcrlf
		ss = ss & "</td>" & vbcrlf
		ss = ss & "</tr>" & vbcrlf
 
		log_str=log_str & ss  & vbcrlf
	next

	log_str=log_str & "</table>" & vbcrlf

	GetRmonStats = log_str & "</UL>" & vbcrlf
end function

Sub ReloadStatus
	if InstanceCount > 0 Then
		Err.Clear
		ss=InstancePaths(CurrentInstanceIndex)
		Set Instance = Service.Get(ss)
		if Err.Number = 0 Then
			ss=GetRmonStats(Instance)
			UpdateStatus(ss)
		Else
			MsgBox Err.Description, ,CurrentObjectPath
		End If
	End If
End Sub

Sub UpdateStatus(ss)
	idStatus.innerHTML="<b>" & ss & "</b>"
End Sub

function ReadTNReg(Service,Name,addr)
	on Error resume next
	dim enumSet,str
	Set enumSet = Service.InstancesOf("THTINdis_RegisterAddress")

	Wscript.Echo(Name)

	str= -1
	for each instance in enumSet
		if (instance.instanceName = Name) then
      			instance.Address = addr
      			instance.Put_()
		end if
	next 'instance
	Set enumSet = Service.InstancesOf("THTINdis_RegisterValue")
	for each instance in enumSet
		if (instance.instanceName = Name) then
     			str= instance.Value
		end if
	next 'instance

    	ReadTNReg=str 

end function

</script>
</head>

<body onload="DoInit()" >
	<div class=Section1>
		<!-- <button onclick="SelectHost()" >Select remote host</button> -->
		<H3>TN4010 Rmon Statistics</H3>
		<span ID=idAdaptersListSpan></span>
		<HR>
		<div ID=idAdapterControl ALIGN=Left>
			<h4 ID=idAdapterControlHeader>No Adapters found</h4>
			<button onclick="ReloadStatus()">Refresh</button>
			<br>  
				<span id=idStatus>undefined</span>
			<br>  
		</div>
	</div>
</body>

</html>
