Ad Widget

Collapse

Translate curl query to script item

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jaclaverogarcia
    Junior Member
    • Dec 2022
    • 5

    #1

    Translate curl query to script item

    I want to get values for items from ovirt rest api.
    Example:

    curl \
    --insecure
    --request GET \
    --header 'Version: 4' \
    --header 'Accept: application/json' \
    --user 'admin@internal:mypassword' \


    This will return a list of managed datacenters and more information about this.

    It can be transformed into script item?

    The objective is to obtain all the necessary information from the machine/host that manages the oVirt virtualization infrastructure and to be able to dynamically add clusters, hosts, virtual machines,... to Zabbix.

    Thanks
  • cyber
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • Dec 2006
    • 4807

    #2
    Script items are for JavaScript. So you should look up how to make http(s) calls with javascript.

    Comment

    • Hamardaban
      Senior Member
      Zabbix Certified SpecialistZabbix Certified Professional
      • May 2019
      • 2713

      #3
      Why not try using HTTP Agent?

      Comment

      • jaclaverogarcia
        Junior Member
        • Dec 2022
        • 5

        #4
        I have tried to do it both ways but are unsuccessful.

        I try again and I put the detail of what I have done.​

        Comment

        • jaclaverogarcia
          Junior Member
          • Dec 2022
          • 5

          #5
          I try:

          Name: datacenters
          Type: HTTP agent
          Key: ovirt.api.datacenters
          Type of information: Text
          URL: https://example.com/ovirt-engine/api/datacenters
          Query fields:
          user => admin@internalassword
          insecure => true
          Request type: GET
          Timeout: 3s
          Rquest body type: Raw data
          Rquest body: idon't undrestand it, i leave blank.
          Headers:
          accept => aplication/json
          version => 4

          I think that the other field in form are not necesary.

          The result is:

          "Response code 401 did not match any of required status codes 200"

          Comment

          • Hamardaban
            Senior Member
            Zabbix Certified SpecialistZabbix Certified Professional
            • May 2019
            • 2713

            #6
            The result reflects the fact that the received return code 401 (Unauthorized) did not match the expected 200,
            Try to use HTTP authentication option and specify login\password not in the "Query fields".

            Comment

            • jaclaverogarcia
              Junior Member
              • Dec 2022
              • 5

              #7
              All is OK at now. Thanks.

              On the other hand, is it possible to create hosts from a discovery rule?

              Comment


              • Hamardaban
                Hamardaban commented
                Editing a comment
                Yes, it is possible. But there are a number of specific and non-obvious restrictions on working with network interfaces
            • jaclaverogarcia
              Junior Member
              • Dec 2022
              • 5

              #8
              I'm successfully retrieving values from the oVirt API, but I don't see where to define my macros for the values I get via HTTP agent.

              I have doubts if I should do this from a script executed on the server or the agent, or if it is possible to do it directly from the Zabbix front.​

              Comment

              • cyber
                Senior Member
                Zabbix Certified SpecialistZabbix Certified Professional
                • Dec 2006
                • 4807

                #9
                What macros are you looking for?

                Comment

                Working...