This project is a Python script that synchronizes UniFi devices with Snipe-IT. It fetches devices from a UniFi controller, formats them, and adds or updates them in Snipe-IT. The script can also create new models in Snipe-IT if they don't already exist.
- Fetch devices from UniFi controller
- Fetch existing UniFi devices from Snipe-IT
- Create new models in Snipe-IT if they don't already exist
- Add or update devices in Snipe-IT based on their serial numbers.
- Dry run mode to preview changes without modifying Snipe-IT
- Python 3.6 or higher
requests
libraryratelimiter
librarytabulate
librarypyunifi
librarytermcolor
libary
These can all be installed using requirements.txt discribed in the steps below.
- Clone the repository or download the source code.
`git clone https://github.com/yourusername/unifi-to-snipeit.git cd unifi-to-snipeit`
- Install the required libraries.
pip3 install -r requirements.txt
- Copy
config_example.ini
toconfig.ini
and update the configuration settings with your UniFi and Snipe-IT credentials and preferences.
cp config_example.ini config.ini
There are a few things to take care of in Snipe-IT before you start the configuration
- Get an API Key
- Create a manufacturer of Ubiquiti (if you have not already, or choose a default manufacturer)
- Create a Networking Asset Category (if you have not already, or choose a default asset category)
- Make sure the fieldset you are using has a ip address custom field
- Make sure the fieldset you are using has a mac address custom field
Update the config.ini
file with your UniFi controller and Snipe-IT API credentials and preferences. The following sections are available for configuration:
[UniFi]
: UniFi controller settings (URL, username, password, port, version, and site ID)[SnipeIT]
: Snipe-IT API settings (API URL, API key, manufacturer, model category ID, MAC address field name, IP address field name, default status ID, device name priority, and rate limit)[unifi_model_mapping]
: UniFi model mapping for converting UniFi model names to Snipe-IT model names
Ubuiquiti has had some "fun" with their model numbers. When originally adding our Unifi devices into Snipe-IT, we used the model numbers shown of the devices detail page in the control panel. However, the API returns a completely different set of model numbers for devices. The unifi_model_mapping allows you to map the API model numbers to existing models numbers you might have set in Snipe-IT already.
We used the PyUnifi libary to interact with the Unifi API. You might want to read through their docs to debug your particular connection. We included a unifi.py file where you can test your settings. https://github.com/finish06/pyunifi
To run the script, execute the following command:
python main.py
To perform a dry run without making changes to Snipe-IT, use the --dry-run
option:
python main.py --dry-run
During the dry run, the script will output a summary of the changes that would be made to Snipe-IT.
To override the site_id
specified in the config file, use the --site-id
option followed by the new site ID:
python main.py --site-id new_site_id
This is useful if your unifi controller has more than one site. There is not currently support for more than one controller. If you have multible controllers we recommend setting up another instance of the script with a different config file.
Please feel free to open issues or submit pull requests with bug fixes or improvements. Your contributions are welcome and appreciated.
This project is licensed under the MIT License. See the LICENSE file for more information.