<%
' Get Zabbix data for this printer (cached) - now includes all supplies
Dim printerIP, cachedData, zabbixConnected, pingStatus, suppliesJSON
Dim statusBadge, statusIcon, statusColor
printerIP = rs("ipaddress")
' Get all supplies data (toner, ink, drums, maintenance kits, etc.)
' Returns array: [zabbixConnected, pingStatus, suppliesJSON]
cachedData = GetAllPrinterSuppliesCached(printerIP)
' Extract data from array
zabbixConnected = cachedData(0)
pingStatus = cachedData(1)
suppliesJSON = cachedData(2)
%>
<%
If zabbixConnected <> "1" Then
' Show error details
If zabbixConnected = "" Then
Response.Write("
Unable to connect to Zabbix monitoring server (empty response)
")
Else
Response.Write("
Zabbix Connection Error:" & Server.HTMLEncode(zabbixConnected) & "
")
End If
ElseIf suppliesJSON = "" Or IsNull(suppliesJSON) Then
Response.Write("
No supply data available for this printer in Zabbix (IP: " & printerIP & ")
")
Else
' Parse the JSON data for all supply items
Dim itemStart, itemEnd, itemBlock, itemName, itemValue
Dim namePos, nameStart, nameEnd, valuePos, valueStart, valueEnd
Dim currentPos, hasData
hasData = False
' Find all items with "Level" in the name (toner, ink, drums, maintenance kits, etc.)
currentPos = 1
Do While currentPos > 0
itemStart = InStr(currentPos, suppliesJSON, "{""itemid""")
If itemStart = 0 Then Exit Do
itemEnd = InStr(itemStart + 1, suppliesJSON, "},")
If itemEnd = 0 Then
itemEnd = InStr(itemStart + 1, suppliesJSON, "}]")
End If
If itemEnd = 0 Then Exit Do
itemBlock = Mid(suppliesJSON, itemStart, itemEnd - itemStart + 1)
' Extract name
namePos = InStr(itemBlock, """name"":""")
If namePos > 0 Then
nameStart = namePos + 8
nameEnd = InStr(nameStart, itemBlock, """")
itemName = Mid(itemBlock, nameStart, nameEnd - nameStart)
Else
itemName = ""
End If
' Only process items with "Level" in the name
If InStr(1, itemName, "Level", 1) > 0 Then
' Extract value (lastvalue)
valuePos = InStr(itemBlock, """lastvalue"":""")
If valuePos > 0 Then
valueStart = valuePos + 13
valueEnd = InStr(valueStart, itemBlock, """")
itemValue = Mid(itemBlock, valueStart, valueEnd - valueStart)
' Try to convert to numeric
On Error Resume Next
Dim numericValue, progressClass
numericValue = CDbl(itemValue)
If Err.Number = 0 Then
' Determine progress bar color based on level
If numericValue < 10 Then
progressClass = "bg-danger" ' Red for critical (< 10%)
ElseIf numericValue < 25 Then
progressClass = "bg-warning" ' Yellow for low (< 25%)
Else
progressClass = "bg-success" ' Green for good (>= 25%)
End If
' Display supply level with progress bar
Response.Write("
")
Response.Write("
")
Response.Write("" & Server.HTMLEncode(itemName) & "")
Response.Write("" & Round(numericValue, 1) & "%")
Response.Write("
")
Response.Write("
")
Response.Write("
" & Round(numericValue, 1) & "%
")
Response.Write("
")
Response.Write("
")
hasData = True
End If
Err.Clear
On Error Goto 0
End If
End If
currentPos = itemEnd + 1
Loop
If Not hasData Then
Response.Write("
No supply level data available for this printer in Zabbix (IP: " & printerIP & ")
")
End If
End If
%>