Exemple #1
0
 def list(
     self,
     entity_selector: str,
     time_from: Optional[Union[datetime, str]] = None,
     time_to: Optional[Union[datetime, str]] = None,
     fields: Optional[str] = None,
     sort: Optional[str] = None,
     page_size: Optional[int] = None,
 ) -> PaginatedList["Entity"]:
     """
     :return: A list of monitored entities along with their properties.
     """
     params = {
         "pageSize": page_size,
         "entitySelector": entity_selector,
         "from": timestamp_to_string(time_from),
         "to": timestamp_to_string(time_to),
         "fields": fields,
         "sort": sort,
     }
     return PaginatedList(Entity,
                          self.__http_client,
                          "/api/v2/entities",
                          target_params=params,
                          list_item="entities")
Exemple #2
0
 def instances(self) -> PaginatedList[ExtensionShortRepresentation]:
     return PaginatedList(
         ExtensionShortRepresentation,
         self._http_client,
         f"/api/config/v1/extensions/{self.id}/instances",
         list_item="configurationsList",
     )
Exemple #3
0
 def list_activegate_extension_modules(self) -> PaginatedList[EntityShortRepresentation]:
     return PaginatedList(
         EntityShortRepresentation,
         self.__http_client,
         f"/api/config/v1/extensions/activeGateExtensionModules",
         list_item="values",
     )
 def list(
     self,
     time_from: Optional[Union[datetime, str]] = None,
     time_to: Optional[Union[datetime, str]] = None,
     start_version_compare_type: Optional[Union[str,
                                                VersionCompareType]] = None,
     start_version: Optional[str] = None,
     update_type: Optional[Union[str, UpdateType]] = None,
     target_version_compare_type: Optional[Union[
         str, VersionCompareType]] = None,
     target_version: Optional[str] = None,
 ) -> PaginatedList["UpdateJobList"]:
     params = {
         "from": timestamp_to_string(time_from),
         "to": timestamp_to_string(time_to),
         "startVersionCompareType": start_version_compare_type,
         "startVersion": start_version,
         "updateType": update_type,
         "targetVersionCompareType": target_version_compare_type,
         "targetVersion": target_version,
     }
     return PaginatedList(UpdateJobList,
                          self.__http_client,
                          f"/api/v2/activeGates/updateJobs",
                          list_item="allUpdateJobs",
                          target_params=params)
Exemple #5
0
 def list_states(self, extension_id: str) -> PaginatedList["ExtensionState"]:
     return PaginatedList(
         ExtensionState,
         self.__http_client,
         f"/api/config/v1/extensions/{extension_id}/states",
         list_item="states",
     )
Exemple #6
0
 def get_plugins(self) -> PaginatedList[PluginShortRepresentation]:
     """
     List all uploaded plugins
     """
     return PaginatedList(PluginShortRepresentation,
                          self.__http_client,
                          "/api/config/v1/plugins",
                          list_item="values")
 def list(self) -> PaginatedList[NotificationConfigStub]:
     """
     Lists all alerting profiles in the environmemt. No configurable parameters.
     """
     return PaginatedList(NotificationConfigStub,
                          self.__http_client,
                          f"/api/config/v1/notifications",
                          list_item="values")
Exemple #8
0
 def list(self) -> PaginatedList["MaintenanceWindowStub"]:
     """
     Lists all maintenance windows in the environment. No configurable parameters.
     """
     return PaginatedList(MaintenanceWindowStub,
                          self.__http_client,
                          f"/api/config/v1/maintenanceWindows",
                          list_item="values")
Exemple #9
0
 def endpoints(self) -> PaginatedList[EndpointShortRepresentation]:
     return PaginatedList(
         EndpointShortRepresentation,
         self._http_client,
         f"/api/config/v1/plugins/{self.id}/endpoints",
         None,
         list_item="values",
     )
Exemple #10
0
 def get_plugin_states(self, plugin_id) -> PaginatedList[PluginState]:
     """
     List the states of the specified plugin
     """
     return PaginatedList(PluginState,
                          self.__http_client,
                          f"/api/config/v1/plugins/{plugin_id}/states",
                          list_item="states")
