KI-AGENT: Asterisk-Statusprüfung robuster machen
This commit is contained in:
@@ -11,6 +11,17 @@ const telephonyEnabled = () =>
|
||||
const asteriskHttpStatusUrl = () =>
|
||||
process.env.TELEPHONY_ASTERISK_HTTP_URL || "http://asterisk-dev:8088/ws"
|
||||
|
||||
const asteriskHttpStatusUrls = () => {
|
||||
const configuredUrl = asteriskHttpStatusUrl()
|
||||
return Array.from(new Set([
|
||||
configuredUrl,
|
||||
"http://asterisk-dev:8088/ws",
|
||||
"http://host.docker.internal:8088/ws",
|
||||
`http://127.0.0.1:${process.env.TELEPHONY_DEV_WS_PORT || "8088"}/ws`,
|
||||
`http://localhost:${process.env.TELEPHONY_DEV_WS_PORT || "8088"}/ws`,
|
||||
]))
|
||||
}
|
||||
|
||||
const publicAsteriskWsUrl = () =>
|
||||
process.env.TELEPHONY_ASTERISK_WS_URL || `ws://localhost:${process.env.TELEPHONY_DEV_WS_PORT || "8088"}/ws`
|
||||
|
||||
@@ -54,40 +65,52 @@ export default async function telephonyRoutes(server: FastifyInstance) {
|
||||
|
||||
server.get("/telephony/status", async () => {
|
||||
const enabled = telephonyEnabled()
|
||||
const url = asteriskHttpStatusUrl()
|
||||
const urls = asteriskHttpStatusUrls()
|
||||
|
||||
if (!enabled) {
|
||||
return {
|
||||
enabled,
|
||||
provider: "asterisk",
|
||||
reachable: false,
|
||||
statusUrl: url,
|
||||
message: "Telefonie ist nicht aktiviert.",
|
||||
let lastError: any = null
|
||||
const attempts = []
|
||||
|
||||
for (const url of urls) {
|
||||
try {
|
||||
const response = await fetchWithTimeout(url)
|
||||
attempts.push({
|
||||
url,
|
||||
reachable: true,
|
||||
statusCode: response.status,
|
||||
})
|
||||
|
||||
return {
|
||||
enabled,
|
||||
provider: "asterisk",
|
||||
reachable: true,
|
||||
statusCode: response.status,
|
||||
statusUrl: url,
|
||||
attempts,
|
||||
message: enabled
|
||||
? (response.ok ? "Asterisk ist erreichbar." : `Asterisk-HTTP ist erreichbar (HTTP ${response.status}).`)
|
||||
: "Asterisk ist erreichbar, Telefonie ist aber noch nicht aktiviert.",
|
||||
}
|
||||
} catch (error: any) {
|
||||
lastError = error
|
||||
attempts.push({
|
||||
url,
|
||||
reachable: false,
|
||||
message: error?.name === "AbortError"
|
||||
? "Abgelaufen"
|
||||
: (error?.message || "Nicht erreichbar"),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetchWithTimeout(url)
|
||||
return {
|
||||
enabled,
|
||||
provider: "asterisk",
|
||||
reachable: true,
|
||||
statusCode: response.status,
|
||||
statusUrl: url,
|
||||
message: response.ok
|
||||
? "Asterisk ist erreichbar."
|
||||
: `Asterisk-HTTP ist erreichbar (HTTP ${response.status}).`,
|
||||
}
|
||||
} catch (error: any) {
|
||||
return {
|
||||
enabled,
|
||||
provider: "asterisk",
|
||||
reachable: false,
|
||||
statusUrl: url,
|
||||
message: error?.name === "AbortError"
|
||||
? "Asterisk-Statusabfrage ist abgelaufen."
|
||||
: (error?.message || "Asterisk ist nicht erreichbar."),
|
||||
}
|
||||
return {
|
||||
enabled,
|
||||
provider: "asterisk",
|
||||
reachable: false,
|
||||
statusUrl: urls[0],
|
||||
attempts,
|
||||
message: lastError?.name === "AbortError"
|
||||
? "Asterisk-Statusabfrage ist abgelaufen."
|
||||
: (lastError?.message || "Asterisk ist nicht erreichbar."),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -11,13 +11,15 @@ const websocketResult = ref(null)
|
||||
const lastUpdated = ref(null)
|
||||
|
||||
const statusColor = computed(() => {
|
||||
if (status.value?.reachable) return "success"
|
||||
if (!status.value?.enabled) return "warning"
|
||||
return status.value?.reachable ? "success" : "error"
|
||||
return "error"
|
||||
})
|
||||
|
||||
const statusIcon = computed(() => {
|
||||
if (status.value?.reachable) return "i-heroicons-signal"
|
||||
if (!status.value?.enabled) return "i-heroicons-pause-circle"
|
||||
return status.value?.reachable ? "i-heroicons-signal" : "i-heroicons-signal-slash"
|
||||
return "i-heroicons-signal-slash"
|
||||
})
|
||||
|
||||
const websocketColor = computed(() => {
|
||||
@@ -174,7 +176,7 @@ onMounted(loadTelephony)
|
||||
<span class="text-sm font-medium text-gray-700">Status</span>
|
||||
</div>
|
||||
<p class="mt-3 text-lg font-semibold text-gray-950">
|
||||
{{ status?.enabled ? (status?.reachable ? "Erreichbar" : "Nicht erreichbar") : "Deaktiviert" }}
|
||||
{{ status?.reachable ? "Erreichbar" : (status?.enabled ? "Nicht erreichbar" : "Deaktiviert") }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@@ -206,6 +208,24 @@ onMounted(loadTelephony)
|
||||
:title="status?.message || 'Telefonie wird geladen'"
|
||||
:description="status?.statusUrl || 'Noch keine Status-URL geladen.'"
|
||||
/>
|
||||
|
||||
<div v-if="status?.attempts?.length" class="mt-4 rounded-lg border border-gray-200 bg-gray-50 p-3">
|
||||
<p class="text-xs font-medium uppercase tracking-wide text-gray-500">
|
||||
Geprüfte Status-Ziele
|
||||
</p>
|
||||
<div class="mt-2 grid gap-2">
|
||||
<div
|
||||
v-for="attempt in status.attempts"
|
||||
:key="attempt.url"
|
||||
class="flex items-center justify-between gap-3 text-sm"
|
||||
>
|
||||
<span class="break-all font-mono text-gray-700">{{ attempt.url }}</span>
|
||||
<UBadge :color="attempt.reachable ? 'success' : 'neutral'" variant="soft">
|
||||
{{ attempt.reachable ? `HTTP ${attempt.statusCode}` : "offline" }}
|
||||
</UBadge>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</UCard>
|
||||
|
||||
<UCard>
|
||||
|
||||
Reference in New Issue
Block a user