Napalm API with netbox API

1,101 views
Skip to first unread message

VK

unread,
Feb 22, 2018, 2:29:23 AM2/22/18
to NetBox
Hello! I apologize for my bad English.
I'm studying your API and I'm having trouble getting information from the API on the command line.
When I use a API netbox, all requests work correctly. For example:

"curl -X GET --header 'Accept: application/json' 'http://localhost/api/dcim/interfaces/"


However, if I want to add napalm API, I do not get any data on the command line. In this case everything works correctly in the browser.
I'm trying to get information about the interfaces of the device:


If I'm logged into the netbox in the browser, everything works correctly. At the command prompt, I get an empty response and an error of 403. I tried to do this with a python and found out that this was related to authorization. If I add an id cookie session I get all the data and it works.

import requests
import json


url
='http://localhost/api/dcim/devices/2/napalm/?format=json&method=get_interfaces'
cookies
= dict(sessionid='my id')
r
= requests.get(url, cookies)
r
.json()


I get the session ID with the help of the wireshark.

Unfortunately I can not understand how I get data on the command line (or python) and what I'm doing is wrong. Thank you.

Shuichiro MAKIGAKI

unread,
Feb 23, 2018, 2:09:23 AM2/23/18
to VK, NetBox
It requires the authentication? (Because API returns 403.)
https://netbox.readthedocs.io/en/latest/api/authentication/

Regards,
Makkie

2018/02/22 16:29、VK <kayu...@gmail.com>のメール:

--
You received this message because you are subscribed to the Google Groups "NetBox" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netbox-discus...@googlegroups.com.
To post to this group, send email to netbox-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netbox-discuss/cc558dd6-66f2-48fa-b566-6aa7b1cc50da%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jeremy Stretch

unread,
Feb 23, 2018, 10:03:15 AM2/23/18
to Shuichiro MAKIGAKI, VK, NetBox
You'll need to authenticate to the API using an API token associated with a user account. This user (or one of its groups) must be assigned NAPALM read access in the admin UI ("dcim | device | Read-only access to devices via NAPALM"). Then you'll be able to access the NAPALM proxy endpoint.

Hope that helps!

jeremy

On Fri, Feb 23, 2018 at 2:09 AM, Shuichiro MAKIGAKI <shuichiro...@gmail.com> wrote:
It requires the authentication? (Because API returns 403.)
https://netbox.readthedocs.io/en/latest/api/authentication/

Regards,
Makkie

2018/02/22 16:29、VK <kayu...@gmail.com>のメール:
Hello! I apologize for my bad English.
I'm studying your API and I'm having trouble getting information from the API on the command line.
When I use a API netbox, all requests work correctly. For example:

"curl -X GET --header 'Accept: application/json' 'http://localhost/api/dcim/interfaces/"


However, if I want to add napalm API, I do not get any data on the command line. In this case everything works correctly in the browser.
I'm trying to get information about the interfaces of the device:


If I'm logged into the netbox in the browser, everything works correctly. At the command prompt, I get an empty response and an error of 403. I tried to do this with a python and found out that this was related to authorization. If I add an id cookie session I get all the data and it works.

import requests
import json


url
='http://localhost/api/dcim/devices/2/napalm/?format=json&method=get_interfaces'
cookies
= dict(sessionid='my id')
r
= requests.get(url, cookies)
r
.json()


I get the session ID with the help of the wireshark.

Unfortunately I can not understand how I get data on the command line (or python) and what I'm doing is wrong. Thank you.

--
You received this message because you are subscribed to the Google Groups "NetBox" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netbox-discuss+unsubscribe@googlegroups.com.
To post to this group, send email to netbox-discuss@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "NetBox" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netbox-discuss+unsubscribe@googlegroups.com.
To post to this group, send email to netbox-discuss@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netbox-discuss/FFE1EE8F-A1E2-4A67-B22D-7CCBAD048646%40gmail.com.

VK

unread,
Feb 26, 2018, 2:42:32 AM2/26/18
to NetBox
Thank you! It works. I added a token to the administrator and get the data. I will write to you if I have any more questions.

taj singh

unread,
Feb 17, 2019, 2:19:41 AM2/17/19
to NetBox
Hi VK, I have installed Netbox NAPALM. I have added my 9300 cisco switch as a network device. Restconf is working on the switch. What should I do now? How can I pull LLDP stats? I have no idea, how can NAPALM can access switch for live data

VK

unread,
Feb 20, 2019, 1:24:39 AM2/20/19
to NetBox
Hello, taj singh!

The first thing you need to do is specify the correct platform for your device — in your case, this is Cisco IOS. You need to add the primary address of this switch in Netbox. After that, the LLDP neighbors tab will become available to you. Netbox should have access to the switch. See the ACL on your switch.

воскресенье, 17 февраля 2019 г., 12:19:41 UTC+5 пользователь taj singh написал:
Reply all
Reply to author
Forward
0 new messages