boundary/measurement_get.py
def output_xml(self, text):
        """
        Output results in JSON format
        """

        # Create the main document nodes
        document = Element('results')
        comment = Comment('Generated by TrueSight Pulse measurement-get CLI')
        document.append(comment)
        aggregates = SubElement(document, 'aggregates')
        aggregate = SubElement(aggregates, 'aggregate')
        measurements = SubElement(aggregate, 'measurements')

        # Parse the JSON result so we can translate to XML
        payload = json.loads(text)

        # Current only support a single metric, if we move to the batch API then
        # we can handle multiple
        metric_name = self._metric_name

        # Loop through the aggregates one row per timestamp, and 1 or more source/value pairs
        for r in payload['result']['aggregates']['key']:
            timestamp = self._format_timestamp(r[0][0])
            for s in r[1]:
                # Each timestamp, metric, source, values is placed in a measure tag
                measure_node = SubElement(measurements, 'measure')
                source = s[0]
                value = str(s[1])
                ts_node = SubElement(measure_node, 'timestamp')
                ts_node.text = str(timestamp)
                metric_node = SubElement(measure_node, 'metric')
                metric_node.text = metric_name
                metric_node = SubElement(measure_node, 'aggregate')
                metric_node.text = self.aggregate
                source_node = SubElement(measure_node, 'source')
                source_node.text = source
                value_node = SubElement(measure_node, 'value')
                value_node.text = value

        rough_string = ElementTree.tostring(document, 'utf-8')
        reparse = minidom.parseString(rough_string)
        output = reparse.toprettyxml(indent=" ")
        print(self.colorize_xml(output))
def output_xml(self, text):
        # Create the main document nodes
        document = Element('results')
        comment = Comment('Generated by TrueSight Pulse measurement-get CLI')
        document.append(comment)
        aggregates = SubElement(document, 'aggregates')
        aggregate = SubElement(aggregates, 'aggregate')
        measurements = SubElement(aggregate, 'measurements')

        # Parse the JSON result so we can translate to XML
        payload = json.loads(text)

        # Current only support a single metric, if we move to the batch API then
        # we can handle multiple
        metric_name = self._metric_name

        # Loop through the aggregates one row per timestamp, and 1 or more source/value pairs
        for r in payload['result']['aggregates']['key']:
            timestamp = self._format_timestamp(r[0][0])
            for s in r[1]:
                # Each timestamp, metric, source, values is placed in a measure tag
                measure_node = SubElement(measurements, 'measure')
                source = s[0]
                value = str(s[1])
                ts_node = SubElement(measure_node, 'timestamp')
                ts_node.text = str(timestamp)
                metric_node = SubElement(measure_node, 'metric')
                metric_node.text = metric_name
                metric_node = SubElement(measure_node, 'aggregate')
                metric_node.text = self.aggregate
                source_node = SubElement(measure_node, 'source')
                source_node.text = source
                value_node = SubElement(measure_node, 'value')
                value_node.text = value

        rough_string = ElementTree.tostring(document, 'utf-8')
        reparse = minidom.parseString(rough_string)
        output = reparse.toprettyxml(indent=" ")
        print(self.colorize_xml(output))
def output_xml ( self , text ) : # Create the main document nodes document = Element ( 'results' ) comment = Comment ( 'Generated by TrueSight Pulse measurement-get CLI' ) document . append ( comment ) aggregates = SubElement ( document , 'aggregates' ) aggregate = SubElement ( aggregates , 'aggregate' ) measurements = SubElement ( aggregate , 'measurements' ) # Parse the JSON result so we can translate to XML payload = json . loads ( text ) # Current only support a single metric, if we move to the batch API then # we can handle multiple metric_name = self . _metric_name # Loop through the aggregates one row per timestamp, and 1 or more source/value pairs for r in payload [ 'result' ] [ 'aggregates' ] [ 'key' ] : timestamp = self . _format_timestamp ( r [ 0 ] [ 0 ] ) for s in r [ 1 ] : # Each timestamp, metric, source, values is placed in a measure tag measure_node = SubElement ( measurements , 'measure' ) source = s [ 0 ] value = str ( s [ 1 ] ) ts_node = SubElement ( measure_node , 'timestamp' ) ts_node . text = str ( timestamp ) metric_node = SubElement ( measure_node , 'metric' ) metric_node . text = metric_name metric_node = SubElement ( measure_node , 'aggregate' ) metric_node . text = self . aggregate source_node = SubElement ( measure_node , 'source' ) source_node . text = source value_node = SubElement ( measure_node , 'value' ) value_node . text = value rough_string = ElementTree . tostring ( document , 'utf-8' ) reparse = minidom . parseString ( rough_string ) output = reparse . toprettyxml ( indent = " " ) print ( self . colorize_xml ( output ) )
Output results in JSON format
Output results in JSON format