mirror of
https://github.com/TheNetworkGuy/netbox-zabbix-sync.git
synced 2025-07-21 19:47:24 -06:00
added option "secured_connections", shell script, README updated
This commit is contained in:
parent
f03926753a
commit
81113af519
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,4 +2,5 @@
|
|||||||
config.py
|
config.py
|
||||||
# Byte-compiled / optimized / DLL files
|
# Byte-compiled / optimized / DLL files
|
||||||
__pycache__/
|
__pycache__/
|
||||||
|
.idea/
|
||||||
*.py[cod]
|
*.py[cod]
|
||||||
|
27
README.md
27
README.md
@ -23,6 +23,12 @@ First time user? Copy the config.py.example file to config.py. This file is used
|
|||||||
cp config.py.example config.py
|
cp config.py.example config.py
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Possible configurations
|
||||||
|
SSL check can be disabled for using the script in local environment. (Not recommended for productive systems)
|
||||||
|
```
|
||||||
|
secured_connections = False
|
||||||
|
```
|
||||||
|
|
||||||
### Set environment variables
|
### Set environment variables
|
||||||
Set the following environment variables
|
Set the following environment variables
|
||||||
```
|
```
|
||||||
@ -73,15 +79,20 @@ To make the user experience easier you could add a custom link that redirects us
|
|||||||
```
|
```
|
||||||
python3 netbox_zabbix_sync.py
|
python3 netbox_zabbix_sync.py
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Running the script as Shell Script
|
||||||
|
```
|
||||||
|
./netbox-zabbix-sync.sh
|
||||||
|
```
|
||||||
### Flags
|
### Flags
|
||||||
| Flag | Option | Description |
|
| Flag | Option | Description |
|
||||||
| ------------ | ------------ | ------------ |
|
|------|-------------|---------------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
| -c | cluster | For clustered devices: only add the primary node of a cluster and use the cluster name as hostname. |
|
| -c | cluster | For clustered devices: only add the primary node of a cluster and use the cluster name as hostname. |
|
||||||
| -H | hostgroup | Create non-existing hostgroups in Zabbix. Usefull for a first run to add all required hostgroups. |
|
| -H | hostgroup | Create non-existing hostgroups in Zabbix. Usefull for a first run to add all required hostgroups. |
|
||||||
| -l | layout | Set the hostgroup layout. Default is site/manufacturer/dev_role. Posible options (seperated with '/'): site, manufacturer, dev_role, tenant |
|
| -l | layout | Set the hostgroup layout. Default is site/manufacturer/dev_role. Posible options (seperated with '/'): site, manufacturer, dev_role, tenant |
|
||||||
| -v | verbose | Log with debugging on. |
|
| -v | verbose | Log with debugging on. |
|
||||||
| -j | journal | Create journal entries in Netbox when a host gets added, modified or deleted in Zabbix |
|
| -j | journal | Create journal entries in Netbox when a host gets added, modified or deleted in Zabbix |
|
||||||
| -p | proxy-power | Force a full proxy sync (includes deleting the proxy in Zabbix if not present in config context in Netbox) |
|
| -p | proxy-power | Force a full proxy sync (includes deleting the proxy in Zabbix if not present in config context in Netbox) |
|
||||||
|
|
||||||
#### Hostgroup
|
#### Hostgroup
|
||||||
In case of omitting the -H flag, manual hostgroup creation is required for devices in a new category.
|
In case of omitting the -H flag, manual hostgroup creation is required for devices in a new category.
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
# Set Options (Not recommended for productive use)
|
||||||
|
secured_connections = True
|
||||||
|
|
||||||
# Set template and device Netbox "custom field" names
|
# Set template and device Netbox "custom field" names
|
||||||
template_cf = "zabbix_template"
|
template_cf = "zabbix_template"
|
||||||
device_cf = "zabbix_hostid"
|
device_cf = "zabbix_hostid"
|
||||||
|
8
netbox-zabbix-sync.sh
Normal file
8
netbox-zabbix-sync.sh
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
export ZABBIX_HOST="https://zabbix.local"
|
||||||
|
export ZABBIX_USER="username"
|
||||||
|
export ZABBIX_PASS="Password"
|
||||||
|
export NETBOX_HOST="https://netbox.local"
|
||||||
|
export NETBOX_TOKEN="secrettoken"
|
||||||
|
|
||||||
|
python3 netbox_zabbix_sync.py
|
@ -9,7 +9,7 @@ from pyzabbix import ZabbixAPI, ZabbixAPIException
|
|||||||
try:
|
try:
|
||||||
from config import *
|
from config import *
|
||||||
except ModuleNotFoundError:
|
except ModuleNotFoundError:
|
||||||
print(f"Configuration file config.py not found in main directory."
|
print(f"Configuration file config.py.example not found in main directory."
|
||||||
"Please create the file or rename the config.py.example file to config.py.")
|
"Please create the file or rename the config.py.example file to config.py.")
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
@ -51,6 +51,9 @@ def main(arguments):
|
|||||||
netbox_token = environ.get("NETBOX_TOKEN")
|
netbox_token = environ.get("NETBOX_TOKEN")
|
||||||
# Set Netbox API
|
# Set Netbox API
|
||||||
netbox = api(netbox_host, token=netbox_token, threading=True)
|
netbox = api(netbox_host, token=netbox_token, threading=True)
|
||||||
|
# Set Connection Rules
|
||||||
|
if not secured_connections:
|
||||||
|
netbox.http_session.verify = False
|
||||||
# Check if the provided Hostgroup layout is valid
|
# Check if the provided Hostgroup layout is valid
|
||||||
if(arguments.layout):
|
if(arguments.layout):
|
||||||
hg_objects = arguments.layout.split("/")
|
hg_objects = arguments.layout.split("/")
|
||||||
@ -460,7 +463,7 @@ class NetworkDevice():
|
|||||||
# Set Netbox custom field to hostID value.
|
# Set Netbox custom field to hostID value.
|
||||||
self.nb.custom_fields[device_cf] = int(self.zabbix_id)
|
self.nb.custom_fields[device_cf] = int(self.zabbix_id)
|
||||||
self.nb.save()
|
self.nb.save()
|
||||||
msg = f"Created host {self.name} in Zabbix."
|
msg = f"Created host {self.name} in Zabbix and edited the custom field in the netbox with {self.nb.custom_fields[device_cf]}"
|
||||||
logger.info(msg)
|
logger.info(msg)
|
||||||
self.create_journal_entry("success", msg)
|
self.create_journal_entry("success", msg)
|
||||||
else:
|
else:
|
||||||
|
@ -1,2 +1,4 @@
|
|||||||
pynetbox
|
pynetbox~=7.0.1
|
||||||
pyzabbix
|
pyzabbix~=1.3.0
|
||||||
|
|
||||||
|
config~=0.5.1
|
Loading…
Reference in New Issue
Block a user