|
3 | 3 | # Copyright 2019-Present Datadog, Inc. |
4 | 4 | from __future__ import annotations |
5 | 5 |
|
| 6 | +import collections |
6 | 7 | from typing import Any, Dict, List, Union |
7 | 8 |
|
8 | 9 | from datadog_api_client.api_client import ApiClient, Endpoint as _Endpoint |
9 | 10 | from datadog_api_client.configuration import Configuration |
10 | 11 | from datadog_api_client.model_utils import ( |
| 12 | + set_attribute_from_path, |
| 13 | + get_attribute_from_path, |
11 | 14 | UnsetType, |
12 | 15 | unset, |
13 | 16 | ) |
@@ -693,6 +696,81 @@ def list_monitors( |
693 | 696 |
|
694 | 697 | return self._list_monitors_endpoint.call_with_http_info(**kwargs) |
695 | 698 |
|
| 699 | + def list_monitors_with_pagination( |
| 700 | + self, |
| 701 | + *, |
| 702 | + group_states: Union[str, UnsetType] = unset, |
| 703 | + name: Union[str, UnsetType] = unset, |
| 704 | + tags: Union[str, UnsetType] = unset, |
| 705 | + monitor_tags: Union[str, UnsetType] = unset, |
| 706 | + with_downtimes: Union[bool, UnsetType] = unset, |
| 707 | + id_offset: Union[int, UnsetType] = unset, |
| 708 | + page: Union[int, UnsetType] = unset, |
| 709 | + page_size: Union[int, UnsetType] = unset, |
| 710 | + ) -> collections.abc.Iterable[Monitor]: |
| 711 | + """Get all monitor details. |
| 712 | +
|
| 713 | + Provide a paginated version of :meth:`list_monitors`, returning all items. |
| 714 | +
|
| 715 | + :param group_states: When specified, shows additional information about the group states. |
| 716 | + Choose one or more from ``all`` , ``alert`` , ``warn`` , and ``no data``. |
| 717 | + :type group_states: str, optional |
| 718 | + :param name: A string to filter monitors by name. |
| 719 | + :type name: str, optional |
| 720 | + :param tags: A comma separated list indicating what tags, if any, should be used to filter the list of monitors by scope. |
| 721 | + For example, ``host:host0``. |
| 722 | + :type tags: str, optional |
| 723 | + :param monitor_tags: A comma separated list indicating what service and/or custom tags, if any, should be used to filter the list of monitors. |
| 724 | + Tags created in the Datadog UI automatically have the service key prepended. For example, ``service:my-app``. |
| 725 | + :type monitor_tags: str, optional |
| 726 | + :param with_downtimes: If this argument is set to true, then the returned data includes all current active downtimes for each monitor. |
| 727 | + :type with_downtimes: bool, optional |
| 728 | + :param id_offset: Use this parameter for paginating through large sets of monitors. Start with a value of zero, make a request, set the value to the last ID of result set, and then repeat until the response is empty. |
| 729 | + :type id_offset: int, optional |
| 730 | + :param page: The page to start paginating from. If this argument is not specified, the request returns all monitors without pagination. |
| 731 | + :type page: int, optional |
| 732 | + :param page_size: The number of monitors to return per page. If the page argument is not specified, the default behavior returns all monitors without a ``page_size`` limit. However, if page is specified and ``page_size`` is not, the argument defaults to 100. |
| 733 | + :type page_size: int, optional |
| 734 | +
|
| 735 | + :return: A generator of paginated results. |
| 736 | + :rtype: collections.abc.Iterable[Monitor] |
| 737 | + """ |
| 738 | + kwargs: Dict[str, Any] = {} |
| 739 | + if group_states is not unset: |
| 740 | + kwargs["group_states"] = group_states |
| 741 | + |
| 742 | + if name is not unset: |
| 743 | + kwargs["name"] = name |
| 744 | + |
| 745 | + if tags is not unset: |
| 746 | + kwargs["tags"] = tags |
| 747 | + |
| 748 | + if monitor_tags is not unset: |
| 749 | + kwargs["monitor_tags"] = monitor_tags |
| 750 | + |
| 751 | + if with_downtimes is not unset: |
| 752 | + kwargs["with_downtimes"] = with_downtimes |
| 753 | + |
| 754 | + if id_offset is not unset: |
| 755 | + kwargs["id_offset"] = id_offset |
| 756 | + |
| 757 | + if page is not unset: |
| 758 | + kwargs["page"] = page |
| 759 | + |
| 760 | + if page_size is not unset: |
| 761 | + kwargs["page_size"] = page_size |
| 762 | + |
| 763 | + local_page_size = get_attribute_from_path(kwargs, "page_size", 100) |
| 764 | + endpoint = self._list_monitors_endpoint |
| 765 | + set_attribute_from_path(kwargs, "page_size", local_page_size, endpoint.params_map) |
| 766 | + pagination = { |
| 767 | + "limit_value": local_page_size, |
| 768 | + "page_param": "page", |
| 769 | + "endpoint": endpoint, |
| 770 | + "kwargs": kwargs, |
| 771 | + } |
| 772 | + return endpoint.call_with_http_info_paginated(pagination) |
| 773 | + |
696 | 774 | def search_monitor_groups( |
697 | 775 | self, |
698 | 776 | *, |
|
0 commit comments