Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add code to ensure interfacedetails is always a hash #793

Merged

Conversation

oraziobattaglia
Copy link
Contributor

@oraziobattaglia oraziobattaglia commented Sep 14, 2021

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:

      "interfaces": [
        {
          "interfaceid": "36",
          "type": "1",
          "main": "1",
          "ip": "10.10.10.1",
          "port": "10050",
          "useip": "1",
          "details": []
        }
      ]

and the error on puppet is:

interfacedetails changed [] to {} (corrective)

@root-expert root-expert added the bug Something isn't working label Sep 14, 2021
@bastelfreak
Copy link
Member

hey @oraziobattaglia, thanks for the PR. do you think there is an easy way to add tests for this?

@root-expert
Copy link
Member

Hey @oraziobattaglia according to the API reference details is supposed to be an Array. Maybe it returns an array of hashes every time?

@oraziobattaglia
Copy link
Contributor Author

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.

@root-expert
Copy link
Member

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

@oraziobattaglia
Copy link
Contributor Author

Hi @root-expert seems it's a known bug, here they have similar problems with ansible ansible-collections/community.zabbix#51

@oraziobattaglia
Copy link
Contributor Author

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

@kenyon kenyon changed the title Add code to ensure interfacedetails is always an hash Add code to ensure interfacedetails is always a hash Oct 4, 2021
@root-expert root-expert merged commit 0d729c7 into voxpupuli:master Oct 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants