<% ' Extended Zabbix functions for supply level queries with flexible tag filtering %> <% ' Function to get printer supply levels with only type:level tag filter Function GetPrinterSupplyLevels(hostIP) Dim jsonRequest, response ' First, find the host by IP jsonRequest = "{" & _ """jsonrpc"":""2.0""," & _ """method"":""host.get""," & _ """params"":{" & _ """output"":[""hostid""]," & _ """filter"":{" & _ """host"":[""" & hostIP & """]" & _ "}" & _ "}," & _ """id"":4" & _ "}" response = ZabbixAPICall(jsonRequest) ' Check if result array is empty If InStr(response, """result"":[]") > 0 Then GetPrinterSupplyLevels = "{""error"":""Host not found in Zabbix"",""ip"":""" & hostIP & """}" Exit Function End If ' Extract hostid from result array Dim hostID, startPos, endPos startPos = InStr(response, """hostid"":""") If startPos > 0 Then startPos = startPos + 10 endPos = InStr(startPos, response, """") hostID = Mid(response, startPos, endPos - startPos) Else GetPrinterSupplyLevels = "{""error"":""Could not extract hostid"",""response"":""" & Left(response, 200) & """}" Exit Function End If If hostID = "" Or IsNull(hostID) Then GetPrinterSupplyLevels = "{""error"":""HostID is empty"",""hostid"":""" & hostID & """}" Exit Function End If ' Now get items for this host with component:printer AND type:info tags ' This will catch toner cartridges, drums, waste cartridges, maintenance kits, etc. Dim itemRequest itemRequest = "{" & _ """jsonrpc"":""2.0""," & _ """method"":""item.get""," & _ """params"":{" & _ """output"":[""itemid"",""name"",""lastvalue"",""lastclock"",""units"",""status"",""state""]," & _ """hostids"":[""" & hostID & """]," & _ """selectTags"":""extend""," & _ """evaltype"":0," & _ """tags"":[" & _ "{""tag"":""component"",""value"":""printer"",""operator"":0}," & _ "{""tag"":""type"",""value"":""info"",""operator"":0}" & _ "]," & _ """sortfield"":""name""," & _ """monitored"":true" & _ "}," & _ """id"":5" & _ "}" ' Make the item.get call Dim itemResponse itemResponse = ZabbixAPICall(itemRequest) ' Return the item response GetPrinterSupplyLevels = itemResponse End Function %>