<?xml version="1.0" encoding="windows-1251" ?>
<document type="SelFTrendxTest" version="0.0" xmlns:m="xTest">
    <xTest type="SNMP" 
		alias        = "PPCS_CBWFQ" 
		TitleRus     = "Тест оценки QoS на основе анализа статистики работы механизма CBWFQ" 
		TitleEng     = "CBWFQ monitoring for Cisco Systems" 
		TitleRootRus    = "Набор тестов для операторов связи (Cisco Systems)" 
		TitleRootEng    = "Provider Pack (Cisco Systems)" 
    TrafficLightsName = "CBWFQ monitoring for Cisco Systems"
		Version="1.1">
        <Files>
            <File type="conf" name = "new_features.4.cbwfq.conf.xml" />
            <File type="help" name="SNMP.CiscoQueue.XFiles.html" />
            <File type="dll" name="x_snmp.dll" />
        </Files>
      <Keywords>
        <Keyword>SNMP</Keyword>
        <Keyword>Cisco</Keyword>
        <Keyword>QoS</Keyword>
        <Keyword>CBWFQ</Keyword>
      </Keywords>
      <xTestProps>
            <AverInervDuration>180</AverInervDuration>
            <pollinterval>57</pollinterval>
            <snmp_timeout_ms>5000</snmp_timeout_ms>
            <snmp_retry_count>3</snmp_retry_count>
            <log_level_def>3</log_level_def>
            <truncate_log>0</truncate_log>
            <use_active_device_only>No</use_active_device_only>
        </xTestProps>
        <VarSet>
            <!--
    $Id: new_features.4.cbwfq.xml,v 1.2 2009/11/10 08:48:19 alex_l Exp $
            
	Value attributes:
		usetype: "hidden" | "pure" | "discovery" | "calculated" | "storage"
		proctype: "absolute" | "delta"

		OID: for scalar values ("1.3.6.1.2.1.1.1")
		ROOT_OID: for tables  ("1.3.6.1.2.1.2.2.1" - A list of interface entries.)
		COLNUM_OID:  for table values
		alias: short ascii name w/o white spaaces

		discovery_func
		work_func
		tlights_func

    Table attributes:
            name: table name defined by user
            ROOT_OID: Table OID     
            Type_data: "Static" | "dynamic" 
                       "Static"  - number of rows in table is constant
                       "dinamic" - number of rows in table is variable
                       Type_data="dinamic"
-->
            <tlights_func>TLights_Proc</tlights_func>
            <discovery_func>OnDiscovery</discovery_func>
            <work_func>OnDataReceived</work_func>
            <din_discovery_func>OnDinDiscovery</din_discovery_func>

            <!--  Type: "String", "Bool", "Integer", "Double", "Enum"  --> 
            <common_attribs TitleRus="Список параметров (общие):" TitleEng="Parameters List (common):" SubTitleRus="Параметр" SubTitleEng="Parameter">
                <Attrib Type="String" TitleRus="Link name filter" TitleEng="Link name filter" Alias="if_filter">
                    "Multilink"
                </Attrib>
                <Attrib Type="String" TitleRus="Description policy-map" TitleEng="Description policy-map" Alias="descr_policymap">
                    "*"
                </Attrib>
                
                <Attrib Type="String" TitleRus="Class name filter (Hi priority)" TitleEng="Class name filter (Hi priority)" Alias="hpr_clmap_filter">
                    "exp7"
                </Attrib>
                <Attrib Type="String" TitleRus="Class name filter (Lo priority)" TitleEng="Class name filter (Lo priority)" Alias="lpr_clmap_filter">
                    "exp5"
                </Attrib>
                <Attrib Type="String" TitleRus="Link name substitution" TitleEng="Link name substitution" Alias="if_substitution">
                    "Multilink=Mu,FastEthernet=Fa,Serial=Se,GigabitEthernet=Gi,Vlan=Vl"
                </Attrib>
                <Attrib Type="Double" TitleRus="Dropped packets threshold Lo priority" TitleEng="Dropped packets threshold Lo priority" Alias="drop_pkts_thres">
                    "10"
                </Attrib>
                <Attrib Type="Double" TitleRus="Dropped bytes threshold Lo priority" TitleEng="Dropped bytes threshold Lo priority" Alias="drop_bytes_thres">
                    "700"
                </Attrib>
                <Attrib Type="Bool" TitleRus="Add Policy Map Name to Event Name" TitleEng="Add Policy Map Name to Event Name" Alias="add_poicyname">
                    "no"
                </Attrib>
                <Attrib Type="String" TitleRus="Имя файла журнала для snmp трапов" TitleEng="Snmp Trap log file name" Alias="snmp_trap_log">
                    "%TEMP%\traps\traps.new_features.4.cbwfq.txt"
                </Attrib>
            </common_attribs>

            <ScalarValues>
            <Value usetype="calculated" proctype="absolute" alias="Availability">
				"QoS Device SNMP Availability (%)"
			</Value> 
            <Value usetype="discovery" proctype="absolute" alias="busyPer" OID="1.3.6.1.4.1.9.2.1.56.0">
				"CPU busy percentage in the last 5 second"
			</Value> 
            <Value usetype="hidden" proctype="absolute" OID="1.3.6.1.2.1.1.3.0" alias="sysUpTime">
				"sysUpTime"
			</Value>
            <Value usetype="storage" proctype="absolute"  alias="sysUpTimeStorage">
				"sysUpTimeStorage"
			</Value>
            </ScalarValues>
                                         
            <TableValues>
            
                <Table name="ifEntry" ROOT_OID="1.3.6.1.2.1.2.2.1" Type_data="Static" Mandatory="yes">
                    <Value usetype="discovery" proctype="absolute" alias="ifDescr" COLNUM_OID="2">
				        "Information about the interface"
			        </Value> 
                </Table>
                
                <Table name="cbQosServicePolicyEntry" ROOT_OID="1.3.6.1.4.1.9.9.166.1.1.1.1" Type_data="Static" Mandatory="yes">
                    <Value usetype="discovery" proctype="absolute" alias="cbQosIfType" COLNUM_OID="2">
				        "interface/media type"
			        </Value> 
                    <Value usetype="discovery" proctype="absolute" alias="cbQosPolicyDirection" COLNUM_OID="3">
				        "direction of traffic"
			        </Value> 
                    <Value usetype="discovery" proctype="absolute" alias="cbQosIfIndex" COLNUM_OID="4">
				        "ifIndex for the interface"
			        </Value> 
                </Table>


                <Table name="cbQosObjectsEntry" ROOT_OID="1.3.6.1.4.1.9.9.166.1.5.1.1" Type_data="Static" Mandatory="yes">
                    <Value usetype="discovery" proctype="absolute" alias="cbQosConfigIndex" COLNUM_OID="2">
				        "index for each Object"
			        </Value> 
                    <Value usetype="discovery" proctype="absolute" alias="cbQosObjectsType" COLNUM_OID="3">
				        "The type of the QoS object."
			        </Value> 
                    <Value usetype="discovery" proctype="absolute" alias="cbQosParentObjectsIndex" COLNUM_OID="4">
				        "The parent instance index of a QoS object."
			        </Value> 
                </Table>

                <Table name="cbQosPolicyMapCfgEntry" ROOT_OID="1.3.6.1.4.1.9.9.166.1.6.1.1" Type_data="Static" Mandatory="yes">
                    <Value usetype="discovery" proctype="absolute" alias="cbQosPolicyMapName" COLNUM_OID="1">
				        "Name of the Policymap."
			        </Value>
                    <Value usetype="discovery" proctype="absolute" alias="cbQosPolicyMapDesc" COLNUM_OID="2">
				        "Description of the PolicyMap."
			        </Value>
                </Table>
                
                <Table name="cbQosCMCfgEntry" ROOT_OID="1.3.6.1.4.1.9.9.166.1.7.1.1" Type_data="Static" Mandatory="yes">
                    <Value usetype="discovery" proctype="absolute" alias="cbQosCMName" COLNUM_OID="1">
				        "Name of the Classmap."
			        </Value> 
                    <Value usetype="discovery" proctype="absolute" alias="cbQosCMInfo" COLNUM_OID="3">
				        "Match all vs Match any in a given class."
			        </Value> 
			        
                </Table>

                <Table name="cbQosCMStatsEntry_static" ROOT_OID="1.3.6.1.4.1.9.9.166.1.15.1.1" Type_data="Static" Mandatory="yes">
                
                <Value usetype="pure" proctype="delta" COLNUM_OID="2" alias="cbQosCMPrePolicyPkt">
					"QoS Pre Policy Packet Rate (Packets/s)"
				</Value>
                <Value usetype="pure" proctype="delta" COLNUM_OID="5" alias="cbQosCMPrePolicyByte">
					"QoS Pre Policy Byte Rate (Byte/sec)"
				</Value>
                <Value usetype="pure" proctype="delta" COLNUM_OID="9" alias="cbQosCMPostPolicyByte">
					"QoS Post Policy Byte Rate (Byte/sec)"
				</Value>
                <Value usetype="hidden" proctype="absolute" COLNUM_OID="13" alias="cbQosCMDropPkt">
					"Dropped Packets"
				</Value>
                <Value usetype="hidden" proctype="absolute" COLNUM_OID="16" alias="cbQosCMDropByte">
					"Dropped Bytes"
				</Value>
                <Value usetype="storage" proctype="absolute"  alias="error_count">
				        "Error Count"
			    </Value>
                </Table>
            
                <Table name="cbQosCMStatsEntry_dynamic" ROOT_OID="1.3.6.1.4.1.9.9.166.1.15.1.1" Type_data="dynamic">
                    <Value usetype="hidden" proctype="absolute" COLNUM_OID="5" alias="cbQosCMPrePolicyByte">
					    "QoS Pre Policy Byte Rate (Byte/sec)"
				    </Value>
                </Table>
                
            </TableValues>
            
            
        </VarSet>
        <popupdisplay>
            <!-- Function: "EventCount", "Average", "Maximum", "Minimum" -->
            <description ru="Сisco Queue Тест" en="Сisco Queue Test"></description>
		
		<display_item ru="QoS Device SNMP Availability (%)" en="QoS Device SNMP Availability (%)" alias="Availability" sign="&lt;">
			90 94 96 99
		</display_item>
            
            
        </popupdisplay>
        <Script language="VBScript">
            <!--

