/********************************************************************************** * 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 type { Notification } from '@adam3am/monika-notification'; import { type Incident } from '../../../context'; import type { Probe, ProbeAlert } from '../../../interfaces/probe'; import { type ProbeRequestResponse } from '../../../interfaces/request'; import type { ValidatedResponse } from '../../../plugins/validate-response'; export type ProbeResult = { isAlertTriggered: boolean; logMessage: string; requestResponse: ProbeRequestResponse; }; export declare enum NotificationType { Incident = "NOTIFY-INCIDENT", Recover = "NOTIFY-RECOVER" } type SendNotificationParams = { requestURL: string; notificationType: NotificationType; validation: ValidatedResponse; alertId: string; }; export interface Prober { probe: (incidentRetryAttempt: number) => Promise; generateVerboseStartupMessage: () => string; } export type ProberMetadata = { counter: number; notifications: Notification[]; probeConfig: Probe; }; export declare class BaseProber implements Prober { protected readonly counter: number; protected readonly notifications: Notification[]; protected readonly probeConfig: Probe; constructor({ counter, notifications, probeConfig }: ProberMetadata); probe(incidentRetryAttempt: number): Promise; generateVerboseStartupMessage(): string; protected processProbeResults(probeResults: ProbeResult[], incidentRetryAttempt: number): void; protected getFailedRequestAssertion(requestIndex?: number): ProbeAlert | undefined; protected hasIncident(): Incident | undefined; /** * If the probe is healthy and previously not (so it's a recovery), this function will call the function to send recovery notification only when the retry attempts equals to the recovery threshold - 1. * Otherwise, it will throw and return the execution to the retry function in src/components/probe/index.ts. * If the probe is healthy just like before, nothing to do in this function. * @param incidentRetryAttempt The number of retry attempts * @param probeResults The probe results * @returns void */ protected sendRecoveryNotificationIfNeeded(incidentRetryAttempt: number, probeResults: Pick[]): void; /** * If the number of attempts is equal to the incidentThreshold - 1, this function will throw which will return execution to the retry function in src/components/probe/index.ts. * Otherwise, it will not do anything. * @param incidentRetryAttempt How many times have monika retry probing * @param incidentThreshold The incident threshold of the probe * @param message Message to display to stdout * @throws * @returns void */ protected throwIncidentIfNeeded(incidentRetryAttempt: number, incidentThreshold?: number, message?: string): void; protected sendNotification({ requestURL, notificationType, validation, alertId, }: SendNotificationParams): Promise; protected handleFailedProbe(probeResults: Pick[]): void; protected handleRecovery(probeResults: Pick[]): void; protected logMessage(isSuccess: boolean, ...message: string[]): void; private initializeProbeState; private getAlerts; private getRequestByAlertId; private hasNotification; private getMessagePrefix; } export {};