<?xml version="1.0" encoding="windows-1251" ?>
<document type="SelFTrendxTest" version="0.0" xmlns:m="xTest">
    <xTest type="SNMP" alias="CiscoVPN" 
           TitleRus="Мониторинг каналов на основе Cisco VPN" 
           TitleEng="Cisco VPN channels monitoring"
           TitleRootRus="Тесты оценки «здоровья» оборудования, поддерживающего SNMP" 
           TitleRootEng="SNMP Devices Performance Tests"
           TrafficLightsName="Cisco VPN channels monitoring"
           Version="1.1">
        <Files>
            <File type="conf" name="SNMP.CiscoVpn.XFiles.xml" />
            <File type="help" name="SLA-ONProbeHelp.html" />
            <File type="dll" name="x_snmp.dll" />
        </Files>
      <Keywords>
        <Keyword>SNMP</Keyword>
        <Keyword>Cisco</Keyword>
        <Keyword>Маршрутизатор</Keyword>
        <Keyword>VPN</Keyword>
        <Keyword>IPsec</Keyword>
      </Keywords>
      <xTestProps>
            <aver_interval_duration_sec>60</aver_interval_duration_sec>
            <pollinterval_sec>20</pollinterval_sec>
            <snmp_timeout_ms>5000</snmp_timeout_ms>
            <snmp_retry_count>3</snmp_retry_count>
            <log_level_def>7</log_level_def>
            <truncate_log>0</truncate_log>
            <use_active_device_only>No</use_active_device_only>
        </xTestProps>
        <VarSet>
            <!--
    $Id: SNMP.CiscoVPN.XFiles.xml,v 1.2 2009/04/27 06:57:30 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="Bool" TitleRus="Add VPN Tunnel Instance to Event Name" TitleEng="Add VPN Tunnel Instance to Event Name"
                    Alias="add_tunnel_instance">
                    "yes"
                </Attrib>
            </common_attribs>
            <ScalarValues>
                <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="cipSecTunnelEntry_static" ROOT_OID="1.3.6.1.4.1.9.9.171.1.3.2.1" Type_data="Static"
                    Mandatory="no">
                    <Value usetype="discovery" proctype="absolute" COLNUM_OID="2" alias="cipSecTunIkeTunnelIndex">
						"The index of the associated IPsec Phase-1 IKE Tunnel.(cikeTunIndex in the cikeTunnelTable)"
					</Value>
                    <Value usetype="hidden" proctype="absolute" COLNUM_OID="3" alias="cipSecTunIkeTunnelAlive">
						"An indicator which specifies whether or not the IPsec Phase-1 IKE Tunnel currently exists."
					</Value>
                    <Value usetype="discovery" proctype="absolute" COLNUM_OID="4" alias="cipSecTunLocalAddr">
						"The IP address of the local endpoint."
					</Value>
                    <Value usetype="discovery" proctype="absolute" COLNUM_OID="5" alias="cipSecTunRemoteAddr">
						"The IP address of the remote endpoint."
					</Value>
                    <Value usetype="hidden" proctype="delta" COLNUM_OID="32" alias="cipSecTunInPkts">
						"The total number of packets received by this IPsec Phase-2 Tunnel."
					</Value>
                    <Value usetype="hidden" proctype="delta" COLNUM_OID="33" alias="cipSecTunInDropPkts">
						"The total number of packets dropped"
					</Value>
                    <Value usetype="hidden" proctype="delta" COLNUM_OID="34" alias="cipSecTunInReplayDropPkts">
						"The total number of packets dropped during receive processing due to Anti-Replay processing"
					</Value>
                    <Value usetype="hidden" proctype="delta" COLNUM_OID="37" alias="cipSecTunInDecrypts">
						"The total number of inbound decryption's performed"
					</Value>
                    <Value usetype="hidden" proctype="delta" COLNUM_OID="38" alias="cipSecTunInDecryptFails">
						"The total number of inbound decryption's which ended in failure"
					</Value>
                    <Value usetype="hidden" proctype="delta" COLNUM_OID="45" alias="cipSecTunOutPkts">
						"The total number of packets sent by this IPsec Phase-2 Tunnel"
					</Value>
                    <Value usetype="hidden" proctype="delta" COLNUM_OID="46" alias="cipSecTunOutDropPkts">
						"The total number of packets dropped during send processing"
					</Value>
                    <Value usetype="hidden" proctype="delta" COLNUM_OID="49" alias="cipSecTunOutEncrypts">
						"The total number of outbound encryption's performed"
					</Value>
                    <Value usetype="hidden" proctype="delta" COLNUM_OID="50" alias="cipSecTunOutEncryptFails">
						"The total number of outbound encryption's which ended in failure"
					</Value>
                    <Value usetype="storage" proctype="absolute" alias="error_count">
				            "Error Count"
			        </Value>
                </Table>
                <Table name="cipSecTunnelEntry_dynamic" ROOT_OID="1.3.6.1.4.1.9.9.171.1.3.2.1" Type_data="dynamic">
                    <Value usetype="hidden" proctype="absolute" COLNUM_OID="33" alias="cipSecTunInDropPkts">
						"The total number of packets dropped"
					</Value>
                </Table>
            </TableValues>
        </VarSet>
        <!--
			Attribute: 
				"AddAliasAsPrefics" add "[alias]" before event name. Alias from <xTest> tag.
									default "no"
				"AddHostNameAsPrefics" add [hostname] past "[alias]" before event name.
									default "yes"
				example:
					"[SNMP.BeeLine.SAA.VoIP.XFiles] [62.61.7.2] SAA Device SNMP Availability (%)"
						  alias						  hostname	   event name
									
		-->
        <popupdisplay AddAliasAsPrefix="yes" AddHostNameAsPrefix="no">
            <!-- Function: "EventCount", "Average", "Maximum", "Minimum" -->
            <description ru="Cisco VPN channels monitoring" en="Cisco VPN channels monitoring"></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">
            <!--


Dim g_dBadValue 
Dim mySendTrap

'// if IKE Tunnel data is not available more then IKETUNNEL_FAILED_COUNT, then launch rediscovery
IKETUNNEL_FAILED_COUNT = 3

g_dBadValue = 1.0e+308

g_if_filter = ""
g_hpr_clmap_filter = ""
g_lpr_clmap_filter = ""

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

SNMP_OK = 0

Sub OnDiscovery(ByRef snmpDev)
    logMessage = "+=========================================================="
    snmpDev.LogMsg(logMessage)

    logMessage = "VBscrip discovery start, ip: " & snmpDev.IpAddress & " device: " & snmpDev.DeviceName
    snmpDev.LogMsg(logMessage)

    Set ScalarTab = snmpDev.ScalarTable
    Set TabSet = snmpDev.TablesSet
   
	snmpDev.ScriptError = SCRIPT_OK
    
    l_strAlias = "Availability"
    l_strEventName = "[" & snmpDev.HostName & "] Device SNMP Availability (%)"
	SLAError = snmpDev.ResSet.EventAdd(l_strEventName, l_strAlias, -1)
	TLError =  snmpDev.ResSet.AddTrafficLight(l_strAlias, l_strEventName, l_strEventName, "Average", "<", 90, 94, 96, 99)	
	Set l_Event = snmpDev.ResSet.Events(l_strAlias)
  
	Set lportTabcipSecTunnelEntry = TabSet.PPortsTableByName("cipSecTunnelEntry_static")
  
    If  lportTabcipSecTunnelEntry.SnmpError = -1  Then
        snmpDev.WasDiscovered = False
    Else    
        snmpDev.WasDiscovered = True
    End If        
  
	TablesCount = lportTabcipSecTunnelEntry.Count
	l_stsInstances = ""
	
	For tIndx = 0 To TablesCount - 1
		Set lipSecTunnel = lportTabcipSecTunnelEntry.Table(tIndx)
		If lipSecTunnel Is Nothing Then
			Exit Sub
        End If
		
	    l_iErr = GetIpAddress(lipSecTunnel.Value("cipSecTunLocalAddr").HexBinaryValue, l_strLocalIpAddress)
	    l_iErr = GetIpAddress(lipSecTunnel.Value("cipSecTunRemoteAddr").HexBinaryValue, l_strRemoteIpAddress)
	    l_strIkeTunnIndex = lipSecTunnel.Value("cipSecTunIkeTunnelIndex").NumericValue
	    l_strInstanse = lipSecTunnel.Instance
	    
	    '// IKE Tunnel currently Alive
	    l_strEventName = "IKE Tunnel Currently Alive"
	    l_strAlias = "IKE_Tunnel_Currently_Alive"
	    l_strAlias = GetEventName(snmpDev, l_strLocalIpAddress, l_strRemoteIpAddress, l_strIkeTunnIndex, l_strInstanse, l_strEventName, l_strAlias, "")
	    SLAError = snmpDev.ResSet.EventAdd(l_strEventName, l_strAlias, -1)
	    TLError =  snmpDev.ResSet.AddTrafficLight(l_strAlias, l_strEventName, l_strEventName, "Average", "<", 1, 1, 1, 1)
	
	    '// Packets received
	    l_strEventName = "Packets Received"
	    l_strAlias = "rcvd_pkt"
	    l_strAlias = GetEventName(snmpDev, l_strLocalIpAddress, l_strRemoteIpAddress, l_strIkeTunnIndex, l_strInstanse, l_strEventName, l_strAlias, "(Pkts/s)")
	    SLAError = snmpDev.ResSet.EventAdd(l_strEventName, l_strAlias, -1)
	    'TLError =  snmpDev.ResSet.AddTrafficLight(l_strAlias, l_strEventName, l_strEventName, "Average", ">", 380000, 310000, 250000, 225000)
		
	    '//  Receive Processing Droped Packets
	    l_strEventName = "Receive Processing Droped Packets"
	    l_strAlias = "rcvd_droped_pkt"
	    l_strAlias = GetEventName(snmpDev, l_strLocalIpAddress, l_strRemoteIpAddress, l_strIkeTunnIndex, l_strInstanse, l_strEventName, l_strAlias, "(%)")
	    SLAError = snmpDev.ResSet.EventAdd(l_strEventName, l_strAlias, -1)
	    TLError =  snmpDev.ResSet.AddTrafficLight(l_strAlias, l_strEventName, l_strEventName, "Average", ">", 0.05, 0.02, 0.01, 0)

	    '//  Receive Processing Droped Packets due to Anti-Replay
	    l_strEventName = "Receive Processing Droped Packets due to Anti-Replay"
	    l_strAlias ="droped_Anti-Replay"
	    l_strAlias = GetEventName(snmpDev, l_strLocalIpAddress, l_strRemoteIpAddress, l_strIkeTunnIndex, l_strInstanse, l_strEventName, l_strAlias, "(%)")
	    SLAError = snmpDev.ResSet.EventAdd(l_strEventName, l_strAlias, -1)
	    TLError =  snmpDev.ResSet.AddTrafficLight(l_strAlias, l_strEventName, l_strEventName, "Average", ">", 0.05, 0.02, 0.01, 0)
		
		'// Inbound Decryptions 
	    l_strEventName = "Inbound Decryptions"
	    l_strAlias = "inbound_decryptions" 
	    l_strAlias = GetEventName(snmpDev, l_strLocalIpAddress, l_strRemoteIpAddress, l_strIkeTunnIndex, l_strInstanse, l_strEventName, l_strAlias, "(Dec/s)")
	    SLAError = snmpDev.ResSet.EventAdd(l_strEventName, l_strAlias, -1)
	    'TLError =  snmpDev.ResSet.AddTrafficLight(l_strAlias, l_strEventName, l_strEventName, "Average", ">", 0.05, 0.02, 0.01, 0)
		
		'// Inbound Decryptions Failed
	    l_strEventName = "Inbound Decryptions Failed"
	    l_strAlias = "inbound_decryptions_failed" 
	    l_strAlias = GetEventName(snmpDev, l_strLocalIpAddress, l_strRemoteIpAddress, l_strIkeTunnIndex, l_strInstanse, l_strEventName, l_strAlias, "(%)")
	    SLAError = snmpDev.ResSet.EventAdd(l_strEventName, l_strAlias, -1)
	    TLError =  snmpDev.ResSet.AddTrafficLight(l_strAlias, l_strEventName, l_strEventName, "Average", ">", 0.05, 0.02, 0.01, 0)
	
	    '// Packets Sent
	    l_strEventName = "Packets Sent"
	    l_strAlias = "sent_pkt"
	    l_strAlias = GetEventName(snmpDev, l_strLocalIpAddress, l_strRemoteIpAddress, l_strIkeTunnIndex, l_strInstanse, l_strEventName, l_strAlias, "(Pkts/s)")
	    SLAError = snmpDev.ResSet.EventAdd(l_strEventName, l_strAlias, -1)
	    'TLError =  snmpDev.ResSet.AddTrafficLight(l_strAlias, l_strEventName, l_strEventName, "Average", ">", 0.05, 0.02, 0.01, 0)
	    
	    '// Send Processing Droped Packets
	    l_strEventName = "Send Processing Droped Packets"
	    l_strAlias = "sent_droped_pkt"
	    l_strAlias = GetEventName(snmpDev, l_strLocalIpAddress, l_strRemoteIpAddress, l_strIkeTunnIndex, l_strInstanse, l_strEventName, l_strAlias, "(%)")
	    SLAError = snmpDev.ResSet.EventAdd(l_strEventName, l_strAlias, -1)
	    TLError =  snmpDev.ResSet.AddTrafficLight(l_strAlias, l_strEventName, l_strEventName, "Average", ">", 0.05, 0.02, 0.01, 0)

        '// Outbound Encryptions
	    l_strEventName = "Outbound Encryptions"
	    l_strAlias = "outbound_encryptions" 
	    l_strAlias = GetEventName(snmpDev, l_strLocalIpAddress, l_strRemoteIpAddress, l_strIkeTunnIndex, l_strInstanse, l_strEventName, l_strAlias, "(Encr/s)")
	    SLAError = snmpDev.ResSet.EventAdd(l_strEventName, l_strAlias, -1)

        '// Outbound Encryptions Failed
	    l_strEventName = "Outbound Encryptions Failed"
	    l_strAlias = "outbound_encryptions_failed" 
	    l_strAlias = GetEventName(snmpDev, l_strLocalIpAddress, l_strRemoteIpAddress, l_strIkeTunnIndex, l_strInstanse, l_strEventName, l_strAlias, "(%)")
	    SLAError = snmpDev.ResSet.EventAdd(l_strEventName, l_strAlias, -1)
	    TLError =  snmpDev.ResSet.AddTrafficLight(l_strAlias, l_strEventName, l_strEventName, "Average", ">", 0.05, 0.02, 0.01, 0)

		
	Next
  
    logMessage = "VBscrip discovery end, ip: " & snmpDev.IpAddress & " device: " & snmpDev.DeviceName
    snmpDev.LogMsg(logMessage)