' 03/11/2006 - Изменен процесс отправки трапа об отброшенных пакетах и байтах. Теперь это отправляется в одном трапе. Stas Kuzubov
'
'
'
'



Dim g_dBadValue 
Dim mySendTrap
Dim DroppedPackets4Trap, DroppedBytes4Trap

'// if queue data is failed more then QUEUE_FAILED_COUNT, then launch rediscovery
QUEUE_FAILED_COUNT = 3

g_dBadValue = 1.0e+308

g_if_filter = ""
g_descr_pm_filter = ""
g_hpr_clmap_filter = ""
g_lpr_clmap_filter = ""
g_subst_list = ""


g_excl_if_filter = ""
g_excl_clmap_filter = ""

'lll

POLICYMAP = 1
CLASSMAP = 2
QUEUEING = 4

INPUT = 1
OUTPUT = 2

MAININTERFACE   = 1
SUBINTERFACE    = 2
FRDLCI          = 3
ATMPVC          = 4


DISCOVERY_VAL   = 1
PURE_VAL        = 2
HIDDEN_VAL      = 3
CALCULATED_VAL  = 4
STORAGE_VAL     = 5

LOWPRIORITY     = 0
HIGHPRIORITY    = 1
NOTMONITORED    = -1

BLANK_STRING    = g_dBadValue

'// Rev: 1.4
SCRIPTFAILED    = 3
SCRIPT_OK       = 0
DEV_ERR_COUNT   = 3


	' Message.GenericTrap Constants
	' Enumerates values of the GenericTrap property.
	Const snmpColdStart = 0					'The agent is initializing (cold start).
	Const snmpWarmStart = 1					'The agent is reinitializing (warm start).
	Const snmpLinkDown = 2					'An interface has changed from the up to down state. Variables(1) of the SnmpMessage object contains the interface.
	Const snmpLinkUp = 3					'An interface has changed from the down to up state. Variables(1) of the SnmpMessage object contains the interface.
	Const snmpAuthenticationFailure = 4		'A message was received from a manager with an invalid community.
	Const snmpEgpNeighborLoss = 5			'An EGP peer has changed to the down state. Variables(1) of the SnmpMessage object contains the IP address of the peer.
	Const snmpEnterpriseSpecific = 6		'The SpecificTrap property contains information on the trap.

	'Snmp Variable Type Constants
	'Enumerates values of the Type property
	Const snmpNull = 0			'NULL.
	Const snmpInteger = 1		'Signed 32 bit integer.
	Const snmpOctetString = 2	'String.
	Const snmpObjectID = 3		'String that represents an Object Identifier (OID).
	Const snmpIpAddress = 4		'String that represents an IP Address in dot notation.
	Const snmpCounter32 = 5		'Unsigned 32 bit integer that represents a counter.
	Const snmpGuage32 = 6		'Unsigned 32 bit integer that represents a guage.
	Const snmpTimeTicks = 7		'Unsigned 32 bit integer that represents time ticks.
	Const snmpOpaque = 8		'String.
	Const snmpNSAPAddress = 9	'String that represents an Network Service Access Point Address.
	Const snmpUInteger32 = 10	'Unsigned 32 bit integer.
	Const snmpCounter64 = 11	'Unsigned 64 bit integer.



Sub OnReDiscovery(ByRef snmpDev, errorCount)

    'snmpDev.LaunchRediscovery
    'snmpDev.RediscoveryInitiator
    
    logMessage = "VBscript ReDiscovery error count: " & snmp_errorCount
    snmpDev.LogMsg(logMessage)


End Sub

Sub OnDiscovery(ByRef snmpDev)
    'stop
    logMessage = "+=========================================================="
    snmpDev.LogMsg(logMessage)

    logMessage = "VBscript discovery start, ip: " & snmpDev.IpAddress & " device: " & snmpDev.DeviceName
    snmpDev.LogMsg(logMessage)

    Set ScalarTab = snmpDev.ScalarTable
    Set TabSet = snmpDev.TablesSet
   
    '// Rev: 1.4
    if snmpDev.ScriptError > 0 Then 
        If snmpDev.LaunchRediscovery = True Then
            OnReDiscovery  snmpDev, snmpDev.ScriptError
            snmpDev.ScriptErrorInfo = "Snmp Discovery is failed"
            
            logMessage = "VBscript: Snmp Discovery is failed  ErrCount: " & snmpDev.ScriptError
            snmpDev.LogMsg(logMessage)
            
            If  snmpDev.ScriptError >= DEV_ERR_COUNT Then
                logMessage = "VBscript: " & snmpDev.IpAddress & ":" & snmpDev.SnmpPort & " Remove from Monitoring process"
                snmpDev.LogMsg(logMessage)
                snmpDev.StopRediscovery = True
            End If
            snmpDev.ScriptError = SCRIPTFAILED    
            Exit Sub
        End If
    End If
    
    
    Set portTab = TabSet.PPortsTableByName("ifEntry")
    If Not (portTab Is Nothing) Then
        portTab.Disable = true
    End If
    
    Set portTab = TabSet.PPortsTableByName("cbQosServicePolicyEntry")
    If Not (portTab Is Nothing) Then
        portTab.Disable = true
    End If

    Set portTab = TabSet.PPortsTableByName("cbQosObjectsEntry")
    If Not (portTab Is Nothing) Then
        portTab.Disable = true
    End If

    Set portTab = TabSet.PPortsTableByName("cbQosPolicyMapCfgEntry")
    If Not (portTab Is Nothing) Then
        portTab.Disable = true
    End If

    Set portTab = TabSet.PPortsTableByName("cbQosCMCfgEntry")
    If Not (portTab Is Nothing) Then
        portTab.Disable = true
    End If

    '// Get names of Class Maps  in cbQosCMStatsTable
    Set portTab = TabSet.PPortsTableByName("cbQosCMStatsEntry_static")
    If (portTab Is Nothing) Then
        snmpDev.ScriptErrorInfo = "Snmp Discovery is failed"
        snmpDev.ScriptError = SCRIPTFAILED
        Exit Sub
    End If
    
    l_bRetCode = CreateSnmpManager(snmpDev, l_SnmpRQ, TabSet)
    If( Err.Number <> 0 ) Then
        TablesCount = 0
        l_iSmnpError = -1
        snmpDev.ScriptErrorInfo = Err.Description
        snmpDev.ScriptError = SCRIPTFAILED
        Exit Sub
    End If
    
    l_strRoot_Oid = portTab.RootOID

    TablesCount = portTab.Count
    logMessage = "Class Maps: " & TablesCount
    snmpDev.LogMsg(logMessage)
    l_iSmnpError = 0

    g_if_filter = ParseFilter(snmpDev.ResSet.CommonProp.Attrib("if_filter").Value)
    g_descr_pm_filter = ParseFilter(snmpDev.ResSet.CommonProp.Attrib("descr_policymap").Value)
    g_hpr_clmap_filter = ParseFilter(snmpDev.ResSet.CommonProp.Attrib("hpr_clmap_filter").Value)
    g_lpr_clmap_filter = ParseFilter(snmpDev.ResSet.CommonProp.Attrib("lpr_clmap_filter").Value)
    g_subst_list = ParseSubstExpress(snmpDev.ResSet.CommonProp.Attrib("if_substitution").Value)
    
    l_bQueuesAvailable = false
    snmpDev.ScriptError = 0
    
    '// Get text description and priority for available quenes (passed through filter)
    For tIndx = 0 To TablesCount - 1
        Set lportTab = portTab.Table(tIndx)

        Set sValue = lportTab.Value("cbQosCMPrePolicyPkt")
        PolicyIndx = GetInstance(sValue.OID, 0)
        ObjIndx = GetInstance(sValue.OID, 1)
        
        lportTab.Instance = "." & PolicyIndx & "." & ObjIndx
        
        l_iDataPriority = LOWPRIORITY
        
        l_strDescr = GetDescription(snmpDev, l_SnmpRQ, PolicyIndx, ObjIndx, l_iDataPriority)
        
        '// Rev: 1.4: Set queues to NOTMONITORED in error Case
        If( Err.Number <> 0 ) Then
            TablesCount = 0
            l_iSmnpError = -1
            snmpDev.ScriptErrorInfo = Err.Description
            snmpDev.ScriptError = SCRIPTFAILED
            
            '//SetUserType snmpDev, portTab, NOTMONITORED, 0            
            
            If snmpDev.LaunchRediscovery = True Then
                OnReDiscovery  snmpDev, snmpDev.ScriptExecCount

                If  snmpDev.ScriptExecCount >= DEV_ERR_COUNT Then
                    snmpDev.StopRediscovery = True
                    portTab.Clear()
                    logMessage = "VBscript: " & snmpDev.IpAddress & ":" & snmpDev.SnmpPort & " Skip rediscovery"
                    snmpDev.LogMsg(logMessage)
                End If
            Else
                If Not snmpDev.UseActiveDeviceOnly Then
                    snmpDev.ScriptError = SCRIPT_OK
                    portTab.Clear()
                    snmpDev.WasDiscovered = False
                End If
            End If
            
            Exit Sub
        End If

        '//sValue.Name = l_strDescr
        lportTab.PortDescription = l_strDescr
        sValue.Tag = l_iDataPriority
        
        If l_iDataPriority <> NOTMONITORED Then
            l_bQueuesAvailable = true
        End If 
    Next
    
    '// if there are not available quenes (passed through filter) - exit with error
'    If l_bQueuesAvailable = false and snmpDev.WasDiscovered = True Then
'        
'        snmpDev.ScriptErrorInfo = "Available queues could not be found"
'        snmpDev.ScriptError = SCRIPTFAILED
'        
'        logMessage = "VB script: "  & snmpDev.ScriptErrorInfo
'        snmpDev.LogMsg(logMessage)
'
'        If snmpDev.LaunchRediscovery = True Then
'            OnReDiscovery  snmpDev, snmpDev.ScriptExecCount
'            
'            '// Rev: 1.4: Set queues to NOTMONITORED
'            SetUserType snmpDev, portTab, NOTMONITORED, 0            
'
'            If  snmpDev.ScriptExecCount >= DEV_ERR_COUNT Then
'                snmpDev.StopRediscovery = True
'                logMessage = "VBscript: " & snmpDev.IpAddress & ":" & snmpDev.SnmpPort & " Skip rediscovery"
'                snmpDev.LogMsg(logMessage)
'            End If
'        Else
'            If Not snmpDev.UseActiveDeviceOnly Then
'                snmpDev.ScriptError = SCRIPT_OK
'                portTab.Clear()
'                snmpDev.WasDiscovered = False
'            End If
'            
'        End If
'
'        Exit Sub
'    End If     
    
    l_iTagIndx = 1
    
    l_dDroppPktsThrh = snmpDev.ResSet.CommonProp.Attrib("drop_pkts_thres").Value
    l_dDroppBytesThrh = snmpDev.ResSet.CommonProp.Attrib("drop_bytes_thres").Value
    
    l_dTLPkts_Yl_Bl = l_dDroppPktsThrh
    l_dTLPkts_Yl    = 3+l_dDroppPktsThrh
    l_dTLPkts_Rd_Bl = 5+l_dDroppPktsThrh
    l_dTLPkts_Rd    = 7+l_dDroppPktsThrh
    
    l_dTLByts_Yl_Bl = l_dDroppBytesThrh
    l_dTLByts_Yl    = 3+l_dDroppBytesThrh
    l_dTLByts_Rd_Bl = 5+l_dDroppBytesThrh
    l_dTLByts_Rd    = 7+l_dDroppBytesThrh
        
    For tIndx = 0 To TablesCount - 1
        Set lportTab = portTab.Table(tIndx)
        
        If lportTab.Disable = False Then
            
            l_iPortsCount = lportTab.Count
            '//Set PortDescrValue = lportTab.Value("cbQosCMPrePolicyPkt")
            Set PrePolicyPkt = lportTab.Value("cbQosCMPrePolicyPkt")
            Set PrePolicyByte = lportTab.Value("cbQosCMPrePolicyByte")
            Set PostPolicyByte = lportTab.Value("cbQosCMPostPolicyByte")
            Set l_dcbQosCMDropPkt = lportTab.Value("cbQosCMDropPkt")
            Set l_dcbQosCMDropByte = lportTab.Value("cbQosCMDropByte")
            
            For pIndx = 0 To l_iPortsCount - 1
                Set sValue = lportTab.ValueByIndx(pIndx)
                
                'If Not InStr(1,sValue.Name,PortDescrValue.Name,1) > 0 Then  
                '   sValue.Name = PortDescrValue.Name & ": " & sValue.Name
                    
                'lportTab.PortDescription
                If Not InStr(1,sValue.Name,lportTab.PortDescription,1) > 0 Then  
                    sValue.Name = lportTab.PortDescription & ": " & sValue.Name
                End If
            Next
            l_strPriority = PrePolicyPkt.Tag
            l_iPriority = CInt(l_strPriority)
            
            '// Add Events and Traffic Lights
            
            '// Drropped Packets
            If l_dcbQosCMDropPkt.NumericValue <> g_dBadValue Then
                l_strEventName = lportTab.PortDescription & ": QoS Dropped Packets" 
                l_strAlias = snmpDev.IpAddress & "_" & snmpDev.SnmpPort
                l_strAlias = l_strAlias & "_" & PrePolicyPkt.OID & "_Dropped_Pkts_PCNT" 
                
                If l_iPriority = HIGHPRIORITY Or l_iPriority = LOWPRIORITY Then 
                    SLAError = snmpDev.ResSet.EventAddEx(l_strEventName, l_strAlias, "", l_strPriority, -1)

                    logMessage = "VB script: Add Event: " & l_strEventName
                    snmpDev.LogMsg(logMessage)

                    logMessage = "VB script: snmpDev.ResSet.EventAdd return: " & SLAError & " ('" & snmpDev.ResSet.InternalErrorInfo & "')"
                    snmpDev.LogMsg(logMessage)
                End If
                
                l_strTLName_ru = lportTab.PortDescription & ": " &  "QoS Dropped Packets"
                l_strTLName_en = lportTab.PortDescription & ": " &  "QoS Dropped Packets"
                
                If l_iPriority = HIGHPRIORITY Then 
                    TLError = snmpDev.ResSet.AddTrafficLight(l_strAlias, l_strTLName_ru, l_strTLName_en, "Maximum", ">", 0.0, 0.0, 0.0, 0.0)
                ElseIf l_iPriority = LOWPRIORITY Then 
                    TLError = snmpDev.ResSet.AddTrafficLight(l_strAlias, l_strTLName_ru, l_strTLName_en, "Maximum", ">", l_dTLPkts_Rd, l_dTLPkts_Rd_Bl, l_dTLPkts_Yl, l_dTLPkts_Yl_Bl)
                End If
                If l_iPriority = HIGHPRIORITY  Or l_iPriority = LOWPRIORITY Then 
                    logMessage = "VB script: AddTrafficLight: "  & l_strTLName_en
                    snmpDev.LogMsg(logMessage)
                    logMessage = "VB script: snmpDev.ResSets.AddTrafficLight return: " & TLError  & " ('" & snmpDev.ResSet.InternalErrorInfo & "')"
                    snmpDev.LogMsg(logMessage)
                End If                
            End If
            
            '// Drropped Bytes
            If l_dcbQosCMDropByte.NumericValue <> g_dBadValue Then
                l_strEventName = lportTab.PortDescription & ": QoS Dropped Bytes" 
                l_strAlias = snmpDev.IpAddress & "_" & snmpDev.SnmpPort
                l_strAlias = l_strAlias & "_" & PrePolicyByte.OID & "_Dropped_Bytes_PCNT" 
               
                l_strOID = "1.3.6.1.2.1.2.2.1.2." & l_iTagIndx
                l_strTag = "tag_" & l_iTagIndx
                l_iTagIndx = l_iTagIndx + 1

                If l_iPriority = HIGHPRIORITY Or l_iPriority = LOWPRIORITY Then 
                    SLAError = snmpDev.ResSet.EventAddEx(l_strEventName, l_strAlias, "", l_strPriority, -1)
                    logMessage = "VB script: snmpDev.ResSet.EventAdd return: " & SLAError & " ('" & snmpDev.ResSet.InternalErrorInfo & "')"
                    snmpDev.LogMsg(logMessage)
                End If
                
                l_strTLName_ru = lportTab.PortDescription & ": " &  "QoS Dropped Bytes"
                l_strTLName_en = lportTab.PortDescription & ": " &  "QoS Dropped Bytes"
                
                If l_iPriority = HIGHPRIORITY Then 
                    TLError = snmpDev.ResSet.AddTrafficLight(l_strAlias, l_strTLName_ru, l_strTLName_en, "Maximum", ">", 0.0, 0.0, 0.0, 0.0)
                ElseIf l_iPriority = LOWPRIORITY Then 
                    TLError = snmpDev.ResSet.AddTrafficLight(l_strAlias, l_strTLName_ru, l_strTLName_en, "Maximum", ">", l_dTLByts_Rd, l_dTLByts_Rd_Bl, l_dTLByts_Yl, l_dTLByts_Yl_Bl)
                End If

                If l_iPriority = HIGHPRIORITY  Or l_iPriority = LOWPRIORITY Then 
                    logMessage = "VB script: AddTrafficLight: "  & l_strTLName_en
                    snmpDev.LogMsg(logMessage)
                    logMessage = "VB script: snmpDev.ResSets.AddTrafficLight return: " & TLError  & " ('" & snmpDev.ResSet.InternalErrorInfo & "')"
                    snmpDev.LogMsg(logMessage)
                End If
            End If
            
            '// change user type from "pure" to "hidden" for not monitored 
            '// instances (do not send it to sla agent)  
            '// and vice versa set "pure" user type for LOWPRIORITY and HIGHPRIORITY Rev: 1.4
            If l_iPriority = NOTMONITORED Then
                PrePolicyByte.UserType = HIDDEN_VAL
                PostPolicyByte.UserType = HIDDEN_VAL
                PrePolicyPkt.UserType = HIDDEN_VAL
            Else
                PrePolicyByte.UserType = PURE_VAL
                PostPolicyByte.UserType = PURE_VAL
                PrePolicyPkt.UserType = PURE_VAL
            End If                            
        End If
        
        lportTab.PortDescription = ""
    Next        

    snmpDev.ScriptError = SCRIPT_OK

    logMessage = "VBscript dump Device Data:"
    snmpDev.LogMsg(logMessage)

    snmpDev.Dump()

    logMessage = "+=========================================================="
    snmpDev.LogMsg(logMessage)

    logMessage = "VBscript discovery end, ip: " & snmpDev.IpAddress & " device: " & snmpDev.DeviceName
    snmpDev.LogMsg(logMessage)

End Sub


Sub OnDataReceived(ByRef snmpDev)
    'Stop
    logMessage = "+=========================================================="
    snmpDev.LogMsg(logMessage)

    logMessage = "VBscript OnDataReceived start, HostName:" & snmpDev.HostName & " ip: " & snmpDev.IpAddress & ":" & snmpDev.SnmpPort & " device: " & snmpDev.DeviceName
    snmpDev.LogMsg(logMessage)
    
	'SendTrap Init
	Set mySendTrap = New cSendTrap
	mySendTrap.Community = "prolan_ro"
	mySendTrap.AgentAddress = CStr(snmpDev.IpAddress)
	mySendTrap.TrapManagersAdd "127.0.0.1"	
	mySendTrap.LogFileName= snmpDev.ResSet.CommonProp.Attrib("snmp_trap_log").Value
	mySendTrap.GenericTrap = snmpEnterpriseSpecific
	mySendTrap.VariableClear
	mySendTrap.SpecificTrap = 6
	mySendTrap.Enterprise = "1.3.6.1.4.1.17184.166.1.15.1.1"
	'mySendTrap.VariableAdd "1.3.6.1.2.1.1.3", snmpOctetString, sysUpTime.Tag
	'mySendTrap.Send

    
    Set ScalarTab = snmpDev.ScalarTable
    Set TabSet = snmpDev.TablesSet
    
    Set l_ValsysUpTime = ScalarTab.Value("sysUpTime")
    Set l_ValsysUpTimeStor = ScalarTab.Value("sysUpTimeStorage")
    'Set l_ValAvailability = ScalarTab.Value("Availability")

    Set portTab = TabSet.PPortsTableByName("cbQosCMStatsEntry_static")
    Set portTab_Din = TabSet.PPortsTableByName("cbQosCMStatsEntry_dynamic")

    TablesCount = portTab.Count

    '// Set bad Value to all calculated Events
    ResetCalculatedEvenst(ScalarTab)

    For tIndx = 0 To TablesCount - 1
        Set TabOnPort = portTab.Table(tIndx)
        
        Set TotalPkts = TabOnPort.Value("cbQosCMPrePolicyPkt")
        Set TotalBytes = TabOnPort.Value("cbQosCMPrePolicyByte")
        Set DroppedPkts = TabOnPort.Value("cbQosCMDropPkt")
        Set DroppedBytes = TabOnPort.Value("cbQosCMDropByte")
        Set ErrorCount = TabOnPort.Value("error_count")

        l_iPriority = CInt(TotalPkts.Tag)

        if snmpDev.ScriptExecCount = 0 Then
            ErrorCount.NumericValue = 0
        End If
        
        If TotalPkts.NumericValue <> g_dBadValue And TotalBytes.NumericValue <> g_dBadValue And DroppedPkts.NumericValue <> g_dBadValue And DroppedBytes.NumericValue <> g_dBadValue Then
            
            'Stop
            DroppedPackets4Trap = 0
            DroppedBytes4Trap = 0
            
            DroppedPackets4Trap = SetDropped_Pkts_Bytes (snmpDev, ScalarTab, TotalPkts, DroppedPkts, "_Dropped_Pkts_PCNT")
            DroppedBytes4Trap = SetDropped_Pkts_Bytes (snmpDev, ScalarTab, TotalBytes, DroppedBytes, "_Dropped_Bytes_PCNT")
            
            ' Отправка объединенного трапа: и пакеты и байты
            If l_iPriority = HIGHPRIORITY And (DroppedPackets4Trap > 0 Or DroppedBytes4Trap > 0) Then
    	    	' Наши действия при наличие дропов на Высокоприоритетной очереди
    	    	mySendTrap.VariableClear
    	    	mySendTrap.VariableAdd "1.3.6.1.4.1.9.9.1000.1", snmpOctetString, GetShortNameQoSQueue (TotalPkts.Name)
    	    	mySendTrap.VariableAdd "1.3.6.1.4.1.9.9.1000.2", snmpInteger, DroppedPackets4Trap
    	    	mySendTrap.VariableAdd "1.3.6.1.4.1.9.9.1000.3", snmpInteger, DroppedBytes4Trap
    	    	mySendTrap.VariableAdd "1.3.6.1.4.1.9.9.1000.4", snmpOctetString, "Hi"
				mySendTrap.Send
        	End If

        	If l_iPriority = LOWPRIORITY And (DroppedBytes4Trap > snmpDev.ResSet.CommonProp.Attrib("drop_bytes_thres").Value Or DroppedPackets4Trap > snmpDev.ResSet.CommonProp.Attrib("drop_pkts_thres").Value) Then
        		' Наши действия при наличие дропов на Низкоприоритетной очереди превышающих порог
    	    	mySendTrap.VariableClear
    	    	mySendTrap.VariableAdd "1.3.6.1.4.1.9.9.1000.1", snmpOctetString, GetShortNameQoSQueue (TotalPkts.Name)
    	    	mySendTrap.VariableAdd "1.3.6.1.4.1.9.9.1000.2", snmpInteger, DroppedPackets4Trap
    	    	mySendTrap.VariableAdd "1.3.6.1.4.1.9.9.1000.3", snmpInteger, DroppedBytes4Trap
    	    	mySendTrap.VariableAdd "1.3.6.1.4.1.9.9.1000.4", snmpOctetString, "Lo"
				mySendTrap.Send
        	End If
        End If 
        
        '// check Queue avalabilyty 
        If l_ValsysUpTime.NumericValue <> g_dBadValue And l_iPriority <> NOTMONITORED Then
             
            If TotalBytes.NumericValue = g_dBadValue Or TotalPkts.NumericValue = g_dBadValue Then
                
                If snmpDev.ScriptExecCount > 0  And portTab.SnmpError <> -1 Then
                    ErrorCount.NumericValue = ErrorCount.NumericValue + 1

                    logMessage = "VBscript Script: Queue [" & GetShortNameQoSQueue(TotalPkts.Name) & "] is failed, but system time is done; Error Count:" & ErrorCount.NumericValue
                    snmpDev.LogMsg(logMessage)

                    If ErrorCount.NumericValue >= QUEUE_FAILED_COUNT Then
                        logMessage = "VBscript Script: Set Rediscovery flag; Error Count:" & ErrorCount.NumericValue
                        snmpDev.LogMsg(logMessage)
                        snmpDev.LaunchRediscovery = true
                        snmpDev.RediscoveryInitiator = true
                    End if
                    
                End if
            else
                If ErrorCount.NumericValue > 0 Then
                    logMessage = "VBscript Script: Reset Error Count"
                    snmpDev.LogMsg(logMessage)
                    ErrorCount.NumericValue = 0
                End if   
            End if    
        End if
        
        'TotalPkts.NumericValue  = g_dBadValue 
        'TotalBytes.NumericValue = g_dBadValue
    Next
  
    '// Rev: 1.4 Was system shutdown ?
    If l_ValsysUpTime.NumericValue <> g_dBadValue And l_ValsysUpTimeStor.NumericValue <> g_dBadValue Then
        '// 
        if l_ValsysUpTime.NumericValue < l_ValsysUpTimeStor.NumericValue Then
            logMessage = "VBscript Script: Current sysUpTime:" & l_ValsysUpTime.NumericValue & " Pev sysUpTime:" & l_ValsysUpTimeStor.NumericValue
            snmpDev.LogMsg(logMessage)
            
            logMessage = "VBscript Script: system shutdown ? - Set Rediscovery flag"
            snmpDev.LogMsg(logMessage)

            snmpDev.LaunchRediscovery = true
            snmpDev.RediscoveryInitiator = true
        End If
    End If
        
    '// Is new queues available
    If portTab.SnmpError <> -1 And portTab_Din.SnmpError <> -1 Then   
        If IsNewQueues(snmpDev, portTab_Din, portTab)  Then
            logMessage = "VBscript Script: New Queues are available - Set Rediscovery flag"
            snmpDev.LogMsg(logMessage)
        
            snmpDev.LaunchRediscovery = true
            snmpDev.RediscoveryInitiator = true
        End If
    End If
    
    '// Rev: 1.4 Store system time (valid value only)
    If l_ValsysUpTime.NumericValue <> g_dBadValue Then
        l_ValsysUpTimeStor.NumericValue = l_ValsysUpTime.NumericValue
    End if

    '// If Use Active Device Only is turn off and
    '// notactive device has wake up - Do rediscovery
    If portTab.SnmpError <> -1 And portTab_Din.SnmpError <> -1 Then   
        If snmpDev.UseActiveDeviceOnly = false and snmpDev.WasDiscovered = false Then
            If l_ValsysUpTime.NumericValue <> g_dBadValue And portTab_Din.Count > 0 Then

                logMessage = "VBscript Script: snmpDev has been responded - Set Rediscovery flag"
                snmpDev.LogMsg(logMessage)

                snmpDev.LaunchRediscovery = true
                snmpDev.RediscoveryInitiator = true
            End If    
        End If
    End If
    
    snmpDev.ScriptExecCount = snmpDev.ScriptExecCount + 1   

    logMessage = "VBscript Script Exec Count: " & snmpDev.ScriptExecCount
    snmpDev.LogMsg(logMessage)

    '// Forced rediscovery       
