1010def get_config ():
1111 p = jsonargparse .ArgumentParser (
1212 default_config_files = [
13- ' /etc/netbox_agent.yaml' ,
14- ' ~/.config/netbox_agent.yaml' ,
15- ' ~/.netbox_agent.yaml' ,
13+ " /etc/netbox_agent.yaml" ,
14+ " ~/.config/netbox_agent.yaml" ,
15+ " ~/.netbox_agent.yaml" ,
1616 ],
17- prog = ' netbox_agent' ,
17+ prog = " netbox_agent" ,
1818 description = "Netbox agent to run on your infrastructure's servers" ,
19- env_prefix = ' NETBOX_AGENT_' ,
20- default_env = True
19+ env_prefix = " NETBOX_AGENT_" ,
20+ default_env = True ,
2121 )
22- p .add_argument ('-c' , ' --config' , action = jsonargparse .ActionConfigFile )
22+ p .add_argument ("-c" , " --config" , action = jsonargparse .ActionConfigFile )
2323
24- p .add_argument ('-r' , '--register' , action = 'store_true' , help = 'Register server to Netbox' )
25- p .add_argument ('-u' , '--update-all' , action = 'store_true' , help = 'Update all infos in Netbox' )
26- p .add_argument ('-d' , '--debug' , action = 'store_true' , help = 'Print debug infos' )
27- p .add_argument ('--update-network' , action = 'store_true' , help = 'Update network' )
28- p .add_argument ('--update-inventory' , action = 'store_true' , help = 'Update inventory' )
29- p .add_argument ('--update-location' , action = 'store_true' , help = 'Update location' )
30- p .add_argument ('--update-psu' , action = 'store_true' , help = 'Update PSU' )
31- p .add_argument ('--update-hypervisor' , action = 'store_true' , help = 'Update virtualization cluster and virtual machines' )
32- p .add_argument ('--update-old-devices' , action = 'store_true' ,
33- help = 'Update serial number of existing (old ?) devices having same name but different serial' )
34- p .add_argument ('--purge-old-devices' , action = 'store_true' ,
35- help = 'Purge existing (old ?) devices having same name but different serial' )
36- p .add_argument ('--expansion-as-device' , action = 'store_true' ,
37- help = 'Manage blade expansions as external devices' )
24+ p .add_argument ("-r" , "--register" , action = "store_true" , help = "Register server to Netbox" )
25+ p .add_argument ("-u" , "--update-all" , action = "store_true" , help = "Update all infos in Netbox" )
26+ p .add_argument ("-d" , "--debug" , action = "store_true" , help = "Print debug infos" )
27+ p .add_argument ("--update-network" , action = "store_true" , help = "Update network" )
28+ p .add_argument ("--update-inventory" , action = "store_true" , help = "Update inventory" )
29+ p .add_argument ("--update-location" , action = "store_true" , help = "Update location" )
30+ p .add_argument ("--update-psu" , action = "store_true" , help = "Update PSU" )
31+ p .add_argument (
32+ "--update-hypervisor" ,
33+ action = "store_true" ,
34+ help = "Update virtualization cluster and virtual machines" ,
35+ )
36+ p .add_argument (
37+ "--update-old-devices" ,
38+ action = "store_true" ,
39+ help = "Update serial number of existing (old ?) devices having same name but different serial" ,
40+ )
41+ p .add_argument (
42+ "--purge-old-devices" ,
43+ action = "store_true" ,
44+ help = "Purge existing (old ?) devices having same name but different serial" ,
45+ )
46+ p .add_argument (
47+ "--expansion-as-device" ,
48+ action = "store_true" ,
49+ help = "Manage blade expansions as external devices" ,
50+ )
3851
39- p .add_argument ('--log_level' , default = 'debug' )
40- p .add_argument ('--netbox.ssl_ca_certs_file' , help = 'SSL CA certificates file' )
41- p .add_argument ('--netbox.url' , help = 'Netbox URL' )
42- p .add_argument ('--netbox.token' , help = 'Netbox API Token' )
43- p .add_argument ('--netbox.ssl_verify' , default = True , action = 'store_true' ,
44- help = 'Disable SSL verification' )
45- p .add_argument ('--virtual.enabled' , action = 'store_true' , help = 'Is a virtual machine or not' )
46- p .add_argument ('--virtual.cluster_name' , help = 'Cluster name of VM' )
47- p .add_argument ('--virtual.hypervisor' , action = 'store_true' , help = 'Is a hypervisor or not' )
48- p .add_argument ('--virtual.list_guests_cmd' , default = None ,
49- help = 'Command to output the list of vrtualization guests in the hypervisor separated by whitespace' )
50- p .add_argument ('--hostname_cmd' , default = None ,
51- help = "Command to output hostname, used as Device's name in netbox" )
52- p .add_argument ('--device.platform' , default = None ,
53- help = 'Override device platform. Here we use OS distribution.' )
54- p .add_argument ('--device.tags' , default = r'' ,
55- help = 'tags to use for a host' )
56- p .add_argument ('--preserve-tags' , action = 'store_true' , help = 'Append new unique tags, preserve those already present' )
57- p .add_argument ('--device.custom_fields' , default = r'' ,
58- help = 'custom_fields to use for a host, eg: field1=v1,field2=v2' )
59- p .add_argument ('--device.blade_role' , default = r'Blade' ,
60- help = 'role to use for a blade server' )
61- p .add_argument ('--device.chassis_role' , default = r'Server Chassis' ,
62- help = 'role to use for a chassis' )
63- p .add_argument ('--device.server_role' , default = r'Server' ,
64- help = 'role to use for a server' )
65- p .add_argument ('--tenant.driver' ,
66- help = 'tenant driver, ie cmd, file' )
67- p .add_argument ('--tenant.driver_file' ,
68- help = 'tenant driver custom driver file path' )
69- p .add_argument ('--tenant.regex' ,
70- help = 'tenant regex to extract Netbox tenant slug' )
71- p .add_argument ('--datacenter_location.driver' ,
72- help = 'Datacenter location driver, ie: cmd, file' )
73- p .add_argument ('--datacenter_location.driver_file' ,
74- help = 'Datacenter location custom driver file path' )
75- p .add_argument ('--datacenter_location.regex' ,
76- help = 'Datacenter location regex to extract Netbox DC slug' )
77- p .add_argument ('--rack_location.driver' , help = 'Rack location driver, ie: cmd, file' )
78- p .add_argument ('--rack_location.driver_file' , help = 'Rack location custom driver file path' )
79- p .add_argument ('--rack_location.regex' , help = 'Rack location regex to extract Rack name' )
80- p .add_argument ('--slot_location.driver' , help = 'Slot location driver, ie: cmd, file' )
81- p .add_argument ('--slot_location.driver_file' , help = 'Slot location custom driver file path' )
82- p .add_argument ('--slot_location.regex' , help = 'Slot location regex to extract slot name' )
83- p .add_argument ('--network.ignore_interfaces' , default = r'(dummy.*|docker.*)' ,
84- help = 'Regex to ignore interfaces' )
85- p .add_argument ('--network.ignore_ips' , default = r'^(127\.0\.0\..*|fe80.*|::1.*)' ,
86- help = 'Regex to ignore IPs' )
87- p .add_argument ('--network.ipmi' , default = True , help = 'Enable gathering IPMI information' )
88- p .add_argument ('--network.lldp' , help = 'Enable auto-cabling feature through LLDP infos' )
89- p .add_argument ('--inventory' , action = 'store_true' ,
90- help = 'Enable HW inventory (CPU, Memory, RAID Cards, Disks) feature' )
91- p .add_argument ('--process-virtual-drives' , action = 'store_true' ,
92- help = 'Process virtual drives information from RAID '
93- 'controllers to fill disk custom_fields' )
94- p .add_argument ('--force-disk-refresh' , action = 'store_true' ,
95- help = 'Forces disks detection reprocessing' )
96- p .add_argument ('--dump-disks-map' ,
97- help = 'File path to dump physical/virtual disks map' )
52+ p .add_argument ("--log_level" , default = "debug" )
53+ p .add_argument ("--netbox.ssl_ca_certs_file" , help = "SSL CA certificates file" )
54+ p .add_argument ("--netbox.url" , help = "Netbox URL" )
55+ p .add_argument ("--netbox.token" , help = "Netbox API Token" )
56+ p .add_argument (
57+ "--netbox.ssl_verify" , default = True , action = "store_true" , help = "Disable SSL verification"
58+ )
59+ p .add_argument ("--virtual.enabled" , action = "store_true" , help = "Is a virtual machine or not" )
60+ p .add_argument ("--virtual.cluster_name" , help = "Cluster name of VM" )
61+ p .add_argument ("--virtual.hypervisor" , action = "store_true" , help = "Is a hypervisor or not" )
62+ p .add_argument (
63+ "--virtual.list_guests_cmd" ,
64+ default = None ,
65+ help = "Command to output the list of vrtualization guests in the hypervisor separated by whitespace" ,
66+ )
67+ p .add_argument (
68+ "--hostname_cmd" ,
69+ default = None ,
70+ help = "Command to output hostname, used as Device's name in netbox" ,
71+ )
72+ p .add_argument (
73+ "--device.platform" ,
74+ default = None ,
75+ help = "Override device platform. Here we use OS distribution." ,
76+ )
77+ p .add_argument ("--device.tags" , default = r"" , help = "tags to use for a host" )
78+ p .add_argument (
79+ "--preserve-tags" ,
80+ action = "store_true" ,
81+ help = "Append new unique tags, preserve those already present" ,
82+ )
83+ p .add_argument (
84+ "--device.custom_fields" ,
85+ default = r"" ,
86+ help = "custom_fields to use for a host, eg: field1=v1,field2=v2" ,
87+ )
88+ p .add_argument ("--device.blade_role" , default = r"Blade" , help = "role to use for a blade server" )
89+ p .add_argument (
90+ "--device.chassis_role" , default = r"Server Chassis" , help = "role to use for a chassis"
91+ )
92+ p .add_argument ("--device.server_role" , default = r"Server" , help = "role to use for a server" )
93+ p .add_argument ("--tenant.driver" , help = "tenant driver, ie cmd, file" )
94+ p .add_argument ("--tenant.driver_file" , help = "tenant driver custom driver file path" )
95+ p .add_argument ("--tenant.regex" , help = "tenant regex to extract Netbox tenant slug" )
96+ p .add_argument (
97+ "--datacenter_location.driver" , help = "Datacenter location driver, ie: cmd, file"
98+ )
99+ p .add_argument (
100+ "--datacenter_location.driver_file" , help = "Datacenter location custom driver file path"
101+ )
102+ p .add_argument (
103+ "--datacenter_location.regex" , help = "Datacenter location regex to extract Netbox DC slug"
104+ )
105+ p .add_argument ("--rack_location.driver" , help = "Rack location driver, ie: cmd, file" )
106+ p .add_argument ("--rack_location.driver_file" , help = "Rack location custom driver file path" )
107+ p .add_argument ("--rack_location.regex" , help = "Rack location regex to extract Rack name" )
108+ p .add_argument ("--slot_location.driver" , help = "Slot location driver, ie: cmd, file" )
109+ p .add_argument ("--slot_location.driver_file" , help = "Slot location custom driver file path" )
110+ p .add_argument ("--slot_location.regex" , help = "Slot location regex to extract slot name" )
111+ p .add_argument (
112+ "--network.ignore_interfaces" ,
113+ default = r"(dummy.*|docker.*)" ,
114+ help = "Regex to ignore interfaces" ,
115+ )
116+ p .add_argument (
117+ "--network.ignore_ips" ,
118+ default = r"^(127\.0\.0\..*|fe80.*|::1.*)" ,
119+ help = "Regex to ignore IPs" ,
120+ )
121+ p .add_argument ("--network.ipmi" , default = True , help = "Enable gathering IPMI information" )
122+ p .add_argument ("--network.lldp" , help = "Enable auto-cabling feature through LLDP infos" )
123+ p .add_argument (
124+ "--inventory" ,
125+ action = "store_true" ,
126+ help = "Enable HW inventory (CPU, Memory, RAID Cards, Disks) feature" ,
127+ )
128+ p .add_argument (
129+ "--process-virtual-drives" ,
130+ action = "store_true" ,
131+ help = "Process virtual drives information from RAID "
132+ "controllers to fill disk custom_fields" ,
133+ )
134+ p .add_argument (
135+ "--force-disk-refresh" , action = "store_true" , help = "Forces disks detection reprocessing"
136+ )
137+ p .add_argument ("--dump-disks-map" , help = "File path to dump physical/virtual disks map" )
98138
99139 options = p .parse_args ()
100140 return options
@@ -105,7 +145,7 @@ def get_config():
105145
106146def get_netbox_instance ():
107147 if config .netbox .url is None or config .netbox .token is None :
108- logging .error (' Netbox URL and token are mandatory' )
148+ logging .error (" Netbox URL and token are mandatory" )
109149 sys .exit (1 )
110150
111151 nb = pynetbox .api (
0 commit comments