Exemple #11
0
 def list_instances(self, extension_id: str, page_size: int = 200) -> PaginatedList["ExtensionShortRepresentation"]:
     params = {"pageSize": page_size}
     return PaginatedList(
         ExtensionShortRepresentation,
         self.__http_client,
         f"/api/config/v1/extensions/{extension_id}/instances",
         list_item="configurationsList",
         target_params=params,
     )
Exemple #12
0
    def list(self, page_size: int = 200) -> PaginatedList["ExtensionDto"]:
        """
        List all uploaded extensions

        :param page_size: The number of results per result page. Must be between 1 and 500
            Default value : 200
        """
        params = {"pageSize": page_size}
        return PaginatedList(ExtensionDto, self.__http_client, f"/api/config/v1/extensions", params, list_item="extensions")
Exemple #13
0
    def get_activegates(
        self,
        hostname: str = None,
        os_type: str = None,
        network_address: str = None,
        activegate_type: str = None,
        network_zone: str = None,
        update_status: str = None,
        version_compare_type: str = None,
        version: str = None,
    ) -> PaginatedList[ActiveGate]:
        """
        Lists all available ActiveGates

        :param hostname: Filters the resulting set of ActiveGates by the name of the host it's running on.
            You can specify a partial name. In that case, the CONTAINS operator is used.

        :param os_type: Filters the resulting set of ActiveGates by the OS type of the host it's running on.
            Available values : LINUX, WINDOWS

        :param network_address: Filters the resulting set of ActiveGates by the network address.
            You can specify a partial address. In that case, the CONTAINS operator is used.

        :param activegate_type: Filters the resulting set of ActiveGates by the ActiveGate type.
            Available values : ENVIRONMENT, ENVIRONMENT_MULTI

        :param network_zone: Filters the resulting set of ActiveGates by the network zone.
            You can specify a partial name. In that case, the CONTAINS operator is used.

        :param update_status: Filters the resulting set of ActiveGates by the auto-update status.
            Available values : INCOMPATIBLE, OUTDATED, SUPPRESSED, UNKNOWN, UP2DATE, UPDATE_IN_PROGRESS, UPDATE_PENDING, UPDATE_PROBLEM

        :param version_compare_type: Filters the resulting set of ActiveGates by the specified version.
            Specify the comparison operator here.
            Available values : EQUAL, GREATER, GREATER_EQUAL, LOWER, LOWER_EQUAL
            Default value : EQUAL

        :param version: Filters the resulting set of ActiveGates by the specified version.
            Specify the version in <major>.<minor>.<revision> format (for example, 1.195.0) here.

        :return: A list of ActiveGates.
        """
        params = {
            "hostname": hostname,
            "osType": os_type,
            "networkAddress": network_address,
            "ActivegateType": activegate_type,
            "networkZone": network_zone,
            "updateStatus": update_status,
            "versionCompareType": version_compare_type,
            "version": version,
        }
        return PaginatedList(ActiveGate,
                             self.__http_client,
                             "/api/v2/activeGates",
                             params,
                             list_item="activeGates")
Exemple #14
0
 def get_endpoints(
         self,
         plugin_id: str) -> PaginatedList[EndpointShortRepresentation]:
     """
     Lists endpoints of the specified ActiveGate plugin
     """
     return PaginatedList(EndpointShortRepresentation,
                          self.__http_client,
                          f"/api/config/v1/plugins/{plugin_id}/endpoints",
                          list_item="values")
Exemple #15
0
 def instances(self, page_size: int = 200) -> PaginatedList["ExtensionShortRepresentation"]:
     """
     Returns the list of instances for this extension
     :param page_size: Page size, default 200
     """
     params = {"pageSize": page_size}
     return PaginatedList(
         ExtensionShortRepresentation,
         self._http_client,
         f"/api/config/v1/extensions/{self.id}/instances",
         list_item="configurationsList",
         target_params=params,
     )
 def list(
     self,
     monitor_type: Optional[Union[MonitorType, str]] = None
 ) -> PaginatedList[MonitorCollectionElement]:
     """
     Lists all synthetic monitors in the environment.
     """
     params = {
         "type": MonitorType(monitor_type).value if monitor_type else None
     }
     return PaginatedList(MonitorCollectionElement,
                          self.__http_client,
                          f"/api/v1/synthetic/monitors",
                          target_params=params,
                          list_item="monitors")
