<?xml version="1.0" encoding="windows-1251"?>
<document type="SelFTrendxTest" version="0.0" xmlns:m="xTest">
     <xTest type="SNMP" alias="CustomSNMPTest" 
            TitleRus="Пользовательский SNMP Тест" 
            TitleEng="Custom SNMP Test" 
             TitleRootRus="Тесты оценки «здоровья» оборудования, поддерживающего SNMP" 
             TitleRootEng="SNMP Devices Performance Tests"             
            Version="1.1"
            >
	<Files>
		<File type="conf" name="SNMP.CustomSNMPTest.xTest.xml"/>
		<File type="help" name="XT.SNMP.what-GetCustomOID.html"/>
		<File type="dll" name="x_snmp.dll"/>
	</Files>
 <Keywords>
   <Keyword>SNMP</Keyword>
   <Keyword>MIB</Keyword>
 </Keywords>
  <xTestProps>
		<AverInervDuration>60</AverInervDuration>
		<pollinterval>30</pollinterval>
        <snmp_timeout_ms>3000</snmp_timeout_ms>
        <snmp_retry_count>2</snmp_retry_count>
        <log_level_def>10</log_level_def>
        <truncate_log>1</truncate_log>
	</xTestProps>

	<VarSet>
		<tlights_func>TLights_Proc</tlights_func>
		<discovery_func>OnDiscovery</discovery_func>
		<work_func>OnDataReceived</work_func>
       	<din_discovery_func>OnDinDiscovery</din_discovery_func>

        <common_attribs TitleRus="Список параметров (общие):" TitleEng="Parameters List (common):" SubTitleRus="Параметр" SubTitleEng="Parameter">
            <Attrib Type="String" TitleRus="Конфигурационный файл" TitleEng="Config File" Alias="att_config_file">"C:\Program Files\ProLAN\NPM Probe Plus\NPM Probe\XFiles\CustomSNMP.txt"</Attrib>
        </common_attribs>

		<ScalarValues>
			<Value usetype="hidden" proctype="absolute" alias="sysUpTime" OID="1.3.6.1.2.1.1.3.0"> "sysUpTime" </Value>
			<Value usetype="calculated" proctype="absolute" alias="Availability"> "Custom SNMP Device Availability (%)"</Value>
        </ScalarValues>

	</VarSet>

	<popupdisplay>
		<description ru="Пользовательский SNMP Тест" en="Custom SNMP Test"></description>
			<display_item ru="Доступность SNMP устройства (%)" en="SNMP Device Availability(%)" alias="Availability" sign="&lt;">90 94 96 99</display_item>
	</popupdisplay>

<Script language="VBScript">
<!--
Const ForReading = 1

Const aEventName = 0
Const aOID = 1
Const aEventType = 2
Const aCounterType = 3
Const aComparisonOperator = 4
Const aRed = 5
Const aBlRed = 6
Const aYellow = 7
Const aBlYellow = 8

Const maxSNMPValue = 4294967295
Const g_dBadValue = 1.0e+308

Dim snmpErrorCount 'кол-во ошибок при получении snmp данных
Dim badSNMPRequest 'число неудачных запросов по SNMP

g_dDinValue = g_dBadValue - 1.0

Sub OnDiscovery(ByRef snmpDev)

	snmpErrorCount = 0

	Set fso = CreateObject("Scripting.FileSystemObject")

	userfile = snmpDev.ResSet.CommonProp.Attrib("att_config_file").Value
	If fso.FileExists(userfile) Then

		Set ts = fso.OpenTextFile(userfile, ForReading)
		Do While ts.AtEndOfStream = False
			OneLine = Replace(ts.ReadLine, vbTab, "")
			FirstLetter = Mid(OneLine, 1, 1)
			
			If Not (FirstLetter = "#" Or FirstLetter = "'" or FirstLetter = "") Then
				arrOneLine=Split(OneLine, ",")
			
				snmpValue = GetSNMP (arrOneLine(aOID), snmpDev)
			
				If snmpValue = g_dBadValue Then
					snmpErrorCount = snmpErrorCount + 1
				Else
					If IsNumeric(snmpValue) Then
	                	SlaName = arrOneLine(aEventName)
	    	            SlaAlias = arrOneLine(aEventName)
    	    	        SLAError = snmpDev.ResSet.EventAddEx(SlaName, SlaAlias, arrOneLine(aOID), LCase(Trim(arrOneLine(aEventType))), -1)
        	        
        		        If UBound(arrOneLine) = aBlYellow Then
        		        	TLError = snmpDev.ResSet.AddTrafficLight(SlaAlias, SlaName, SlaName, Trim(arrOneLine(aCounterType)), Trim(arrOneLine(aComparisonOperator)), Trim(arrOneLine(aRed)), Trim(arrOneLine(aBlRed)), Trim(arrOneLine(aYellow)), Trim(arrOneLine(aBlYellow)))
        	    	    End If
					End If
				End If
			End If
		Loop
		ts.close
	Else
		snmpDev.ScriptErrorInfo = "Не найден конфигурационный файл, указанный в настройках теста. Проверьте наличие файла: '" & userfile & "' и повторите запуск теста."
		snmpDev.ScriptError = 3
		Exit Sub
	End If
	
	If snmpErrorCount > 0 Then
		snmpDev.Disable = True
	Else
		snmpDev.Disable = False
	End If
	
	Set fso = Nothing
	Set arrOneLine = Nothing
	
