/********************************************************************************** * MIT License * * * * Copyright (c) 2021 Hyperjump Technology * * * * Permission is hereby granted, free of charge, to any person obtaining a copy * * of this software and associated documentation files (the "Software"), to deal * * in the Software without restriction, including without limitation the rights * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * * copies of the Software, and to permit persons to whom the Software is * * furnished to do so, subject to the following conditions: * * * * The above copyright notice and this permission notice shall be included in all * * copies or substantial portions of the Software. * * * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * * SOFTWARE. * **********************************************************************************/ /// import SQLite3 from 'sqlite3'; import { Database, ISqlite } from 'sqlite'; import { ProbeRequestResponse } from '../../interfaces/request'; import { Probe } from '../../interfaces/probe'; import type { Notification } from '@adam3am/monika-notification'; type RequestsLog = { id: number; probeId: string; responseStatus: number; requestUrl: string; responseTime: number; }; export type UnreportedRequestsLog = { id: number; timestamp: number; probeId: string; responseStatus: number; responseTime: number; alerts: string[]; }; export type UnreportedNotificationsLog = { id: number; timestamp: number; probeId: string; probeName: string; alertType: string; type: string; notificationId: string; channel: string; }; export type UnreportedLog = { requests: UnreportedRequestsLog[]; notifications: UnreportedNotificationsLog[]; }; export type ProbeIdDate = { id: string; createdAt: number; }; export type ProbeReqIdDate = { id: number; createdAt: number; }; export type DeleteProbeRes = { probeIds: ProbeIdDate[]; probeRequestIds: ProbeReqIdDate[]; }; type Summary = { numberOfProbes: number; numberOfIncidents: number; numberOfRecoveries: number; numberOfSentNotifications: number; }; export declare function database(): Database; export declare function setDatabase(database: Database): void; /** * openLogfile will open the file history.db and if it doesn't exist, create it and sets up the table * @returns Promise */ export declare function openLogfile(): Promise; export declare function deleteFromProbeRequests(limit: number): Promise; export declare function deleteFromAlerts(probeReqIds: ProbeReqIdDate[]): Promise; export declare function deleteFromNotifications(probeIds: ProbeIdDate[]): Promise; /** * getAllLogs gets all the history table from sqlite db * @returns {obj} result of logs table */ export declare function getAllLogs(): Promise; export declare function getUnreportedLogsCount(): Promise; export declare function getUnreportedLogs(ids: string[], limit: number, database?: Database): Promise; export declare function deleteRequestLogs(ids: string[], database?: Database): Promise; export declare function deleteNotificationLogs(ids: string[], database?: Database): Promise; /** * flushAllLogs drops the table and recreates it * @returns Promise */ export declare function flushAllLogs(): Promise; /** * saveProbeRequestLog inserts probe request log information into the database * * @param {object} data is the log data containing information about probe request * @returns Promise */ export declare function saveProbeRequestLog({ probe, requestIndex, probeRes, alertQueries, error: errorResp, }: { probe: Probe; requestIndex: number; probeRes: ProbeRequestResponse; alertQueries?: string[]; error?: string; }): Promise; /** * saveNotificationLog inserts probe request log information into the database * * @param {object} probe is the probe config * @param {object} notification is the notification config * @param {string} type is the type of notification 'NOTIFY-INCIDENT' | 'NOTIFY-RECOVER' * @param {string} alertQuery the alerts triggered * @returns Promise */ export declare function saveNotificationLog(probe: Probe, notification: Notification, type: 'NOTIFY-INCIDENT' | 'NOTIFY-RECOVER' | 'NOTIFY-TLS', alertQuery: string): Promise; export declare function getSummary(): Promise; /** * closeLog closes the database * @returns Promise */ export declare function closeLog(): Promise; export {};