Exemple #17
0
    def get_entity_types(self, page_size=50) -> PaginatedList[EntityType]:
        """
        Gets a list of properties for all entity types

        :param page_size: The desired amount of entities in a single response payload.
            The maximal allowed page size is 500.
            If not set, 50 is used.
        :return: A list of properties of all available entity types.
        """
        params = {"pageSize": page_size}
        return PaginatedList(EntityType,
                             self.__http_client,
                             "/api/v2/entityTypes",
                             params,
                             list_item="types")
Exemple #18
0
 def get_dashboards(self,
                    owner: str = None,
                    tags: List[str] = None) -> PaginatedList[DashboardStub]:
     """
     Lists all dashboards of the environment
     :param owner: The owner of the dashboard.
     :param tags: A list of tags applied to the dashboard.
         The dashboard must match all the specified tags.
     """
     params = {"owner": owner, "tags": tags}
     return PaginatedList(DashboardStub,
                          self.__http_client,
                          f"/api/config/v1/dashboards",
                          params,
                          list_item="dashboards")
Exemple #19
0
    def list(
        self,
        api_token_selector: Optional[str] = None,
        fields: Optional[str] = None,
        time_from: Optional[Union[str, datetime]] = None,
        time_to: Optional[Union[str, datetime]] = None,
        sort: Optional[str] = None,
    ) -> PaginatedList["ApiToken"]:

        params = {
            "apiTokenSelector": api_token_selector,
            "fields": fields,
            "from": timestamp_to_string(time_from),
            "to": timestamp_to_string(time_to),
            "sort": sort,
        }

        return PaginatedList(ApiToken, self.__http_client, "/api/v2/apiTokens", params, list_item="apiTokens")
Exemple #20
0
 def list(
     self,
     log_filter: Optional[str] = None,
     time_from: Optional[Union[datetime, str]] = None,
     time_to: Optional[Union[datetime, str]] = None,
     sort: Optional[str] = None,
 ) -> PaginatedList["AuditLogEntry"]:
     params = {
         "filter": log_filter,
         "from": timestamp_to_string(time_from),
         "to": timestamp_to_string(time_to),
         "sort": sort
     }
     return PaginatedList(target_class=AuditLogEntry,
                          http_client=self.__http_client,
                          target_url="/api/v2/auditlogs",
                          target_params=params,
                          list_item="auditLogs")
Exemple #21
0
    def query(
        self,
        metric_selector: str,
        resolution: str = None,
        time_from: Optional[Union[datetime, str]] = None,
        time_to: Optional[Union[datetime, str]] = None,
        entity_selector: Optional[str] = None,
    ) -> PaginatedList["MetricSeriesCollection"]:

        params = {
            "metricSelector": metric_selector,
            "resolution": resolution,
            "from": timestamp_to_string(time_from),
            "to": timestamp_to_string(time_to),
            "entitySelector": entity_selector,
        }
        return PaginatedList(MetricSeriesCollection,
                             self.__http_client,
                             "/api/v2/metrics/query",
                             params,
                             list_item="result")
Exemple #22
0
 def list(
     self,
     hostname: Optional[str] = None,
     os_type: Optional[Union[OsType, str]] = None,
     network_address: Optional[str] = None,
     activegate_type: Optional[Union[ActivegateType, str]] = None,
     network_zone: Optional[str] = None,
     update_status: Optional[Union[UpdateStatus, str]] = None,
     version_compare_type: Optional[Union[VersionCompareType, str]] = None,
     version: Optional[str] = None,
     auto_update: Optional[Union[AutoUpdate, str]] = None,
     group: Optional[str] = None,
     online: Optional[bool] = None,
     enabled_modules: Optional[List[Union[Module, str]]] = None,
     disabled_modules: Optional[List[Union[Module, str]]] = None,
 ) -> PaginatedList["ActiveGate"]:
     """
     Lists all available ActiveGates
     :return: A list of ActiveGates.
     """
     params = {
         "hostname": hostname,
         "osType": os_type,
         "networkAddress": network_address,
         "ActivegateType": activegate_type,
         "networkZone": network_zone,
         "updateStatus": update_status,
         "versionCompareType": version_compare_type,
         "version": version,
         "autoUpdate": auto_update,
         "group": group,
         "online": online,
         "enabledModule": enabled_modules,
         "disabledModule": disabled_modules,
     }
     return PaginatedList(ActiveGate,
                          self.__http_client,
                          "/api/v2/activeGates",
                          params,
                          list_item="activeGates")
