diff --git a/backend/SC4SNMP_UI_backend/common/backend_ui_conversions.py b/backend/SC4SNMP_UI_backend/common/backend_ui_conversions.py index cad9d05..61a72a5 100644 --- a/backend/SC4SNMP_UI_backend/common/backend_ui_conversions.py +++ b/backend/SC4SNMP_UI_backend/common/backend_ui_conversions.py @@ -84,8 +84,8 @@ def backend2ui(self, document: dict, **kwargs): var_binds = [] for vb in backend_var_binds: new_vb = { - "family": vb[0], - "category": vb[1] if len(vb) >= 2 else "", + "component": vb[0], + "object": vb[1] if len(vb) >= 2 else "", "index": '.'.join(map(str, vb[2:])) if len(vb) >= 3 else "", } var_binds.append(new_vb) @@ -168,9 +168,9 @@ def ui2backend(self, document: dict, **kwargs): } var_binds = [] for var_b in document['varBinds']: - single_var_bind = [var_b['family']] - if len(var_b['category']) > 0: - single_var_bind.append(var_b['category']) + single_var_bind = [var_b['component']] + if len(var_b['object']) > 0: + single_var_bind.append(var_b['object']) if len(var_b['index']) > 0: single_var_bind += var_b['index'].split(".") var_binds.append(single_var_bind) diff --git a/backend/tests/common/test_backend_ui_conversions.py b/backend/tests/common/test_backend_ui_conversions.py index 0a41f41..659dd68 100644 --- a/backend/tests/common/test_backend_ui_conversions.py +++ b/backend/tests/common/test_backend_ui_conversions.py @@ -26,10 +26,10 @@ def setUpClass(cls): "patterns": [], "conditions": [] }, - "varBinds": [{"family": "IF-MIB", "category": "ifInDiscards", "index": "1.test.2"}, - {"family": "IF-MIB", "category": "ifInDiscards", "index": "1"}, - {"family": "IF-MIB", "category": "", "index": ""}, - {"family": "IF-MIB", "category": "ifOutErrors", "index": ""}], + "varBinds": [{"component": "IF-MIB", "object": "ifInDiscards", "index": "1.test.2"}, + {"component": "IF-MIB", "object": "ifInDiscards", "index": "1"}, + {"component": "IF-MIB", "object": "", "index": ""}, + {"component": "IF-MIB", "object": "ifOutErrors", "index": ""}], "profileInInventory": True } @@ -43,9 +43,9 @@ def setUpClass(cls): "patterns": [], "conditions": [] }, - "varBinds": [{"family": "IF-MIB", "category": "ifInDiscards", "index": "1"}, - {"family": "IF-MIB", "category": "", "index": ""}, - {"family": "IF-MIB", "category": "ifOutErrors", "index": ""}], + "varBinds": [{"component": "IF-MIB", "object": "ifInDiscards", "index": "1"}, + {"component": "IF-MIB", "object": "", "index": ""}, + {"component": "IF-MIB", "object": "ifOutErrors", "index": ""}], "profileInInventory": False } @@ -59,9 +59,9 @@ def setUpClass(cls): "patterns": [{"pattern": "^MIKROTIK"}, {"pattern": "^MIKROTIK2"}], "conditions": [] }, - "varBinds": [{"family": "IF-MIB", "category": "ifInDiscards", "index": "1"}, - {"family": "IF-MIB", "category": "", "index": ""}, - {"family": "IF-MIB", "category": "ifOutErrors", "index": ""}], + "varBinds": [{"component": "IF-MIB", "object": "ifInDiscards", "index": "1"}, + {"component": "IF-MIB", "object": "", "index": ""}, + {"component": "IF-MIB", "object": "ifOutErrors", "index": ""}], "profileInInventory": True } @@ -80,9 +80,9 @@ def setUpClass(cls): {"field": "field: IF-MIB.ifIndex", "operation": "greater than", "value": ["5"]} ] }, - "varBinds": [{"family": "IF-MIB", "category": "ifInDiscards", "index": "1"}, - {"family": "IF-MIB", "category": "", "index": ""}, - {"family": "IF-MIB", "category": "ifOutErrors", "index": ""}], + "varBinds": [{"component": "IF-MIB", "object": "ifInDiscards", "index": "1"}, + {"component": "IF-MIB", "object": "", "index": ""}, + {"component": "IF-MIB", "object": "ifOutErrors", "index": ""}], "profileInInventory": False } diff --git a/backend/tests/ui_handling/get_endpoints/test_get_endpoints.py b/backend/tests/ui_handling/get_endpoints/test_get_endpoints.py index b91591f..9f9848e 100644 --- a/backend/tests/ui_handling/get_endpoints/test_get_endpoints.py +++ b/backend/tests/ui_handling/get_endpoints/test_get_endpoints.py @@ -57,9 +57,9 @@ def test_get_all_profiles_list(m_client, client): "field": "", "patterns": [] }, - "varBinds": [{"family": "IF-MIB", "category": "ifInDiscards", "index": "1"}, - {"family": "IF-MIB", "category": "", "index": ""}, - {"family": "IF-MIB", "category": "ifOutErrors", "index": ""}], + "varBinds": [{"component": "IF-MIB", "object": "ifInDiscards", "index": "1"}, + {"component": "IF-MIB", "object": "", "index": ""}, + {"component": "IF-MIB", "object": "ifOutErrors", "index": ""}], 'profileInInventory': True, } @@ -73,9 +73,9 @@ def test_get_all_profiles_list(m_client, client): "field": "SNMPv2-MIB.sysObjectID", "patterns": [{"pattern": "^MIKROTIK"}, {"pattern": "^MIKROTIK2"}] }, - "varBinds": [{"family": "IF-MIB", "category": "ifInDiscards", "index": "1"}, - {"family": "IF-MIB", "category": "", "index": ""}, - {"family": "IF-MIB", "category": "ifOutErrors", "index": ""}], + "varBinds": [{"component": "IF-MIB", "object": "ifInDiscards", "index": "1"}, + {"component": "IF-MIB", "object": "", "index": ""}, + {"component": "IF-MIB", "object": "ifOutErrors", "index": ""}], 'profileInInventory': True, } diff --git a/backend/tests/ui_handling/post_endpoints/test_post_profiles.py b/backend/tests/ui_handling/post_endpoints/test_post_profiles.py index b9bfd84..3c5ce56 100644 --- a/backend/tests/ui_handling/post_endpoints/test_post_profiles.py +++ b/backend/tests/ui_handling/post_endpoints/test_post_profiles.py @@ -17,9 +17,9 @@ def test_add_profile_record_success(m_insert, m_find, client): "field": "", "patterns": None }, - "varBinds": [{"family": "IF-MIB", "category": "ifInDiscards", "index": "1"}, - {"family": "IF-MIB", "category": "", "index": ""}, - {"family": "IF-MIB", "category": "ifOutErrors", "index": ""}] + "varBinds": [{"component": "IF-MIB", "object": "ifInDiscards", "index": "1"}, + {"component": "IF-MIB", "object": "", "index": ""}, + {"component": "IF-MIB", "object": "ifOutErrors", "index": ""}] } backend_prof = { "profile_1": { @@ -133,7 +133,7 @@ def test_update_profile_record_no_name_change_success(m_find, m_update, client): "field": "SNMPv2-MIB.sysObjectID", "patterns": [{"pattern": "^MIKROTIK"}, {"pattern": "^MIKROTIK2"}] }, - "varBinds": [{"family": "IF-MIB", "category": "ifInDiscards", "index": "1"}] + "varBinds": [{"component": "IF-MIB", "object": "ifInDiscards", "index": "1"}] } backend_prof_1_old = { @@ -183,7 +183,7 @@ def test_update_profile_record_with_name_change_success(m_find, m_update, client "field": "SNMPv2-MIB.sysObjectID", "patterns": [{"pattern": "^MIKROTIK"}, {"pattern": "^MIKROTIK2"}] }, - "varBinds": [{"family": "IF-MIB", "category": "ifInDiscards", "index": "1"}] + "varBinds": [{"component": "IF-MIB", "object": "ifInDiscards", "index": "1"}] } backend_prof_1_new = { diff --git a/frontend/packages/manager/src/components/profiles/ProfilesList.jsx b/frontend/packages/manager/src/components/profiles/ProfilesList.jsx index 96f27d5..21539ce 100644 --- a/frontend/packages/manager/src/components/profiles/ProfilesList.jsx +++ b/frontend/packages/manager/src/components/profiles/ProfilesList.jsx @@ -23,13 +23,13 @@ function getExpansionRow(row) { {/* Empty cell */} {row.varBinds.map((value) => ( -

{value.family}

+

{value.component}

))}
{row.varBinds.map((value) => ( -

{value.category}

+

{value.object}

))}
@@ -50,8 +50,8 @@ function ProfilesList() { {sortKey: 'profileName', label: 'Profile name'}, {sortKey: 'frequency', label: 'Frequency'}, {sortKey: 'profileType', label: 'Profile type'}, - {sortKey: `mibFamily`, label: 'MIB family'}, - {sortKey: `mibCategory`, label: 'MIB category'}, + {sortKey: `mibComponent`, label: 'MIB Component'}, + {sortKey: `mibObject`, label: 'MIB Object'}, {sortKey: `index`, label: 'MIB Index'}, {sortKey: `actions`, label: 'Actions'}, ]; diff --git a/frontend/packages/manager/src/components/profiles/VarBinds.jsx b/frontend/packages/manager/src/components/profiles/VarBinds.jsx index ca98d92..41e2a7c 100644 --- a/frontend/packages/manager/src/components/profiles/VarBinds.jsx +++ b/frontend/packages/manager/src/components/profiles/VarBinds.jsx @@ -51,15 +51,15 @@ function VarBinds(props){ setReload((prev)=>{return !prev}); }; - const handleItemValueFamily = (index, e) => { + const handleItemValueComponent = (index, e) => { const varBindsCopy = ProfCtx.varBinds; - varBindsCopy[index].family = e.target.value + varBindsCopy[index].component = e.target.value ProfCtx.setVarBinds(varBindsCopy); } - const handleItemValueCategory = (index, e) => { + const handleItemValueObject = (index, e) => { const varBindsCopy = ProfCtx.varBinds; - varBindsCopy[index].category = e.target.value + varBindsCopy[index].object = e.target.value ProfCtx.setVarBinds(varBindsCopy); } @@ -74,7 +74,7 @@ function VarBinds(props){ const newIndex = rowItems.length; const keyID = createDOMID(); const varBindsCopy = ProfCtx.varBinds; - varBindsCopy.push({family: "", category: "", index: ""}); + varBindsCopy.push({component: "", object: "", index: ""}); indicesCopy[`${keyID}`] = newIndex; setIndices(indicesCopy); ProfCtx.setVarBinds(varBindsCopy); @@ -93,13 +93,13 @@ function VarBinds(props){
- handleItemValueFamily(newIndices[`${keyID}`], e)} + handleItemValueComponent(newIndices[`${keyID}`], e)} error={((ValCtx.varBindsErrors && newIndices[`${keyID}`] in ValCtx.varBindsErrors))}/> - handleItemValueCategory(newIndices[`${keyID}`], e)} + handleItemValueObject(newIndices[`${keyID}`], e)} error={((ValCtx.varBindsErrors && newIndices[`${keyID}`] in ValCtx.varBindsErrors))}/> - handleItemValueIndex(newIndices[`${keyID}`], e)} error={((ValCtx.varBindsErrors && newIndices[`${keyID}`] in ValCtx.varBindsErrors))}/>
diff --git a/frontend/packages/manager/src/components/validation/ValidateProfiles.jsx b/frontend/packages/manager/src/components/validation/ValidateProfiles.jsx index 3540aa6..e82fc87 100644 --- a/frontend/packages/manager/src/components/validation/ValidateProfiles.jsx +++ b/frontend/packages/manager/src/components/validation/ValidateProfiles.jsx @@ -222,9 +222,9 @@ const validateProfiles = (validationObj) => { const configuredVarBinds = {}; let varBindKey; for (let i = 0; i < validationObj.varBinds.length; i++){ - varBindKey = `${validationObj.varBinds[i].family}${validationObj.varBinds[i].category}${validationObj.varBinds[i].index}` + varBindKey = `${validationObj.varBinds[i].component}${validationObj.varBinds[i].object}${validationObj.varBinds[i].index}` if (varBindKey in configuredVarBinds && varBindKey.length > 0){ - message = "The same varbind has been already configured for this profile" + message = "The same varBind has been already configured for this profile" if (i in errors.varBinds){ errors.varBinds[i].push(message); }else{ @@ -234,7 +234,7 @@ const validateProfiles = (validationObj) => { }else{ configuredVarBinds[varBindKey] = true } - if (validationObj.varBinds[i].family.length === 0){ + if (validationObj.varBinds[i].component.length === 0){ message = "MIB-Component is required"; if (i in errors.varBinds){ errors.varBinds[i].push(message); @@ -243,9 +243,9 @@ const validateProfiles = (validationObj) => { } isValid = false; - }else if (!validationObj.varBinds[i].family.match(/^[a-zA-Z0-9_-]+$/)){ - message = "MIB-Component can consist only of upper and lower english letters, " + - "numbers and two special characters: '-' and '_'. No spaces are allowed." + }else if (!validationObj.varBinds[i].component.match(/^[a-zA-Z0-9._-]+$/) || !isNaN(validationObj.varBinds[i].component)){ + message = "MIB component can consist only of upper and lower english letters, " + + "numbers and three special characters: '.', '-' and '_'. No spaces are allowed. MIB component can't be a number." if (i in errors.varBinds){ errors.varBinds[i].push(message); }else{ @@ -254,10 +254,10 @@ const validateProfiles = (validationObj) => { isValid = false; } - if (validationObj.varBinds[i].category.length > 0){ - if (!validationObj.varBinds[i].category.match(/^[a-zA-Z0-9_-]+$/)){ + if (validationObj.varBinds[i].object.length > 0){ + if (!validationObj.varBinds[i].object.match(/^[a-zA-Z0-9._-]+$/) || !isNaN(validationObj.varBinds[i].object)){ message = "MIB object can consist only of upper and lower english letters, " + - "numbers and two special characters: '-' and '_'. No spaces are allowed."; + "numbers and three special characters: '.', '-' and '_'. No spaces are allowed. MIB object can't be a number."; if (i in errors.varBinds){ errors.varBinds[i].push(message); }else{ @@ -268,7 +268,7 @@ const validateProfiles = (validationObj) => { } if (validationObj.varBinds[i].index.length > 0){ - if (validationObj.varBinds[i].category.length === 0){ + if (validationObj.varBinds[i].object.length === 0){ message = "MIB object is required when MIB index is specified"; if (i in errors.varBinds){ errors.varBinds[i].push(message); diff --git a/frontend/packages/manager/src/tests/AddProfileModal.test.jsx b/frontend/packages/manager/src/tests/AddProfileModal.test.jsx index 237921a..bd15c65 100644 --- a/frontend/packages/manager/src/tests/AddProfileModal.test.jsx +++ b/frontend/packages/manager/src/tests/AddProfileModal.test.jsx @@ -61,11 +61,11 @@ describe("AddProfileModal", () => { fireEvent.click(addVarBindButton); fireEvent.change(frequencyInput, {target: {value: 2}}) let mibFamilyInput0 = - screen.getByDataTest("sc4snmp:form:varbind0-mib-family-input").querySelector("input") + screen.getByDataTest("sc4snmp:form:varbind-mib-component-input-0").querySelector("input") const mibCategoryInput1 = - screen.getByDataTest("sc4snmp:form:varbind1-mib-category-input").querySelector("input") + screen.getByDataTest("sc4snmp:form:varbind-mib-object-input-1").querySelector("input") const mibIndexInput2 = - screen.getByDataTest("sc4snmp:form:varbind2-mib-index-input").querySelector("input") + screen.getByDataTest("sc4snmp:form:varbind-mib-index-input-2").querySelector("input") fireEvent.change(mibFamilyInput0, {target: {value: "mi b"}}) fireEvent.change(mibCategoryInput1, {target: {value: "aa?"}}) @@ -77,12 +77,12 @@ describe("AddProfileModal", () => { const secondRow = screen.getByDataTest("sc4snmp:form:varbind-row-1") const thirdRow = screen.getByDataTest("sc4snmp:form:varbind-row-2") - expect(within(firstRow).queryByText("MIB-Component can consist only of upper and lower english letters, " + - "numbers and two special characters: '-' and '_'. No spaces are allowed.")).toBeInTheDocument() + expect(within(firstRow).queryByText("MIB component can consist only of upper and lower english letters, " + + "numbers and three special characters: '.', '-' and '_'. No spaces are allowed. MIB component can't be a number.")).toBeInTheDocument() expect(within(secondRow).queryByText("MIB-Component is required")).toBeInTheDocument() expect(within(secondRow).queryByText("MIB object can consist only of upper and lower english letters, " + - "numbers and two special characters: '-' and '_'. No spaces are allowed.")).toBeInTheDocument() + "numbers and three special characters: '.', '-' and '_'. No spaces are allowed. MIB object can't be a number.")).toBeInTheDocument() expect(within(thirdRow).queryByText("MIB-Component is required")).toBeInTheDocument() expect(within(thirdRow).queryByText("MIB object is required when MIB index is specified")).toBeInTheDocument() @@ -111,7 +111,7 @@ describe("AddProfileModal", () => { await sleep(10); mibFamilyInput0 = - screen.getByDataTest("sc4snmp:form:varbind0-mib-family-input").querySelector("input") + screen.getByDataTest("sc4snmp:form:varbind-mib-component-input-0").querySelector("input") fireEvent.change(mibFamilyInput0, {target: {value: "mib"}}) firstRow = screen.getByDataTest("sc4snmp:form:varbind-row-0") @@ -285,23 +285,23 @@ describe("AddProfileModal", () => { fireEvent.click(addVarBindButton); await sleep(20); const mibFamilyInput0 = - screen.getByDataTest("sc4snmp:form:varbind0-mib-family-input").querySelector("input") + screen.getByDataTest("sc4snmp:form:varbind-mib-component-input-0").querySelector("input") const mibCategoryInput0 = - screen.getByDataTest("sc4snmp:form:varbind0-mib-category-input").querySelector("input") + screen.getByDataTest("sc4snmp:form:varbind-mib-object-input-0").querySelector("input") const mibIndexInput0 = - screen.getByDataTest("sc4snmp:form:varbind0-mib-index-input").querySelector("input") + screen.getByDataTest("sc4snmp:form:varbind-mib-index-input-0").querySelector("input") const mibFamilyInput1 = - screen.getByDataTest("sc4snmp:form:varbind1-mib-family-input").querySelector("input") + screen.getByDataTest("sc4snmp:form:varbind-mib-component-input-1").querySelector("input") const mibCategoryInput1 = - screen.getByDataTest("sc4snmp:form:varbind1-mib-category-input").querySelector("input") + screen.getByDataTest("sc4snmp:form:varbind-mib-object-input-1").querySelector("input") const mibFamilyInput2 = - screen.getByDataTest("sc4snmp:form:varbind2-mib-family-input").querySelector("input") + screen.getByDataTest("sc4snmp:form:varbind-mib-component-input-2").querySelector("input") const mibCategoryInput2 = - screen.getByDataTest("sc4snmp:form:varbind2-mib-category-input").querySelector("input") + screen.getByDataTest("sc4snmp:form:varbind-mib-object-input-2").querySelector("input") const mibIndexInput2 = - screen.getByDataTest("sc4snmp:form:varbind2-mib-index-input").querySelector("input") + screen.getByDataTest("sc4snmp:form:varbind-mib-index-input-2").querySelector("input") fireEvent.change(mibFamilyInput0, {target: {value: "SNMPv2-MIB"}}) fireEvent.change(mibCategoryInput0, {target: {value: "sysUpTime"}}) @@ -318,7 +318,7 @@ describe("AddProfileModal", () => { await sleep(5) const varBindError = screen.getByDataTest("sc4snmp:varbind-error-2-0") - expect(varBindError.textContent).toBe("The same varbind has been already configured for this profile") + expect(varBindError.textContent).toBe("The same varBind has been already configured for this profile") }) it("Test same patterns error", async () => {