mirror of
https://github.com/TheNetworkGuy/netbox-zabbix-sync.git
synced 2025-07-22 03:56:55 -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
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
.idea/
|
||||
*.py[cod]
|
||||
|
13
README.md
13
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
|
||||
```
|
||||
|
||||
#### 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 the following environment variables
|
||||
```
|
||||
@ -73,9 +79,14 @@ To make the user experience easier you could add a custom link that redirects us
|
||||
```
|
||||
python3 netbox_zabbix_sync.py
|
||||
```
|
||||
|
||||
## Running the script as Shell Script
|
||||
```
|
||||
./netbox-zabbix-sync.sh
|
||||
```
|
||||
### Flags
|
||||
| Flag | Option | Description |
|
||||
| ------------ | ------------ | ------------ |
|
||||
|------|-------------|---------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| -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. |
|
||||
| -l | layout | Set the hostgroup layout. Default is site/manufacturer/dev_role. Posible options (seperated with '/'): site, manufacturer, dev_role, tenant |
|
||||
|
@ -1,3 +1,6 @@
|
||||
# Set Options (Not recommended for productive use)
|
||||
secured_connections = True
|
||||
|
||||
# Set template and device Netbox "custom field" names
|
||||
template_cf = "zabbix_template"
|
||||
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:
|
||||
from config import *
|
||||
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.")
|
||||
sys.exit(0)
|
||||
|
||||
@ -51,6 +51,9 @@ def main(arguments):
|
||||
netbox_token = environ.get("NETBOX_TOKEN")
|
||||
# Set Netbox API
|
||||
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
|
||||
if(arguments.layout):
|
||||
hg_objects = arguments.layout.split("/")
|
||||
@ -460,7 +463,7 @@ class NetworkDevice():
|
||||
# Set Netbox custom field to hostID value.
|
||||
self.nb.custom_fields[device_cf] = int(self.zabbix_id)
|
||||
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)
|
||||
self.create_journal_entry("success", msg)
|
||||
else:
|
||||
|
@ -1,2 +1,4 @@
|
||||
pynetbox
|
||||
pyzabbix
|
||||
pynetbox~=7.0.1
|
||||
pyzabbix~=1.3.0
|
||||
|
||||
config~=0.5.1
|
Loading…
Reference in New Issue
Block a user