Exemple #23
0
 def list(
     self,
     metric_selector: Optional[str] = None,
     text: Optional[str] = None,
     fields: Optional[str] = None,
     written_since: Optional[Union[str, datetime]] = None,
     metadata_selector: Optional[str] = None,
     page_size=100,
 ) -> PaginatedList["MetricDescriptor"]:
     params = {
         "pageSize": page_size,
         "metricSelector": metric_selector,
         "text": text,
         "fields": fields,
         "writtenSince": timestamp_to_string(written_since),
         "metadataSelector": metadata_selector,
     }
     return PaginatedList(MetricDescriptor,
                          self.__http_client,
                          "/api/v2/metrics",
                          params,
                          list_item="metrics")
Exemple #24
0
 def states(self) -> PaginatedList[PluginState]:
     return PaginatedList(PluginState,
                          self._http_client,
                          f"/api/config/v1/plugins/{self.id}/states",
                          None,
                          list_item="states")
Exemple #25
0
 def list(self) -> PaginatedList[MetricEventShortRepresentation]:
     """
     Lists all metric events in the environment. No configurable parameters.
     """
     return PaginatedList(MetricEventShortRepresentation, self.__http_client, f"/api/config/v1/anomalyDetection/metricEvents", list_item="values")
Exemple #26
0
    def get_entities(
        self,
        entity_selector: str,
        time_from: str = "now-2h",
        time_to: str = "now",
        fields: Optional[str] = None,
        page_size=50,
        threads=20,
    ) -> PaginatedList[Entity]:
        """
        Lists entities observed within the specified timeframe along with their properties.

        :param entity_selector: Defines the scope of the query. Only entities matching the specified criteria are included into response.

            You need to set one of these criteria:

            Entity type: type("value").
            Dynatrace entity ID: entityId("id"). You can specify several IDs, separated by a comma (entityId("id-1","id-2")).

            And you can add one or several of the following criteria:

            Tag: tag("value"). Tags in [context]key:value, key:value, and value formats are detected and parsed automatically.
            If a value-only tag has a colon (:) in it, you must escape the colon with a backslash \\.
            Otherwise, the tag will be parsed as a key:value tag. All tag values are case-sensitive.
            Management zone ID: mzId("ID")
            Management zone name: mzName("value"). Management zone names are case-sensitive.
            Dynatrace entity name: entityName("value"). You can specify several entity names, separated by a comma (entityName("name-1","name-2")).
            Entity names are case-sensitive.
            Health state (HEALTHY,UNHEALTHY): healthState("HEALTHY")

            Further information can be found at https://www.dynatrace.com/support/help/dynatrace-api/environment-api/entity-v2/.
            To set several criteria, separate them with a comma (,). For example, type("HOST"),healthState("HEALTHY").
            Only results matching all criteria are included in response.

            The length of the string is limited to 10,000 characters.

            The field is required when you're querying the first page of results.

        :param time_from: The start of the requested timeframe.

            You can use one of the following formats:

            Timestamp in UTC milliseconds.
            Human-readable format of 2019-12-21T05:57:01.123+01:00. If no time zone is specified, UTC is used. You can use a space character instead of the T. Seconds and fractions of a second are optional.
            Relative timeframe, back from now. The format is now-NU/A, where N is the amount of time, U is the unit of time, and A is an alignment. For example, now-1y/w is one year back, aligned by a week. The alignment rounds to the past. Supported time units for the relative timeframe are:
            m: minutes
            h: hours
            d: days
            w: weeks
            M: months
            y: years

            If not set, the relative timeframe of two weeks is used (now-2w).

        :param time_to: The end of the requested timeframe.

            You can use one of the following formats:

            Timestamp in UTC milliseconds.
            Human-readable format of 2019-12-21T05:57:01.123+01:00. If no time zone is specified, UTC is used. You can use a space character instead of the T. Seconds and fractions of a second are optional.
            Relative timeframe, back from now. The format is now-NU/A, where N is the amount of time, U is the unit of time, and A is an alignment. For example, now-1y/w is one year back, aligned by a week. The alignment rounds to the past. Supported time units for the relative timeframe are:
            m: minutes
            h: hours
            d: days
            w: weeks
            M: months
            y: years

            If not set, the relative timeframe of two weeks is used (now-2w).

        :param fields:  Defines the list of entity properties included in the response.
            The ID and the name of an entity are always included to the response.

            To add properties, list them with leading plus +. You can specify several properties,
            separated by a comma (for example fields=+lastSeenTms,+properties.BITNESS).

            Use the GET /entityTypes/{type} request to fetch the list of properties available for your entity type.
            Fields from the properties object must be specified in the properties.FIELD format (for example, properties.BITNESS).

        :param page_size: The desired amount of entities in a single response payload.
            The maximal allowed page size is configurable per environment.
            If not set, 50 is used.

        :return: A list of monitored entities along with their properties.
        """
        params = {
            "pageSize": page_size,
            "entitySelector": entity_selector,
            "from": time_from,
            "to": time_to,
            "fields": fields
        }
        return PaginatedList(Entity,
                             self.__http_client,
                             "/api/v2/entities",
                             params,
                             list_item="entities")