'    if snmpDev.ScriptExecCount = 4  Then
'        snmpDev.LaunchRediscovery = true
'        snmpDev.RediscoveryInitiator = true
'    End If

    logMessage = "+=========================================================="
    snmpDev.LogMsg(logMessage)

    logMessage = "VBscript OnDataReceived End, HostName:" & snmpDev.HostName & " ip: " & snmpDev.IpAddress & ":" & snmpDev.SnmpPort & " device: " & snmpDev.DeviceName
    snmpDev.LogMsg(logMessage)

End Sub

Sub ResetCalculatedEvenst(ByRef ScalarTab)

    l_iValCount =  ScalarTab.Count

    For l_iIndx = 0 To l_iValCount - 1
        Set SValue = ScalarTab.ValueByIndx(l_iIndx)
        if SValue.UserType = CALCULATED_VAL Then
            SValue.NumericValue = g_dBadValue
        End If
    Next
End Sub

Sub SetPerCent(ByRef snmpDev, ByRef ScalarTab, ByRef TotalCounter, ByRef DroppedCounter, CouterType, LastNamePart)
    On Error Resume Next
    
    ' CouterType = "_Dropped_Pkts_PCNT" Or CouterType = "_Dropped_Bytes_PCNT"
    ' 
    
    l_strName = TotalCounter.Name
    
    l_strAlias = snmpDev.IpAddress & "_" & snmpDev.SnmpPort
    l_strAlias = l_strAlias & "_" & TotalCounter.OID & CouterType 
    
    Set CalcVal = ScalarTab.Value(l_strAlias)
    If   Not (CalcVal Is Nothing) Then
        ' Считаем процент отброшенных пакетов или байт (в зависимости от CouterType)
        If TotalCounter.NumericValue > 0.0 Then
            CalcVal.NumericValue =  (DroppedCounter.NumericValue*100.0)/TotalCounter.NumericValue
        Else
            CalcVal.NumericValue = 0
        End If
        l_strMessage = "Val: '" & CalcVal.Name & "' :" & CalcVal.NumericValue
        snmpDev.LogMsg(l_strMessage)
        
        l_iPriority = CInt(CalcVal.Tag)
        
        ' Шлем трапы только при получении данных по пакетам (не по байтам)
        If CouterType = "_Dropped_Bytes_PCNT" Then
        	
        	' Имя очереди - CalcVal.Name ("[62.141.95.76] Multilink1|pmout|snmp: QoS Dropped Packets (%)")
        	' Сброшено пакетов - DroppedCounter.NumericValue
        	' Адрес устройства - snmpDev.IpAddress
        	
	        If l_iPriority = HIGHPRIORITY And CalcVal.NumericValue > 0 Then
    	    	' Наши действия при наличие дропов на Высокоприоритетной очереди
    	    	mySendTrap.VariableClear
    	    	mySendTrap.VariableAdd "1.3.6.1.4.1.9.9.1000.1", snmpOctetString, GetShortNameQoSQueue (CalcVal.Name)
    	    	mySendTrap.VariableAdd "1.3.6.1.4.1.9.9.1000.2", snmpInteger, DroppedCounter.NumericValue
    	    	mySendTrap.VariableAdd "1.3.6.1.4.1.9.9.1000.3", snmpOctetString, CStr(Round(CalcVal.NumericValue, 2)) & "%"
    	    	mySendTrap.VariableAdd "1.3.6.1.4.1.9.9.1000.4", snmpOctetString, "Hi"
				mySendTrap.Send
        
        	End If

        	If l_iPriority = LOWPRIORITY and CalcVal.NumericValue > snmpDev.ResSet.CommonProp.Attrib("drop_bytes_thres").Value Then
        		' Наши действия при наличие дропов на Низкоприоритетной очереди превышающих порог
    	    	mySendTrap.VariableClear
    	    	mySendTrap.VariableAdd "1.3.6.1.4.1.9.9.1000.1", snmpOctetString, GetShortNameQoSQueue (CalcVal.Name)
    	    	mySendTrap.VariableAdd "1.3.6.1.4.1.9.9.1000.2", snmpInteger, DroppedCounter.NumericValue
    	    	mySendTrap.VariableAdd "1.3.6.1.4.1.9.9.1000.3", snmpOctetString, CStr(Round(CalcVal.NumericValue, 2)) & "%"
    	    	mySendTrap.VariableAdd "1.3.6.1.4.1.9.9.1000.4", snmpOctetString, "Lo"
				mySendTrap.Send
        	End If
        End If

    End If    
End Sub

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Функция расчета сброшенных байт и пакетов в АБСОЛЮТНЫХ значениях    '
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function SetDropped_Pkts_Bytes(ByRef snmpDev, ByRef ScalarTab, ByRef TotalCounter, ByRef DroppedCounter, CounterType)
    On Error Resume Next
	Dim l_strName, l_strAlias, CalcVal, DroppedValue
    
    DroppedValue = 0
    ' CounterType = "_Dropped_Pkts_PCNT" Or CounterType = "_Dropped_Bytes_PCNT"
    
    l_strName = TotalCounter.Name
    l_strAlias = snmpDev.IpAddress & "_" & snmpDev.SnmpPort & "_" & TotalCounter.OID & CounterType 
    
    ' CalcVal - вычисляемое значение. Здесь будет сохранено число сброшенных пакетов или байт
    Set CalcVal = ScalarTab.Value(l_strAlias)
    
    If Not (CalcVal Is Nothing) And DroppedCounter.NumericValue <> g_dBadValue And DroppedCounter.PrevValue <> g_dBadValue Then
        ' Считаем число отброшенных пакетов или байт за интервал усреднения (в зависимости от CounterType)
        If DroppedCounter.NumericValue > DroppedCounter.PrevValue Then
            CalcVal.NumericValue = DroppedCounter.NumericValue - DroppedCounter.PrevValue
        Else
            CalcVal.NumericValue = 0
        End If
      
        DroppedValue = CalcVal.NumericValue
        l_strMessage = "Val: '" & CalcVal.Name & "' :" & CalcVal.NumericValue
        snmpDev.LogMsg(l_strMessage)
    End If
    SetDropped_Pkts_Bytes = DroppedValue
End Function


Function IsNewQueues(ByRef snmpDev, portTab_Din, portTab_static) 

    l_bIsNewQueues = False

    portTab_Din.InitInstancesIterations()
    
    Set TabOnPort = portTab_Din.CurrTable
    
    Do While Not (TabOnPort Is Nothing)
        l_strInstance = TabOnPort.Instance
        If Not IsInstncInStaticTable(snmpDev, l_strInstance, portTab_static) Then
           l_bIsNewQueues = True
           Exit Do
        End If
        
        portTab_Din.NextTable()
        Set TabOnPort = portTab_Din.CurrTable
   Loop

    IsNewQueues = l_bIsNewQueues
End Function

Function IsInstncInStaticTable(ByRef snmpDev, instanse_din, portTab_static) 

    l_bIsInstncInStaticTable = False

    portTab_static.InitInstancesIterations()
    
    Set TabOnPort = portTab_static.CurrTable
    
    Do While Not (TabOnPort Is Nothing)
        l_strInstance = TabOnPort.Instance
        l_iCompare = InStr(1, l_strInstance,  instanse_din, 1)
        If l_iCompare > 0 Then
           l_bIsInstncInStaticTable = True
           Exit Do
        End If
        
        portTab_static.NextTable()
        Set TabOnPort = portTab_static.CurrTable
   Loop

    IsInstncInStaticTable = l_bIsInstncInStaticTable
End Function

'// Rev: 1.4  change user tupe 
Sub SetUserType(ByRef snmpDev, ByRef portTab, iPriority, iStartIndx)

    l_iTablesCount = portTab.Count
    
    For tIndx = iStartIndx To l_iTablesCount - 1
        Set lportTab = portTab.Table(tIndx)
        'Set PortDescrValue = lportTab.Value("cbQosCMPrePolicyPkt")
        Set PrePolicyPkt = lportTab.Value("cbQosCMPrePolicyPkt")
        Set PrePolicyByte = lportTab.Value("cbQosCMPrePolicyByte")
        Set PostPolicyByte = lportTab.Value("cbQosCMPostPolicyByte")
        
        'PortDescrValue.Tag = CStr(iPriority)
        PrePolicyPkt.Tag = CStr(iPriority)
        
        
        If iPriority = NOTMONITORED Then
            PrePolicyPkt.UserType = HIDDEN_VAL
            PrePolicyByte.UserType = HIDDEN_VAL
            PostPolicyByte.UserType = HIDDEN_VAL
        Else
            PrePolicyPkt.UserType = PURE_VAL
            PrePolicyByte.UserType = PURE_VAL
            PostPolicyByte.UserType = PURE_VAL
        End If                            
    Next

