ninech / netbox-client-ruby

A ruby client library for Netbox v2.
MIT License
24 stars 23 forks source link

How do I get all the interfaces for the device #67

Open wilful opened 6 months ago

wilful commented 6 months ago

Hi, tell me how, having only the hostname (name/display), to get all the interfaces of the device with addresses? In my case, I'm trying to use a device query and I get nil.

>> NetboxClientRuby.dcim.interfaces.find_by(device: 'brz-v-itmg-1')

I, [2024-03-12T23:14:48.133484 #73591]  INFO -- request: GET https://netbox.../api/dcim/interfaces.json?device=brz-v-itmg-1&limit=50
I, [2024-03-12T23:14:48.133513 #73591]  INFO -- request: Authorization: "Token ***"
User-Agent: "Faraday v1.10.3"
I, [2024-03-12T23:14:49.461606 #73591]  INFO -- response: Status 200
I, [2024-03-12T23:14:49.461814 #73591]  INFO -- response: content-type: "application/json"
vary: "HX-Request, Cookie, origin, Accept-Encoding"
allow: "GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS, TRACE"
x-request-id: "1129bd3c-283c-49a0-9be5-14a6eefaf198"
x-content-type-options: "nosniff"
referrer-policy: "same-origin"
cross-origin-opener-policy: "same-origin"
x-frame-options: "SAMEORIGIN"
server: "envoy"
date: "Tue, 12 Mar 2024 20:14:49 GMT"
x-envoy-upstream-service-time: "862"
transfer-encoding: "chunked"
nil

But the same request in the console works and I get the necessary interfaces

curl -H "Authorization: Token ***" 'https://netbox.../api/dcim/interfaces.json?device=brz-v-itmg-1&limit=50' | jq
{
  "count": 7,
...
shaneshort commented 4 months ago

You want to use filter, not find_by, this tripped me up too.