Exemple #27
0
    def query_metrics(
        self,
        metric_selector: str,
        page_size: int = None,
        resolution: str = None,
        time_from=None,
        time_to=None,
        entity_selector=None,
    ) -> PaginatedList[MetricSeriesCollection]:
        """
        Gets data points of the specified metrics

        :param metric_selector: Selects metrics for the query by their keys. You can select up to 10 metrics for one query.
            You can specify multiple metric keys separated by commas (for example, metrickey1,metrickey2).
            To select multiple metrics belonging to the same parent, list the last part of the required metric keys in parentheses, separated by commas,
            while keeping the common part untouched.
            For example, to list the builtin:host.cpu.idle and builtin:host.cpu.user metric, write: builtin:host.cpu.(idle,user).
            You can set additional transformation operators, separated by a colon (:).
            See the Metrics API - selector transformations help page for additional information on available result transformations.
            The length of the string is limited to 1,000 characters.

        :param page_size: The desired amount of primary entities in a single response payload.
            The maximal allowed page size is 5000.
            If not set, 100 is used.
            If a value higher than 5000 is used, only 5000 results per page are returned.

        :param resolution: The desired resolution of data points.
            You can use one of the following options:

            One aggregated data point of each series. Set Inf to use this option.
            The desired amount of data points. This is the default option.
            This is a reference number of points, which is not necessarily equal to the number of the returned data points.
            The desired timespan between data points. This is a reference timespan, which is not necessarily equal to the returned timespan.
            To use this option, specify the unit of the timespan.

            Valid units for the timespan are:

            m: minutes
            h: hours
            d: days
            w: weeks
            M: months
            y: years

            If not set, the default is 120 data points.

        :param time_from: The start of the requested timeframe.

            You can use one of the following formats:

            Timestamp in UTC milliseconds.
            Human-readable format of 2019-12-21T05:57:01.123+01:00. If no time zone is specified, UTC is used. You can use a space character instead of the T. Seconds and fractions of a second are optional.
            Relative timeframe, back from now. The format is now-NU/A, where N is the amount of time, U is the unit of time, and A is an alignment. For example, now-1y/w is one year back, aligned by a week. The alignment rounds to the past. Supported time units for the relative timeframe are:
            m: minutes
            h: hours
            d: days
            w: weeks
            M: months
            y: years

            If not set, the relative timeframe of two weeks is used (now-2w).

        :param time_to:
            The end of the requested timeframe.

            You can use one of the following formats:

            Timestamp in UTC milliseconds.
            Human-readable format of 2019-12-21T05:57:01.123+01:00. If no time zone is specified, UTC is used. You can use a space character instead of the T. Seconds and fractions of a second are optional.
            Relative timeframe, back from now. The format is now-NU/A, where N is the amount of time, U is the unit of time, and A is an alignment. For example, now-1y/w is one year back, aligned by a week. The alignment rounds to the past. Supported time units for the relative timeframe are:
            m: minutes
            h: hours
            d: days
            w: weeks
            M: months
            y: years

            If not set, the relative timeframe of two weeks is used (now-2w).

        :param entity_selector: Specifies the entity scope of the query. Only data points delivered by matched entities are included in response.
            You need to set one of these criteria:

            Entity type: type("value").
            Dynatrace entity ID: entityId("id"). You can specify several IDs, separated by a comma (entityId("id-1","id-2")).

            And you can add one or several of the following criteria:

            Tag: tag("value"). Tags in [context]key:value, key:value, and value formats are detected and parsed automatically. If a value-only tag has a colon (:) in it, you must escape the colon with a backslash(\). Otherwise, the tag will be parsed as a key:value tag. All tag values are case-sensitive.
            Management zone ID: mzId("ID")
            Management zone name: mzName("value"). Management zone names are case-sensitive.
            Dynatrace entity name: entityName("value"). You can specify several entity names, separated by a comma (entityName("name-1","name-2")). Entity names are case-sensitive.
            Health state (HEALTHY,UNHEALTHY): healthState("HEALTHY")

            Further information can be found here. To set several criteria, separate them with a comma (,). For example, type("HOST"),healthState("HEALTHY"). Only results matching all criteria are included in response.

            The length of the string is limited to 10,000 characters.
            Use the GET /metrics/{metricId} call to fetch the list of possible entity types for your metric.
            To set a universal scope matching all entities, omit this parameter.
        :return: A list of metrics and their data points.
        """

        params = {
            "pageSize": page_size,
            "metricSelector": metric_selector,
            "resolution": resolution,
            "from": time_from,
            "to": time_to,
            "entitySelector": entity_selector,
        }
        return PaginatedList(MetricSeriesCollection,
                             self.__http_client,
                             "/api/v2/metrics/query",
                             params,
                             list_item="result")