End Sub



Sub Other_Calculate(ByRef snmpDev, ByRef portTab_Din, ByRef portTab_Static, ByRef ScalarTab)

    l_dTotalPkts = 0
    l_dTotalBytes = 0
    Dropped_Pkts = g_dBadValue
    Dropped_Bytes = g_dBadValue
    l_bCountsInit = False

    TablesCount = portTab_Din.Count
    For tIndx = 0 To TablesCount - 1
        Set TabOnPort = portTab_Din.Table(tIndx)
        
        '// If there are not current instance in statitic table, then
        '// this instance is "Other"
        l_bRemoved = IsRemoved(snmpDev, portTab_Static, TabOnPort.Instance) 
        If l_bRemoved Then 

            Set TotalPkts = TabOnPort.Value("cbQosCMPrePolicyPkt")
            Set TotalBytes = TabOnPort.Value("cbQosCMPrePolicyByte")
            Set DroppedPkts = TabOnPort.Value("cbQosCMDropPkt")
            Set DroppedBytes = TabOnPort.Value("cbQosCMDropByte")
            
            If TotalPkts.NumericValue <> g_dBadValue And TotalBytes.NumericValue <> g_dBadValue And DroppedPkts.NumericValue <> g_dBadValue And DroppedBytes.NumericValue <> g_dBadValue Then
                If Not l_bCountsInit Then
                Dropped_Pkts = 0
                Dropped_Bytes = 0
                l_bCountsInit = True
                End If
                
                l_dTotalPkts =  l_dTotalPkts + TotalPkts.NumericValue
                l_dTotalBytes = l_dTotalBytes + TotalBytes.NumericValue               
                Dropped_Pkts = Dropped_Pkts + DroppedPkts.NumericValue
                Dropped_Bytes = Dropped_Bytes + DroppedBytes.NumericValue
            End If
            
        End If            
    Next

    If Dropped_Pkts <> g_dBadValue And l_dTotalPkts > 0 Then
        Set CalcVal = ScalarTab.Value("Other_Dropped_Pkts_PCNT")
        CalcVal.NumericValue = Dropped_Pkts*100.0/l_dTotalPkts
    End If
    If Dropped_Bytes <> g_dBadValue And l_dTotalBytes > 0 Then
        Set CalcVal = ScalarTab.Value("Other_Dropped_Bytes_PCNT")
        CalcVal.NumericValue = Dropped_Bytes*100.0/l_dTotalBytes
    End If

End Sub

Function GetInstance(strOID, iNum)

    Oid_Arr = Split(strOID, ".", -1, 1)
    l_iLenArr = UBound(Oid_Arr)

    If iNum = 0 Then
        l_strInst = Oid_Arr(l_iLenArr-1)
    Else
        l_strInst = Oid_Arr(l_iLenArr)
    End If
            
GetInstance = l_strInst
End Function

Function InitSnmpEngine(ByRef snmpDev, ByRef SnmpRQ)

SnmpRQ.ReadCommunity    = snmpDev.Community
SnmpRQ.IpAddress        = snmpDev.IpAddress
SnmpRQ.SnmpPort         = snmpDev.SnmpPort
SnmpRQ.SnmpLevel        = snmpDev.SNMPVer
SnmpRQ.SnmpTimeout      = snmpDev.SnmpTimeout
SnmpRQ.SnmpRetryCount   = snmpDev.SnmpRetryCount
InitSnmpEngine = 0

l_LogInstance = snmpDev.GetLogInstance

l_lRetCode = SnmpRQ.Init(l_LogInstance)

If l_lRetCode = 0 Then
    l_lRetCode = SnmpRQ.CreateSession()
End If
InitSnmpEngine = l_lRetCode

End Function

Function GetDescription(ByRef snmpDev, ByRef l_SnmpRQ, PolicyIndx, ObjIndex, ByRef iDataPriority)

    On Error Resume Next
    
    l_strPMComposName = ""
    GetDescription = ""
    
    l_bCMDesrMatched = false
    l_iIterat = 0
    
    Do
        l_iIterat = l_iIterat + 1
        
        l_iObjType = GetObjType(snmpDev, l_SnmpRQ, PolicyIndx, ObjIndex)
        If( Err.Number <> 0 ) Then
            Exit Function
        End If

        l_strParentIndx = GetParentIndx(snmpDev, l_SnmpRQ, PolicyIndx, ObjIndex)
        If( Err.Number <> 0 ) Then
            Exit Function
        End If
        
        Select Case l_iObjType
            Case POLICYMAP
                logMessage = "Get Policy Map name by " & PolicyIndx & "." & ObjIndex
                snmpDev.LogMsg(logMessage)
                
                l_strDescr = GetPMName(snmpDev, l_SnmpRQ, PolicyIndx, ObjIndex)
                If( Err.Number <> 0 ) Then
                    Exit Function
                End If
                logMessage = "Policy name: " & Chr(34) & l_strDescr & Chr(34)
                snmpDev.LogMsg(logMessage)
                logMessage = PolicyIndx & "." & ObjIndex & " " & Chr(34) & l_strDescr & Chr(34)
                snmpDev.SendNotifyMsg(logMessage)
                
                l_strPMDescr = GetPMDescription(snmpDev, l_SnmpRQ, PolicyIndx, ObjIndex)
                If( Err.Number <> 0 ) Then
                    Exit Function
                End If
                logMessage = "Policy name: " & Chr(34) & l_strDescr & Chr(34) & " Policy description: " & Chr(34) & l_strPMDescr & Chr(34)
                snmpDev.LogMsg(logMessage)
                
                If IsDataInFilter(g_descr_pm_filter, l_strPMDescr) Then
                    l_bCMDesrMatched = true
                    logMessage = "Policy description: " & Chr(34) & l_strPMDescr & Chr(34) & " is in filter"
                    snmpDev.LogMsg(logMessage)
                Else
                    l_bCMDesrMatched = false
                    logMessage = "Policy description: " & Chr(34) & l_strPMDescr & Chr(34) & " is not in filter"
                    snmpDev.LogMsg(logMessage)
                End If
                
                If l_strParentIndx = 0 Then
                    
                    If Not snmpDev.ResSet.CommonProp.Attrib("add_poicyname").Value Then
                        logMessage = "Policy : " & Chr(34) & l_strDescr & Chr(34) & " not add to event name"
                        snmpDev.LogMsg(logMessage)
                        l_strDescr = ""
                    End If
                    
                    logMessage = "Get Interface name by " & PolicyIndx
                    snmpDev.LogMsg(logMessage)

                    l_strDirection = ""
                    l_strIfDescr = GetInterface(snmpDev, l_strDirection, l_SnmpRQ, PolicyIndx)
                    If( Err.Number <> 0 ) Then
                        Exit Function
                    End If
                    
                    logMessage = "Interface name: " & Chr(34) & l_strIfDescr & Chr(34)
                    snmpDev.LogMsg(logMessage)
                    
                    logMessage = PolicyIndx & " " & Chr(34) & l_strIfDescr & Chr(34)
                    snmpDev.SendNotifyMsg(logMessage)
                    
                    If IsDataInFilter(g_if_filter, l_strIfDescr) = False Then
                        iDataPriority = NOTMONITORED
                    End If
                    
                    l_strIfDescr = IfSubst(g_subst_list, l_strIfDescr)
                    l_strIfDescr = l_strIfDescr & "|" & l_strDirection
                    
                End If
                
            Case CLASSMAP    
                logMessage = "Get Class Map name by " & PolicyIndx & "." & ObjIndex
                snmpDev.LogMsg(logMessage)

                l_strDescr = GetCMDescription(snmpDev, l_SnmpRQ, PolicyIndx, ObjIndex)
                If( Err.Number <> 0 ) Then
                    Exit Function
                End If
                
                logMessage = "Class Map name: " & Chr(34) & l_strDescr & Chr(34)
                snmpDev.LogMsg(logMessage)
                logMessage = PolicyIndx & "." & ObjIndex & " " & Chr(34) & l_strDescr & Chr(34)
                snmpDev.SendNotifyMsg(logMessage)
                
                If l_iIterat = 1 Then 
                    If IsDataInFilter(g_hpr_clmap_filter, l_strDescr) = True Then
                        iDataPriority = HIGHPRIORITY
                    ElseIf IsDataInFilter(g_lpr_clmap_filter, l_strDescr) = True Then
                        iDataPriority = LOWPRIORITY
                    Else
                        iDataPriority = NOTMONITORED
                        logMessage = Chr(34) & l_strDescr & Chr(34) & " Disable" 
                        snmpDev.SendNotifyMsg(logMessage)
                        logMessage = "Not Monitored: " & Chr(34) & l_strDescr & Chr(34)
                        snmpDev.LogMsg(logMessage)
                        Exit Function
                    End If     
                End If
                
            Case Else
                logMessage = "Parent object is not PolicyMap or ClassMap type: " & l_iObjType
                snmpDev.LogMsg(logMessage)
            
                Err.Raise vbObjectError + 1, "GetDescription", "Non supported router configuration"
                Exit Function
            
        End Select     
        
        If Len(l_strPMComposName) = 0 Then
            l_strPMComposName = l_strDescr
        ElseIf Len(l_strDescr) > 0 Then
            l_strPMComposName = l_strDescr & "|" & l_strPMComposName
        End If            
        ObjIndex = l_strParentIndx
        
    Loop While l_strParentIndx <> 0
    
    GetDescription = l_strIfDescr & "|" & l_strPMComposName
    
    if Not l_bCMDesrMatched Then
        iDataPriority = NOTMONITORED
    End If
    
    If iDataPriority = HIGHPRIORITY Then
        logMessage = "High Priority: " & GetDescription
        snmpDev.LogMsg(logMessage)
    ElseIf iDataPriority = LOWPRIORITY Then        
        logMessage = "Low Priority: " & GetDescription
        snmpDev.LogMsg(logMessage)
    Else
        logMessage = "Not Monitored: " & GetDescription
        snmpDev.LogMsg(logMessage)
    End If    
      
End Function

Function GetCMDescription(ByRef snmpDev, ByRef SnmpRQ, PolicyIndx, ObjIndex)

    l_strConfigIndx = GetConfigIndx(snmpDev, SnmpRQ, PolicyIndx, ObjIndex)
    If( Err.Number <> 0 ) Then
        Exit Function
    End If

    l_strCMName = GetCMName(snmpDev, SnmpRQ, l_strConfigIndx)
    If( Err.Number <> 0 ) Then
        Exit Function
    End If

    GetCMDescription = l_strCMName
End Function

Function GetParentIndx(ByRef snmpDev, ByRef SnmpRQ, PolicyIndx, ObjIndex)
    l_strDataOID = "1.3.6.1.4.1.9.9.166.1.5.1.1.4." & PolicyIndx & "." & ObjIndex
    l_strParentIndx = SnmpRQ.SnmpGetFromMem(l_strDataOID, snmpErr)
    If snmpErr <> 0 Then 
        l_strErr = SnmpRQ.ErrorInfo
        l_strErr = "Snmp error: " & l_strErr
        Err.Raise vbObjectError + 1, "GetDescription", l_strErr
        Exit Function
    End If
    GetParentIndx = l_strParentIndx
End Function

Function GetConfigIndx(ByRef snmpDev, ByRef SnmpRQ, PolicyIndx, ObjIndex)
    l_strDataOID = "1.3.6.1.4.1.9.9.166.1.5.1.1.2." & PolicyIndx & "." & ObjIndex
    l_strConfigIndx = SnmpRQ.SnmpGetFromMem(l_strDataOID, snmpErr)
    If snmpErr <> 0 Then 
        l_strErr = SnmpRQ.SnmpRQ.ErrorInfo
        l_strErr = "Snmp error: " & l_strErr
        Err.Raise vbObjectError + 1, "GetDescription", l_strErr
        Exit Function
    End If
    GetConfigIndx = l_strConfigIndx
End Function

Function GetObjType(ByRef snmpDev, ByRef SnmpRQ, PolicyIndx, ObjIndex)
    l_strDataOID = "1.3.6.1.4.1.9.9.166.1.5.1.1.3." & PolicyIndx & "." & ObjIndex
    
    l_iObjType = SnmpRQ.SnmpGetFromMem(l_strDataOID, snmpErr)
    If snmpErr <> 0 Then 
        l_strErr = SnmpRQ.ErrorInfo
        l_strErr = "Snmp error: " & l_strErr
        Err.Raise vbObjectError + 1, "GetDescription", l_strErr
        Exit Function
    End If
    GetObjType = l_iObjType
End Function

Function GetCMName(ByRef snmpDev, ByRef SnmpRQ, ObjIndex)
    l_strDataOID = "1.3.6.1.4.1.9.9.166.1.7.1.1.1." &  ObjIndex
    l_strName = SnmpRQ.SnmpGetFromMem(l_strDataOID, snmpErr)
    If snmpErr <> 0 Then 
        l_strErr = SnmpRQ.ErrorInfo
        l_strErr = "Snmp error: " & l_strErr
        Err.Raise vbObjectError + 1, "GetDescription", l_strErr
        Exit Function
    End If
    GetCMName = l_strName
End Function

Function GetInterface(ByRef snmpDev, ByRef l_strDirection, ByRef SnmpRQ, ObjIndex)
    
    l_strDataOID = "1.3.6.1.4.1.9.9.166.1.1.1.1.2." &  ObjIndex
    'l_icbQosIfType = SnmpRQ.SnmpGetFromMem(l_strDataOID, snmpErr)

    l_icbQosIfType = SnmpRQ.SnmpGetFromMem(l_strDataOID, snmpErr)

    If snmpErr <> 0 Then 
        l_strErr = SnmpRQ.ErrorInfo
        l_strErr = "Snmp error: " & l_strErr
        Err.Raise vbObjectError + 1, "GetDescription", l_strErr
        Exit Function
    End If

    If l_icbQosIfType = MAININTERFACE Then
       l_strIfType = "maininterface" 
    ElseIf  l_icbQosPolicyDirection = SUBINTERFACE Then
       l_strIfType = "subinterface" 
    ElseIf  l_icbQosPolicyDirection = FRDLCI Then
       l_strIfType = "frDLCI" 
    ElseIf  l_icbQosPolicyDirection = ATMPVC Then
       l_strIfType = "atmPVC"
    Else    
       l_strIfType = "" & l_icbQosPolicyDirection 
    End If
    
    l_strDataOID = "1.3.6.1.4.1.9.9.166.1.1.1.1.3." &  ObjIndex
    l_icbQosPolicyDirection = SnmpRQ.SnmpGetFromMem(l_strDataOID, snmpErr)

    If snmpErr <> 0 Then 
        l_strErr = SnmpRQ.ErrorInfo
        l_strErr = "Snmp error: " & l_strErr
        Err.Raise vbObjectError + 1, "GetDescription", l_strErr
        Exit Function
    End If
    If l_icbQosPolicyDirection = OUTPUT Then
       l_strDirection = "out" 
    ElseIf  l_icbQosPolicyDirection = INPUT Then
       l_strDirection = "in"
    End If
    
    l_strDataOID = "1.3.6.1.4.1.9.9.166.1.1.1.1.4." &  ObjIndex
    l_icbQosIfIndex = SnmpRQ.SnmpGetFromMem(l_strDataOID, snmpErr)

    If snmpErr <> 0 Then 
        l_strErr = SnmpRQ.ErrorInfo
        l_strErr = "Snmp error: " & l_strErr
        Err.Raise vbObjectError + 1, "GetDescription", l_strErr
        Exit Function
    End If
    
    l_strDataOID = "1.3.6.1.2.1.2.2.1.2." & l_icbQosIfIndex
    l_strIfName = SnmpRQ.SnmpGetFromMem(l_strDataOID, snmpErr)
    
    If snmpErr <> 0 Then 
        l_strErr = SnmpRQ.ErrorInfo
        l_strErr = "Snmp error: " & l_strErr
        Err.Raise vbObjectError + 1, "GetDescription", l_strErr
        Exit Function
    End If
 
    'l_strName = l_strIfType & "/" & l_strDirection & "/" & Chr(39) &  l_strIfName & Chr(39)
    l_strName = l_strIfName
    
    GetInterface = l_strName
End Function

Function GetPMName(ByRef snmpDev, ByRef SnmpRQ, PolicyIndx, ObjIndex)
    
    On Error Resume Next
    
    l_strConfigIndx = GetConfigIndx(snmpDev, SnmpRQ, PolicyIndx, ObjIndex)
    If( Err.Number <> 0 ) Then
        Exit Function
    End If
    
    l_strDataOID = "1.3.6.1.4.1.9.9.166.1.6.1.1.1." &  l_strConfigIndx

    l_strPMName = SnmpRQ.SnmpGetFromMem(l_strDataOID, snmpErr)
    If snmpErr <> 0 Then 
        l_strErr = SnmpRQ.ErrorInfo
        l_strErr = "Snmp error: " & l_strErr
        Err.Raise vbObjectError + 1, "GetDescription", l_strErr
        Exit Function
    End If
    
    GetPMName = l_strPMName
End Function

Function GetPMDescription(ByRef snmpDev, ByRef SnmpRQ, PolicyIndx, ObjIndex)
    
    On Error Resume Next
    
    l_strConfigIndx = GetConfigIndx(snmpDev, SnmpRQ, PolicyIndx, ObjIndex)
    If( Err.Number <> 0 ) Then
        Exit Function
    End If
    
    l_strDataOID = "1.3.6.1.4.1.9.9.166.1.6.1.1.2." &  l_strConfigIndx
    l_strPMDescription = SnmpRQ.SnmpGetFromMem(l_strDataOID, snmpErr)

    If snmpErr <> 0 Then 
        l_strErr = SnmpRQ.ErrorInfo
        l_strErr = "Snmp error: " & l_strErr
        Err.Raise vbObjectError + 1, "GetDescription", l_strErr
        Exit Function
    End If
    
    If IsNumeric(l_strPMDescription) Then
        l_strPMDescription = ""
    End If    
    
    GetPMDescription = l_strPMDescription
End Function

Function ParseFilter(FilterList)
    
    l_FilterArray = Split(FilterList, ",", -1, 1)
       
    ParseFilter = l_FilterArray
