예제 #1
0
    def add_additional_results(self, checktime=None, results=None):
        """Add additional results to an existing result
        
        checktime: the checktime of a previously submitted result
        results: an instance of AdditionalResults 
        
        """

        if not checktime:
            raise MonitisError("addAdditionalResults: checktime required")

        if not results:
            raise MonitisError("addAdditionalResults: " + \
                                   "results required")

        action = 'addAdditionalResults'
        # use the current time if the user didn't specify one
        checktime = checktime or api_checktime()

        # use dumps to format the results parameter as a JSON list
        response_string = self.post(action=action,
                                    monitorId=self.monitor_id,
                                    checktime=checktime,
                                    results=dumps(results))
        response = decode_json(response_string)
        if response['status'] != 'ok':
            raise MonitisError('addAdditionalResults failed: ' + response)

        return checktime
예제 #2
0
 def add_additional_results(self, checktime=None, results=None):
     """Add additional results to an existing result
     
     checktime: the checktime of a previously submitted result
     results: an instance of AdditionalResults 
     
     """
     
     if not checktime:
         raise MonitisError("addAdditionalResults: checktime required")
     
     if not results:
         raise MonitisError("addAdditionalResults: " + \
                                "results required")
     
     action = 'addAdditionalResults'
     # use the current time if the user didn't specify one
     checktime = checktime or api_checktime()
     
     # use dumps to format the results parameter as a JSON list
     response_string =  self.post(action=action,
                                  monitorId=self.monitor_id,
                                  checktime=checktime,
                                  results=dumps(results))
     response = decode_json(response_string)
     if response['status'] != 'ok':
         raise MonitisError('addAdditionalResults failed: ' + response)
         
     return checktime
예제 #3
0
    def add_result(self, checktime=None, results=None, **kwargs):
        """add results for the specified Custom monitor
        
        One or more results should be passed in a kwargs of the form:
            paramName1=paramValue1,paramName2=paramValue2,...
        
        Returns the checktime, whether passed in as a parameter
        or automatically generated.  This is useful for passing
        to add_additional_results

        """
        action = 'addResult'
        # use the current time if the user didn't specify one
        result_checktime = checktime or api_checktime()

        # merge kwargs and results items into one list
        if results is None:
            results_items = list()
        else:
            results_items = results.items()
        results_items.extend(kwargs.items())

        # build post string elements from combined results items
        result_strings = list()
        for name, value in results_items:
            # urllib.quote each to implement "double encoding"
            # http://monitis.com/api/api.html#api_home
            result_strings.append(quote(':'.join((name, str(value))), ':'))

        result_string = self.post(action=action,
                                  monitorId=self.monitor_id,
                                  checktime=result_checktime,
                                  results=';'.join(result_strings))
        result = decode_json(result_string)
        if result['status'] != 'ok':
            raise MonitisError('add_result failed')

        return result_checktime
예제 #4
0
    def add_result(self, checktime=None, results=None, **kwargs):
        """add results for the specified Custom monitor
        
        One or more results should be passed in a kwargs of the form:
            paramName1=paramValue1,paramName2=paramValue2,...
        
        Returns the checktime, whether passed in as a parameter
        or automatically generated.  This is useful for passing
        to add_additional_results

        """
        action = 'addResult'
        # use the current time if the user didn't specify one
        result_checktime = checktime or api_checktime()
        
        # merge kwargs and results items into one list
        if results is None:
            results_items = list()
        else:
            results_items = results.items()
        results_items.extend(kwargs.items())

        # build post string elements from combined results items
        result_strings = list()
        for name, value in results_items:
            # urllib.quote each to implement "double encoding"
            # http://monitis.com/api/api.html#api_home
            result_strings.append(quote(':'.join((name, str(value)))))
        
        result_string =  self.post(action=action, monitorId=self.monitor_id,
                         checktime=result_checktime,
                         results=';'.join(result_strings))
        result = decode_json(result_string)
        if result['status'] != 'ok':
            raise MonitisError('add_result failed')
            
        return result_checktime