mirror of
https://github.com/matrix-org/matrix-hookshot.git
synced 2025-03-10 21:19:13 +00:00
Add alert manager
This commit is contained in:
parent
e9613225be
commit
29e52a7b23
@ -9,7 +9,7 @@ import { GetIssueResponse, GetIssueOpts } from "./Gitlab/Types"
|
||||
import { GithubInstance } from "./Github/GithubInstance";
|
||||
import { IBridgeStorageProvider } from "./Stores/StorageProvider";
|
||||
import { IConnection, GitHubDiscussionSpace, GitHubDiscussionConnection, GitHubUserSpace, JiraProjectConnection, GitLabRepoConnection,
|
||||
GitHubIssueConnection, GitHubProjectConnection, GitHubRepoConnection, GitLabIssueConnection, FigmaFileConnection, FeedConnection, GenericHookConnection } from "./Connections";
|
||||
GitHubIssueConnection, GitHubProjectConnection, GitHubRepoConnection, GitLabIssueConnection, FigmaFileConnection, FeedConnection, GenericHookConnection, AlertmanagerConnection } from "./Connections";
|
||||
import { IGitLabWebhookIssueStateEvent, IGitLabWebhookMREvent, IGitLabWebhookNoteEvent, IGitLabWebhookPushEvent, IGitLabWebhookReleaseEvent, IGitLabWebhookTagPushEvent, IGitLabWebhookWikiPageEvent } from "./Gitlab/WebhookTypes";
|
||||
import { JiraIssueEvent, JiraIssueUpdatedEvent } from "./Jira/WebhookTypes";
|
||||
import { JiraOAuthResult } from "./Jira/Types";
|
||||
@ -41,6 +41,7 @@ import { JiraOAuthRequestCloud, JiraOAuthRequestOnPrem, JiraOAuthRequestResult }
|
||||
import { GenericWebhookEvent, GenericWebhookEventResult } from "./generic/types";
|
||||
import { SetupWidget } from "./Widgets/SetupWidget";
|
||||
import { FeedEntry, FeedError, FeedReader } from "./feeds/FeedReader";
|
||||
import { IAlertmanagerEvent } from "./alertmanager/types";
|
||||
const log = new LogWrapper("Bridge");
|
||||
|
||||
export class Bridge {
|
||||
@ -619,6 +620,12 @@ export class Bridge {
|
||||
(c, data) => c.handleFeedError(data),
|
||||
);
|
||||
|
||||
this.bindHandlerToQueue<IAlertmanagerEvent, AlertmanagerConnection>(
|
||||
"alertmanager.event",
|
||||
(data) => connManager.getConnectionsForAlertmanager(data.room_id),
|
||||
(c, data) => c.onAmEvent(data),
|
||||
);
|
||||
|
||||
// Set the name and avatar of the bot
|
||||
if (this.config.bot) {
|
||||
// Ensure we are registered before we set a profile
|
||||
|
@ -466,6 +466,9 @@ export class BridgeConfig {
|
||||
@configKey("Prometheus metrics support", true)
|
||||
public readonly metrics?: BridgeConfigMetrics;
|
||||
|
||||
@configKey("Configure this to enable support for alert manager", true)
|
||||
public readonly alertmanager?: BridgeConfigAlertmanager;
|
||||
|
||||
@configKey(`HTTP Listener configuration.
|
||||
Bind resource endpoints to ports and addresses.
|
||||
'port' must be specified. Each listener must listen on a unique port.
|
||||
|
@ -7,7 +7,7 @@
|
||||
import { Appservice, StateEvent } from "matrix-bot-sdk";
|
||||
import { CommentProcessor } from "./CommentProcessor";
|
||||
import { BridgeConfig, BridgePermissionLevel, GitLabInstance } from "./Config/Config";
|
||||
import { ConnectionDeclarations, GenericHookConnection, GitHubDiscussionConnection, GitHubDiscussionSpace, GitHubIssueConnection, GitHubProjectConnection, GitHubRepoConnection, GitHubUserSpace, GitLabIssueConnection, GitLabRepoConnection, IConnection, JiraProjectConnection } from "./Connections";
|
||||
import { ConnectionDeclarations, GenericHookConnection, GitHubDiscussionConnection, GitHubDiscussionSpace, GitHubIssueConnection, GitHubProjectConnection, GitHubRepoConnection, GitHubUserSpace, GitLabIssueConnection, GitLabRepoConnection, IConnection, JiraProjectConnection, AlertmanagerConnection } from "./Connections";
|
||||
import { GithubInstance } from "./Github/GithubInstance";
|
||||
import { GitLabClient } from "./Gitlab/Client";
|
||||
import { JiraProject } from "./Jira/Types";
|
||||
@ -220,6 +220,10 @@ export class ConnectionManager extends EventEmitter {
|
||||
return this.connections.filter((c) => (c instanceof GenericHookConnection && c.hookId === hookId)) as GenericHookConnection[];
|
||||
}
|
||||
|
||||
public getConnectionsForAlertmanager(roomId: string): AlertmanagerConnection[] {
|
||||
return this.connections.filter((c) => (c instanceof AlertmanagerConnection && c.roomId === roomId)) as AlertmanagerConnection[];
|
||||
}
|
||||
|
||||
public getForFigmaFile(fileKey: string, instanceName: string): FigmaFileConnection[] {
|
||||
return this.connections.filter((c) => (c instanceof FigmaFileConnection && (c.fileId === fileKey || c.instanceName === instanceName))) as FigmaFileConnection[];
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import { MessageSenderClient } from "../MatrixSender";
|
||||
import { IBridgeStorageProvider } from "../Stores/StorageProvider";
|
||||
import { GithubInstance } from "../Github/GithubInstance";
|
||||
import "reflect-metadata";
|
||||
import { ApiError, ErrCode } from "../api";
|
||||
|
||||
export type PermissionCheckFn = (service: string, level: BridgePermissionLevel) => boolean;
|
||||
|
||||
@ -17,6 +18,27 @@ export interface IConnectionState {
|
||||
commandPrefix?: string;
|
||||
}
|
||||
|
||||
export function validateConnectionState(state: unknown): IConnectionState {
|
||||
const {commandPrefix, priority} = state as Partial<IConnectionState>;
|
||||
if (commandPrefix) {
|
||||
if (typeof commandPrefix !== "string") {
|
||||
throw new ApiError("Expected 'commandPrefix' to be a string", ErrCode.BadValue);
|
||||
}
|
||||
if (commandPrefix.length < 2 || commandPrefix.length > 24) {
|
||||
throw new ApiError("Expected 'commandPrefix' to be between 2-24 characters", ErrCode.BadValue);
|
||||
}
|
||||
}
|
||||
if (priority !== undefined) {
|
||||
if (typeof priority !== "number") {
|
||||
throw new ApiError("Expected 'number' to be a string", ErrCode.BadValue);
|
||||
}
|
||||
if (Number.isSafeInteger(priority)) {
|
||||
throw new ApiError("Expected 'number' to be a safe integer", ErrCode.BadValue);
|
||||
}
|
||||
}
|
||||
return {commandPrefix, priority};
|
||||
}
|
||||
|
||||
export interface IConnection {
|
||||
/**
|
||||
* The roomId that this connection serves.
|
||||
|
@ -11,3 +11,4 @@ export * from "./IConnection";
|
||||
export * from "./JiraProject";
|
||||
export * from "./FigmaFileConnection";
|
||||
export * from "./FeedConnection";
|
||||
export * from "./AlertmanagerConnection";
|
Loading…
x
Reference in New Issue
Block a user