End Function

Function ParseSubstExpress(l_strExpress)
    ParseSubstExpress = Split(l_strExpress, ",", -1, 1)
End Function

Function IfSubst(l_SubstArr, ifName)

    l_strOut = ifName

    l_iCount = UBound(l_SubstArr)
    For tIndx = 0 To l_iCount
        l_SubstPair = Split(l_SubstArr(tIndx), "=", -1, 1)
        If UBound(l_SubstArr) > 0 Then
            
            l_strPattern = Trim(l_SubstPair(0))
            l_strSubstExpr = Trim(l_SubstPair(1))
            
            l_iStartPos = InStr(LCase(ifName), LCase(l_strPattern))
            
            
            If l_iStartPos > 0 Then 
                l_ilPatternLen = Len(l_strPattern)
                l_iEndPos = l_iStartPos + l_ilPatternLen
                l_strBf = Mid(ifName, 1, l_iStartPos-1)
                l_strAf = Mid(ifName, l_iEndPos)
                
                l_strOut = l_strBf & l_strSubstExpr & l_strAf
                Exit For
            End If
            
        End If
    Next   

    IfSubst = l_strOut
End Function

Function IsDataInFilter(FilterList, CompareStr)
    
    IsDataInFilter = False
    
    'If FilterList = BLANK_STRING Then
    '    Exit Function
    'End If
    
    
    l_iCount = UBound(FilterList)
    
    For tIndx = 0 To l_iCount
        l_strListItem = LCase(FilterList(tIndx))
        l_strCompareStr = LCase(CompareStr)
        
        If InStr(1,l_strListItem,"*",1) > 0 Then 
            IsDataInFilter = True
            Exit Function
        ElseIf InStr(1,l_strCompareStr,l_strListItem,1) > 0 Then 
            IsDataInFilter = True
            Exit Function
        End If
    Next
End Function

' Return "Multilink1|snmp" from "[62.141.95.76] Multilink1|pmout|snmp: QoS Dropped Packets (%)"
Function GetShortNameQoSQueue (l_FullString)
	Dim beginA, beginB, InterfaceName, ClassName

	beginA = InStr(l_FullString,"]") + 2
	beginB = InStr(l_FullString,"|")
	InterfaceName = Mid (l_FullString, beginA, beginB - beginA)

	beginB = InStrRev(l_FullString,":")
	beginA = InStrRev(l_FullString,"|") + 1
	ClassName = Mid (l_FullString, beginA, beginB - beginA)

	GetShortNameQoSQueue = InterfaceName & "|" & ClassName
End Function

Function CreateSnmpManager(ByRef snmpDev, ByRef l_SnmpRQ, ByRef TabSet)
    On Error Resume Next

    Set l_SnmpRQ = CreateObject("SnmpManagerComponent.PLSnmpManager.1")
    If Err.Number <> 0 Then 
        l_strErr = Err.Description
        l_strErr = "VBscript error: " & l_strErr
        
		logMessage = "VBScript: Cannot create SnmpManagerComponent err: " & Err.Number & " " & Err.Description
		snmpDev.LogMsg(logMessage)
        
        Err.Raise vbObjectError + 1, "GetDescription", l_strErr
        Exit Function
    End If

    snmpErr = InitSnmpEngine(snmpDev, l_SnmpRQ)
      If snmpErr <> 0 Then 
        l_strErr = l_SnmpRQ.ErrorInfo
        l_strErr = "Snmp error: " & l_strErr

		logMessage = "VBScript: Cannot init SnmpManagerComponent " & l_strErr
		snmpDev.LogMsg(logMessage)

        Err.Raise vbObjectError + 1, "GetDescription", l_strErr
        Exit Function
    End If

    l_SnmpRQ.SetTablesSet TabSet
    CreateSnmpManager = true

End Function


Class cSendTrap
	Private TrapAgent, fso, l_LogFileName, l_MaxRepeat

	Private Sub Class_Initialize   ' Setup Initialize event.
    	Set fso = CreateObject("Scripting.FileSystemObject")
    	l_LogFileName = "c:\SendSNMPTrap_" & Timer & ".Log"
    	l_MaxRepeat = 15
    	Set TrapAgent = CreateObject("Dart.Agent.1")
		TrapAgent.Open
		TrapAgent.Message.Reset
		TrapAgent.Message.Community = "prolan_ro"
		TrapAgent.Message.Type = 36 'Trap version 1 message
		'TrapAgent.Message.Type = 71 'Trap version 2 message
		TrapAgent.Message.GenericTrap = 6 'The SpecificTrap property contains information on the trap.
		TrapAgent.Message.SpecificTrap = 0
		TrapAgent.Message.Enterprise = "1.3.6.1.4.1.9"
		TrapAgent.Message.AgentAddress = "127.0.0.1"
		TrapAgent.TrapManagers.Clear
	End Sub

	Private Sub Class_Terminate   ' Setup Terminate event.
		TrapAgent.Close
		Set TrapAgent = Nothing
	End Sub
	
	Private Function Write2Log (l_txt)
		'Const ForReading = 1	' Open a file for reading only. You can't write to this file.
		'Const ForWriting =  2	' Open a file for writing.
		'Const ForAppending = 8	' Open a file and write to the end of the file.
		Dim LogFile, CountRepeat
		On Error Resume Next
		CountRepeat = 0
		Do
			Err.Clear
			Set LogFile = fso.OpenTextFile(l_LogFileName, 8, True)
			CountRepeat = CountRepeat + 1
		Loop Until (CountRepeat => l_MaxRepeat) or (Err.Number = 0)

		LogFile.WriteLine(Now & ": " & l_txt)
		LogFile.Close
		If Err.Number = 0 Then Write2Log = True Else Write2Log = False
	End Function
	
	Public Property Get LogFileName
   		LogFileName = l_LogFileName
	End Property 
    Public Property Let LogFileName(ByVal lValue)
        l_LogFileName = lValue
    End Property

	Public Property Get Community
   		Community = TrapAgent.Message.Community
	End Property 
    Public Property Let Community(ByVal lValue)
        TrapAgent.Message.Community = lValue
    End Property

	Public Property Get GenericTrap
   		GenericTrap = TrapAgent.Message.GenericTrap
	End Property 
    Public Property Let GenericTrap(ByVal lValue)
        TrapAgent.Message.GenericTrap = lValue
    End Property

	Public Property Get SpecificTrap
   		SpecificTrap = TrapAgent.Message.SpecificTrap
	End Property 
    Public Property Let SpecificTrap(ByVal lValue)
        TrapAgent.Message.SpecificTrap = lValue
    End Property

	Public Property Get Enterprise
   		Enterprise = TrapAgent.Message.Enterprise
	End Property 
    Public Property Let Enterprise(ByVal lValue)
        TrapAgent.Message.Enterprise = lValue
    End Property

	Public Property Get AgentAddress
   		AgentAddress = TrapAgent.Message.AgentAddress
	End Property 
    Public Property Let AgentAddress(ByVal lValue)
        TrapAgent.Message.AgentAddress = lValue
    End Property

	Public Property Get MaxRepeat
   		MaxRepeat = l_MaxRepeat
	End Property 
    Public Property Let MaxRepeat(ByVal lValue)
        l_MaxRepeat = lValue
    End Property


	Public Sub VariableAdd (ByVal l_oid, ByVal l_type, ByVal l_Value)
		Dim v
		
		Set v = CreateObject("Dart.SnmpVariable.1")
		v.Oid = l_oid
		v.Type = l_type
		v.Value = l_Value
		TrapAgent.Message.Variables.Add(v)
		Set v = Nothing
	End Sub
	
	Public Sub VariableClear
		TrapAgent.Message.Variables.Clear
	End Sub

	Public Sub TrapManagersAdd (ByVal l_ipaddress)
		TrapAgent.TrapManagers.Add l_ipaddress
	End Sub

	Public Sub TrapManagersClear
		TrapAgent.TrapManagers.Clear
	End Sub

	Public Sub Send
		Call TrapSpeciality
		TrapAgent.Send
	End Sub
	
	Sub TrapSpeciality
		Dim i
		On Error Resume Next
		Write2Log (" +++++++++++++ Start Send SNMP Trap +++++++++++++")
		Write2Log ("Community = '" & TrapAgent.Message.Community & "'")
		Write2Log ("Enterprise = '" & TrapAgent.Message.Enterprise & "'")
		Write2Log ("Type = '" & TrapAgent.Message.Type & "'")
		Write2Log ("GenericTrap = '" & TrapAgent.Message.GenericTrap & "'")
		Write2Log ("SpecificTrap = '" & TrapAgent.Message.SpecificTrap & "'")
		Write2Log ("AgentAddress = '" & TrapAgent.Message.AgentAddress & "'")
		Write2Log ("LocalAddress = '" & TrapAgent.LocalAddress & "'")
		
		For i = 1 To TrapAgent.TrapManagers.Count
			Write2Log ("Trap Manager - " & i & ": " & TrapAgent.TrapManagers.Item(i))
		Next
		
		For i = 1 To TrapAgent.Message.Variables.Count
			Write2Log (i & ")" & TrapAgent.Message.Variables(i).Oid & " = '" & TrapAgent.Message.Variables(i).Value & "'")
		Next
		Write2Log (" +++++++++++++ End Send SNMP Trap +++++++++++++")
	End Sub


End Class

 
--></Script>
    </xTest>
</document>
