-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prepare device monitring workflow (#157)
Co-authored-by: Jozef Volak <[email protected]>
- Loading branch information
Showing
5 changed files
with
243 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import copy | ||
from frinx_conductor_workers.frinx_rest import conductor_headers | ||
import json | ||
|
||
import requests | ||
|
||
# Templates | ||
create_schedule_tmpl = { | ||
"name": None, | ||
"workflowName": None, | ||
"workflowVersion": None, | ||
"cronString": None, | ||
"enabled": None, | ||
"parallelRuns": False, | ||
"workflowContext": None, | ||
"correlationId": 'network-admin', | ||
"taskToDomain": None | ||
} | ||
|
||
SCHELLAR_URL = 'http://workflow-proxy:8088/schedule/' | ||
|
||
|
||
def create_schedule(task): | ||
body = copy.deepcopy(create_schedule_tmpl) | ||
|
||
body['name'] = task['inputData']['workflow_name'] + ":" + task['inputData']['workflow_version'] | ||
body['workflowName'] = task['inputData']['workflow_name'] | ||
body['workflowVersion'] = str(task['inputData']['workflow_version']) | ||
body['cronString'] = str(task['inputData']['cron']) | ||
body['enabled'] = bool(task['inputData']['enabled']) | ||
|
||
if task['inputData']['workflow_context'] is not None: | ||
body['workflowContext'] = task['inputData']['workflow_context'] | ||
|
||
response = requests.put(SCHELLAR_URL + body['name'], data=json.dumps(body), headers=conductor_headers) | ||
status = 'FAILED' | ||
if response.ok: | ||
status = 'COMPLETED' | ||
|
||
return {'status': status, 'output': {'url': SCHELLAR_URL, 'response_code': response.status_code, 'response_body': {}}, 'logs': []} | ||
|
||
|
||
|
||
def start(cc): | ||
print('Starting Inventory workers') | ||
|
||
cc.register('SCHELLAR_create_schedule', { | ||
"description": '{"description": "create simple schedule", "labels": ["BASICS","MAIN","SCHELLAR"]}', | ||
"responseTimeoutSeconds": 60, | ||
"timeoutSeconds": 60, | ||
"inputKeys": [ | ||
"workflow_name", | ||
"workflow_version", | ||
"enabled", | ||
"cron", | ||
"workflow_context" | ||
], | ||
"outputKeys": [ | ||
"url", | ||
"response_code", | ||
"response_body" | ||
] | ||
}, create_schedule) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"name": "Add_device", | ||
"description": "{\"description\": \"Add device to device inventory and install\", \"labels\": [\"BASICS\",\"CLI\",\"INVENTORY\",\"MAIN\"]}", | ||
"version": 1, | ||
"tasks": [ | ||
{ | ||
"name": "INVENTORY_add_device", | ||
"taskReferenceName": "INVENTORY_add_device_1", | ||
"inputParameters": { | ||
"device_id": "${workflow.input.device_id}", | ||
"mount_body": "${workflow.input.mount_body}", | ||
"labels": "${workflow.input.labels}", | ||
"uniconfig_zone": "${workflow.input.uniconfig_zone}", | ||
"service_state": "${workflow.input.service_state}" | ||
}, | ||
"type": "SIMPLE", | ||
"optional": true | ||
}, | ||
{ | ||
"name": "INVENTORY_install_device_by_name", | ||
"taskReferenceName": "INVENTORY_install_device_by_name_1", | ||
"inputParameters": { | ||
"device_name": "${workflow.input.device_id}" | ||
}, | ||
"type": "SIMPLE" | ||
} | ||
], | ||
"inputParameters": [ | ||
"{\"device_id\": {\"value\": \"\", \"description\": \"Unique device name\", \"type\": \"string\", \"options\": null}}", | ||
"{\"mount_body\": {\"value\": \"\", \"description\": \"Device mount body\", \"type\": \"textarea\", \"options\": null}}", | ||
"{\"labels\": {\"value\": \"\", \"description\": \"Device labels\", \"type\": \"string\", \"options\": null}}", | ||
"{\"uniconfig_zone\": {\"value\": \"uniconfig\", \"description\": \"Uniconfig zone\", \"type\": \"string\", \"options\": null}}", | ||
"{\"service_state\": {\"value\": \"IN_SERVICE\", \"description\": \"Current service state\", \"type\": \"select\", \"options\": [\"IN_SERVICE\", \"PLANNING\", \"OUT_OF_SERVICE\"]}}" | ||
], | ||
"outputParameters": {}, | ||
"schemaVersion": 2, | ||
"restartable": true, | ||
"variables": {}, | ||
"inputTemplate": {}, | ||
"hasSchedule": false, | ||
"expectedScheduleName": "Add_device:1" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
{ | ||
"name": "Schedule_device_monitoring", | ||
"description": "{\"description\":\"\",\"labels\":[\"INFLUXDB\"]}", | ||
"version": 1, | ||
"inputParameters": [ | ||
"{\"device_name\": {\"value\": \"asr9k\", \"description\": \"Unique Device name\", \"type\": \"string\", \"options\": null}}", | ||
"{\"mount_body\": {\"value\": \"\", \"description\": \"Installation body compatible with inventory format\", \"type\": \"textarea\", \"options\": null}}", | ||
"{\"periode\": {\"value\": 5, \"description\": \"Time, how often to collect data from the device in minutes\", \"type\": \"int\", \"options\": null}}", | ||
"{\"interface\": {\"value\": \"MgmtEth0/RSP0/CPU0/0\", \"description\": \"Monitored interface\", \"type\": \"string\", \"options\": null}}" | ||
], | ||
"outputParameters": {}, | ||
"schemaVersion": 2, | ||
"tasks": [ | ||
{ | ||
"name": "Add_device", | ||
"taskReferenceName": "Add_deviceRef_yWKj", | ||
"inputParameters": { | ||
"device_id": "${workflow.input.device_name}", | ||
"mount_body": "${workflow.input.mount_body}", | ||
"uniconfig_zone": "uniconfig", | ||
"service_state": "IN_SERVICE", | ||
"optional": true | ||
}, | ||
"type": "SUB_WORKFLOW", | ||
"subWorkflowParam": { | ||
"name": "Add_device", | ||
"version": 1 | ||
} | ||
}, | ||
{ | ||
"name": "Create_influxdb_bucket", | ||
"taskReferenceName": "Create_influxdb_bucketRef_IbZN", | ||
"inputParameters": { | ||
"bucket": "devices" | ||
}, | ||
"type": "SUB_WORKFLOW", | ||
"subWorkflowParam": { | ||
"name": "Create_influxdb_bucket", | ||
"version": 1 | ||
} | ||
}, | ||
{ | ||
"name": "SCHELLAR_create_schedule", | ||
"taskReferenceName": "SCHELLAR_create_scheduleRefName_QQtR", | ||
"inputParameters": { | ||
"workflow_name": "Device_interface_monitoring", | ||
"workflow_version": "1", | ||
"enabled": true, | ||
"cron": "*/${workflow.input.periode} * * * *", | ||
"workflow_context": { | ||
"interface-name": "${workflow.input.interface}", | ||
"node-id": "${workflow.input.device_name}" | ||
} | ||
}, | ||
"type": "SIMPLE" | ||
}, | ||
{ | ||
"name": "SCHELLAR_create_schedule", | ||
"taskReferenceName": "SCHELLAR_create_scheduleRefName_e0CN", | ||
"inputParameters": { | ||
"workflow_name": "Device_memory_monitoring", | ||
"workflow_version": "1", | ||
"enabled": true, | ||
"cron": "*/${workflow.input.periode} * * * *", | ||
"workflow_context": { | ||
"interface-name": "${workflow.input.interface}", | ||
"node-id": "${workflow.input.device_name}" | ||
} | ||
}, | ||
"type": "SIMPLE" | ||
} | ||
] | ||
} |