making the select rules option work for pipelines

This commit is contained in:
Hari Krishna
2024-06-25 12:35:49 +00:00
committed by satti-hari-krishna-reddy
parent a3841e0602
commit 6ec9433564
2 changed files with 70 additions and 27 deletions
+4
View File
@@ -5199,7 +5199,11 @@ func initHandlers() {
r.HandleFunc("/api/v1/files/detection/sigma_rules", shuffle.HandleGetSigmaRules).Methods("GET", "OPTIONS") r.HandleFunc("/api/v1/files/detection/sigma_rules", shuffle.HandleGetSigmaRules).Methods("GET", "OPTIONS")
r.HandleFunc("/api/v1/files/detection/{fileId}/{action}", shuffle.HandleToggleRule).Methods("PUT", "OPTIONS") r.HandleFunc("/api/v1/files/detection/{fileId}/{action}", shuffle.HandleToggleRule).Methods("PUT", "OPTIONS")
r.HandleFunc("/api/v1/files/detection/{action}", shuffle.HandleFolderToggle).Methods("PUT", "OPTIONS") r.HandleFunc("/api/v1/files/detection/{action}", shuffle.HandleFolderToggle).Methods("PUT", "OPTIONS")
r.HandleFunc("/api/v1/detection/siem/node_health", handleTenzirHealthUpdate).Methods("POST","OPTIONS") r.HandleFunc("/api/v1/detection/siem/node_health", handleTenzirHealthUpdate).Methods("POST","OPTIONS")
r.HandleFunc("/api/v1/detection/{triggerId}/selected_rules", shuffle.HandleGetSelectedRules).Methods("GET","OPTIONS")
r.HandleFunc("/api/v1/detection/{triggerId}/selected_rules/save", shuffle.HandleSaveSelectedRules).Methods("POST","OPTIONS")
// Introduced in 0.9.21 to handle notifications for e.g. failed Workflow // Introduced in 0.9.21 to handle notifications for e.g. failed Workflow
r.HandleFunc("/api/v1/notifications", shuffle.HandleCreateNotification).Methods("POST", "OPTIONS") r.HandleFunc("/api/v1/notifications", shuffle.HandleCreateNotification).Methods("POST", "OPTIONS")
+63 -24
View File
@@ -21194,9 +21194,37 @@ const releaseToConnectLabel = "Release to Connect"
) : null; ) : null;
const TenzirConfigModal = () => { const TenzirConfigModal = () => {
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(true);
const [selectedRules, setSelectedRules] = useState([]); const [selectedRules, setSelectedRules] = useState([]);
useEffect(() => {
if (tenzirConfigModalOpen) {
try {
const url = globalUrl + "/api/v1/detection/" + selectedTrigger.id + "/selected_rules"
fetch(url, {
method: "GET",
credentials: "include",
headers: {
"Content-Type": "application/json",
},
})
.then(response => response.json())
.then(data => {
const savedRules = data.selected_rules.map(rule => rule.file_id);
setSelectedRules(savedRules);
setLoading(false);
})
.catch(error => {
console.error('Error fetching selected rules:', error);
setLoading(false);
});
} catch (error) {
console.error('Error:', error);
setLoading(false);
}
}
}, [tenzirConfigModalOpen]);
const handleRuleChange = (event) => { const handleRuleChange = (event) => {
setSelectedRules(event.target.value); setSelectedRules(event.target.value);
}; };
@@ -21211,30 +21239,42 @@ const releaseToConnectLabel = "Release to Connect"
}; };
const handleSubmit = () => { const handleSubmit = () => {
const selectedRuleFiles = rules const selectedRuleFiles = rules.filter(rule => selectedRules.includes(rule.file_id));
.filter(rule => selectedRules.includes(rule.file_id));
if (selectedTrigger.trigger_type !== "PIPELINE") { const payload = {
toast("Unable to save the configuration"); selected_rules: selectedRuleFiles.map(rule => ({
return; file_name: rule.file_name,
} title: rule.title,
description: rule.description,
file_id: rule.file_id,
is_enabled: rule.is_enabled,
}))
};
selectedTrigger.parameters = selectedRuleFiles; try {
const url = globalUrl + "/api/v1/detection/" + selectedTrigger.id + "/selected_rules/save"
fetch(url, {
console.log('Selected Rule Files:', selectedRuleFiles); method: 'POST',
console.log('Selected Rule File Names:', selectedRuleFiles.map(rule => rule.file_id)); credentials: "include",
headers: {
setTenzirConfigModalOpen(false); 'Content-Type': 'application/json',
}; },
body: JSON.stringify(payload),
useEffect(()=>{ })
if (selectedTrigger.trigger_type !== "PIPELINE") { .then(response => response.json())
//toast("Unable to save the configuration"); .then(data => {
return; console.log('Rules saved successfully:', data);
setTenzirConfigModalOpen(false);
})
.catch(error => {
console.error('Error saving selected rules:', error);
toast("Unable to save the configuration");
});
} catch (error) {
console.error('Error:', error);
toast("Unable to save the configuration");
} }
setSelectedRules(selectedTrigger.parameters); };
},[])
const enabledSigmaInfo = rules.filter(rule => rule.is_enabled); const enabledSigmaInfo = rules.filter(rule => rule.is_enabled);
@@ -21319,8 +21359,7 @@ const releaseToConnectLabel = "Release to Connect"
</IconButton> </IconButton>
</Dialog> </Dialog>
); );
} };