mirror of
https://github.com/fankes/beszel.git
synced 2025-10-20 02:09:28 +08:00
clean up / small refactoring
This commit is contained in:
@@ -4,7 +4,6 @@ package alerts
|
|||||||
import (
|
import (
|
||||||
"beszel/internal/entities/system"
|
"beszel/internal/entities/system"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"net/mail"
|
"net/mail"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
@@ -179,8 +178,7 @@ func (am *AlertManager) sendAlert(data AlertData) {
|
|||||||
}
|
}
|
||||||
// send alerts via webhooks
|
// send alerts via webhooks
|
||||||
for _, webhook := range userAlertSettings.Webhooks {
|
for _, webhook := range userAlertSettings.Webhooks {
|
||||||
err := am.SendShoutrrrAlert(webhook, data.Title, data.Message, data.Link, data.LinkText)
|
if err := am.SendShoutrrrAlert(webhook, data.Title, data.Message, data.Link, data.LinkText); err != nil {
|
||||||
if err != nil {
|
|
||||||
am.app.Logger().Error("Failed to send shoutrrr alert", "err", err.Error())
|
am.app.Logger().Error("Failed to send shoutrrr alert", "err", err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -202,7 +200,6 @@ func (am *AlertManager) sendAlert(data AlertData) {
|
|||||||
Name: am.app.Settings().Meta.SenderName,
|
Name: am.app.Settings().Meta.SenderName,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
log.Println("Sending alert via email")
|
|
||||||
if err := am.app.NewMailClient().Send(&message); err != nil {
|
if err := am.app.NewMailClient().Send(&message); err != nil {
|
||||||
am.app.Logger().Error("Failed to send alert: ", "err", err.Error())
|
am.app.Logger().Error("Failed to send alert: ", "err", err.Error())
|
||||||
} else {
|
} else {
|
||||||
|
@@ -5,7 +5,7 @@ import { pb } from '@/lib/stores'
|
|||||||
import { Separator } from '@/components/ui/separator'
|
import { Separator } from '@/components/ui/separator'
|
||||||
import { Card } from '@/components/ui/card'
|
import { Card } from '@/components/ui/card'
|
||||||
import { BellIcon, LoaderCircleIcon, PlusIcon, SaveIcon, Trash2Icon } from 'lucide-react'
|
import { BellIcon, LoaderCircleIcon, PlusIcon, SaveIcon, Trash2Icon } from 'lucide-react'
|
||||||
import { useState } from 'react'
|
import { ChangeEventHandler, useState } from 'react'
|
||||||
import { toast } from '@/components/ui/use-toast'
|
import { toast } from '@/components/ui/use-toast'
|
||||||
import { InputTags } from '@/components/ui/input-tags'
|
import { InputTags } from '@/components/ui/input-tags'
|
||||||
import { UserSettings } from '@/types'
|
import { UserSettings } from '@/types'
|
||||||
@@ -15,7 +15,7 @@ import { isAdmin } from '@/lib/utils'
|
|||||||
|
|
||||||
interface ShoutrrrUrlCardProps {
|
interface ShoutrrrUrlCardProps {
|
||||||
url: string
|
url: string
|
||||||
onUrlChange: (value: string) => void
|
onUrlChange: ChangeEventHandler<HTMLInputElement>
|
||||||
onRemove: () => void
|
onRemove: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,7 +61,7 @@ const SettingsNotificationsPage = ({ userSettings }: { userSettings: UserSetting
|
|||||||
Configure how you receive alert notifications.
|
Configure how you receive alert notifications.
|
||||||
</p>
|
</p>
|
||||||
<p className="text-sm text-muted-foreground mt-1.5 leading-relaxed">
|
<p className="text-sm text-muted-foreground mt-1.5 leading-relaxed">
|
||||||
Looking instead for where to create system alerts? Click the bell{' '}
|
Looking instead for where to create alerts? Click the bell{' '}
|
||||||
<BellIcon className="inline h-4 w-4" /> icons in the systems table.
|
<BellIcon className="inline h-4 w-4" /> icons in the systems table.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
@@ -117,7 +117,9 @@ const SettingsNotificationsPage = ({ userSettings }: { userSettings: UserSetting
|
|||||||
<ShoutrrrUrlCard
|
<ShoutrrrUrlCard
|
||||||
key={index}
|
key={index}
|
||||||
url={webhook}
|
url={webhook}
|
||||||
onUrlChange={(value: string) => updateWebhook(index, value)}
|
onUrlChange={(e: React.ChangeEvent<HTMLInputElement>) =>
|
||||||
|
updateWebhook(index, e.target.value)
|
||||||
|
}
|
||||||
onRemove={() => removeWebhook(index)}
|
onRemove={() => removeWebhook(index)}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
@@ -178,11 +180,12 @@ const ShoutrrrUrlCard = ({ url, onUrlChange, onRemove }: ShoutrrrUrlCardProps) =
|
|||||||
<Card className="bg-muted/30 p-2 md:p-3">
|
<Card className="bg-muted/30 p-2 md:p-3">
|
||||||
<div className="flex items-center gap-1">
|
<div className="flex items-center gap-1">
|
||||||
<Input
|
<Input
|
||||||
|
type="url"
|
||||||
className="light:bg-card"
|
className="light:bg-card"
|
||||||
required
|
required
|
||||||
placeholder="generic://webhook.site/xxxxxx"
|
placeholder="generic://webhook.site/xxxxxx"
|
||||||
value={url}
|
value={url}
|
||||||
onChange={(e) => onUrlChange(e.target.value)}
|
onChange={onUrlChange}
|
||||||
/>
|
/>
|
||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
|
@@ -9,7 +9,7 @@ import {
|
|||||||
DialogTitle,
|
DialogTitle,
|
||||||
} from '@/components/ui/dialog'
|
} from '@/components/ui/dialog'
|
||||||
import { BellIcon } from 'lucide-react'
|
import { BellIcon } from 'lucide-react'
|
||||||
import { cn, isAdmin } from '@/lib/utils'
|
import { cn } from '@/lib/utils'
|
||||||
import { Button } from '@/components/ui/button'
|
import { Button } from '@/components/ui/button'
|
||||||
import { Switch } from '@/components/ui/switch'
|
import { Switch } from '@/components/ui/switch'
|
||||||
import { AlertRecord, SystemRecord } from '@/types'
|
import { AlertRecord, SystemRecord } from '@/types'
|
||||||
|
Reference in New Issue
Block a user