Solvik / netbox-agent

Netbox agent to run on your infrastructure's servers
Apache License 2.0
285 stars 74 forks source link

pynetbox.core.query.RequestError: The request failed with code 400 Bad Request: {'role': ['This field is required.']} with version 0.7.2 #303

Open juhnny5 opened 1 month ago

juhnny5 commented 1 month ago

Describe the bug As soon as I want to register a physical machine (Dell PowerEdge R620), I get the message below.

/usr/loca/usr/local/bin/netbox_agent -c /etc/netbox_agent.yaml -r

INFO:root:Creating server (serial: xxxxx) myserver
DEBUG:urllib3.connectionpool:https://netbox.example.org:443 "POST /api/dcim/devices/ HTTP/1.1" 400 36
Traceback (most recent call last):
  File "/usr/local/bin/netbox_agent", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.10/dist-packages/netbox_agent/cli.py", line 50, in main
    return run(config)
  File "/usr/local/lib/python3.10/dist-packages/netbox_agent/cli.py", line 43, in run
    server.netbox_create_or_update(config)
  File "/usr/local/lib/python3.10/dist-packages/netbox_agent/server.py", line 407, in netbox_create_or_update
    server = self._netbox_create_server(datacenter, tenant, rack)
  File "/usr/local/lib/python3.10/dist-packages/netbox_agent/server.py", line 272, in _netbox_create_server
    new_server = nb.dcim.devices.create(
  File "/usr/local/lib/python3.10/dist-packages/pynetbox/core/endpoint.py", line 309, in create
    ).post(args[0] if args else kwargs)
  File "/usr/local/lib/python3.10/dist-packages/pynetbox/core/query.py", line 387, in post
    return self._make_call(verb="post", data=data)
  File "/usr/local/lib/python3.10/dist-packages/pynetbox/core/query.py", line 282, in _make_call
    raise RequestError(req)
pynetbox.core.query.RequestError: The request failed with code 400 Bad Request: {'role': ['This field is required.']}

Expected behavior A clear and concise description of what you expected to happen :

As soon as I want to register a physical machine (Dell PowerEdge R620), I get the message below.

Configuration file Paste here your netbox agent configuration file :

netbox:
 url: https://netbox.example.org
 token: xxxxx
device:
 server_role: "Server"

# Enable datacenter location feature in Netbox
datacenter_location:
 driver: "cmd:cat /etc/qualification | tr [A-Z] [a-z]"
 regex: "datacenter: \"(?P<datacenter>[A-Za-z0-9]+)\""

tenant:
 driver: "cmd:cat /etc/qualification | tr [A-Z] [a-z]"
 regex: "tenant: \"(?P<tenant>[A-Za-z0-9]+)\""

# Network configuration
network:
 # Regex to ignore interfaces
 ignore_interfaces: (lo.*|dummy.*|docker.*)
 # Regex to ignore IP addresses
 ignore_ips: (127\.0\.0\..*)
 # enable auto-cabling by parsing LLDP answers
 lldp: True

inventory: True

Environment:

msteggink commented 1 month ago

This is a known issue but has not been merged yet. See: https://github.com/Solvik/netbox-agent/pull/289

CllaudiaB commented 1 week ago

@juhnny5 Hello I can confirm that you need to replace device_role with role. I'll look into this in the next few weeks.