Hello there,
It's my first post on this forum so I'd like to say hi
On start, I'd like to emphasize that I'm a complete noob in Zabbix API scripting and some of my questions may sound just stupid. I am aware of Zabbix documentation and I am reading it but still, for a new person it all seems a little bit overwhelming. I got this piece of code from my co-worker:
itemids = zapi.item.get(output=["itemid"],selectHosts = ["host"], search={"name": "Log4j check on port*"}, searchWildcardsEnabled=True)
for item in itemids:
print("Hostname: "+ item["hosts"][0]["host"] + " Itemid: "+item["itemid"])
print(json.dumps(zapi.history.get( itemids = itemids[0]["itemid"] , history="4")))
If I understand correctly, it's purpose is firstly to retrieve all items which names are starting with "Log4j check on port". Then, it will print all hostnames and items that it is connected to. Last step is to print history of all items from list itemids. So, my questions are:
1. Why are some values in code in square brackets and in " ". I understand that it has something to do with json format.
2. In the first line output=["itemid"] indicates that code should return only values that are ids of the items?
3. First line - selectHosts = ["host"] - I understand that statement selectHosts is a parameter from item.get method. I can't understand where can I find list of arguments I can use for this statement. In this case it's "host" in the square bracket. Is that statement used as additional "filter" next to output?
4. Third line - Can't understand why next to items there are three square brackets with hosts, 0 and host. 0 is indicating which position of the list code should print but that's all I can figure out of it.
5. Last line - the same situation with three brackets.
I know that it looks like I'm asking for explaining a whole script. I'm sure that those are very basic questions but still, I would be extremely grateful if someone could explain this to me because as I am completely new to the topic it is quite overwhelming.
It's my first post on this forum so I'd like to say hi

On start, I'd like to emphasize that I'm a complete noob in Zabbix API scripting and some of my questions may sound just stupid. I am aware of Zabbix documentation and I am reading it but still, for a new person it all seems a little bit overwhelming. I got this piece of code from my co-worker:
itemids = zapi.item.get(output=["itemid"],selectHosts = ["host"], search={"name": "Log4j check on port*"}, searchWildcardsEnabled=True)
for item in itemids:
print("Hostname: "+ item["hosts"][0]["host"] + " Itemid: "+item["itemid"])
print(json.dumps(zapi.history.get( itemids = itemids[0]["itemid"] , history="4")))
If I understand correctly, it's purpose is firstly to retrieve all items which names are starting with "Log4j check on port". Then, it will print all hostnames and items that it is connected to. Last step is to print history of all items from list itemids. So, my questions are:
1. Why are some values in code in square brackets and in " ". I understand that it has something to do with json format.
2. In the first line output=["itemid"] indicates that code should return only values that are ids of the items?
3. First line - selectHosts = ["host"] - I understand that statement selectHosts is a parameter from item.get method. I can't understand where can I find list of arguments I can use for this statement. In this case it's "host" in the square bracket. Is that statement used as additional "filter" next to output?
4. Third line - Can't understand why next to items there are three square brackets with hosts, 0 and host. 0 is indicating which position of the list code should print but that's all I can figure out of it.
5. Last line - the same situation with three brackets.
I know that it looks like I'm asking for explaining a whole script. I'm sure that those are very basic questions but still, I would be extremely grateful if someone could explain this to me because as I am completely new to the topic it is quite overwhelming.