Skip to content

Table of Contents

alerting

Alerting Objects

class Alerting()

The class includes all necessary methods to access the Grafana alerting API endpoints

Arguments:

  • grafana_api_model APIModel - Inject a Grafana API model object that includes all necessary values and information

Attributes:

  • grafana_api_model APIModel - This is where we store the grafana_api_model

get_alertmanager_alerts

def get_alertmanager_alerts(datasource_uid: str = "grafana") -> list

The method includes a functionality to get the Alertmanager alerts specified by the datasource_uid

Arguments:

  • datasource_uid str - Specify the datasource uid or recipient of the alerts (default grafana)

Raises:

  • ValueError - Missed specifying a necessary value
  • Exception - Unspecified error by executing the API call

Returns:

  • api_call list - Returns the list of Alertmanager alerts

create_or_update_alertmanager_alerts

def create_or_update_alertmanager_alerts(alerts: list,
                                         datasource_uid: str = "grafana")

The method includes a functionality to create or update the Alertmanager alerts specified by the datasource_uid and the alerts list

Arguments:

  • alerts list - Specify a list of the alert objects
  • datasource_uid str - Specify the datasource uid or recipient of the alerts (default grafana)

Raises:

  • ValueError - Missed specifying a necessary value
  • Exception - Unspecified error by executing the API call

Returns:

None

get_alertmanager_group_alerts

def get_alertmanager_group_alerts(datasource_uid: str = "grafana") -> list

The method includes a functionality to get the Alertmanager group alerts specified by the datasource_uid

Arguments:

  • datasource_uid str - Specify the datasource uid or recipient of the alerts (default grafana)

Raises:

  • ValueError - Missed specifying a necessary value
  • Exception - Unspecified error by executing the API call

Returns:

  • api_call list - Returns the list of Alertmanager group alerts

delete_alertmanager_silence_by_id

def delete_alertmanager_silence_by_id(silence_id: str,
                                      datasource_uid: str = "grafana")

The method includes a functionality to delete the Alertmanager silence specified by the silence id and the datasource_uid

Arguments:

  • silence_id str - Specify the silence id of the alerts
  • datasource_uid str - Specify the datasource uid or recipient of the alerts (default grafana)

Raises:

  • ValueError - Missed specifying a necessary value
  • Exception - Unspecified error by executing the API call

Returns:

None

get_alertmanager_silence_by_id

def get_alertmanager_silence_by_id(silence_id: str,
                                   datasource_uid: str = "grafana") -> dict

The method includes a functionality to get the Alertmanager silence specified by the silence id and the datasource_uid

Arguments:

  • silence_id str - Specify the silence id of the alerts
  • datasource_uid str - Specify the datasource uid or recipient of the alerts (default grafana)

Raises:

  • ValueError - Missed specifying a necessary value
  • Exception - Unspecified error by executing the API call

Returns:

  • api_call dict - Returns the dict of Alertmanager silence alert

get_alertmanager_silences

def get_alertmanager_silences(datasource_uid: str = "grafana") -> list

The method includes a functionality to get all Alertmanager silences specified by the datasource_uid

Arguments:

  • datasource_uid str - Specify the datasource uid or recipient of the alerts (default grafana)

Raises:

  • ValueError - Missed specifying a necessary value
  • Exception - Unspecified error by executing the API call

Returns:

  • api_call list - Returns the list of Alertmanager silence alerts

create_or_update_alertmanager_silence

def create_or_update_alertmanager_silence(silence: Silence,
                                          datasource_uid: str = "grafana"
                                          ) -> dict

The method includes a functionality to create or update the Alertmanager silence specified by the silence object and the datasource_uid

Arguments:

silence -> Specify the silence object - datasource_uid str - Specify the datasource uid or recipient of the alerts (default grafana)

Raises:

  • ValueError - Missed specifying a necessary value
  • Exception - Unspecified error by executing the API call

Returns:

  • api_call dict - Returns the dict of newly created silence alert

get_alertmanager_status

def get_alertmanager_status(datasource_uid: str = "grafana") -> dict

The method includes a functionality to get the Alertmanager status specified by the datasource_uid

Arguments:

  • datasource_uid str - Specify the datasource uid or recipient of the alerts (default grafana)

Raises:

  • ValueError - Missed specifying a necessary value
  • Exception - Unspecified error by executing the API call

Returns:

  • api_call dict - Returns the dict of the Alertmanager status

delete_alertmanager_config

def delete_alertmanager_config(datasource_uid: str = "grafana")

The method includes a functionality to delete the Alertmanager config specified by the datasource_uid

