mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
Flows work + #302
This commit is contained in:
31
pialert/flows.py
Normal file
31
pialert/flows.py
Normal file
@@ -0,0 +1,31 @@
|
||||
import json
|
||||
|
||||
def update_value(json_data, object_path, key, value, target_property, desired_value):
|
||||
# Helper function to traverse the JSON structure and get the target object
|
||||
def traverse(obj, path):
|
||||
keys = path.split(".")
|
||||
for key in keys:
|
||||
if isinstance(obj, list):
|
||||
key = int(key)
|
||||
obj = obj[key]
|
||||
return obj
|
||||
|
||||
# Helper function to update the target property with the desired value
|
||||
def update(obj, path, key, value, target_property, desired_value):
|
||||
keys = path.split(".")
|
||||
for i, key in enumerate(keys):
|
||||
if isinstance(obj, list):
|
||||
key = int(key)
|
||||
# Check if we have reached the desired object
|
||||
if i == len(keys) - 1 and obj[key][key] == value:
|
||||
# Update the target property with the desired value
|
||||
obj[key][target_property] = desired_value
|
||||
else:
|
||||
obj = obj[key]
|
||||
return obj
|
||||
|
||||
# Get the target object based on the object path
|
||||
target_obj = traverse(json_data, object_path)
|
||||
# Update the value in the target object
|
||||
updated_obj = update(json_data, object_path, key, value, target_property, desired_value)
|
||||
return updated_obj
|
||||
@@ -1,13 +1,54 @@
|
||||
{
|
||||
"name":"apply_template",
|
||||
"triggers": [
|
||||
"name":"apply_template",
|
||||
"params" : [
|
||||
{
|
||||
"type": "new",
|
||||
"object":
|
||||
{
|
||||
"type": "db.row",
|
||||
"target": "Devices"
|
||||
}
|
||||
"name" : "target_macs",
|
||||
"type" : "setting",
|
||||
"value" : "KNWN_target_macs"
|
||||
},
|
||||
{
|
||||
"name" : "dev_AlertDeviceDown",
|
||||
"type" : "setting",
|
||||
"value" : "KNWN_dev_AlertDeviceDown"
|
||||
},
|
||||
{
|
||||
"name" : "dev_AlertEvents",
|
||||
"type" : "setting",
|
||||
"value" : "KNWN_dev_AlertEvents"
|
||||
},
|
||||
{
|
||||
"name" : "",
|
||||
"type":"array",
|
||||
"value": "trigger.Object_PrimaryID"
|
||||
},
|
||||
{
|
||||
"type":"array",
|
||||
"value": "trigger"
|
||||
}
|
||||
],
|
||||
"trigger": [
|
||||
{
|
||||
"object_type": "dbtable",
|
||||
"object_key": "Devices",
|
||||
"object_event": "new",
|
||||
"object_filter": "",
|
||||
"object_mappings":
|
||||
[
|
||||
{
|
||||
"column": "Object_PrimaryID",
|
||||
"mapped_to_column": "Dev_MAC",
|
||||
"css_classes": "col-sm-2",
|
||||
"show": true,
|
||||
"type": "devicemac",
|
||||
"default_value":"",
|
||||
"options": [],
|
||||
"localized": ["name"],
|
||||
"name":[{
|
||||
"language_code":"en_us",
|
||||
"string" : "MAC address"
|
||||
}]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"steps": [
|
||||
@@ -51,9 +92,15 @@
|
||||
"params":
|
||||
{
|
||||
"unique_prefix": "KNWN",
|
||||
"override":{
|
||||
|
||||
}
|
||||
"overrides":[
|
||||
{
|
||||
"object_path": "settings.0",
|
||||
"key":"function",
|
||||
"value":"target_macs",
|
||||
"target_property":"default_value",
|
||||
"desired_value": "triggers.keys"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -81,6 +81,7 @@ def cleanResult(str):
|
||||
str = str.replace(".lan", "")
|
||||
str = str.replace(".home", "")
|
||||
str = re.sub(r'-[a-fA-F0-9]{32}', '', str) # removing last part of e.g. Nest-Audio-ff77ff77ff77ff77ff77ff77ff77ff77
|
||||
str = re.sub(r'#.*', '', str) # Remove everything after '#' including the '#'
|
||||
# remove trailing dots
|
||||
if str.endswith('.'):
|
||||
str = str[:-1]
|
||||
|
||||
Reference in New Issue
Block a user