import { apiCall } from './util' import { getUnixTime, sub } from 'date-fns'; export interface Recursor { ipAddress: string timeoutMs: number weight: number } export const getRecursors = async () => await apiCall('recursors') export class LogPayload { pageSize: number = 0; pageCount: number = 0; page: number = 0; total: number = 0; logs: Log[] = []; } export interface Log { Started: string Domain: string ClientIP: string Status: string Protocol: string Error: string RecurseUpstreamIP: string RecurseRoundTripTimeMs: number TotalTimeMs: number }; export interface LogSearchOptions { start: Date end: Date page: number pageSize: number filter: string } export const getLogs = async({ start = sub(new Date(), { hours: 24 }), end = new Date(), page = 0, pageSize = 25, filter = "" }: LogSearchOptions) => await apiCall('metrics/log', 'GET', { filter, page, start: getUnixTime(start || sub(new Date(), { hours: 24 })), end: getUnixTime(end || new Date()), pageSize }); export interface StatsSearchOptions { start: Date end: Date key: StatSearchKey interval: number } export enum StatSearchKey { Domain = "domain", ClientIp = "clientIp", Status = "status", Protocol = "protocol" } export interface StatDataset { label: string data: DataPoint[] } export interface DataPoint { Header: string Value: Number Count: number, Time: string } export interface Stat { labels: string[] datasets: StatDataset[] }; export const getStats = async ({ start = sub(new Date(), { hours: 24 }), end = new Date(), key = StatSearchKey.Domain, interval = 30, }: StatsSearchOptions) => await apiCall('metrics/stats', 'GET', { start: getUnixTime(start || sub(new Date(), { hours: 24 })), end: getUnixTime(end || new Date()), key, interval }); export interface RuleAnswer { type: string value: string } export interface Rule { id: number weight: number enabled: boolean created: string name: string value: string answer: RuleAnswer ttl: number } export const getRules = () => apiCall('rules');