Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ The plugin is configuration to do exactly what you want, by means of the plugin
'no_alerting_tag_value': '1',
'attach_objtag': True,
'objtag_type': 'nb_type',
'objtag_id': 'nb_id'
'objtag_id': 'nb_id',
'custom_field_hostname':'',
'custom_field_display_name':''
}
```

Expand Down Expand Up @@ -208,6 +210,9 @@ These tags allow you to navigate from a Zabbix host back to the corresponding N
| `objtag_type` | `nb_type` | Tag name for the NetBox object type |
| `objtag_id` | `nb_id` | Tag name for the NetBox object ID |

### custom_field_hostname and custom_field_display_name
You can use these fields to map the connection between NetBox and the Zabbix hostname and display name. The device name is used as the default.

## Enabling and Disabling Synchronization

Two separate `sync_enabled` flags control whether synchronization to Zabbix is active.
Expand All @@ -216,4 +221,4 @@ Two separate `sync_enabled` flags control whether synchronization to Zabbix is a

**On `ZabbixServerAssignment`**: disabling this stops synchronization for that specific device/VM assignment only. Other assignments to the same or different Zabbix servers are unaffected.

Both flags must be `True` for a sync to proceed. The "Sync Status" column on the Zabbix Server Assignments list shows a green check only when both the assignment and its server are enabled.
Both flags must be `True` for a sync to proceed. The "Sync Status" column on the Zabbix Server Assignments list shows a green check only when both the assignment and its server are enabled.
2 changes: 2 additions & 0 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ PLUGINS_CONFIG = {
'attach_objtag': True,
'objtag_type': 'nb_type',
'objtag_id': 'nb_id',
'custom_field_hostname':'',
'custom_field_display_name':'',
}
}
```
Expand Down
2 changes: 2 additions & 0 deletions nbxsync/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ class nbxSync(PluginConfig):
'attach_objtag': False,
'objtag_type': 'nb_type',
'objtag_id': 'nb_id',
'custom_field_hostname': '',
'custom_field_display_name': '',
}
queues = []
validated_config = None
Expand Down
4 changes: 4 additions & 0 deletions nbxsync/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ class PluginSettingsModel(BaseModel):
objtag_id: str = Field(default='nb_id')


custom_field_hostname: str = Field(default='')
custom_field_display_name: str = Field(default='')


# Helper function
def get_plugin_settings() -> PluginSettingsModel:
plugin_config = apps.get_app_config('nbxsync')
Expand Down
25 changes: 23 additions & 2 deletions nbxsync/utils/sync/hostsync.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,34 @@ class HostSync(ZabbixSyncBase):
def api_object(self):
return self.api.host

def get_name_value(self):
def get_base_name(self):
# If the object has the "name" attribute, only return that (Device). If not (cornercase?), return the display string
if hasattr(self.obj.assigned_object, 'name'):
return self.obj.assigned_object.name

return str(self.obj.assigned_object)

def get_name_value(self):
base_name = self.get_base_name()
cf_name = getattr(self.pluginsettings, 'custom_field_hostname', '')
if cf_name and hasattr(self.obj.assigned_object, 'custom_field_data'):
cf_value = self.obj.assigned_object.custom_field_data.get(cf_name)
if cf_value:
return str(cf_value)
return base_name

def get_display_name(self):
base_name = self.get_base_name()
cf_name = getattr(self.pluginsettings, 'custom_field_display_name', '')
if cf_name and hasattr(self.obj.assigned_object, 'custom_field_data'):
cf_value = self.obj.assigned_object.custom_field_data.get(cf_name)
if cf_value:
return str(cf_value)
return base_name

def find_by_name(self):
return self.api_object().get(filter={'host': self.sanitize_string(input_str=str(self.get_name_value()))})

def get_create_params(self):
status = self.obj.assigned_object.status
object_type = self.obj.assigned_object._meta.model_name # "device" or "virtualmachine"
Expand All @@ -41,7 +62,7 @@ def get_create_params(self):

return {
'host': self.sanitize_string(input_str=str(self.get_name_value())),
'name': self.get_name_value(),
'name': self.get_display_name(),
'groups': self.get_groups(),
'status': host_status,
'description': self.obj.assigned_object.description or '',
Expand Down