You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Make sure that you have a python environment with the following packages installed. You can also use the requirements.txt file for installation with pip.
16
+
```
17
+
pynetbox
18
+
pyzabbix
19
+
```
20
+
20
21
### Config file
21
22
First time user? Copy the config.py.example file to config.py. This file is used for modifying filters and setting variables such as custom field names.
22
23
```
@@ -52,6 +53,83 @@ You can make the hostID field hidden or read-only to prevent human intervention.
52
53
53
54
This is optional and there is a use case for leaving it read-write in the UI to manually change the ID. For example to re-run a sync.
54
55
56
+
## Config file
57
+
58
+
### Hostgroup
59
+
Setting the create_hostgroups variable to False requires manual hostgroup creation for devices in a new category.
60
+
61
+
The format can be set with the hostgroup_format variable.
62
+
63
+
Make sure that the Zabbix user has proper permissions to create hosts.
64
+
The hostgroups are in a nested format. This means that proper permissions only need to be applied to the site name hostgroup and cascaded to any child hostgroups.
65
+
66
+
#### layout
67
+
The default hostgroup layout is "site/manufacturer/device_role".
68
+
69
+
**Variables**
70
+
71
+
You can change this behaviour with the hostgroup_format variable. The following values can be used:
72
+
| name | description |
73
+
| ------------ | ------------ |
74
+
|dev_location|The device location name|
75
+
|dev_role|The device role name|
76
+
|manufacturer|Manufacturer name|
77
+
|region|The region name of the device|
78
+
|site|Site name|
79
+
|site_group|Site group name|
80
+
|tenant|Tenant name|
81
+
|tenant_group|Tenant group name|
82
+
83
+
84
+
You can specify the value like so, sperated by a "/":
You can also use the value of custom fields under the device object.
91
+
92
+
This allows more freedom and even allows a full static mapping instead of a dynamic rendered hostgroup name.
93
+
```
94
+
hostgroup_format = "site/mycustomfieldname"
95
+
```
96
+
**Empty variables or hostgroups**
97
+
98
+
Should the content of a variable be empty, then the hostgroup position is skipped.
99
+
100
+
For example, consider the following scenario with 2 devices, both the same device type and site. One of them is linked to a tenant, the other one does not have a relationship with a tenant.
101
+
- Device_role: PDU
102
+
- Site: HQ-AMS
103
+
```
104
+
hostgroup_format = "site/tenant/device_role"
105
+
```
106
+
When running the script like above, the following hostgroup (HG) will be generated for both hosts:
107
+
- Device A with no relationship with a tenant: HQ-AMS/PDU
108
+
- Device B with a relationship to tenant "Fork Industries": HQ-AMS/Fork Industries/PDU
109
+
110
+
The same logic applies to custom fields being used in the HG format:
111
+
```
112
+
hostgroup_format = "site/mycustomfieldname"
113
+
```
114
+
For device A with the value "ABC123" in the custom field "mycustomfieldname" -> HQ-AMS/ABC123
115
+
For a device which does not have a value in the custom field "mycustomfieldname" -> HQ-AMS
116
+
117
+
Should there be a scenario where a custom field does not have a value under a device, and the HG format only uses this single variable, then this will result in an error:
118
+
```
119
+
hostgroup_format = "mycustomfieldname"
120
+
121
+
Netbox-Zabbix-sync - ERROR - ESXI1 has no reliable hostgroup. This is most likely due to the use of custom fields that are empty.
122
+
```
123
+
### Device status
124
+
By setting a status on a Netbox device you determine how the host is added (or updated) in Zabbix. There are, by default, 3 options:
125
+
* Delete the host from Zabbix (triggered by Netbox status "Decommissioning" and "Inventory")
126
+
* Create the host in Zabbix but with a disabled status (Trigger by "Offline", "Planned", "Staged" and "Failed")
127
+
* Create the host in Zabbix with an enabled status (For now only enabled with the "Active" status)
128
+
129
+
You can modify this behaviour by changing the following list variables in the script:
130
+
- zabbix_device_removal
131
+
- zabbix_device_disable
132
+
55
133
### Template source
56
134
You can either use a Netbox device type custom field or Netbox config context for the Zabbix template information.
| -c | cluster | For clustered devices: only add the primary node of a cluster and use the cluster name as hostname. |
110
-
| -H | hostgroup | Create non-existing hostgroups in Zabbix. Usefull for a first run to add all required hostgroups. |
111
-
| -l | layout | Set the hostgroup layout. Default is site/manufacturer/dev_role. Posible options (seperated with '/'): site, manufacturer, dev_role, tenant |
112
187
| -v | verbose | Log with debugging on. |
113
-
| -j | journal | Create journal entries in Netbox when a host gets added, modified or deleted in Zabbix |
114
-
| -p | proxy-power | Force a full proxy sync (includes deleting the proxy in Zabbix if not present in config context in Netbox) |
115
-
116
-
#### Hostgroup
117
-
In case of omitting the -H flag, manual hostgroup creation is required for devices in a new category.
118
-
119
-
The format can be set with the -l flag. If not provided the default format will be:
120
-
{Site name}/{Manufacturer name}/{Device role name}
121
-
122
-
Make sure that the Zabbix user has proper permissions to create hosts.
123
-
The hostgroups are in a nested format. This means that proper permissions only need to be applied to the site name hostgroup and cascaded to any child hostgroups.
124
-
125
-
#### layout
126
-
The default hostgroup layout is "site/manufacturer/device_role".
127
-
128
-
**Variables**
129
-
130
-
You can change this behaviour with the --layout flag. The following variables can be used:
131
-
| name | description |
132
-
| ------------ | ------------ |
133
-
|tenant|Tenant name|
134
-
|site|Site name|
135
-
|manufacturer|Manufacturer name|
136
-
|device_role|The device role name|
137
-
138
-
You can specify the variables like so, sperated by a "/":
Should the content of a variable be empty, then the hostgroup position is skipped.
153
-
154
-
For example, consider the following scenario with 2 devices, both the same device type and site. One of them is linked to a tenant, the other one does not have a relationship with a tenant.
For device A with the value "ABC123" in the custom field "mycustomfieldname" -> HQ-AMS/ABC123
169
-
For a device which does not have a value in the custom field "mycustomfieldname" -> HQ-AMS
170
-
171
-
Should there be a scenario where a custom field does not have a value under a device, and the HG format only uses this signle variable, then this will result in an error:
Netbox-Zabbix-sync - ERROR - ESXI1 has no reliable hostgroup. This is most likely due to the use of custom fields that are empty.
176
-
```
177
-
### Device status
178
-
By setting a status on a Netbox device you determine how the host is added (or updated) in Zabbix. There are, by default, 3 options:
179
-
* Delete the host from Zabbix (triggered by Netbox status "Decommissioning" and "Inventory")
180
-
* Create the host in Zabbix but with a disabled status (Trigger by "Offline", "Planned", "Staged" and "Failed")
181
-
* Create the host in Zabbix with an enabled status (For now only enabled with the "Active" status)
182
-
183
-
You can modify this behaviour by changing the following list variables in the script:
184
-
- zabbix_device_removal
185
-
- zabbix_device_disable
189
+
## Config context
186
190
187
191
### Zabbix proxy
188
192
You can set the proxy for a device using the 'proxy' key in config context.
@@ -193,7 +197,7 @@ You can set the proxy for a device using the 'proxy' key in config context.
193
197
}
194
198
}
195
199
```
196
-
Because of the posible amount of destruction when setting up Netbox but forgetting the proxy command, the sync works a bit different. By default everything is synced except in a situation where the Zabbix host has a proxy configured but nothing is configured in Netbox. To force deletion and a full sync, use the -p flag.
200
+
Because of the posible amount of destruction when setting up Netbox but forgetting the proxy command, the sync works a bit different. By default everything is synced except in a situation where the Zabbix host has a proxy configured but nothing is configured in Netbox. To force deletion and a full sync, set the full_proxy_sync variable in the config file.
197
201
198
202
### Set interface parameters within Netbox
199
203
When adding a new device, you can set the interface type with custom context. By default, the following configuration is applied when no config context is provided:
@@ -256,4 +260,7 @@ To configure the interface parameters you'll need to use custom context. Custom
256
260
}
257
261
}
258
262
```
263
+
264
+
I would recommend using macros for sensitive data such as community strings since the data in Netbox is plain-text.
265
+
259
266
Note: Not all SNMP data is required for a working configuration. [The following parameters are allowed ](https://www.zabbix.com/documentation/current/manual/api/reference/hostinterface/object#details_tag"The following parameters are allowed ")but are not all required, depending on your environment.
0 commit comments