End Sub


Sub OnDataReceived(ByRef snmpDev)
    
    logMessage = "+=========================================================="
    snmpDev.LogMsg(logMessage)

    logMessage = "VBscrip OnDataReceived start, HostName:" & snmpDev.HostName & " ip: " & snmpDev.IpAddress & ":" & snmpDev.SnmpPort & " device: " & snmpDev.DeviceName
    snmpDev.LogMsg(logMessage)
    
    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 lportTabcipSecTunnelEntry_Din = TabSet.PPortsTableByName("cipSecTunnelEntry_dynamic")
    Set lportTabcipSecTunnelEntry = TabSet.PPortsTableByName("cipSecTunnelEntry_static")

    '// Set bad Value to all calculated Events
    ResetCalculatedEvenst(ScalarTab)

    '// check device availability
    If l_ValsysUpTime.NumericValue = g_dBadValue  Then
        logMessage = "VBscrip OnDataReceived: SysUpTime is bad - devuce not respond Availability is 0 exit"
        snmpDev.LogMsg(logMessage)
        exit sub
    End If

    If lportTabcipSecTunnelEntry_Din.SnmpError = -1  Then
        logMessage = "VBscrip OnDataReceived: Snmp error in din table (lportTabcipSecTunnelEntry) - device not respond Availability is 0 exit"
        snmpDev.LogMsg(logMessage)
        exit sub
    End If

    '// 
    If snmpDev.UseActiveDeviceOnly = false and snmpDev.WasDiscovered = false Then
        logMessage = "VBscrip OnDataReceived: snmpDev has been responded - Set Rediscovery flag"
        snmpDev.LogMsg(logMessage)

        snmpDev.LaunchRediscovery = true
        snmpDev.RediscoveryInitiator = true
        Exit Sub
    End If
   
    l_iCount = lportTabcipSecTunnelEntry.Count
   
    For l_Indx = 0 To l_iCount - 1   
        Set lipSecTunnel = lportTabcipSecTunnelEntry.Table(l_Indx)
        l_iIKETunnelInst = lipSecTunnel.Instance
        
        l_iIKETunnelAlive = lipSecTunnel.Value("cipSecTunIkeTunnelAlive").NumericValue
        
        l_iInPackets = lipSecTunnel.Value("cipSecTunInPkts").NumericValue
        l_iInDropPackets = lipSecTunnel.Value("cipSecTunInDropPkts").NumericValue
        l_iInReplayDropPackets = lipSecTunnel.Value("cipSecTunInReplayDropPkts").NumericValue
       
        l_iOutPackets = lipSecTunnel.Value("cipSecTunOutPkts").NumericValue
        l_iOutDropPackets = lipSecTunnel.Value("cipSecTunOutDropPkts").NumericValue

        l_iInDecrypts = lipSecTunnel.Value("cipSecTunInDecrypts").NumericValue
        l_iInDecryptFails = lipSecTunnel.Value("cipSecTunInDecryptFails").NumericValue

        l_iOutEncrypts = lipSecTunnel.Value("cipSecTunOutEncrypts").NumericValue
        l_iOutEncryptFails = lipSecTunnel.Value("cipSecTunOutEncryptFails").NumericValue
        Set ErrorCount = lipSecTunnel.Value("error_count")

        if snmpDev.ScriptExecCount = 0 Then
            ErrorCount.NumericValue = 0
        End If

        If l_iIKETunnelAlive <> g_dBadValue Then
            If l_iIKETunnelAlive <> 1 Then
                l_iIKETunnelAlive = 0
            End If
        End If
        SetCounter snmpDev, l_iIKETunnelInst, l_iIKETunnelAlive, "IKE_Tunnel_Currently_Alive"
    
        '// rcvd_pkt
        SetCounter snmpDev, l_iIKETunnelInst, l_iInPackets, "rcvd_pkt"
        
        '// rcvd_droped_pkt
        If l_iInPackets <> g_dBadValue And l_iInDropPackets <> g_dBadValue Then
            If l_iInDropPackets > 0 Then
                l_iInDropPackets =  (l_iInDropPackets * 100) / (l_iInPackets + l_iInDropPackets)  
            Else
                l_iInDropPackets = 0               
            End If
        End If
        SetCounter snmpDev, l_iIKETunnelInst, l_iInDropPackets, "rcvd_droped_pkt"

        '// droped_Anti-Replay
        If l_iInReplayDropPackets <> g_dBadValue And l_iInReplayDropPackets <> g_dBadValue Then
            If l_iInReplayDropPackets > 0 Then
                l_iInReplayDropPackets = (l_iInReplayDropPackets * 100) / (l_iInPackets + l_iInReplayDropPackets)  
            Else
                l_iInReplayDropPackets = 0               
            End If
        End If
        SetCounter snmpDev, l_iIKETunnelInst, l_iInReplayDropPackets, "droped_Anti-Replay"

        '// Inbound Decryptions
        SetCounter snmpDev, l_iIKETunnelInst, l_iInDecrypts, "inbound_decryptions"
        
        '// Inbound Decryptions Failed
        If l_iInDecrypts <> g_dBadValue And l_iInDecryptFails <> g_dBadValue Then
            If l_iInDecrypts > 0 Then
                l_iInDecryptFails = (l_iInDecryptFails * 100) / l_iInDecrypts
            Else
                l_iInDecryptFails = 0               
            End If
        End If
        SetCounter snmpDev, l_iIKETunnelInst, l_iInDecryptFails, "inbound_decryptions_failed"

        '// sent_pkt
        SetCounter snmpDev, l_iIKETunnelInst, l_iOutPackets, "sent_pkt"
        
        '// sent_droped_pkt       
        If l_iOutPackets <> g_dBadValue And l_iOutDropPackets <> g_dBadValue Then
            If l_iOutDropPackets > 0 Then
                l_iOutDropPackets = (l_iOutDropPackets * 100) / (l_iOutPackets + l_iOutDropPackets)  
            Else
                l_iOutDropPackets = 0               
            End If
        End If
        SetCounter snmpDev, l_iIKETunnelInst, l_iOutDropPackets, "sent_droped_pkt"
        
        '// outbound_encryptions
        SetCounter snmpDev, l_iIKETunnelInst, l_iOutEncrypts, "outbound_encryptions"
        
        '// outbound_encryptions_failed
        If l_iOutEncrypts <> g_dBadValue And l_iOutEncryptFails <> g_dBadValue Then
            If l_iOutEncrypts > 0 Then
                l_iOutEncryptFails = (l_iOutEncryptFails * 100) / l_iOutEncrypts
            Else
                l_iOutEncryptFails = 0               
            End If
        End If
        SetCounter snmpDev, l_iIKETunnelInst, l_iInDecryptFails, "outbound_encryptions_failed"
        
        '// check ike tunnel availability
        If l_iIKETunnelAlive = g_dBadValue Or l_iInPackets = g_dBadValue Then
            If snmpDev.ScriptExecCount > 0  And lportTabcipSecTunnelEntry.SnmpError <> -1 Then
                ErrorCount.NumericValue = ErrorCount.NumericValue + 1
                logMessage = "VBscript Script: IKE Tunnel [#" & l_iIKETunnelInst & "] is not available; Error Count:" & ErrorCount.NumericValue
                snmpDev.LogMsg(logMessage)

                If ErrorCount.NumericValue >= IKETUNNEL_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    
                
    Next

    '// Is new IKE Tunnel  available
    If lportTabcipSecTunnelEntry.SnmpError <> -1 And lportTabcipSecTunnelEntry_Din.SnmpError <> -1 Then   
        If IsNewQueues(snmpDev, lportTabcipSecTunnelEntry_Din, lportTabcipSecTunnelEntry)  Then
            logMessage = "VBscript Script: New IKE Tunnels are available - Set Rediscovery flag"
            snmpDev.LogMsg(logMessage)
        
            snmpDev.LaunchRediscovery = true
            snmpDev.RediscoveryInitiator = true
        End If
    End If


    snmpDev.ScriptExecCount = snmpDev.ScriptExecCount + 1


    logMessage = "+=========================================================="
    snmpDev.LogMsg(logMessage)

    logMessage = "VBscrip 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


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, instance_din, portTab_static) 

    l_bIsInstncInStaticTable = False

    portTab_static.InitInstancesIterations()
    
    Set TabOnPort = portTab_static.CurrTable
    
    '// remomove "." from begining instance 
     If  Mid(instance_din, 1, 1) = "." And Len(instance_din) > 1 Then
        instance_din = Mid(instance_din, 2)
     End If
    
    
    Do While Not (TabOnPort Is Nothing)
        l_strInstance = TabOnPort.Instance
        '//l_iCompare = InStr(1, instance_din, l_strInstance, 1)
        If StrComp(l_strInstance, instance_din) =  0 Then
           l_bIsInstncInStaticTable = True
           Exit Do
        End If
        
        portTab_static.NextTable()
        Set TabOnPort = portTab_static.CurrTable
   Loop

    IsInstncInStaticTable = l_bIsInstncInStaticTable
End Function


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 ParseFilter(FilterList)
    
    l_FilterArray = Split(FilterList, ",", -1, 1)
       
    ParseFilter = l_FilterArray
End Function

Function IsDataInFilter(ByRef snmpDev, CompareStr)
    IsDataInFilter = False
    
    FilterList = Split(snmpDev.ResSet.CommonProp.Attrib("tag_filter").Value, ",", -1, 1)
    
    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

'// snmpDev, l_strLocalIpAddress, l_strRemoteIpAddress, l_strIkeTunnIndex, l_strInstanse, l_strEventName, "Packets received", "(Pckt/s)"
Function GetEventName(ByRef snmpDev, l_strLocalIpAddress, l_strRemoteIpAddress, l_strIkeTunnIndex, l_strInstanse, ByRef strEventName, strAlias, strUnits)
    
    l_strIpAddr = snmpDev.HostName
    l_strRespIP = strIpTarget

	l_bAddInst = snmpDev.ResSet.CommonProp.Attrib("add_tunnel_instance").Value
	
    l_strPrefix = "[" & l_strIpAddr & "]"  & "(" & l_strRemoteIpAddress & "-" & Chr(62) & l_strLocalIpAddress & " IKETunnel: " & l_strIkeTunnIndex & ") "
	If l_bAddInst = True Then
		l_strPrefix = l_strPrefix & " #" & l_strInstanse
	End If
    
    l_strAlias = strAlias & "_" & l_strInstanse
    strEventName = l_strPrefix & " " & strEventName & " " & strUnits
    GetEventName = l_strAlias

