Closed oraziobattaglia closed 2 years ago
hey @oraziobattaglia, thanks for the PR. do you think there is an easy way to add tests for this?
Hey @oraziobattaglia according to the API reference details is supposed to be an Array. Maybe it returns an array of hashes every time?
Hi @root-expert me and my colleague working on this have seen that if interfacedetails has data the API returns an hash of data like
"details": {
"version": "2",
"bulk": "1",
"community": "{$SNMP_COMMUNITY}"
}
In case interfacedetails has no data the API returns an empty array like
"details": []
I don't know why, maybe is a question related to the API, but the resource isn't idempotent.
So the solution I found here is to declare a variant type for interfacedetails:
Variant[Array, Hash] $interfacedetails = [],
We also tried to declare interfacedetails as an array of hashes and seems to work fine too:
Array[Hash] $interfacedetails = [],
But in this second case I don't full understand how it works!! :-O
Let me know if you have suggestions. Thanks for the help.
I would say that this could be a Zabbix bug or incorrect documentation. Can you try raising an issue to their Jira before continuing further with this PR?
The Variant solution seems okay to me. The Array[Hash]
we have to ensure that passing
"details": [
{ "foo": "bar" }
]
to the API is okay, or the API throws an error
Hi @root-expert seems it's a known bug, here they have similar problems with ansible https://github.com/ansible-collections/community.zabbix/pull/51
The interface details as array of hashes doesn't work:
"details": [ { "foo": "bar" } ]
Puppet doesn't converge and there is always the error:
expected "details": [ { "foo": "bar" } ]
received "details": { "foo": "bar" }
This is because, I think, there is a bug on the zabbix API. When interface details are given as hash the API returns an hash of data (not an array of hash). When interface details are not given the API returns an empty array [].
I add a test, test4.example.com, that show that an empty interface details returns an empty array.
If you have suggestions they are welcome! Thank you
Pull Request (PR) description
This PR follow PR #785 to ensure the host object idempotency. When interface details are empty the zabbix API returns an empty array and I need to convert it in an empty hash.
Example
This is returned by the api call:
and the error on puppet is: