Skip to content

Commit df32f53

Browse files
committed
feat: Merge branch 'feature/k8s-new-docs' of https://github.com/palad-in/keep into feature/k8s-new-docs
2 parents ea095cf + 114ff3c commit df32f53

File tree

96 files changed

+1538
-843
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+1538
-843
lines changed

keep-ui/app/ai/ai.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { Card, List, ListItem, Title, Subtitle } from "@tremor/react";
33
import { useAIStats, usePollAILogs } from "utils/hooks/useAI";
44
import { useSession } from "next-auth/react";
5-
import { getApiURL } from "utils/apiUrl";
5+
import { useApiUrl } from "utils/hooks/useConfig";
66
import { toast } from "react-toastify";
77
import { useEffect, useState, useRef, FormEvent } from "react";
88
import { AILogs } from "./model";
@@ -15,6 +15,7 @@ export default function Ai() {
1515
const [newText, setNewText] = useState("Mine incidents");
1616
const [animate, setAnimate] = useState(false);
1717
const onlyOnce = useRef(false);
18+
const apiUrl = useApiUrl();
1819

1920
const mutateAILogs = (logs: AILogs) => {
2021
setBasicAlgorithmLog(logs.log);
@@ -42,7 +43,6 @@ export default function Ai() {
4243
e.preventDefault();
4344
setAnimate(true);
4445
setNewText("Mining 🚀🚀🚀 ...");
45-
const apiUrl = getApiURL();
4646
const response = await fetch(`${apiUrl}/incidents/mine`, {
4747
method: "POST",
4848
headers: {

keep-ui/app/alerts/ViewAlertModal.tsx

+60-36
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,32 @@
11
import { AlertDto } from "./models"; // Adjust the import path as needed
22
import Modal from "@/components/ui/Modal"; // Ensure this path matches your project structure
3-
import {Button, Icon, Switch, Text} from "@tremor/react";
3+
import { Button, Icon, Switch, Text } from "@tremor/react";
44
import { toast } from "react-toastify";
5-
import { getApiURL } from "../../utils/apiUrl";
5+
import { useApiUrl } from "utils/hooks/useConfig";
66
import { useSession } from "next-auth/react";
77
import { XMarkIcon } from "@heroicons/react/24/outline";
88
import "./ViewAlertModal.css";
9-
import React, {useState} from "react";
9+
import React, { useState } from "react";
1010

1111
interface ViewAlertModalProps {
1212
alert: AlertDto | null | undefined;
1313
handleClose: () => void;
1414
mutate: () => void;
1515
}
1616

17-
const objectToJSONLine = (obj: any) => {
17+
const objectToJSONLine = (obj: any) => {
1818
return JSON.stringify(obj, null, 2).slice(2, -2);
19-
}
19+
};
2020

21-
export const ViewAlertModal: React.FC<ViewAlertModalProps> = ({ alert, handleClose, mutate}) => {
21+
export const ViewAlertModal: React.FC<ViewAlertModalProps> = ({
22+
alert,
23+
handleClose,
24+
mutate,
25+
}) => {
2226
const isOpen = !!alert;
2327
const [showHighlightedOnly, setShowHighlightedOnly] = useState(false);
24-
const {data: session} = useSession();
28+
const { data: session } = useSession();
29+
const apiUrl = useApiUrl();
2530

2631
const unEnrichAlert = async (key: string) => {
2732
if (confirm(`Are you sure you want to un-enrich ${key}?`)) {
@@ -30,7 +35,7 @@ export const ViewAlertModal: React.FC<ViewAlertModalProps> = ({ alert, handleClo
3035
enrichments: [key],
3136
fingerprint: alert!.fingerprint,
3237
};
33-
const response = await fetch(`${getApiURL()}/alerts/unenrich`, {
38+
const response = await fetch(`${apiUrl}/alerts/unenrich`, {
3439
method: "POST",
3540
headers: {
3641
"Content-Type": "application/json",
@@ -52,35 +57,46 @@ export const ViewAlertModal: React.FC<ViewAlertModalProps> = ({ alert, handleClo
5257
toast.error("An unexpected error occurred");
5358
}
5459
}
55-
}
60+
};
5661

5762
const highlightKeys = (json: any, keys: string[]) => {
58-
5963
const lines = Object.keys(json).length;
60-
const isLast = (index: number) => index == lines - 1
64+
const isLast = (index: number) => index == lines - 1;
6165

6266
return Object.keys(json).map((key: string, index: number) => {
6367
if (keys.includes(key)) {
64-
return <p key={key} className="text-green-600 cursor-pointer line-container" onClick={() => unEnrichAlert(key)}>
65-
<span className="un-enrich-icon">
66-
<Icon
67-
icon={XMarkIcon}
68-
tooltip={`Click to un-enrich ${key}`}
69-
size="xs"
70-
color="red"
71-
className="cursor-pointer px-0 py-0"
72-
variant="outlined"
73-
/>
74-
</span>
75-
{objectToJSONLine({[key]: json[key]})}{isLast(index) ? null : ","}
76-
</p>
68+
return (
69+
<p
70+
key={key}
71+
className="text-green-600 cursor-pointer line-container"
72+
onClick={() => unEnrichAlert(key)}
73+
>
74+
<span className="un-enrich-icon">
75+
<Icon
76+
icon={XMarkIcon}
77+
tooltip={`Click to un-enrich ${key}`}
78+
size="xs"
79+
color="red"
80+
className="cursor-pointer px-0 py-0"
81+
variant="outlined"
82+
/>
83+
</span>
84+
{objectToJSONLine({ [key]: json[key] })}
85+
{isLast(index) ? null : ","}
86+
</p>
87+
);
7788
} else {
7889
if (!showHighlightedOnly || keys.length == 0) {
79-
return <p key={key}>{objectToJSONLine({[key]: json[key]})}{isLast(index) ? null : ","}</p>
90+
return (
91+
<p key={key}>
92+
{objectToJSONLine({ [key]: json[key] })}
93+
{isLast(index) ? null : ","}
94+
</p>
95+
);
8096
}
8197
}
82-
})
83-
}
98+
});
99+
};
84100

85101
const handleCopy = async () => {
86102
if (alert) {
@@ -94,23 +110,31 @@ export const ViewAlertModal: React.FC<ViewAlertModalProps> = ({ alert, handleClo
94110
};
95111

96112
return (
97-
<Modal onClose={handleClose} isOpen={isOpen} className="overflow-visible max-w-fit">
113+
<Modal
114+
onClose={handleClose}
115+
isOpen={isOpen}
116+
className="overflow-visible max-w-fit"
117+
>
98118
<div className="flex justify-between items-center mb-4 min-w-full">
99119
<h2 className="text-lg font-semibold">Alert Details</h2>
100-
<div className="flex gap-x-2"> {/* Adjust gap as needed */}
120+
<div className="flex gap-x-2">
121+
{" "}
122+
{/* Adjust gap as needed */}
101123
<div className="placeholder-resizing min-w-48"></div>
102124
<div className="flex items-center space-x-2">
103125
<Switch
104-
color="orange"
105-
id="showHighlightedOnly"
106-
checked={showHighlightedOnly}
107-
onChange={() => setShowHighlightedOnly(!showHighlightedOnly)}
108-
/>
109-
<label htmlFor="showHighlightedOnly" className="text-sm text-gray-500">
126+
color="orange"
127+
id="showHighlightedOnly"
128+
checked={showHighlightedOnly}
129+
onChange={() => setShowHighlightedOnly(!showHighlightedOnly)}
130+
/>
131+
<label
132+
htmlFor="showHighlightedOnly"
133+
className="text-sm text-gray-500"
134+
>
110135
<Text>Enriched Fields Only</Text>
111136
</label>
112137
</div>
113-
114138
<Button onClick={handleCopy} color="orange">
115139
Copy to Clipboard
116140
</Button>

keep-ui/app/alerts/alert-actions.tsx

+13-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useState } from "react";
22
import { Button } from "@tremor/react";
33
import { getSession } from "next-auth/react";
4-
import { getApiURL } from "utils/apiUrl";
4+
import { useApiUrl } from "utils/hooks/useConfig";
55
import { AlertDto } from "./models";
66
import { PlusIcon } from "@radix-ui/react-icons";
77
import { toast } from "react-toastify";
@@ -23,14 +23,16 @@ export default function AlertActions({
2323
alerts,
2424
clearRowSelection,
2525
setDismissModalAlert,
26-
mutateAlerts
26+
mutateAlerts,
2727
}: Props) {
2828
const router = useRouter();
2929
const { useAllPresets } = usePresets();
30+
const apiUrl = useApiUrl();
3031
const { mutate: presetsMutator } = useAllPresets({
3132
revalidateOnFocus: false,
3233
});
33-
const [isIncidentSelectorOpen, setIsIncidentSelectorOpen] = useState<boolean>(false);
34+
const [isIncidentSelectorOpen, setIsIncidentSelectorOpen] =
35+
useState<boolean>(false);
3436

3537
const selectedAlerts = alerts.filter((_alert, index) =>
3638
selectedRowIds.includes(index.toString())
@@ -54,7 +56,6 @@ export default function AlertActions({
5456
);
5557
const options = [{ value: formattedCel, label: "CEL" }];
5658
const session = await getSession();
57-
const apiUrl = getApiURL();
5859
const response = await fetch(`${apiUrl}/preset`, {
5960
method: "POST",
6061
headers: {
@@ -82,18 +83,18 @@ export default function AlertActions({
8283

8384
const showIncidentSelector = () => {
8485
setIsIncidentSelectorOpen(true);
85-
}
86+
};
8687
const hideIncidentSelector = () => {
8788
setIsIncidentSelectorOpen(false);
88-
}
89+
};
8990

9091
const handleSuccessfulAlertsAssociation = () => {
9192
hideIncidentSelector();
9293
clearRowSelection();
9394
if (mutateAlerts) {
9495
mutateAlerts();
9596
}
96-
}
97+
};
9798

9899
return (
99100
<div className="w-full flex justify-end items-center">
@@ -130,10 +131,11 @@ export default function AlertActions({
130131
Associate with incident
131132
</Button>
132133
<AlertAssociateIncidentModal
133-
isOpen={isIncidentSelectorOpen}
134-
alerts={selectedAlerts}
135-
handleSuccess={handleSuccessfulAlertsAssociation}
136-
handleClose={hideIncidentSelector}/>
134+
isOpen={isIncidentSelectorOpen}
135+
alerts={selectedAlerts}
136+
handleSuccess={handleSuccessfulAlertsAssociation}
137+
handleClose={hideIncidentSelector}
138+
/>
137139
</div>
138140
);
139141
}

keep-ui/app/alerts/alert-assign-ticket-modal.tsx

+5-8
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { PlusIcon } from "@heroicons/react/20/solid";
55
import { useForm, Controller, SubmitHandler } from "react-hook-form";
66
import { Providers } from "./../providers/providers";
77
import { useSession } from "next-auth/react";
8-
import { getApiURL } from "utils/apiUrl";
8+
import { useApiUrl } from "utils/hooks/useConfig";
99
import { AlertDto } from "./models";
1010
import Modal from "@/components/ui/Modal";
1111

@@ -45,6 +45,7 @@ const AlertAssignTicketModal = ({
4545
} = useForm<FormData>();
4646
// get the token
4747
const { data: session } = useSession();
48+
const apiUrl = useApiUrl();
4849

4950
// if this modal should not be open, do nothing
5051
if (!alert) return null;
@@ -61,7 +62,7 @@ const AlertAssignTicketModal = ({
6162
fingerprint: alert.fingerprint,
6263
};
6364

64-
const response = await fetch(`${getApiURL()}/alerts/enrich`, {
65+
const response = await fetch(`${apiUrl}/alerts/enrich`, {
6566
method: "POST",
6667
headers: {
6768
"Content-Type": "application/json",
@@ -225,18 +226,14 @@ const AlertAssignTicketModal = ({
225226
</div>
226227
<div className="mt-6 flex gap-2">
227228
<Button color="orange" type="submit">
228-
<Text>
229-
Assign Ticket
230-
</Text>
229+
<Text>Assign Ticket</Text>
231230
</Button>
232231
<Button
233232
onClick={handleClose}
234233
variant="secondary"
235234
className="border border-orange-500 text-orange-500"
236235
>
237-
<Text>
238-
Cancel
239-
</Text>
236+
<Text>Cancel</Text>
240237
</Button>
241238
</div>
242239
</form>

keep-ui/app/alerts/alert-associate-incident-modal.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { useSession } from "next-auth/react";
66
import { useRouter } from "next/navigation";
77
import { FormEvent, useCallback, useEffect, useState } from "react";
88
import { toast } from "react-toastify";
9-
import { getApiURL } from "../../utils/apiUrl";
9+
import { useApiUrl } from "utils/hooks/useConfig";
1010
import { useIncidents, usePollIncidents } from "../../utils/hooks/useIncidents";
1111
import Loading from "../loading";
1212
import { AlertDto } from "./models";
@@ -34,10 +34,10 @@ const AlertAssociateIncidentModal = ({
3434
>();
3535
// get the token
3636
const { data: session } = useSession();
37+
const apiUrl = useApiUrl();
3738
const router = useRouter();
3839

3940
const associateAlertsHandler = async (incidentId: string) => {
40-
const apiUrl = getApiURL();
4141
const response = await fetch(`${apiUrl}/incidents/${incidentId}/alerts`, {
4242
method: "POST",
4343
headers: {

keep-ui/app/alerts/alert-change-status-modal.tsx

+21-17
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import Select, {
88
} from "react-select";
99
import { useState } from "react";
1010
import { AlertDto, Status } from "./models";
11-
import { getApiURL } from "utils/apiUrl";
11+
import { useApiUrl } from "utils/hooks/useConfig";
1212
import { useSession } from "next-auth/react";
1313
import { toast } from "react-toastify";
1414
import {
@@ -79,6 +79,7 @@ export default function AlertChangeStatusModal({
7979
const { useAllPresets } = usePresets();
8080
const { mutate: presetsMutator } = useAllPresets();
8181
const { useAllAlerts } = useAlerts();
82+
const apiUrl = useApiUrl();
8283
const { mutate: alertsMutator } = useAllAlerts(presetName, {
8384
revalidateOnMount: false,
8485
});
@@ -109,23 +110,26 @@ export default function AlertChangeStatusModal({
109110
}
110111

111112
try {
112-
const response = await fetch(`${getApiURL()}/alerts/enrich?dispose_on_new_alert=true`, {
113-
method: "POST",
114-
headers: {
115-
"Content-Type": "application/json",
116-
Authorization: `Bearer ${session?.accessToken}`,
117-
},
118-
body: JSON.stringify({
119-
enrichments: {
120-
status: selectedStatus,
121-
...(selectedStatus !== Status.Suppressed && {
122-
dismissed: false,
123-
dismissUntil: "",
124-
}),
113+
const response = await fetch(
114+
`${apiUrl}/alerts/enrich?dispose_on_new_alert=true`,
115+
{
116+
method: "POST",
117+
headers: {
118+
"Content-Type": "application/json",
119+
Authorization: `Bearer ${session?.accessToken}`,
125120
},
126-
fingerprint: alert.fingerprint,
127-
}),
128-
});
121+
body: JSON.stringify({
122+
enrichments: {
123+
status: selectedStatus,
124+
...(selectedStatus !== Status.Suppressed && {
125+
dismissed: false,
126+
dismissUntil: "",
127+
}),
128+
},
129+
fingerprint: alert.fingerprint,
130+
}),
131+
}
132+
);
129133

130134
if (response.ok) {
131135
toast.success("Alert status changed successfully!");

0 commit comments

Comments
 (0)