From b0c47e824d42fbc7d503002ae42f81d1b833b19d Mon Sep 17 00:00:00 2001 From: jokob-sk Date: Wed, 29 May 2024 17:06:35 +1000 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=8DSNMP=20bugfix=20#690=20=20+=20?= =?UTF-8?q?=E2=9A=99=20settings=20saving=20improvemnts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- front/plugins/snmp_discovery/script.py | 5 +++- front/settings.php | 41 +++++++++++++++++++------- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/front/plugins/snmp_discovery/script.py b/front/plugins/snmp_discovery/script.py index fa9d7066..3bb4019e 100755 --- a/front/plugins/snmp_discovery/script.py +++ b/front/plugins/snmp_discovery/script.py @@ -64,11 +64,12 @@ def main(): if len(tmpSplt) == 3: + ipStr = tmpSplt[0].split('.')[-4:] # Get the last 4 elements to extract the IP macStr = tmpSplt[1].strip().split(' ') # Remove leading/trailing spaces from MAC - if 'iso.' in output and len(ipStr) == 4: + if len(ipStr) == 4: macAddress = ':'.join(macStr) ipAddress = '.'.join(ipStr) @@ -82,6 +83,8 @@ def main(): extra = handleEmpty(line), foreignKey = handleEmpty(macAddress) # Use the primary ID as the foreign key ) + else: + mylog('verbose', [f'[SNMPDSC] ipStr does not seem to contain a valid IP:', ipStr]) mylog('verbose', ['[SNMPDSC] Entries found: ', len(plugin_objects)]) diff --git a/front/settings.php b/front/settings.php index 903d1f83..7f311de4 100755 --- a/front/settings.php +++ b/front/settings.php @@ -48,6 +48,7 @@ while ($row = $result -> fetchArray (SQLITE3_ASSOC)) { ); } +$settingsJSON_DB = json_encode($settings, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT); ?> @@ -299,7 +300,7 @@ while ($row = $result -> fetchArray (SQLITE3_ASSOC)) { ` } - console.log(pluginsData); + // console.log(pluginsData); // Start constructing the main settings HTML let pluginHtml = ` @@ -663,6 +664,7 @@ while ($row = $result -> fetchArray (SQLITE3_ASSOC)) { // display the name of the first person // echo $settingsJson[0]->name; var settingsNumberDB = ; + var settingsJSON_DB = ; var settingsNumberJSON = data)?>; // Wrong number of settings processing @@ -731,7 +733,7 @@ while ($row = $result -> fetchArray (SQLITE3_ASSOC)) { const noConversion = ['text', 'integer', 'string', 'password', 'readonly', 'text.select', 'list.select', 'integer.select', 'text.multiselect']; // get settings to determine setting type to store values appropriately - $.get('api/table_settings.json', function(res) { + $.get('api/table_settings.json?nocache=' + Date.now(), function(res) { settingsJSON = res; @@ -786,10 +788,34 @@ while ($row = $result -> fetchArray (SQLITE3_ASSOC)) { // if ok, double check the number collected of settings is correct if(sanityCheck_notOK == false) { - sanityCheck_notOK = settingsNumberDB != settingsArray.length; + + console.log(settingsArray); + + // Step 1: Extract Code_Name values from settingsList + const settingsCodeNames = settingsJSON_DB.map(setting => setting.Code_Name); + + // Step 2: Extract second elements from detailedList + const detailedCodeNames = settingsArray.map(item => item[1]); + + // Step 3: Find missing Code_Name values + const missingCodeNamesOnPage = detailedCodeNames.filter(codeName => !settingsCodeNames.includes(codeName)); + const missingCodeNamesInDB = settingsCodeNames.filter(codeName => !detailedCodeNames.includes(codeName)); + + + if(missingCodeNamesOnPage.length != missingCodeNamesInDB.length) + { + sanityCheck_notOK = true; + + console.log(`⚠ Error: The following settings are missing in the DB or on the page (Reload page to fix):`); + console.log(missingCodeNamesOnPage); + console.log(missingCodeNamesInDB); + + showModalOk('WARNING', ""); + } + } - if(sanityCheck_notOK == false) + if(sanityCheck_notOK == false ) { // trigger a save settings event in the backend $.ajax({ @@ -810,10 +836,7 @@ while ($row = $result -> fetchArray (SQLITE3_ASSOC)) { } }); - } else{ - console.log(`Error settingsNumberDB != settingsArray.length: ${settingsNumberDB} != ${settingsArray.length}`); - showModalOk('WARNING', ""); - } + } }) @@ -893,8 +916,6 @@ while ($row = $result -> fetchArray (SQLITE3_ASSOC)) { } document.getElementById('lastImportedTime').innerHTML = humanReadable; - - }) }