Ejemplo n.º 1
0
    def create_anomaly_score(self, anomaly, input_data=None,
                             args=None, wait_time=3, retries=10):
        """Creates a new anomaly score.

        """
        anomaly_id = None
        resource_type = get_resource_type(anomaly)
        if resource_type == ANOMALY_PATH:
            anomaly_id = get_anomaly_id(anomaly)
            check_resource(anomaly_id,
                           query_string=TINY_RESOURCE,
                           wait_time=wait_time, retries=retries,
                           raise_on_error=True, api=self)
        else:
            raise Exception("An anomaly detector id is needed to create an"
                            " anomaly score. %s found." % resource_type)

        if input_data is None:
            input_data = {}
        create_args = {}
        if args is not None:
            create_args.update(args)
        create_args.update({
            "input_data": input_data})
        create_args.update({
            "anomaly": anomaly_id})

        body = json.dumps(create_args)
        return self._create(self.anomaly_score_url, body,
                            verify=self.verify)
Ejemplo n.º 2
0
    def create_anomaly_score(self,
                             anomaly,
                             input_data=None,
                             args=None,
                             wait_time=3,
                             retries=10):
        """Creates a new anomaly score.

        """
        anomaly_id = None
        resource_type = get_resource_type(anomaly)
        if resource_type == ANOMALY_PATH:
            anomaly_id = get_anomaly_id(anomaly)
            check_resource(anomaly_id,
                           query_string=TINY_RESOURCE,
                           wait_time=wait_time,
                           retries=retries,
                           raise_on_error=True,
                           api=self)
        else:
            raise Exception("An anomaly detector id is needed to create an"
                            " anomaly score. %s found." % resource_type)

        if input_data is None:
            input_data = {}
        create_args = {}
        if args is not None:
            create_args.update(args)
        create_args.update({"input_data": input_data})
        create_args.update({"anomaly": anomaly_id})

        body = json.dumps(create_args)
        return self._create(self.anomaly_score_url, body, verify=self.verify)
Ejemplo n.º 3
0
    def get_anomaly(self,
                    anomaly,
                    query_string='',
                    shared_username=None,
                    shared_api_key=None):
        """Retrieves an anomaly detector.

           The anomaly parameter should be a string containing the
           anomaly id or the dict returned by create_anomaly.
           As the anomaly detector is an evolving object that is processed
           until it reaches the FINISHED or FAULTY state, the function will
           return a dict that encloses the model values and state info
           available at the time it is called.

           If this is a shared anomaly detector, the username and sharing api
           key must also be provided.
        """
        check_resource_type(anomaly,
                            ANOMALY_PATH,
                            message="A anomaly id is needed.")
        anomaly_id = get_anomaly_id(anomaly)
        if anomaly_id:
            return self._get("%s%s" % (self.url, anomaly_id),
                             query_string=query_string,
                             shared_username=shared_username,
                             shared_api_key=shared_api_key)
Ejemplo n.º 4
0
    def delete_anomaly(self, anomaly):
        """Deletes an anomaly detector.

        """
        check_resource_type(anomaly, ANOMALY_PATH,
                            message="An anomaly detector id is needed.")
        anomaly_id = get_anomaly_id(anomaly)
        if anomaly_id:
            return self._delete("%s%s" % (self.url, anomaly_id))
Ejemplo n.º 5
0
    def delete_anomaly(self, anomaly):
        """Deletes an anomaly detector.

        """
        check_resource_type(anomaly, ANOMALY_PATH,
                            message="An anomaly detector id is needed.")
        anomaly_id = get_anomaly_id(anomaly)
        if anomaly_id:
            return self._delete("%s%s" % (self.url, anomaly_id))
Ejemplo n.º 6
0
    def update_anomaly(self, anomaly, changes):
        """Updates an anomaly detector.

        """
        check_resource_type(anomaly, ANOMALY_PATH,
                            message="An anomaly detector id is needed.")
        anomaly_id = get_anomaly_id(anomaly)
        if anomaly_id:
            body = json.dumps(changes)
            return self._update("%s%s" % (self.url, anomaly_id), body)
Ejemplo n.º 7
0
    def update_anomaly(self, anomaly, changes):
        """Updates an anomaly detector.

        """
        check_resource_type(anomaly, ANOMALY_PATH,
                            message="An anomaly detector id is needed.")
        anomaly_id = get_anomaly_id(anomaly)
        if anomaly_id:
            body = json.dumps(changes)
            return self._update("%s%s" % (self.url, anomaly_id), body)
Ejemplo n.º 8
0
    def get_anomaly(self, anomaly, query_string='',
                    shared_username=None, shared_api_key=None):
        """Retrieves an anomaly detector.

           The anomaly parameter should be a string containing the
           anomaly id or the dict returned by create_anomaly.
           As the anomaly detector is an evolving object that is processed
           until it reaches the FINISHED or FAULTY state, the function will
           return a dict that encloses the model values and state info
           available at the time it is called.

           If this is a shared anomaly detector, the username and sharing api
           key must also be provided.
        """
        check_resource_type(anomaly, ANOMALY_PATH,
                            message="A anomaly id is needed.")
        anomaly_id = get_anomaly_id(anomaly)
        if anomaly_id:
            return self._get("%s%s" % (self.url, anomaly_id),
                             query_string=query_string,
                             shared_username=shared_username,
                             shared_api_key=shared_api_key)