Skip to content

Commit e7d42a0

Browse files
committed
Add sample scripted connector
1 parent 602d41e commit e7d42a0

File tree

3 files changed

+178
-0
lines changed

3 files changed

+178
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ Examples include
1010

1111
- [Amsterdam Internet Exchange](Amsterdam%20Internet%20Exchange) : scrapes data from the AMS-IX website for various locations, including Amsterdam, Bay Area, Caribbean, Chicago, Hong Kong, and Mumbai.
1212
- [Azure Data v2](Azure%20Data%20v2) : collects data on both active and deallocated Windows Server 2022 VMs in Azure.
13+
- [Sample Scripted Connector](SampleScriptedConnector): starter script designed to demonstrate how to push fixed data to Data API from outside of DataMiner. It leverages a user-defined API.
1314
- [Coincap](Coincap) : fetches data from the CoinCap API, converting certain string values to floats, and sending the modified data to Data API.
1415
- [Status Page](Status%20Page) : retrieve status information from services using the Atlassian Status Page.
1516

17+
1618
# Meta Data (for Skyline Communications)
1719

1820
Skyline Example Scripted Connectors is added to DCP with Driver ID DMS-DRV-9044 & Device OID 21.

SampleScriptedConnector/README.md

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
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.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Import necessary modules
2+
import sys
3+
import os
4+
import json
5+
import requests
6+
7+
8+
# Main function to execute the script
9+
def main():
10+
11+
# Define authentication and host details
12+
bearer ='Ahy+7XhvW6FhRZKb1KYxvzOdrh9TARCdALmyuPtidTo='
13+
host ='ziine.dataminer.services'
14+
15+
# Define URL parameters for the Data API request
16+
url_params = {
17+
"identifier": 'DeviceIdentifier', #e.g., Sensor001
18+
"type": 'DeviceType', #e.g., Sensor, Actuator
19+
}
20+
21+
# Set HTTP headers for Data API request
22+
header_params = {
23+
"Authorization": 'Bearer ' + bearer,
24+
"Content-Type": 'application/json',
25+
}
26+
27+
# Print header parameters for reference
28+
print(header_params)
29+
30+
# Create a session for HTTP requests
31+
session = requests.Session()
32+
33+
# Prepare body as a JSON-serializable object
34+
body = { "Voltage": 0.1 }
35+
36+
# Send the Data API request and capture the response
37+
try:
38+
response = session.put(
39+
"https://{}/api/custom/data/parameters?identifier={}&type={}".format(host, url_params["identifier"], url_params["type"]),
40+
json=body,
41+
headers=header_params,
42+
)
43+
44+
print("PUT status:", response.status_code)
45+
46+
47+
except requests.exceptions.RequestException as e:
48+
print("HTTP request failed:", e)
49+
sys.exit(1)
50+
51+
if __name__ == "__main__":
52+
main()

0 commit comments

Comments
 (0)