Tosch Automatisering N-Central libary
Project description
NCentralConnection:
A Python Class for N-central API Interaction The NCentralConnection class is designed to facilitate interactions with the N-central API. This class provides methods to authenticate, retrieve, and update data from the N-central server, making it easier to manage customers, devices, and other resources.
Class Summary
API Authentication: Automatically handles API token authentication and manages access tokens. Data Retrieval: Fetch data from various N-central endpoints, including organizations, customers, devices, and their properties. Data Manipulation: Create or update customers and their associated properties. Pagination Support: Automatically handles paginated API responses. Debugging: Optional debugging mode to print API responses.
Command-list
get_access_token: Retrieves the access token by authenticating with the N-central server. get: Makes a GET request to the N-central server and handles pagination. post: Makes a POST request to the N-central server to create or update resources. put: Makes a PUT request to the N-central server to update resources. clean_entry: Removes special characters such as '&', '/', and '"' from the given input string, and strips any leading or trailing whitespace. get_organisation: Retrieves the service organization from the N-central server. get_organisation_properties: Retrieves the default custom properties for the service organization from the N-central server. get_customers: Retrieves all customers and sub-customers from the N-central server. get_customer_sites: Retrieves all sites for a specific customer from the N-central server. get_customer_devices: Retrieves all devices associated with a specific customer from the N-central server. get_device_custom_properties: Retrieves the custom properties of a specific device from the N-central server. get_device_assets: Retrieves the asset information of a specific device from the N-central server. new_customer: Creates a new customer in the N-central server. update_customer_propertie: Updates a specific custom property for a customer in the N-central server. update_customer_contract: Updates the contract property for a customer in the N-central server. update_customer_sla: Updates the SLA property for a customer in the N-central server.
To use the NCentralConnection class, you need the following Python libraries:
requests json pandas time Install the required libraries using pip:
Initialization and Authentication
Before using any of the methods, initialize the NCentralConnection class with your N-central host and API token. from ncentral_connection import NCentralConnection ncentral = NCentralConnection(ncentral_host="your-ncentral-host", api_token="your-api-token")
The class automatically retrieves an access token upon initialization, which is used for subsequent API requests.
Methods
Get Organization Information Retrieve information about the service organization. org_info = ncentral.get_organisation(json_output=True) print(org_info)
Get Organization Properties Retrieve the default custom properties for the service organization. org_props = ncentral.get_organisation_properties(json_output=True) print(org_props)
Get Customers Retrieve all customers and sub-customers. customers = ncentral.get_customers(json_output=True) print(customers)
Get Customer Sites Retrieve all sites for a specific customer. customer_id = 12345 customer_sites = ncentral.get_customer_sites(customerid=customer_id, json_output=True) print(customer_sites)
Get Customer Devices Retrieve all devices associated with a specific customer. To get all devices, use customerid = 50. customer_id = 12345 customer_devices = ncentral.get_customer_devices(customerid=customer_id, json_output=True) print(customer_devices)
Get Device Custom Properties Retrieve the custom properties of a specific device. device_id = 67890 device_props = ncentral.get_device_custom_properties(deviceid=device_id, json_output=True) print(device_props)
Get Device Assets Retrieve the asset information of a specific device with optional filters. device_id = 67890 device_assets = ncentral.get_device_assets(deviceid=device_id, include_os=True, json_output=True) print(device_assets)
Create a New Customer Create a new customer in the N-central server. new_customer = ncentral.new_customer(customername="New Customer", externalid="12345", json_output=True) print(new_customer)
Update Customer Property Update a specific custom property for a customer. property_id = 112233 customer_id = 12345 updated_property = ncentral.update_customer_propertie(property_id=property_id, customerid=customer_id, property_value="New Value", json_output=True) print(updated_property)
Update Customer Contract Update the contract property for a customer. customer_id = 12345 updated_contract = ncentral.update_customer_contract(customerid=customer_id, property_value="New Contract", json_output=True) print(updated_contract)
Update Customer SLA Update the SLA property for a customer. customer_id = 12345 updated_sla = ncentral.update_customer_sla(customerid=customer_id, property_value="New SLA", json_output=True) print(updated_sla)
Error Handling The class uses the APIErrorHandler to handle common HTTP errors such as 400 (Bad Request), 401 (Unauthorized), 403 (Forbidden), 404 (Not Found), and 500 (Internal Server Error).
Debugging
Enable the debug mode to print the JSON response for any request. customers = ncentral.get_customers(debug=True) Contributing
Code commands by ChatGPT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ncentral-1.0.0.tar.gz.
File metadata
- Download URL: ncentral-1.0.0.tar.gz
- Upload date:
- Size: 8.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8c75d1cd0a6f81f9897b231323ccc525280703b5ac33f96ddfb2a7f02b054255
|
|
| MD5 |
3b5ea28bd70ecdc11dd09e2226d4eeea
|
|
| BLAKE2b-256 |
d882b5488da6288708f8fe07a9d5104806750f431f63ecb0e7c56c6499b7d889
|
File details
Details for the file ncentral-1.0.0-py3-none-any.whl.
File metadata
- Download URL: ncentral-1.0.0-py3-none-any.whl
- Upload date:
- Size: 9.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1477f0542537d56f1c5bc0a08d31bd6fa6493437eb774c8c042c647efaa52e0b
|
|
| MD5 |
539461ee266fc49755f533503b682bd2
|
|
| BLAKE2b-256 |
ce47c3aa72e591edbf0b967ff4db00d0507a7fa99555523748a82d181efcd123
|