home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 May / Chip_2000-05_cd1.bin / servis / ovladace / drivers / 850win2000.exe / asppages / snmp.inc < prev    next >
Encoding:
Text File  |  1999-09-24  |  14.0 KB  |  435 lines

  1. <%
  2. '*********************************************************
  3. '
  4. '   Tektronix Windows 2000 Print Status ASP Page Project
  5. '
  6. '   Copyright (c) Tektronix, Inc. 1999
  7. '
  8. '   Description
  9. '
  10. '    Printer SNMP Interface Functions
  11. '
  12. '   History
  13. '
  14. '       Version 1.0 7/22/99     Greg Thornton
  15. '    Version 1.1 8/12/99    Greg Thornton
  16. '    Version 1.2 9/24/99    Greg Thornton, MS session variable bug
  17. '
  18. '*********************************************************
  19.  
  20. '*********************************************************
  21. '
  22. ' SNMP Definitions
  23. '
  24. '*********************************************************
  25.  
  26. Const     SNMP_PROGID                   = "OlePrn.OleSNMP"
  27. Const    SNMP_RETRY_COUNT        = 3
  28. Const   SNMP_TIMEOUT            = 2000
  29.  
  30. Const    gpidGeneral             = ".1.3.6.1.4.1.128.2.1.3.1"
  31. Const    gpidGeneralProduct        = ".1.3.6.1.4.1.128.2.1.3.1.2.0"
  32. Const    gpidGeneralStatus         = ".1.3.6.1.4.1.128.2.1.3.1.4.0"
  33. Const   gpidGeneralPrinterBusy         = ".1.3.6.1.4.1.128.2.1.3.1.5.0"
  34. Const    gpidGeneralEngineFailure    = ".1.3.6.1.4.1.128.2.1.3.1.6.0"
  35.  
  36. Const    prtAlert            = ".1.3.6.1.2.1.43.18"
  37. Const    prtAlertIndex            = ".1.3.6.1.2.1.43.18.1.1.1."
  38. Const    prtAlertSeverityLevel        = ".1.3.6.1.2.1.43.18.1.1.2."
  39. Const    prtAlertCode            = ".1.3.6.1.2.1.43.18.1.1.7."
  40.  
  41. Const    gpidInput            = ".1.3.6.1.4.1.128.2.1.3.2"
  42. Const    gpidInputNumber            = ".1.3.6.1.4.1.128.2.1.3.2.1.0"
  43. Const    gpidInputTrayId            = ".1.3.6.1.4.1.128.2.1.3.2.2.1.2."
  44. Const    gpidInputTrayType        = ".1.3.6.1.4.1.128.2.1.3.2.2.1.3."
  45. Const   gpidInputMaxCapacity        = ".1.3.6.1.4.1.128.2.1.3.2.2.1.5."
  46. Const   gpidInputCurrentLevel        = ".1.3.6.1.4.1.128.2.1.3.2.2.1.6."
  47. Const    gpidInputStatus            = ".1.3.6.1.4.1.128.2.1.3.2.2.1.7."
  48. Const    gpidInputMediaType        = ".1.3.6.1.4.1.128.2.1.3.2.2.1.8."
  49. Const    gpidInputMediaSize        = ".1.3.6.1.4.1.128.2.1.3.2.2.1.9."
  50.  
  51. Const    gpidMarker            = ".1.3.6.1.4.1.128.2.1.3.4"
  52. Const   gpidMarkerLifeCounts        = ".1.3.6.1.4.1.128.2.1.3.4.4.0"
  53. Const    gpidMarkerStatus        = ".1.3.6.1.4.1.128.2.1.3.4.8.0"
  54. Const    gpidMarkerSuppliesNumber    = ".1.3.6.1.4.1.128.2.1.3.4.9.0"
  55. Const    gpidMarkerSuppliesColorantId       = ".1.3.6.1.4.1.128.2.1.3.4.10.1.2."
  56. Const   gpidMarkerSuppliesType            = ".1.3.6.1.4.1.128.2.1.3.4.10.1.4."
  57. Const    gpidMarkerSuppliesMaxCapacity      = ".1.3.6.1.4.1.128.2.1.3.4.10.1.6."
  58. Const    gpidMarkerSuppliesCurrentLevel     = ".1.3.6.1.4.1.128.2.1.3.4.10.1.7." 
  59. Const    gpidMarkerSuppliesMaxLifeCount     = ".1.3.6.1.4.1.128.2.1.3.4.10.1.8."
  60. Const    gpidMarkerSuppliesLifeCount        = ".1.3.6.1.4.1.128.2.1.3.4.10.1.9."
  61. Const    gpidMarkerSuppliesStatus     = ".1.3.6.1.4.1.128.2.1.3.4.10.1.10."
  62. Const    gpidMarkerSuppliesRemaining     = ".1.3.6.1.4.1.128.2.1.3.4.10.1.11."
  63.  
  64. Const   sysContact            = ".1.3.6.1.2.1.1.4.0"
  65. Const    sysLocation            = ".1.3.6.1.2.1.1.6.0"
  66.   
  67.  
  68. '*********************************************************
  69. '
  70. ' snmpXXXX Definitions
  71. '
  72. '*********************************************************
  73. const     GENERAL_PRODUCT            = 0
  74. const     GENERAL_STATUS            = 1
  75. const     GENERAL_PRINTER_BUSY        = 2
  76. const     GENERAL_ENGINE_FAILURE        = 3
  77.  
  78. const     INPUT_TRAY_ID            = 0
  79. const     INPUT_STATUS            = 1
  80. const     INPUT_MEDIA_TYPE        = 2
  81. const     INPUT_MEDIA_SIZE        = 3
  82. const    INPUT_MAX_CAPACITY        = 4
  83. const    INPUT_CURRENT_LEVEL        = 5
  84. const   INPUT_TRAY_TYPE            = 6
  85.  
  86. const     MARKER_COLORANT            = 0
  87. const     MARKER_TYPE            = 1
  88. const     MARKER_MAX_CAPACITY        = 2
  89. const     MAKER_LEVEL            = 3
  90. const     MARKER_MAX_LIFE            = 4
  91. const     MARKER_LIFE            = 5
  92. const     MARKER_SUPPLY_STATUS        = 6
  93. const   MARKER_SUPPLY_REMAINING        = 7
  94.  
  95. const     ALERT_LEVEL            = 0
  96. const     ALERT_CODE            = 1
  97.  
  98. Dim     snmpGpidInput
  99. Dim    snmpGpidMarkerStatus
  100. Dim    snmpGpidMarkerLifeCounts
  101. Dim     snmpGpidMarker
  102. Dim     snmpPrtAlert
  103. Dim     snmpGpidGeneral
  104. Dim    snmpSysContact
  105. Dim    snmpSysLocation
  106.  
  107. '*********************************************************
  108. '
  109. ' Explicit SNMP object values
  110. '
  111. '*********************************************************
  112. Const SNMP_GPID_INPUT_STATUS_LOW         = 5
  113. Const SNMP_GPID_INPUT_MEDIA_SIZE_OTHER         = 1
  114. Const SNMP_GPID_INPUT_MEDIA_SIZE_UNKNOWN     = 2
  115. Const SNMP_GPID_INPUT_MEDIA_TYPE_OTHER         = 1
  116. Const SNMP_GPID_INPUT_MEDIA_TYPE_UNKNOWN     = 2
  117. Const SNMP_GPID_INPUT_TRAY_TYPE_REMOVEABLE    = 3
  118. Const SNMP_GPID_MARKER_SUPPLIES_TYPE_OTHER    = 1
  119. Const SNMP_GPID_MARKER_SUPPLIES_COLORANTID_C    = 4
  120. Const SNMP_GPID_MARKER_SUPPLIES_COLORANTID_M    = 5
  121. Const SNMP_GPID_MARKER_SUPPLIES_COLORANTID_Y    = 6
  122. Const SNMP_GPID_MARKER_SUPPLIES_COLORANTID_K    = 7
  123. Const cyanMarker                = 4
  124. Const magentaMarker                = 5
  125. Const yellowMarker                = 6
  126. Const blackMarker                = 7
  127. Const tonerDischarge                = 12
  128. Const paperFeedUnit                = 17
  129. Const tensionUnit                = 18
  130. Const wasteToner                = 4
  131. Const toner                    = 3
  132. Const wasteInk                    = 8
  133. Const wax_solid                    = 12
  134. Const wasteWax                    = 14
  135. Const feeder                    = 16
  136. Const tensioner                    = 17
  137.  
  138. ' gpidGeneralStatus enumerations
  139.  
  140. Const other                    = 1
  141. Const unknown                    = 2
  142. Const ready                    = 3
  143. Const critical                    = 4
  144. Const non_critical                = 5
  145. Const critical_and_non_critical            = 6
  146. Const onRequest                    = 7
  147. Const unavailable                = 8
  148. Const busy                    = 9
  149. Const waiting                    = 10
  150.  
  151. Const prtAlertSeverityLevelOther        = 1
  152. Const prtAlertSeverityLevelCritical        = 3
  153. Const prtAlertSeverityLevelWarning        = 4
  154.  
  155. Const gpidGeneralPrinterBusyReady        = 2
  156. Const gpidGeneralPrinterBusyPrinting        = 3
  157. Const gpidGeneralPrinterBusyReceivingData    = 4
  158.  
  159.  
  160. ' Printer Model Enumerations
  161.  
  162. Const M_340    = 1
  163. Const M_350    = 2
  164. Const M_360    = 3
  165. Const M_380    = 4
  166. Const M_450    = 5
  167. Const M_480    = 6
  168. Const M_540    = 7
  169. Const M_550    = 8
  170. Const M_560    = 9
  171. Const M_600    = 10
  172. Const M_740    = 11
  173. Const M_780    = 12
  174. Const M_840    = 13
  175. Const M_UNKNOWN    = 14
  176.  
  177.  
  178. Function GetModel(snmpModel)
  179.     If NOT Instr(snmpModel,"740") = O Then
  180.         GetModel = M_740
  181.     ElseIf NOT Instr(snmpModel,"840") = O Then
  182.         GetModel = M_840
  183.     ElseIf NOT Instr(snmpModel,"780") = O Then
  184.         GetModel = M_780
  185.     ElseIf NOT Instr(snmpModel,"340") = O Then
  186.         GetModel = M_340
  187.     ElseIf NOT Instr(snmpModel,"350") = O Then
  188.         GetModel = M_350
  189.     ElseIf NOT Instr(snmpModel,"360") = O Then
  190.         GetModel = M_360
  191.     ElseIf NOT Instr(snmpModel,"540") = O Then
  192.         GetModel = M_540
  193.     ElseIf NOT Instr(snmpModel,"550") = O Then
  194.         GetModel = M_550
  195.     ElseIf NOT Instr(snmpModel,"560") = O Then
  196.         GetModel = M_560
  197.     ElseIf NOT Instr(snmpModel,"380") = O Then
  198.         GetModel = M_380
  199.     ElseIf NOT Instr(snmpModel,"450") = O Then
  200.         GetModel = M_450
  201.     ElseIf NOT Instr(snmpModel,"480") = O Then
  202.         GetModel = M_480
  203.     ElseIf NOT Instr(snmpModel,"600") = O Then
  204.         GetModel = M_600
  205.     Else
  206.         GetModel = M_UNKNOWN
  207.     End If
  208. End Function
  209.  
  210. Function FilterGpidMarker(model,m_colorant,m_type)
  211.     Dim Filter
  212.  
  213.     Filter = FALSE
  214.  
  215.     Select Case m_type
  216.         Case wasteToner, wasteInk, wasteWax, unknown, feeder, tensioner
  217.             ' Only report true consumables
  218.             Filter = TRUE
  219.         Case Else
  220.             Select Case model
  221.                 Case M_740, M_560, M_550, M_540
  222.                     If m_type = other Then
  223.                         Select Case m_colorant
  224.                             Case tonerDischarge, paperFeedUnit, tensionUnit
  225.                                 Filter = TRUE
  226.                         End Select
  227.                     End If
  228.             End Select
  229.     End Select
  230.     FilterGpidMarker = Filter
  231. End Function
  232.  
  233. '*********************************************************
  234. ' Name: GetSNMPStatus
  235. '
  236. ' Description:  
  237. '    This function gets raw SNMP printer status and
  238. '    stores this status in the global snmpXXXX variables.
  239. '    If the printer model specified by snmpGpidGeneral
  240. '    is M_UNKNOWN, this function will return with only
  241. '    the snmpGpidGeneral variable initialized.
  242. ' Inputs:
  243. '    None.
  244. ' Outputs:
  245. '    snmpXXXX variables initiated with printer status.
  246. '    Serveral of the variables are arrays. Use Ubound function
  247. '    to determine array size.        
  248. ' Returns:  
  249. '    Model value.
  250. '*********************************************************
  251.  
  252.  
  253. Function GetSNMPStatus()
  254.  
  255.     Dim objSNMP, snmpQuery, snmpResponse, i, strIndex
  256.     Dim strIP, strCommunity, strDevice, model
  257.  
  258.     strIP         = request("MS_IPaddress")
  259.     strCommunity    = request("MS_Community")
  260.     strDevice    = cStr(request("MS_Device"))
  261.  
  262.     Set objSNMP     = Server.CreateObject(SNMP_PROGID)
  263.  
  264.     objSNMP.open strIP, strCommunity, SNMP_RETRY_COUNT, SNMP_TIMEOUT
  265.  
  266.     '******************************************************
  267.     'Get gpidGeneral
  268.     '******************************************************
  269.     snmpQuery    = Array(gpidGeneralProduct, gpidGeneralStatus, gpidGeneralPrinterBusy, gpidGeneralEngineFailure)
  270.     snmpGpidGeneral    = objSNMP.GetList(snmpQuery)
  271.      model = GetModel(snmpGpidGeneral(GENERAL_PRODUCT))
  272.     GetSNMPStatus = model
  273.  
  274.     If model = M_UNKNOWN Then
  275.         Exit Function
  276.     End If
  277.  
  278.     '******************************************************
  279.     'Get prtAlert
  280.     '******************************************************
  281.  
  282.     Select Case model
  283.         '******************************************************
  284.         'GetTree returns an array of dimension 2 x N. The 
  285.         'first dimension selects between the SNMP object id 
  286.         '(with index value 0) and the SNMP object value (with 
  287.         'index value 1). The second dimension defines the number
  288.         'of SNMP object id / value pairs returned.
  289.         '******************************************************            
  290.  
  291.         Case M_360, M_740, M_780, M_840
  292.             snmpResponse = objSNMP.GetTree(prtAlertIndex & strDevice)
  293.             If UBound(snmpResponse, 2) >= 0 Then
  294.                 ReDim snmpPrtAlert(1, UBound(snmpResponse, 2))
  295.                 For i = 0 To UBound(snmpResponse, 2)
  296.                     strIndex = "." &  cStr(i+1)
  297.                     snmpPrtAlert(ALERT_LEVEL, i)     = objSNMP.Get(prtAlertSeverityLevel & strDevice & strIndex)
  298.                     snmpPrtAlert(ALERT_CODE, i)     = objSNMP.Get(prtAlertCode & strDevice & strIndex)
  299.                 Next            
  300.             End If
  301.  
  302.         Case Else
  303.             '******************************************************
  304.             'A bug in older printer model prtAlert reporting requires 
  305.             'different method for reading prtAlert. This method could be
  306.             'used for all printers. Since the above method has been
  307.             'tested already I will apply this only to the older
  308.             'printer models (call it superstition).
  309.             '******************************************************
  310.             snmpResponse1 = objSNMP.GetTree(prtAlertSeverityLevel & strDevice)
  311.             snmpResponse2 = objSNMP.GetTree(prtAlertCode & strDevice)
  312.             If UBound(snmpResponse1, 2) >= 0 Then
  313.  
  314.                 If UBound(snmpResponse1, 2) <= UBound(snmpResponse2, 2) Then
  315.                     j = UBound(snmpResponse1, 2) 
  316.                 Else
  317.                     j = UBound(snmpResponse2, 2)
  318.                 End If
  319.  
  320.                 ReDim snmpPrtAlert(1,j)
  321.                 For i = 0 To j 
  322.                     snmpPrtAlert(ALERT_LEVEL, i)    = snmpResponse1(1,i)
  323.                     snmpPrtAlert(ALERT_CODE, i)     = snmpResponse2(1,i)
  324.                 Next
  325.             End If
  326.  
  327.     End Select 
  328.  
  329.     '******************************************************
  330.     'Get gpidInput
  331.     '******************************************************
  332.     snmpResponse = objSNMP.Get(gpidInputNumber)
  333.     If snmpResponse > 0 Then
  334.         ReDim snmpGpidInput(6, snmpResponse - 1)
  335.         For i = 0 To snmpResponse - 1
  336.             strIndex = cStr(i+1)
  337.             snmpGpidInput(INPUT_TRAY_ID, i)     = objSNMP.Get(gpidInputTrayId         & strIndex)
  338.             snmpGpidInput(INPUT_STATUS, i)         = objSNMP.Get(gpidInputStatus         & strIndex)            
  339.             snmpGpidInput(INPUT_MEDIA_TYPE, i)     = objSNMP.Get(gpidInputMediaType     & strIndex)
  340.             snmpGpidInput(INPUT_MEDIA_SIZE, i)     = objSNMP.Get(gpidInputMediaSize     & strIndex)
  341.             snmpGpidInput(INPUT_MAX_CAPACITY, i)     = objSNMP.Get(gpidInputMaxCapacity     & strIndex)
  342.             snmpGpidInput(INPUT_CURRENT_LEVEL, i)     = objSNMP.Get(gpidInputCurrentLevel     & strIndex)
  343.             snmpGpidInput(INPUT_TRAY_TYPE, i)     = objSNMP.Get(gpidInputTrayType     & strIndex)
  344.         Next
  345.     End If
  346.  
  347.     '******************************************************
  348.     'Get gpidMarker filtering any unwanted marker devices
  349.     '******************************************************
  350.     snmpGpidMarkerStatus = objSNMP.Get(gpidMarkerStatus)
  351.     snmpGpidMarkerLifeCounts = objSNMP.Get(gpidMarkerLifeCounts)
  352.     snmpResponse = objSNMP.Get(gpidMarkerSuppliesNumber)
  353.     Select Case model
  354.         Case M_740, M_780
  355.             supply_parms = 7
  356.         Case Else
  357.             supply_parms = 6
  358.     End Select
  359.     If snmpResponse > 0 Then
  360.         ReDim snmpGpidMarker(supply_parms, snmpResponse - 1)
  361.         j = 0
  362.         For i = 0 To snmpResponse - 1
  363.             strIndex = cStr(i+1)
  364.             m_colorant = objSNMP.Get(gpidMarkerSuppliesColorantId     & strIndex)
  365.             m_type     = objSNMP.Get(gpidMarkerSuppliesType     & strIndex)
  366.             If NOT FilterGpidMarker(model,m_colorant,m_type) Then
  367.                 snmpGpidMarker(MARKER_COLORANT, j)     = m_colorant
  368.                 snmpGpidMarker(MARKER_TYPE, j)         = m_type            
  369.                 snmpGpidMarker(MARKER_MAX_CAPACITY, j)     = objSNMP.Get(gpidMarkerSuppliesMaxCapacity     & strIndex)
  370.                 snmpGpidMarker(MAKER_LEVEL, j)         = objSNMP.Get(gpidMarkerSuppliesCurrentLevel     & strIndex)
  371.                 snmpGpidMarker(MARKER_MAX_LIFE, j)     = objSNMP.Get(gpidMarkerSuppliesMaxLifeCount     & strIndex)
  372.                 snmpGpidMarker(MARKER_LIFE, j)         = objSNMP.Get(gpidMarkerSuppliesLifeCount     & strIndex)
  373.                 snmpGpidMarker(MARKER_SUPPLY_STATUS, j) = objSNMP.Get(gpidMarkerSuppliesStatus         & strIndex)
  374.                 If supply_parms = 7 Then
  375.                     snmpGpidMarker(MARKER_SUPPLY_REMAINING, j) = objSNMP.Get(gpidMarkerSuppliesRemaining     & strIndex)
  376.                 End If            
  377.                 j = j + 1
  378.             End If 
  379.         Next
  380.         ReDim Preserve snmpGpidMarker(supply_parms,j-1)
  381.     End If    
  382.  
  383.     '******************************************************
  384.     'Get sys
  385.     '******************************************************
  386.     snmpSysContact = objSNMP.Get(sysContact)
  387.     snmpSysLocation = objSNMP.Get(sysLocation)
  388.  
  389.     objSNMP.close
  390.  
  391. End Function
  392.  
  393. Function DumpStatus( label, status, dimensions )
  394.  
  395.     Dim strHTML, i, j
  396.  
  397.     If IsArray( status ) = False Then Exit Function
  398.  
  399.     If dimensions = 1 Then
  400.         strHTML = label & "(" & cStr( UBound( status, 1 )) & ")<br>"
  401.         For i = 0 To UBound(status, 1)
  402.             strHTML = strHTML & "  " & cStr(status(i)) & "<br>"
  403.         Next    
  404.     ElseIf dimensions = 2 Then
  405.         strHTML = label & "(" & cStr(UBound(status, 1)) & "," & cStr(UBound(status, 2)) & ")<br>"
  406.         For i = 0 To UBound(status, 2)
  407.             For j = 0 To UBound(status, 1)
  408.                 strHTML = strHTML & cStr(status(j, i)) & "    "
  409.             Next
  410.             strHTML = strHTML & "<br>"
  411.         Next    
  412.     End If
  413.  
  414.     DumpStatus = strHTML
  415.  
  416. End Function
  417.  
  418. Function DumpSNMPStatus()
  419.  
  420.     Dim strHTML, i, j
  421.  
  422.     strHTML = DumpStatus( "snmpGpidGeneral", snmpGpidGeneral, 1 )
  423.     strHTML = strHTML & DumpStatus( "snmpGpidInput", snmpGpidInput, 2 )    
  424.     strHTML = strHTML & DumpStatus( "snmpGpidMarker", snmpGpidMarker, 2 )
  425.     strHTML = strHTML & DumpStatus( "snmpPrtAlert", snmpPrtAlert, 2 )    
  426.  
  427.     DumpSNMPStatus = strHTML
  428.  
  429. End Function
  430.  
  431. %>
  432.  
  433.  
  434.  
  435.