Arguments:

  • datasource_uid str - Specify the datasource uid or recipient of the alerts (default grafana)

Raises:

  • ValueError - Missed specifying a necessary value
  • Exception - Unspecified error by executing the API call

Returns:

None

get_alertmanager_config

def get_alertmanager_config(datasource_uid: str = "grafana") -> dict

The method includes a functionality to get the Alertmanager config specified by the datasource_uid

Arguments:

  • datasource_uid str - Specify the datasource uid or recipient of the alerts (default grafana)

Raises:

  • ValueError - Missed specifying a necessary value
  • Exception - Unspecified error by executing the API call

Returns:

  • api_call dict - Returns the dict of the Alertmanager config

create_or_update_alertmanager_config

def create_or_update_alertmanager_config(
        alertmanager_config: AlertmanagerConfig,
        datasource_uid: str = "grafana",
        template_files: dict = None)

The method includes a functionality to create or update the Alertmanager config specified by the Alertmanager config object, datasource_uid and template_files

Arguments:

  • alertmanager_config AlertmanagerConfig - Specify the Alertmanager config object
  • datasource_uid str - Specify the datasource uid or recipient of the alerts (default grafana)
  • template_files(dict) - Specify the optional template files (default None)

Raises:

  • ValueError - Missed specifying a necessary value
  • Exception - Unspecified error by executing the API call

Returns:

None

test_alertmanager_receivers

def test_alertmanager_receivers(alert: dict,
                                receivers: list,
                                datasource_uid: str = "grafana")

The method includes a functionality to test the Alertmanager receivers specified by the alert dict, receivers object and the datasource_uid

Arguments:

  • alert dict - Specify the alert dict
  • receivers list - Specify the list of AlertmanagerReceivers objects
  • datasource_uid str - Specify the datasource uid or recipient of the alerts (default grafana)

Raises:

  • ValueError - Missed specifying a necessary value
  • Exception - Unspecified error by executing the API call

Returns:

None

get_prometheus_alerts

def get_prometheus_alerts(datasource_uid: str = "grafana") -> dict

The method includes a functionality to get all prometheus alerts specified by the datasource_uid

Arguments:

  • datasource_uid str - Specify the datasource uid or recipient of the alerts (default grafana)

Raises:

  • ValueError - Missed specifying a necessary value
  • Exception - Unspecified error by executing the API call

Returns:

  • api_call dict - Returns the dict of the prometheus alerts

get_prometheus_rules

def get_prometheus_rules(datasource_uid: str = "grafana") -> dict

The method includes a functionality to get all prometheus rules specified by the datasource_uid

Arguments:

  • datasource_uid str - Specify the datasource uid or recipient of the alerts (default grafana)

Raises:

  • ValueError - Missed specifying a necessary value
  • Exception - Unspecified error by executing the API call

Returns:

  • api_call dict - Returns the dict of the prometheus rules

get_ruler_rules

def get_ruler_rules(datasource_uid: str = "grafana") -> dict

The method includes a functionality to get all ruler rules specified by the datasource_uid

Arguments:

  • datasource_uid str - Specify the datasource uid or recipient of the alerts (default grafana)

Raises:

  • ValueError - Missed specifying a necessary value
  • Exception - Unspecified error by executing the API call

Returns:

  • api_call dict - Returns the dict of the ruler rules

delete_ruler_namespace

def delete_ruler_namespace(namespace: str, datasource_uid: str = "grafana")

The method includes a functionality to delete a ruler namespace specified by the namespace name and the datasource_uid

Arguments:

  • namespace str - Specify the namespace name
  • datasource_uid str - Specify the datasource uid or recipient of the alerts (default grafana)

Raises:

  • ValueError - Missed specifying a necessary value
  • Exception - Unspecified error by executing the API call

Returns:

None

get_ruler_groups_by_namespace

def get_ruler_groups_by_namespace(namespace: str,
                                  datasource_uid: str = "grafana") -> dict

The method includes a functionality to get all ruler groups specified by the namespace name and the datasource_uid

Arguments:

  • namespace str - Specify the namespace name
  • datasource_uid str - Specify the datasource uid or recipient of the alerts (default grafana)

Raises:

  • ValueError - Missed specifying a necessary value
  • Exception - Unspecified error by executing the API call

Returns:

  • api_call dict - Returns the dict of the ruler groups

create_or_update_ruler_group_by_namespace

def create_or_update_ruler_group_by_namespace(namespace: str,
                                              group_name: str,
                                              rules: list,
                                              datasource_uid: str = "grafana",
                                              interval: int = 0)