Exemple #28
0
    def get_metrics(self,
                    metric_selector: str = None,
                    text: str = None,
                    fields: str = None,
                    page_size=100):
        """

        Lists all available metrics

        :param metric_selector: Selects metrics for the query by their keys.
            You can specify multiple metric keys separated by commas (for example, metrickey1,metrickey2).
            To select multiple metrics belonging to the same parent,
            list the last part of the required metric keys in parentheses, separated by commas,
            while keeping the common part untouched.
            For example, to list the builtin:host.cpu.idle and builtin:host.cpu.user metric, write: builtin:host.cpu.(idle,user).

            You can select a full set of related metrics by using a trailing asterisk (*) wildcard.
            For example, builtin:host.* selects all host-based metrics and builtin:* selects all Dynatrace-provided metrics.
            You can set additional transformation operators, separated by a colon (:).
            See the Metrics API - selector transformations help page for additional information on available result transformations.

            The length of the string is limited to 1,000 characters.
            To find metrics based on a search term, rather than metric_id, use the text query parameter instead of this one.

        :param text: Metric registry search term
            Only show metrics that contain the term in their ID, display name, or description.
            Use the metric_selector parameter instead of this one to select a complete metric hierarchy instead of doing a text-based search.

        :param fields: Defines the list of metric properties included in the response.
            metric_id is always included in the result. The following additional properties are available:
            display_name: The name of the metric in the user interface. Enabled by default.
            description: A short description of the metric. Enabled by default.
            unit: The unit of the metric. Enabled by default.
            aggregation_types: The list of allowed aggregations for the metric. Note that it may be different after a transformation is applied.
            default_aggregation: The default aggregation of the metric. It is used when no aggregation is specified or the :auto transformation is set.
            dimension_definitions: The fine metric division (for example, process group and process ID for some process-related metric).
            transformations: A list of transformations that can be applied to the metric.
            entity_type: A list of entity types supported by the metric.

            To add properties, list them with leading plus +. To exclude default properties, list them with leading minus -.

            To specify several properties, join them with a comma (for example fields=+aggregationTypes,-description).

            If you specify just one property, the response contains the metric key and the specified property.
            To return metric keys only, specify metric_id here.

        :param page_size: The desired amount of primary entities in a single response payload.
            The maximal allowed page size is 5000.
            If not set, 100 is used.
            If a value higher than 5000 is used, only 5000 results per page are returned.
        :return: A list of metric descriptors
        :rtype: PaginatedList[MetricDescriptor]
        """

        params = {
            "pageSize": page_size,
            "metricSelector": metric_selector,
            "text": text,
            "fields": fields,
        }
        return PaginatedList(MetricDescriptor,
                             self.__http_client,
                             "/api/v2/metrics",
                             params,
                             list_item="metrics")