End Function

Function GetTestInstanses(ByRef snmpDev)
    Set l_ValAvailability = snmpDev.ScalarTable.Value("Availability")
    l_InstArr = Split(l_ValAvailability.Tag, "_", -1, 1)
    
    l_iCount = UBound(l_InstArr)
    GetTestInstanses = l_InstArr
End Function

Sub SetCounter(ByRef snmpDev, l_strInstance, l_dCounter, l_strAlias )

    l_strAlias = l_strAlias & "_" & l_strInstance
    Set l_EventVal = snmpDev.ScalarTable.Value(l_strAlias)

    If IsObject(l_EventVal) And Not (l_EventVal Is Nothing) And l_dCounter <> g_dBadValue Then
        l_EventVal.NumericValue = l_dCounter
    End If
End Sub

Function IsNewSaaTests(ByRef snmpDev, InstArr)
    
    IsNewSaaTests = False
    l_bIsCurrInstInWorkedTests = False
    
    l_iWorkedTestsCount = UBound(InstArr)
 
    Set l_PortsTabAdminEntry =  snmpDev.TablesSet.PPortsTableByName("rttMonCtrlAdminEntry_dynamic")
    l_iTestsCount = l_PortsTabAdminEntry.Count
    
    For tIndx = 0 To l_iTestsCount - 1
        
        l_strTag = l_PortsTabAdminEntry.Table(tIndx).Value("rttMonCtrlAdminTag").SValue
        l_lTestType = l_PortsTabAdminEntry.Table(tIndx).Value("rttMonCtrlAdminRttType").NumericValue
        l_lTestStatus = l_PortsTabAdminEntry.Table(tIndx).Value("rttMonCtrlAdminStatus").NumericValue
        l_strTestInst = Mid(l_PortsTabAdminEntry.Table(tIndx).Instance, 2)

        If IsDataInFilter(snmpDev, l_strTag) = True And l_lTestType = 9 And l_lTestStatus = 1 Then
            l_bIsCurrInstInWorkedTests = False    
            
            For l_iIndx = 0 To l_iWorkedTestsCount 
                'If InStr(1,l_strTestInst,InstArr(l_iIndx),1) > 0 Then
                If l_strTestInst = InstArr(l_iIndx) Then 
                    l_bIsCurrInstInWorkedTests = True
                    Exit For
                End If
            Next
            
            If l_bIsCurrInstInWorkedTests = False Then
                logMessage = "VBscrip IsNewSaaTests: there is new test (" &  l_strTestInst & ") with tag: " & Chr(34) & l_strTag & Chr(34)
                snmpDev.LogMsg(logMessage)
                
                
                IsNewSaaTests = True
                Exit Function
            End If
               
        End If
    Next