End Sub


Sub OnDataReceived(ByRef snmpDev)

	For i=1 To snmpDev.ScalarTable.Count - 1
		alias = snmpDev.ScalarTable.ValueByIndx(i).Alias
		oid = snmpDev.ScalarTable.ValueByIndx(i).OID
		If LCase(alias) <> "availability" Then
			snmpValue = ""
			snmpValue = GetSNMP (oid, snmpDev)
			snmpTimer = Timer
			If snmpTimer = 0 Then snmpTimer = 0.01

			Select Case snmpDev.ScalarTable.ValueByIndx(i).Tag
				Case "value"
					snmpDev.ScalarTable.ValueByIndx(i).NumericValue = snmpValue
						
				Case "delta/int"
					If snmpValue = g_dBadValue Then
						snmpDev.ScalarTable.ValueByIndx(i).PrevValue = g_dBadValue
						snmpDev.ScalarTable.ValueByIndx(i).NumericValue = g_dBadValue
					Else
						If snmpDev.ScalarTable.ValueByIndx(i).PrevValue = g_dBadValue Then
							snmpDev.ScalarTable.ValueByIndx(i).PrevValue = snmpValue
							snmpDev.ScalarTable.ValueByIndx(i).NumericValue = g_dBadValue
						Else
							deltaSnmpValue = snmpValue - snmpDev.ScalarTable.ValueByIndx(i).PrevValue
							snmpDev.ScalarTable.ValueByIndx(i).PrevValue = snmpValue
							If deltaSnmpValue < 0 Then
								snmpDev.ScalarTable.ValueByIndx(i).NumericValue = maxSNMPValue + deltaSnmpValue
							Else
								snmpDev.ScalarTable.ValueByIndx(i).NumericValue = deltaSnmpValue
							End If
						End If
					End If

				Case "delta/sec"
					If snmpValue = g_dBadValue Then
						snmpDev.ScalarTable.ValueByIndx(i).PrevValue = g_dBadValue
						snmpDev.ScalarTable.ValueByIndx(i).NumericValue = g_dBadValue
						snmpDev.ScalarTable.ValueByIndx(i).HTimer = 0
					Else
						If snmpDev.ScalarTable.ValueByIndx(i).PrevValue = g_dBadValue Then
							snmpDev.ScalarTable.ValueByIndx(i).PrevValue = snmpValue
							snmpDev.ScalarTable.ValueByIndx(i).NumericValue = g_dBadValue
							snmpDev.ScalarTable.ValueByIndx(i).HTimer = snmpTimer
						Else
							deltaSnmpValue = snmpValue - snmpDev.ScalarTable.ValueByIndx(i).PrevValue
							deltaTimerValue = snmpTimer - CLng(snmpDev.ScalarTable.ValueByIndx(i).HTimer)
							snmpDev.ScalarTable.ValueByIndx(i).PrevValue = snmpValue
							snmpDev.ScalarTable.ValueByIndx(i).HTimer = snmpTimer
							If deltaTimerValue < 0 Then deltaTimerValue = 86400 + deltaTimerValue
							If deltaSnmpValue < 0 Then
								snmpDev.ScalarTable.ValueByIndx(i).NumericValue = (maxSNMPValue + deltaSnmpValue) / deltaTimerValue
							Else
								snmpDev.ScalarTable.ValueByIndx(i).NumericValue = deltaSnmpValue / deltaTimerValue
							End If
						End If
					End If
			End Select
		End If
	Next
    
End Sub

Function GetSNMP (l_strOID, l_snmpDev)
	On Error Resume Next

	Dim l_snmpValue

	l_snmpValue = l_snmpDev.SnmpGet(Trim(l_strOID), snmpErr)

	If snmpErr <> 0 Then
		logMessage = vbNewLine & "!!!Try Get OID: " & l_strOID & vbNewLine & "!!!Error Description: " & l_snmpDev.GetSnmpErrorText()
		l_snmpDev.LogMsg(logMessage)
		GetSNMP = g_dBadValue
	Else
		GetSNMP = l_snmpValue	
	End If
	
End Function



Sub OnDinDiscovery(ByRef snmpDev)
End Sub
-->
</Script>


     </xTest>
</document>
