From bd3b15dedccd862e3d47545476fcef8dd93328ee Mon Sep 17 00:00:00 2001 From: jokob-sk Date: Sat, 8 Jun 2024 10:39:53 +1000 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=83=20Sync=20Hub=20v0.7.3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- front/plugins/sync/config.json | 514 ++++++++++++++++----------------- front/plugins/sync/sync.py | 23 +- 2 files changed, 269 insertions(+), 268 deletions(-) diff --git a/front/plugins/sync/config.json b/front/plugins/sync/config.json index 13fea199..4c92ba24 100755 --- a/front/plugins/sync/config.json +++ b/front/plugins/sync/config.json @@ -1,10 +1,19 @@ { "code_name": "sync", - "template_type": "database-entry", "unique_prefix": "SYNC", "plugin_type": "system", "enabled": true, "data_source": "script", + "mapped_to_table": "CurrentScan", + "data_filters": [ + { + "compare_column": "Object_PrimaryID", + "compare_operator": "==", + "compare_field_id": "txtMacFilter", + "compare_js_template": "'{value}'.toString()", + "compare_use_quotes": true + } + ], "show_ui": true, "localized": ["display_name", "description", "icon"], "display_name": [{ @@ -22,263 +31,6 @@ } ], "params" : [], - "database_column_definitions": [ - { - "column": "Index", - "css_classes": "col-sm-2", - "show": false, - "type": "label", - "default_value": "", - "options": [], - "localized": [ - "name" - ], - "name": [ - { - "language_code": "en_us", - "string": "N/A" - }, - { - "language_code": "es_es", - "string": "N/A" - } - ] - }, - { - "column": "Plugin", - "css_classes": "col-sm-2", - "show": false, - "type": "label", - "default_value": "", - "options": [], - "localized": [ - "name" - ], - "name": [ - { - "language_code": "en_us", - "string": "N/A" - }, - { - "language_code": "es_es", - "string": "N/A" - } - ] - }, - { - "column": "Object_PrimaryID", - "css_classes": "col-sm-2", - "show": true, - "type": "label", - "default_value": "", - "options": [], - "localized": [ - "name" - ], - "name": [ - { - "language_code": "en_us", - "string": "Plugin" - } - ] - }, - { - "column": "Object_SecondaryID", - "css_classes": "col-sm-2", - "show": false, - "type": "label", - "default_value": "", - "options": [], - "localized": [ - "name" - ], - "name": [ - { - "language_code": "en_us", - "string": "Time" - } - ] - }, - { - "column": "DateTimeCreated", - "css_classes": "col-sm-2", - "show": true, - "type": "label", - "default_value": "", - "options": [], - "localized": [ - "name" - ], - "name": [ - { - "language_code": "en_us", - "string": "Sent when" - } - ] - }, - { - "column": "DateTimeChanged", - "css_classes": "col-sm-2", - "show": false, - "type": "label", - "default_value": "", - "options": [], - "localized": [ - "name" - ], - "name": [ - { - "language_code": "en_us", - "string": "Changed" - } - ] - }, - { - "column": "Watched_Value1", - "css_classes": "col-sm-2", - "show": true, - "type": "label", - "default_value":"", - "options": [ - ], - "localized": [ - "name" - ], - "name": [ - { - "language_code": "en_us", - "string": "Node name" - } - ] - }, - { - "column": "Watched_Value2", - "css_classes": "col-sm-8", - "show": true, - "type": "label", - "default_value": "", - "options": [], - "localized": [ - "name" - ], - "name": [ - { - "language_code": "en_us", - "string": "Status code" - } - ] - }, - { - "column": "Watched_Value3", - "css_classes": "col-sm-2", - "show": true, - "type": "textarea_readonly", - "default_value": "", - "options": [], - "localized": [ - "name" - ], - "name": [ - { - "language_code": "en_us", - "string": "Response" - } - ] - }, - { - "column": "Watched_Value4", - "css_classes": "col-sm-2", - "show": false, - "type": "label", - "default_value": "", - "options": [], - "localized": [ - "name" - ], - "name": [ - { - "language_code": "en_us", - "string": "N/A" - } - ] - }, - { - "column": "UserData", - "css_classes": "col-sm-2", - "show": false, - "type": "textbox_save", - "default_value": "", - "options": [], - "localized": [ - "name" - ], - "name": [ - { - "language_code": "en_us", - "string": "Comments" - } - ] - }, - { - "column": "Status", - "css_classes": "col-sm-1", - "show": false, - "type": "replace", - "default_value": "", - "options": [ - { - "equals": "watched-not-changed", - "replacement": "
" - }, - { - "equals": "watched-changed", - "replacement": "
" - }, - { - "equals": "new", - "replacement": "
" - }, - { - "equals": "missing-in-last-scan", - "replacement": "
" - } - ], - "localized": [ - "name" - ], - "name": [ - { - "language_code": "en_us", - "string": "Status" - }, - { - "language_code": "es_es", - "string": "Estado" - } - ] - }, - { - "column": "Extra", - "css_classes": "col-sm-3", - "show": false, - "type": "label", - "default_value": "", - "options": [], - "localized": [ - "name" - ], - "name": [ - { - "language_code": "en_us", - "string": "Extra" - }, - { - "language_code": "es_es", - "string": "Extra" - } - ] - } - ], "settings":[ { "function": "instance_type", @@ -579,6 +331,252 @@ } + ], + "database_column_definitions": [ + { + "column": "Object_PrimaryID", + "mapped_to_column": "cur_MAC", + "css_classes": "col-sm-2", + "show": true, + "type": "device_name_mac", + "default_value": "", + "options": [], + "localized": [ + "name" + ], + "name": [ + { + "language_code": "en_us", + "string": "MAC" + }, + { + "language_code": "es_es", + "string": "MAC" + }, + { + "language_code": "de_de", + "string": "MAC" + } + ] + }, + { + "column": "Object_SecondaryID", + "mapped_to_column": "cur_IP", + "css_classes": "col-sm-2", + "show": true, + "type": "device_ip", + "default_value": "", + "options": [], + "localized": [ + "name" + ], + "name": [ + { + "language_code": "en_us", + "string": "IP" + }, + { + "language_code": "es_es", + "string": "IP" + }, + { + "language_code": "de_de", + "string": "IP" + } + ] + }, + { + "column": "Watched_Value1", + "mapped_to_column": "cur_Name", + "css_classes": "col-sm-2", + "show": true, + "type": "label", + "default_value": "", + "options": [], + "localized": [ + "name" + ], + "name": [ + { + "language_code": "en_us", + "string": "Name" + } + ] + }, + { + "column": "Watched_Value2", + "mapped_to_column": "cur_Vendor", + "css_classes": "col-sm-2", + "show": true, + "type": "label", + "default_value": "", + "options": [], + "localized": [ + "name" + ], + "name": [ + { + "language_code": "en_us", + "string": "Vendor" + }, + { + "language_code": "es_es", + "string": "Proveedor" + }, + { + "language_code": "de_de", + "string": "Hersteller" + } + ] + }, + { + "column": "Watched_Value3", + "mapped_to_column": "cur_SyncHubNodeName", + "css_classes": "col-sm-2", + "show": true, + "type": "label", + "default_value":"", + "options": [], + "localized": ["name"], + "name":[{ + "language_code":"en_us", + "string" : "Sync Node" + }] + }, + { + "column": "Watched_Value4", + "css_classes": "col-sm-2", + "show": true, + "type": "label", + "default_value":"", + "options": [], + "localized": ["name"], + "name":[{ + "language_code":"en_us", + "string" : "Device GUID" + }] + }, + { + "column": "Dummy", + "mapped_to_column": "cur_ScanMethod", + "mapped_to_column_data": { + "value": "sync" + }, + "css_classes": "col-sm-2", + "show": true, + "type": "label", + "default_value": "", + "options": [], + "localized": [ + "name" + ], + "name": [ + { + "language_code": "en_us", + "string": "Scan method" + }, + { + "language_code": "es_es", + "string": "Método de escaneo" + }, + { + "language_code": "de_de", + "string": "Scanmethode" + } + ] + }, + { + "column": "DateTimeCreated", + "css_classes": "col-sm-2", + "show": true, + "type": "label", + "default_value": "", + "options": [], + "localized": [ + "name" + ], + "name": [ + { + "language_code": "en_us", + "string": "Created" + }, + { + "language_code": "es_es", + "string": "Creado" + }, + { + "language_code": "de_de", + "string": "Erstellt" + } + ] + }, + { + "column": "DateTimeChanged", + "css_classes": "col-sm-2", + "show": true, + "type": "label", + "default_value": "", + "options": [], + "localized": [ + "name" + ], + "name": [ + { + "language_code": "en_us", + "string": "Changed" + }, + { + "language_code": "es_es", + "string": "Cambiado" + }, + { + "language_code": "de_de", + "string": "Geändert" + } + ] + }, + { + "column": "Status", + "css_classes": "col-sm-1", + "show": true, + "type": "replace", + "default_value": "", + "options": [ + { + "equals": "watched-not-changed", + "replacement": "
" + }, + { + "equals": "watched-changed", + "replacement": "
" + }, + { + "equals": "new", + "replacement": "
" + }, + { + "equals": "missing-in-last-scan", + "replacement": "
" + } + ], + "localized": [ + "name" + ], + "name": [ + { + "language_code": "en_us", + "string": "Status" + }, + { + "language_code": "es_es", + "string": "Estado" + }, + { + "language_code": "de_de", + "string": "Status" + } + ] + } ] } diff --git a/front/plugins/sync/sync.py b/front/plugins/sync/sync.py index 0049680e..9abe3498 100755 --- a/front/plugins/sync/sync.py +++ b/front/plugins/sync/sync.py @@ -141,8 +141,21 @@ def main(): for device in new_devices: device.pop('rowid', None) + # Prepare the insert statement if new_devices: + # insert devices into the lats_result.log to manage state + for device in new_devices: + plugin_objects.add_object( + primaryId = device['dev_MAC'], + secondaryId = device['dev_LastIP'], + watched1 = device['dev_Name'], + watched2 = device['dev_Vendor'], + watched3 = device['dev_SyncHubNodeName'], + watched4 = device['dev_GUID'], + extra = '', + foreignKey = device['dev_GUID']) + columns = ', '.join(k for k in new_devices[0].keys() if k != 'rowid') placeholders = ', '.join('?' for k in new_devices[0] if k != 'rowid') sql = f'INSERT INTO Devices ({columns}) VALUES ({placeholders})' @@ -199,16 +212,6 @@ def send_data(api_token, file_content, encryption_key, plugin_folder, node_name, mylog('verbose', [message]) write_notification(message, 'alert', timeNowTZ()) - # log result - plugin_objects.add_object( - primaryId = pref, - secondaryId = timeNowTZ(), - watched1 = node_name, - watched2 = response.status_code, - watched3 = response, - watched4 = '', - extra = '', - foreignKey = '') if __name__ == '__main__':