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

id parameter of get.dcim.devices action #48

Open
rgrueebler opened this issue Feb 25, 2024 · 4 comments
Open

id parameter of get.dcim.devices action #48

rgrueebler opened this issue Feb 25, 2024 · 4 comments
Assignees
Labels

Comments

@rgrueebler
Copy link

Hi everyone,

I played around with the netbox.get.dcim.devices action. When I execute it without any parameters, it returns all the devices, which is expected. There is also the 'id' parameter. I assumed that I can get the data from a specific device with it. I realized that I need to enter a list. So I executed the action with an 'id' of '[1]'.

The return value of the action is this:

{
  "raw": {},
  "status": 404
}

In the nginx access logs from Netbox there is the following entry:

25/Feb/2024:08:15:33 -0500] "GET /api/dcim/devices/%5B1%5D/?save_in_key_store=False&save_in_key_store_ttl=60 HTTP/1.1" 404 23 "-" "python-requests/2.31.0"

My understanding is that '%5B1%5D/' represents '[1]'. So the action tries to access '/api/dcim/device/[1]...'.
Am I using the id parameter in the wrong way?

Thank you
Remo

@aopdal
Copy link

aopdal commented Feb 26, 2024

I think you are right, when I test creating a workflow using the action like this:

version: 1.0
tasks:
  task1:
    action: netbox.get.dcim.devices
    input:
      id:
        - 1

I get:
st2.actions.python.NetboxHTTPAction: DEBUG endpoint_uri transformed to /dcim/devices/[1]/ because id was passed

When I try in NetBox API /api/dcim/devices/{id}/ I get:

/api/dcim/devices/1/

And If I tries

version: 1.0
tasks:
  # [261, 196]
  task1:
    action: netbox.get.dcim.devices
    input:
      id:
        - 1
        - 2

I get

endpoint_uri transformed to /dcim/devices/[1, 2]/ because id was passed

But I want something like:
api/dcim/devices/?id=1&id=2

So I think it looks like the action get.dcim.devices is a combination of two API endpoints:

/api/dcim/devices/
/api/dcim/devices/{id}/

@aopdal
Copy link

aopdal commented Feb 26, 2024

Looks like its her in the run.py:

        if http_verb == 'get':
            if kwargs.get('id', False) and get_detail_route_eligible:
                # modify the `endpoint_uri` to use the detail route
                endpoint_uri = '{}{}/'.format(endpoint_uri, str(kwargs.pop('id')))
                self.logger.debug(
                    'endpoint_uri transformed to {} because id was passed'.format(endpoint_uri)
                )

For this to work it must be only one ID used in the get, and the [] must be stripped. And it may be hitting all the get actions when ID is used.

@rgrueebler
Copy link
Author

Do you mean something like tihs:
endpoint_uri = '{}{}/'.format(endpoint_uri, str(kwargs.pop('id')[0]))

@abhi1693 abhi1693 self-assigned this Feb 28, 2024
@abhi1693 abhi1693 added the bug label Feb 28, 2024
@aopdal
Copy link

aopdal commented Feb 28, 2024

Do you mean something like tihs: endpoint_uri = '{}{}/'.format(endpoint_uri, str(kwargs.pop('id')[0]))

No, I just pointed out the api request is changed when ID is used. If other fields is used it works with more than one. When the api is the way it is it support just one.

I don't use the ID in my workflows, so I have not been hit by this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants