Skip to content

Commit

Permalink
fix: enable compound indices in profiles and configuration of hosts i…
Browse files Browse the repository at this point in the history
…n the inventory using string address

fix: enable compound indices and configuration of string based hosts

fix: refactor condition in profiles form

fix: in ProfileConversion._backend2ui_map for empty patterns filed return empty list instead of None

fix: refactor varBinds form
  • Loading branch information
wojtekzyla committed Jul 7, 2023
1 parent fea03d5 commit 30f6d90
Show file tree
Hide file tree
Showing 14 changed files with 397 additions and 507 deletions.
8 changes: 4 additions & 4 deletions backend/SC4SNMP_UI_backend/common/conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def _backend2ui_map(self, document: dict, **kwargs):
new_vb = {
"family": vb[0],
"category": vb[1] if len(vb) >= 2 else "",
"index": str(vb[2]) if len(vb) == 3 else "",
"index": '.'.join(vb[2:]) if len(vb) >= 3 else "",
}
var_binds.append(new_vb)

Expand All @@ -70,7 +70,7 @@ def _backend2ui_map(self, document: dict, **kwargs):
condition_type = backend_condition["type"]
field = backend_condition["field"] if condition_type == "field" else ""
patterns = [{"pattern": p} for p in backend_condition["patterns"]] \
if condition_type == "field" else None
if condition_type == "field" else []
conditions = {
"condition": condition_type,
"field": field,
Expand All @@ -80,7 +80,7 @@ def _backend2ui_map(self, document: dict, **kwargs):
conditions = {
"condition": "None",
"field": "",
"patterns": None
"patterns": []
}
result = {
"_id": str(document["_id"]),
Expand Down Expand Up @@ -110,7 +110,7 @@ def _ui2backend_map(self, document: dict, **kwargs):
if len(var_b['category']) > 0:
single_var_bind.append(var_b['category'])
if len(var_b['index']) > 0:
single_var_bind.append(int(var_b['index']))
single_var_bind += var_b['index'].split(".")
var_binds.append(single_var_bind)

item = {
Expand Down
4 changes: 2 additions & 2 deletions backend/SC4SNMP_UI_backend/common/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ def add_group_to_inventory(self, group_name: str, group_port: str, group_object=
deleted_inventory_record = list(self._mongo_inventory.find({'address': group_name, "delete": True}))
group = list(self._mongo_groups.find({group_name: {"$exists": 1}}))
if len(group) == 0:
group_added = False
message = f"There is no group {group_name} configured. Record was not added."
group_added = True
message = f"Group {group_name} doesn't exist in the configuration. Treating {group_name} as a hostname."
elif len(existing_inventory_record) > 0:
group_added = False
message = f"Group {group_name} has already been added to the inventory. Record was not added."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ function Header(){
const handleRequestOpenProfile = () => {
ProfCtx.setProfileName("");
ProfCtx.setFrequency(1);
ProfCtx.setVarBinds(null);
ProfCtx.setConditions(null);
ProfCtx.setVarBinds([]);
ProfCtx.setCondition("None");
ProfCtx.setConditionField("");
ProfCtx.setConditionPatterns([]);
ProfCtx.setAddOpen(true);
ProfCtx.setIsEdit(false);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import Number from '@splunk/react-ui/Number';
import Text from '@splunk/react-ui/Text';
import { createDOMID } from '@splunk/ui-utils/id';
import P from '@splunk/react-ui/Paragraph';
import VarbindsCreator from "./VarbindsCreator";
import Conditions from "./Conditions";
import VarBinds from "./VarBinds";
import Condition from "./Condition";
import axios from "axios";
import ProfileContext from "../../store/profile-contxt";
import validateProfiles from "../validation/ValidateProfiles";
Expand All @@ -21,16 +21,7 @@ function AddProfileModal(props) {
const ProfCtx = useContext(ProfileContext);
const ValCtx = useContext(ProfilesValidationContxt);
const ErrCtx = useContext(ErrorsModalContext);
const [newSubmitPatterns, setNewSubmitPatterns] = useState(false);
const [newSubmitVarBinds, setNewSubmitVarBinds] = useState(false);

const newSubmitPatternsHandler = () =>{
setNewSubmitPatterns(!newSubmitPatterns);
};

const newSubmitVarBindsHandler = () =>{
setNewSubmitVarBinds(!newSubmitVarBinds);
};
const [newSubmit, setNewSubmit] = useState(false);


const handleProfileName = useCallback((e, { value: val }) => {
Expand All @@ -41,14 +32,6 @@ function AddProfileModal(props) {
ProfCtx.setFrequency(val);
}, []);

const handleVarBinds = (value) => {
ProfCtx.setVarBinds(value);
}

const handleConditions = (value) => {
ProfCtx.setConditions(value);
}

const postProfile = (profileObj) => {
axios.post(`http://${backendHost}/profiles/add`, profileObj)
.then((response) => {
Expand Down Expand Up @@ -91,11 +74,15 @@ function AddProfileModal(props) {
const handleApply = useCallback(
(e) => {

let profileObj = {
const profileObj = {
profileName: ProfCtx.profileName,
frequency: ProfCtx.frequency,
varBinds: ProfCtx.varBinds,
conditions: ProfCtx.conditions
conditions: {
condition: ProfCtx.condition,
field: ProfCtx.conditionField,
patterns: ProfCtx.conditionPatterns
}
};

const validation = validateProfiles(profileObj);
Expand All @@ -112,16 +99,16 @@ function AddProfileModal(props) {
ProfCtx.addModalToggle?.current?.focus();
}else{
// form is invalid
setNewSubmitPatterns(prevNewSubmitPatterns => {return !prevNewSubmitPatterns;});
setNewSubmitVarBinds(prevNewSubmitVarBinds => {return !prevNewSubmitVarBinds;});
setNewSubmit(prevNewSubmitPatterns => {return !prevNewSubmitPatterns;});
const errors = validation[1];
for (const property in errors) {
if (errors[property].length > 0 || Object.keys(errors[property]).length > 0){
ValCtx.setErrors(property, errors[property]);
const errorKeys = Object.keys(errors);
errorKeys.forEach((errorKey) => {
if (errors[errorKey].length > 0 || Object.keys(errors[errorKey]).length > 0){
ValCtx.setErrors(errorKey, errors[errorKey]);
}else {
ValCtx.resetErrors(property);
ValCtx.resetErrors(errorKey);
};
};
})
};

},
Expand Down Expand Up @@ -150,14 +137,10 @@ function AddProfileModal(props) {
</div>
</StyledControlGroup>

<Conditions onConditionsCreator={handleConditions} value={ProfCtx.conditions} errorField={ValCtx.conditionFieldErrors}
errorPatterns={ValCtx.conditionPatternsErrors} setErrorPatterns={ValCtx.setConditionPatternsErrors}
validationMessage={validationMessage} validationGroup={validationGroup} newSubmit={newSubmitPatterns}/>
<Condition newSubmit={newSubmit}/>

<StyledControlGroup label="VarBinds">
<VarbindsCreator onVarbindsCreator={handleVarBinds} value={ProfCtx.varBinds} error={ValCtx.varBindsErrors} setError={ValCtx.setVarBindsErrors}
validationMessage={validationMessage} validationGroup={validationGroup}
newSubmit={newSubmitVarBinds}/>
<VarBinds newSubmit={newSubmit}/>
</StyledControlGroup>

</StyledModalBody>
Expand Down
59 changes: 59 additions & 0 deletions frontend/packages/manager/src/components/profiles/Condition.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import React, {useState, useRef, useCallback, useContext, useEffect} from 'react';
import { createDOMID } from '@splunk/ui-utils/id';
import ProfileContext from "../../store/profile-contxt";
import {StyledControlGroup} from "../../styles/inventory/InventoryStyle";
import Select from "@splunk/react-ui/Select";
import Text from "@splunk/react-ui/Text";
import P from "@splunk/react-ui/Paragraph";
import FieldPatterns from "./FieldPatterns";
import {validationGroup, validationMessage} from "../../styles/ValidationStyles";
import ProfilesValidationContxt from "../../store/profiles-validation-contxt";

function Condition(props){
const ProfCtx = useContext(ProfileContext);
const ValCtx = useContext(ProfilesValidationContxt);

const handleFieldChange = useCallback((e, { value: val }) => {
ProfCtx.setConditionField(val);
}, []);

const handleChange = useCallback((e, { value: val }) => {
ProfCtx.setCondition(val);
}, []);

return(
<div>
<StyledControlGroup label="Condition"
labelFor="customized-select-after">
<Select value={ProfCtx.condition} onChange={handleChange} filter>
<Select.Option label="None" value="None"/>
<Select.Option label="base" value="base"/>
<Select.Option label="field" value="field"/>
<Select.Option label="walk" value="walk"/>
<Select.Option label="conditional" value="conditional"/>
</Select>
</StyledControlGroup>
{
ProfCtx.condition === 'field' ? (
<div>
<StyledControlGroup label="field">
<div style={validationGroup}>
<Text value={ProfCtx.conditionField} onChange={handleFieldChange} error={((ValCtx.conditionFieldErrors) ? true : false)}/>
{((ValCtx.conditionFieldErrors) ? ValCtx.conditionFieldErrors.map((el) =>
<P key={createDOMID()} style={validationMessage}>{el}</P>) : <P/>)}
</div>
</StyledControlGroup>
<StyledControlGroup label="patterns">
<FieldPatterns newSubmit={props.newSubmit}/>
</StyledControlGroup>
</div>) : null
}

{ProfCtx.condition === 'conditional' ? (
<div />
) : null}
</div>
)
}

export default Condition;
75 changes: 0 additions & 75 deletions frontend/packages/manager/src/components/profiles/Conditions.jsx

This file was deleted.

Loading

0 comments on commit 30f6d90

Please sign in to comment.