<%
' Zabbix function to get supply levels AND part numbers
%>
<!--#include file="./zabbix.asp"-->
<%

' Function to get ALL printer supply items (levels + part numbers)
Function GetAllPrinterSuppliesWithParts(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
        GetAllPrinterSuppliesWithParts = "{""error"":""Host not found in Zabbix"",""ip"":""" & hostIP & """}"
        Exit Function
    End If

    ' Extract hostid
    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
        GetAllPrinterSuppliesWithParts = "{""error"":""Could not extract hostid""}"
        Exit Function
    End If

    ' Get ALL items with type:level OR type:info tags (supplies and maintenance)
    ' This will get both the levels and the part numbers
    Dim itemRequest
    itemRequest = "{" & _
        """jsonrpc"":""2.0""," & _
        """method"":""item.get""," & _
        """params"":{" & _
            """output"":[""itemid"",""name"",""lastvalue"",""lastclock"",""units"",""status"",""state""]," & _
            """hostids"":[""" & hostID & """]," & _
            """selectTags"":""extend""," & _
            """sortfield"":""name""," & _
            """monitored"":true" & _
        "}," & _
        """id"":5" & _
    "}"

    ' Make the item.get call
    Dim itemResponse
    itemResponse = ZabbixAPICall(itemRequest)

    GetAllPrinterSuppliesWithParts = itemResponse
End Function

%>
