|
| 1 | +# Sample Scripted Connector |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +The **Sample Scripted Connector** scripted connector is a starter script designed to demonstrate how to push fixed data to DataMiner using the Data API. Unlike other connectors that fetch data from external sources, this script simply uses hardcoded data and sends it directly to DataMiner via HTTP PUT requests. |
| 6 | + |
| 7 | +This connector is ideal for: |
| 8 | + |
| 9 | +- Learning how to use the Data API for pushing data |
| 10 | +- Testing DataMiner integrations without external dependencies |
| 11 | +- Prototyping and development workflows |
| 12 | +- Understanding authentication and HTTP request patterns |
| 13 | + |
| 14 | +## Features |
| 15 | + |
| 16 | +- **Simple Data Push**: Sends fixed data to DataMiner without requiring external data sources |
| 17 | +- **Bearer Token Authentication**: Uses secure bearer token authentication with the Data API |
| 18 | +- **Error Handling**: Includes exception handling for HTTP request failures |
| 19 | +- **Lightweight**: Minimal dependencies with only Python's `requests` library required |
| 20 | + |
| 21 | +## Prerequisites |
| 22 | + |
| 23 | +- Python 3.x |
| 24 | +- `requests` library (install via `pip install requests`) |
| 25 | +- Access to a DataMiner agent with the Data API enabled |
| 26 | +- Valid bearer token for authentication |
| 27 | +- **User-defined API deployed and configured on DataMiner** - This connector requires the user-defined API [DataAPI Proxy](https://catalog.dataminer.services/details/159e3f05-b1e6-43c8-b71f-44f9b8a6f4f3) to be deployed and configured on DataMiner. The API exposes the `/api/custom/data/parameters` endpoint that this connector sends requests to. |
| 28 | + |
| 29 | +## Configuration |
| 30 | + |
| 31 | +Before running the script, update the following variables in `dummy.py`: |
| 32 | + |
| 33 | +```python |
| 34 | +bearer = 'YOUR_BEARER_TOKEN_HERE' |
| 35 | +host = 'system-organisation.on.dataminer.services' |
| 36 | +``` |
| 37 | + |
| 38 | +### Parameters |
| 39 | + |
| 40 | +The script sends data to the DataMiner Data API with the following configuration: |
| 41 | + |
| 42 | +| Parameter | Description | Example | |
| 43 | +|-----------|-------------|---------| |
| 44 | +| `identifier` | The unique identifier for the data element | `Equipment01` | |
| 45 | +| `type` | The data type or category | `PFU` | |
| 46 | +| `body` | The JSON data payload to push | `{"Voltage": 0.1}` | |
| 47 | + |
| 48 | +## Usage |
| 49 | + |
| 50 | +Run the script from the command line: |
| 51 | + |
| 52 | +```bash |
| 53 | +python dummy.py |
| 54 | +``` |
| 55 | + |
| 56 | +### Expected Output |
| 57 | + |
| 58 | +On successful execution: |
| 59 | + |
| 60 | +``` |
| 61 | +{'Authorization': 'Bearer YOUR_BEARER_TOKEN', 'Content-Type': 'application/json'} |
| 62 | +PUT status: 200 |
| 63 | +``` |
| 64 | + |
| 65 | +### Error Handling |
| 66 | + |
| 67 | +If the HTTP request fails, the script will display an error message and exit: |
| 68 | +``` |
| 69 | +HTTP request failed: [error details] |
| 70 | +``` |
| 71 | + |
| 72 | +## How It Works |
| 73 | + |
| 74 | +1. **Authentication Setup**: Defines bearer token and host details for API access |
| 75 | +2. **URL Construction**: Builds the API endpoint with identifier and type parameters |
| 76 | +3. **Request Headers**: Sets up authorization and content-type headers |
| 77 | +4. **Data Payload**: Creates a JSON object with fixed data (e.g., `{"Voltage": 0.1}`) |
| 78 | +5. **HTTP PUT Request**: Sends the data to the user-defined API endpoint on DataMiner |
| 79 | +6. **Response Handling**: Prints the HTTP status code and handles any exceptions |
| 80 | + |
| 81 | +## User-Defined API |
| 82 | + |
| 83 | +This scripted connector sends requests to a **user-defined API** endpoint exposed by DataMiner. The user-defined API that needs to be deployed and configured on your DataMiner instance before this connector can function. |
| 84 | + |
| 85 | +**Reference**: [Skyline DataMiner Catalog - Custom User-Defined API](https://catalog.dataminer.services/details/159e3f05-b1e6-43c8-b71f-44f9b8a6f4f3) |
| 86 | + |
| 87 | +### Endpoint |
| 88 | + |
| 89 | +The script targets: |
| 90 | +``` |
| 91 | +https://{host}/api/custom/data/parameters?identifier={identifier}&type={type} |
| 92 | +``` |
| 93 | + |
| 94 | +**Method**: PUT |
| 95 | +**Content-Type**: application/json |
| 96 | +**Authentication**: Bearer Token |
| 97 | + |
| 98 | +This endpoint is exposed by the user-defined API and handles incoming PUT requests with custom data payloads. |
| 99 | + |
| 100 | +## Customization |
| 101 | + |
| 102 | +To modify the data being pushed, edit the `body` variable: |
| 103 | + |
| 104 | +```python |
| 105 | +body = { "Voltage": 0.1, "Current": 2.5, "Name": "Device 01" } |
| 106 | +``` |
| 107 | + |
| 108 | +To change the target identifier or type: |
| 109 | + |
| 110 | +```python |
| 111 | +url_params = { |
| 112 | + "identifier": 'DeviceIdentifier', |
| 113 | + "type": 'DeviceType', |
| 114 | +} |
| 115 | +``` |
| 116 | + |
| 117 | +## Related Resources |
| 118 | + |
| 119 | +- [Skyline DataMiner Data API Documentation](https://docs.dataminer.services/dataminer/Functions/Data_Sources/Data_API.html) |
| 120 | +- [Other Scripted Connectors](../) |
| 121 | + |
| 122 | +## License |
| 123 | + |
| 124 | +See the root [LICENSE](../../LICENSE) file for license information. |
0 commit comments