End Function

Function GetIpAddress(lstrIpHex, ByRef l_strIpAddress)
    l_strIpAddress = ""
    GetIpAddress = -1
    
    lstrHexNum = Mid(lstrIpHex, 1, 2)
    l_iAA = CInt("&H" & lstrHexNum)
    If IsNumeric(l_iAA) AND l_iAA > 1 AND l_iAA < 256 Then
        GetIpAddress = 0
    Else
        GetIpAddress = -1
        Exit Function
    End If                

    lstrHexNum = Mid(lstrIpHex, 3, 2)
    l_iBB = CInt("&H" & lstrHexNum)
    If IsNumeric(l_iBB) AND l_iBB >= 0 AND l_iBB < 256 Then
        GetIpAddress = 0
    Else
        GetIpAddress = -1
        Exit Function
    End If                

    lstrHexNum = Mid(lstrIpHex, 5, 2)
    l_iCC = CInt("&H" & lstrHexNum)
    If IsNumeric(l_iCC) AND l_iCC >= 0 AND l_iCC < 256 Then
        GetIpAddress = 0
    Else
        GetIpAddress = -1
        Exit Function
    End If                

    lstrHexNum = Mid(lstrIpHex, 7, 2)
    l_iDD = CInt("&H" & lstrHexNum)
    If IsNumeric(l_iDD) AND l_iDD >= 0 AND l_iDD < 256 Then
        GetIpAddress = 0
    Else
        GetIpAddress = -1
        Exit Function
    End If                

    l_strIpAddress = l_iAA & "." & l_iBB & "." & l_iCC & "." & l_iDD

  GetIpAddress = 0
  
End Function



--></Script>
    </xTest>
</document>
