-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
874 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { observable } from "@trpc/server/observable"; | ||
|
||
import type { Modify } from "@homarr/common/types"; | ||
import type { Integration } from "@homarr/db/schema"; | ||
import type { IntegrationKindByCategory } from "@homarr/definitions"; | ||
import { getIntegrationKindsByCategory } from "@homarr/definitions"; | ||
import type { NetworkControllerSummary } from "@homarr/integrations/types"; | ||
import { networkControllerRequestHandler } from "@homarr/request-handler/network-controller"; | ||
|
||
import { createManyIntegrationMiddleware } from "../../middlewares/integration"; | ||
import { createTRPCRouter, publicProcedure } from "../../trpc"; | ||
|
||
export const networkControllerRouter = createTRPCRouter({ | ||
summary: publicProcedure | ||
.unstable_concat(createManyIntegrationMiddleware("query", ...getIntegrationKindsByCategory("networkController"))) | ||
.query(async ({ ctx }) => { | ||
const results = await Promise.all( | ||
ctx.integrations.map(async (integration) => { | ||
const innerHandler = networkControllerRequestHandler.handler(integration, {}); | ||
const { data, timestamp } = await innerHandler.getCachedOrUpdatedDataAsync({ forceUpdate: false }); | ||
|
||
return { | ||
integration: { | ||
id: integration.id, | ||
name: integration.name, | ||
kind: integration.kind, | ||
updatedAt: timestamp, | ||
}, | ||
summary: data, | ||
}; | ||
}), | ||
); | ||
return results; | ||
}), | ||
|
||
subscribeToSummary: publicProcedure | ||
.unstable_concat(createManyIntegrationMiddleware("query", ...getIntegrationKindsByCategory("networkController"))) | ||
.subscription(({ ctx }) => { | ||
return observable<{ | ||
integration: Modify<Integration, { kind: IntegrationKindByCategory<"networkController"> }>; | ||
summary: NetworkControllerSummary; | ||
}>((emit) => { | ||
const unsubscribes: (() => void)[] = []; | ||
for (const integrationWithSecrets of ctx.integrations) { | ||
const { decryptedSecrets: _, ...integration } = integrationWithSecrets; | ||
const innerHandler = networkControllerRequestHandler.handler(integrationWithSecrets, {}); | ||
const unsubscribe = innerHandler.subscribe((summary) => { | ||
emit.next({ | ||
integration, | ||
summary, | ||
}); | ||
}); | ||
unsubscribes.push(unsubscribe); | ||
} | ||
return () => { | ||
unsubscribes.forEach((unsubscribe) => { | ||
unsubscribe(); | ||
}); | ||
}; | ||
}); | ||
}), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
packages/cron-jobs/src/jobs/integrations/network-controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { EVERY_MINUTE } from "@homarr/cron-jobs-core/expressions"; | ||
import { createRequestIntegrationJobHandler } from "@homarr/request-handler/lib/cached-request-integration-job-handler"; | ||
import { networkControllerRequestHandler } from "@homarr/request-handler/network-controller"; | ||
|
||
import { createCronJob } from "../../lib"; | ||
|
||
export const networkControllerJob = createCronJob("networkController", EVERY_MINUTE).withCallback( | ||
createRequestIntegrationJobHandler(networkControllerRequestHandler.handler, { | ||
widgetKinds: ["networkControllerSummary"], | ||
getInput: { | ||
networkControllerSummary: () => ({}), | ||
}, | ||
}), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
...tions/src/interfaces/network-controller-summary/network-controller-summary-integration.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import type { NetworkControllerSummary } from "./network-controller-summary-types"; | ||
|
||
export interface NetworkControllerSummaryIntegration { | ||
getNetworkSummaryAsync(): Promise<NetworkControllerSummary>; | ||
} |
19 changes: 19 additions & 0 deletions
19
...ntegrations/src/interfaces/network-controller-summary/network-controller-summary-types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export interface NetworkControllerSummary { | ||
wanStatus: "enabled" | "disabled"; | ||
|
||
wwwStatus: "enabled" | "disabled"; | ||
wwwLatency: number; | ||
wwwPing: number; | ||
wwwUptime: number; | ||
|
||
wifiStatus: "enabled" | "disabled"; | ||
wifiUsers: number; | ||
wifiGuests: number; | ||
|
||
lanStatus: "enabled" | "disabled"; | ||
lanUsers: number; | ||
lanGuests: number; | ||
|
||
vpnStatus: "enabled" | "disabled"; | ||
vpnUsers: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
export * from "./calendar-types"; | ||
export * from "./interfaces/dns-hole-summary/dns-hole-summary-types"; | ||
export * from "./interfaces/network-controller-summary/network-controller-summary-types"; | ||
export * from "./interfaces/health-monitoring/healt-monitoring"; | ||
export * from "./interfaces/indexer-manager/indexer"; | ||
export * from "./interfaces/media-requests/media-request"; | ||
export * from "./base/searchable-integration"; | ||
export * from "./homeassistant/homeassistant-types"; | ||
export * from "./proxmox/proxmox-types"; | ||
export * from "./unifi-controller/unifi-controller-types"; |
22 changes: 22 additions & 0 deletions
22
packages/integrations/src/unifi-controller/error-by-status-code.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { IntegrationTestConnectionError } from "../base/test-connection-error"; | ||
|
||
export const throwByUnifiControllerResponseStatusCode = (statusCode: number) => { | ||
switch (statusCode) { | ||
case 400: | ||
throw new IntegrationTestConnectionError("badRequest"); | ||
case 401: | ||
throw new IntegrationTestConnectionError("unauthorized"); | ||
case 403: | ||
throw new IntegrationTestConnectionError("forbidden"); | ||
case 404: | ||
throw new IntegrationTestConnectionError("notFound"); | ||
case 429: | ||
throw new IntegrationTestConnectionError("tooManyRequests"); | ||
case 500: | ||
throw new IntegrationTestConnectionError("internalServerError"); | ||
case 503: | ||
throw new IntegrationTestConnectionError("serviceUnavailable"); | ||
default: | ||
throw new IntegrationTestConnectionError("commonError"); | ||
} | ||
}; |
Oops, something went wrong.