Skip to main content

add_alertmanager.go

014_add_alertmanager.go - Overview

  1. Overview This file defines a SQL migration to add Alertmanager configurations and states to the database, including handling notification channels and converting MS Teams configurations.

  2. Detailed Documentation

addAlertmanager

  • Purpose: Struct to hold the sqlstore instance for the migration.
  • Parameters: None
  • Returns: None

NewAddAlertmanagerFactory

  • Purpose: Creates a new factory for the addAlertmanager migration.
  • Parameters:
    • store (sqlstore.SQLStore): The SQL store instance.
  • Returns:
    • factory.ProviderFactory[SQLMigration, Config]: A factory that creates addAlertmanager instances.

newAddAlertmanager

  • Purpose: Creates a new addAlertmanager instance.
  • Parameters:
    • _ (context.Context): Context (not used).
    • _ (factory.ProviderSettings): Provider settings (not used).
    • _ (Config): Configuration (not used).
    • store (sqlstore.SQLStore): The SQL store instance.
  • Returns:
    • (SQLMigration, error): A new addAlertmanager instance and an error if any.

addAlertmanager.Register

  • Purpose: Registers the Up and Down migration functions.
  • Parameters:
    • migrations (*migrate.Migrations): The migration registry.
  • Returns:
    • error: An error if registration fails.

addAlertmanager.Up

  • Purpose: Executes the Up migration, which adds tables and columns for Alertmanager configuration and state, and populates initial data.
  • Parameters:
    • ctx (context.Context): The context.
    • db (*bun.DB): The database connection.
  • Returns:
    • error: An error if the migration fails.

addAlertmanager.populateOrgIDInChannels

  • Purpose: Populates the org_id column in the notification_channels table with the provided organization ID.
  • Parameters:
    • ctx (context.Context): The context.
    • tx (bun.Tx): The database transaction.
    • orgID (string): The organization ID.
  • Returns:
    • error: An error if the operation fails.

addAlertmanager.populateAlertmanagerConfig

  • Purpose: Populates the alertmanager_config table with the initial configuration based on existing notification channels and rules.
  • Parameters:
    • ctx (context.Context): The context.
    • tx (bun.Tx): The database transaction.
    • orgID (string): The organization ID.
  • Returns:
    • error: An error if the operation fails.

addAlertmanager.Down

  • Purpose: Executes the Down migration (currently empty).
  • Parameters:
    • ctx (context.Context): The context.
    • db (*bun.DB): The database connection.
  • Returns:
    • error: An error if the migration fails.

addAlertmanager.msTeamsChannelToMSTeamsV2Channel

  • Purpose: Converts a MS Teams notification channel to a MS Teams V2 notification channel.
  • Parameters:
    • c (*alertmanagertypes.Channel): The channel to convert.
  • Returns:
    • error: An error if the conversion fails.

addAlertmanager.msTeamsReceiverToMSTeamsV2Receiver

  • Purpose: Converts MS Teams receiver configuration to MS Teams V2 receiver configuration.
  • Parameters:
    • receiver (alertmanagertypes.Receiver): The receiver to convert.
  • Returns:
    • alertmanagertypes.Receiver: The converted receiver.
  1. Code Examples N/A

  2. Clarity and Accuracy The documentation reflects the code accurately.

  3. Markdown & MDX Perfection The markdown is correctly formatted.

  4. Edge Cases To Avoid Breaking MDX All potential MDX breaking characters have been escaped.

  5. Getting Started Relevance Include in Getting Started: NO