The method includes a functionality to create or update a ruler group specified by the namespace name, a ruler group name, a ruler rule object list, the datasource_uid and an interval

Arguments:

  • namespace str - Specify the namespace name
  • group_name str - Specify the ruler group name
  • rules list - Specify the ruler rule object list
  • datasource_uid str - Specify the datasource uid or recipient of the alerts (default grafana)
  • interval int - Specify the interval of the ruler (default 0)

Raises:

  • ValueError - Missed specifying a necessary value
  • Exception - Unspecified error by executing the API call

Returns:

None

delete_ruler_group

def delete_ruler_group(namespace: str,
                       group_name: str,
                       datasource_uid: str = "grafana")

The method includes a functionality to delete a ruler group specified by the namespace name, a ruler group name and the datasource_uid

Arguments:

  • namespace str - Specify the namespace name
  • group_name str - Specify the ruler group name
  • datasource_uid str - Specify the datasource uid or recipient of the alerts (default grafana)

Raises:

  • ValueError - Missed specifying a necessary value
  • Exception - Unspecified error by executing the API call

Returns:

None

get_ruler_group

def get_ruler_group(namespace: str,
                    group_name: str,
                    datasource_uid: str = "grafana") -> dict

The method includes a functionality to get a ruler group specified by the namespace name, a ruler group name and the datasource_uid

Arguments:

  • namespace str - Specify the namespace name
  • group_name str - Specify the ruler group name
  • datasource_uid str - Specify the datasource uid or recipient of the alerts (default grafana)

Raises:

  • ValueError - Missed specifying a necessary value
  • Exception - Unspecified error by executing the API call

Returns:

  • api_call dict - Returns the dict of all ruler groups

test_rule

def test_rule(data_query: list) -> dict

The method includes a functionality to test a rule specified by a list of datasource rule query objects

Arguments:

  • data_query list - Specify a list of datasource rule query objects

Raises:

  • ValueError - Missed specifying a necessary value
  • Exception - Unspecified error by executing the API call

Returns:

  • api_call str - Returns the result of the specified query

test_datasource_uid_rule

def test_datasource_uid_rule(expr: str,
                             condition: str,
                             data_query: list,
                             datasource_uid: str = "grafana") -> dict

The method includes a functionality to test a datasource uid rule specified by the expr, the condition, a list of data queries and the datasource_uid

Arguments:

  • expr str - Specify a list of datasource rule query objects
  • condition str - Specify the condition
  • data_query list - Specify a list of datasource rule query objects
  • datasource_uid str - Specify the datasource uid or recipient of the alerts (default grafana)

Raises:

  • ValueError - Missed specifying a necessary value
  • Exception - Unspecified error by executing the API call

Returns:

  • api_call dict - Returns the result of the specified datasource_uid rule

test_backtest_rule

def test_backtest_rule(condition: str, data_query: list) -> dict

The method includes a functionality to test a rule specified by the condition, a list of data queries

Arguments:

  • condition str - Specify the condition
  • data_query list - Specify a list of datasource rule query objects

Raises:

  • ValueError - Missed specifying a necessary value
  • Exception - Unspecified error by executing the API call

Returns:

  • api_call dict - Returns the result of the specified rule

delete_ngalert_organization_configuration

def delete_ngalert_organization_configuration()

The method includes a functionality to delete the NGAlert organization admin configuration

Raises:

  • Exception - Unspecified error by executing the API call

Returns:

None

get_ngalert_organization_configuration

def get_ngalert_organization_configuration() -> dict

The method includes a functionality to get the NGAlert organization admin configuration

Raises:

  • Exception - Unspecified error by executing the API call

Returns:

  • api_call dict - Returns the NGAlert organization configuration

create_or_update_ngalert_organization_configuration

def create_or_update_ngalert_organization_configuration(
        alert_managers: list, alertmanagers_choice: str = "all")

The method includes a functionality to create or update the NGAlert organization admin configuration

Arguments:

  • alert_managers list - Specify the list of alert manager names
  • alertmanagers_choice str - Specify the Alertmanagers choice (default all)

Raises:

  • ValueError - Missed specifying a necessary value
  • Exception - Unspecified error by executing the API call

Returns:

None

get_ngalert_alertmanagers_by_organization

def get_ngalert_alertmanagers_by_organization() -> dict

The method includes a functionality to get the discovered and dropped Alertmanagers of the user's organization and based on the specified configuration

Raises:

  • Exception - Unspecified error by executing the API call

Returns:

  • api_call dict - Returns the NGAlert Alertmanagers