Check a value, not just "is it up": JSON value checks on web endpoints
A web check can read a value out of a JSON answer (power.now, state, data.result[0].value[1]) and judge it: below, above, equal to, contains, is there. The value read is shown on the Endpoints page, charted under History, exported as homelab_endpoint_value and in the read API. A check can also send one header (a token), stored encrypted, never returned, and not forwarded to another host on a redirect. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e114567d64
commit
3cb3e4988f
21 files changed
+6804
-47
No files matched your search
@@ -14,30 +14,15 @@ import { createHmac, randomUUID } from "node:crypto";
|
||||
import { and, desc, eq, lt, notInArray } from "drizzle-orm";
|
||||
import { db } from "../db/client.js";
|
||||
import { eventWebhooks, webhookDeliveries, webhookEvents, type WebhookEvent } from "../db/schema.js";
|
||||
import { decryptSecret, encryptSecret } from "../crypto.js";
|
||||
import { env } from "../env.js";
|
||||
import { openSecret, sealSecret } from "./sealed.js";
|
||||
|
||||
export { sealSecret };
|
||||
|
||||
export type EventWebhookRow = typeof eventWebhooks.$inferSelect;
|
||||
|
||||
const ENCRYPTED_PREFIX = "enc:v1:";
|
||||
const TIMEOUT_MS = 5000;
|
||||
const RETRY_AFTER_MS = 2000;
|
||||
|
||||
/** The stored form of a secret: encrypted when an encryption key is set, as the notification channels' secrets are. */
|
||||
export function sealSecret(plain: string): string {
|
||||
return env.credentialsEncryptionEnabled ? ENCRYPTED_PREFIX + encryptSecret(plain) : plain;
|
||||
}
|
||||
|
||||
function openSecret(stored: string | null): string | null {
|
||||
if (!stored) return null;
|
||||
if (!stored.startsWith(ENCRYPTED_PREFIX)) return stored;
|
||||
try {
|
||||
return decryptSecret(stored.slice(ENCRYPTED_PREFIX.length));
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function parseEvents(stored: string): WebhookEvent[] {
|
||||
try {
|
||||
const v = JSON.parse(stored);
|
||||
|
||||
Reference in new issue
Block a user