Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions backend/modules/soar/executor/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (Notify) Type() string { return "notify" }

type notifyParams struct {
Message string `json:"message"`
Type string `json:"type,omitempty"` // INFO (default) | WARNING
Type string `json:"type,omitempty"`
}

func (n *Notify) Execute(ctx context.Context, exec *soardomain.SoarExecution) (json.RawMessage, error) {
Expand All @@ -47,8 +47,11 @@ func (n *Notify) Execute(ctx context.Context, exec *soardomain.SoarExecution) (j
return nil, errors.New("soar notify: message is required")
}
ntype := domain.TypeInfo
if p.Type == string(domain.TypeWarning) {
switch domain.NotificationType(p.Type) {
case domain.TypeWarning:
ntype = domain.TypeWarning
case domain.TypeError:
ntype = domain.TypeError
}
if err := n.client.Notify(ctx, domain.SourceSystem, ntype, p.Message); err != nil {
return nil, err
Expand Down
11 changes: 7 additions & 4 deletions backend/modules/soar/usecase/command_summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,14 @@ func summarizeNodeAction(executor string, params json.RawMessage) string {
}
return ""
case "notify":
label := "notify (INFO)"
if g.Get("type").Str == string(notificationdomain.TypeWarning) {
label = "notify (WARNING)"
ntype := "INFO"
switch g.Get("type").Str {
case string(notificationdomain.TypeWarning):
ntype = "WARNING"
case string(notificationdomain.TypeError):
ntype = "ERROR"
}
return label + ": " + g.Get("message").Str
return "notify (" + ntype + "): " + g.Get("message").Str
case "incident":
return "open incident: " + g.Get("name").Str
case "conditional":
Expand Down
13 changes: 12 additions & 1 deletion frontend/src/features/soar/components/NodeInspector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { IncidentParamsEditor } from './IncidentParamsEditor'
import { InsertFieldMenu } from './InsertFieldMenu'
import { MailParamsEditor } from './MailParamsEditor'
import { LLMParamsEditor } from './LLMParamsEditor'
import { NotifyParamsEditor } from './NotifyParamsEditor'

interface Props {
nodeId: string
Expand Down Expand Up @@ -244,6 +245,16 @@ export function NodeInspector({ nodeId, node, nodes, readOnly, onRename, onChang
/>
)}

{node.executor === 'notify' && (
<NotifyParamsEditor
nodeId={nodeId}
nodes={nodes}
params={node.params}
readOnly={readOnly}
onChange={(next) => onChange({ params: next })}
/>
)}

{(node.executor === 'llm_enrich' || node.executor === 'llm_action') && (
<LLMParamsEditor
nodeId={nodeId}
Expand All @@ -255,7 +266,7 @@ export function NodeInspector({ nodeId, node, nodes, readOnly, onRename, onChang
/>
)}

{node.executor !== 'shell' && node.executor !== 'conditional' && node.executor !== 'http' && node.executor !== 'incident' && node.executor !== 'mail' && node.executor !== 'llm_enrich' && node.executor !== 'llm_action' && (
{node.executor !== 'shell' && node.executor !== 'conditional' && node.executor !== 'http' && node.executor !== 'incident' && node.executor !== 'mail' && node.executor !== 'notify' && node.executor !== 'llm_enrich' && node.executor !== 'llm_action' && (
<Field label={t('soar.editor.canvas.paramsJson')}>
{!readOnly && (
<div className="mb-1 flex flex-wrap items-center gap-1.5">
Expand Down
95 changes: 95 additions & 0 deletions frontend/src/features/soar/components/NotifyParamsEditor.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import { useRef } from 'react'
import { useTranslation } from 'react-i18next'
import type { FlowNode } from '../types/soar.types'
import { InsertFieldMenu } from './InsertFieldMenu'

interface NotifyParams {
message?: string
type?: string
}

interface Props {
nodeId: string
nodes: Record<string, FlowNode>
params: unknown
readOnly?: boolean
onChange: (params: NotifyParams) => void
}

const LEVELS = ['INFO', 'WARNING', 'ERROR'] as const

const SELECT =
'h-8 rounded-md border border-input bg-background px-2 text-xs focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring'

export function NotifyParamsEditor({ nodeId, nodes, params, readOnly, onChange }: Props) {
const { t } = useTranslation()
const p = normalize(params)
const messageRef = useRef<HTMLTextAreaElement>(null)

const insertIntoMessage = (token: string) => {
const el = messageRef.current
const cur = p.message ?? ''
const start = el?.selectionStart ?? cur.length
const end = el?.selectionEnd ?? cur.length
const next = cur.slice(0, start) + token + cur.slice(end)
onChange({ ...p, message: next })
requestAnimationFrame(() => {
const el2 = messageRef.current
if (!el2) return
el2.focus()
const pos = start + token.length
el2.setSelectionRange(pos, pos)
})
}

return (
<div className="space-y-2">
<Field label={t('soar.editor.canvas.notify.level')}>
<select
value={p.type ?? 'INFO'}
disabled={readOnly}
onChange={(e) => onChange({ ...p, type: e.target.value })}
className={SELECT}
>
{LEVELS.map((l) => (
<option key={l} value={l}>
{l}
</option>
))}
</select>
</Field>
<Field label={t('soar.editor.canvas.notify.message')}>
{!readOnly && (
<div className="mb-1 flex flex-wrap items-center gap-1.5">
<InsertFieldMenu nodes={nodes} currentNodeId={nodeId} onInsert={insertIntoMessage} />
</div>
)}
<textarea
ref={messageRef}
value={p.message ?? ''}
readOnly={readOnly}
onChange={(e) => onChange({ ...p, message: e.target.value })}
rows={6}
placeholder={t('soar.editor.canvas.notify.messagePlaceholder')}
className="w-full rounded-md border border-input bg-background px-2 py-1.5 text-[11px] focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"
/>
</Field>
</div>
)
}

function Field({ label, children }: { label: string; children: React.ReactNode }) {
return (
<div>
<label className="mb-1 block text-[10px] font-medium uppercase tracking-wider text-muted-foreground">
{label}
</label>
{children}
</div>
)
}

function normalize(params: unknown): NotifyParams {
if (!params || typeof params !== 'object') return {}
return params as NotifyParams
}
5 changes: 5 additions & 0 deletions frontend/src/shared/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -5192,6 +5192,11 @@
"subjectPlaceholder": "e.g. Alert on $(alert.dataSource)",
"body": "Body",
"bodyPlaceholder": "Message body. Templates like $(alert.name) are interpolated."
},
"notify": {
"level": "Level",
"message": "Message",
"messagePlaceholder": "Notification text. Templates like $(alert.name) are interpolated."
}
}
},
Expand Down
Loading