cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to create a topology?

jannick_deturck
Organizer

In extensions framework I can't use groups and devices any more.

Therefor I need to create a topology for the definition here below that I need to add in the extension.yaml file 

 # report device metrics from the API
    def reportDeviceMetrics(self, session):
        # Create group - provide group id used to calculate unique entity id in dynatrace
        #   and display name for UI presentation
        group = self.topology_builder.create_group(identifier=self.unifisitename,
                                                   group_name=self.unifisitedesc)
                                                   
        response = session.get(
            url="{}/api/s/{}/stat/device".format(self.url, self.unifisitename),
            headers = self.headers,
            verify = False,
            timeout = 1
        )
        if response.status_code != 200:
            logger.error("Exception happened during device-basic api call = " + resp.text)
       
        devices = response.json().get("data")
        for device in devices:
            print(device.get("name"))
           
            # Create device - provide device id used to calculate unique entity id in dynatrace
            #   and display name for UI presentation
            node = group.create_device(identifier="unifi-device-{}".format(device.get("name")), display_name=device.get("name"))
            logger.info("Topology: group name=%s, device name=%s", group.name, node.name)
           
            # report property - any string-string values pair. It is added to device metadata displayed in dynatrace UI
            node.report_property(key='mac', value=device.get('mac'))
            node.report_property(key='disabled', value=str(device.get('disabled')))
            node.report_property(key='adopted', value=str(device.get('adopted')))
            node.report_property(key='type', value=device.get('type'))
            node.report_property(key='model', value=device.get('model'))
           
            # report state - value must be one from list located in json file.
            devicestate = 'OFF'
            if device.get('state') == 1:
                devicestate = 'ON'
            node.state_metric(key='state', value=devicestate)

            systemStats = device.get('system-stats')
            if systemStats is not None:
                node.absolute(key='sys-cpu', value=float(systemStats.get("cpu")))
                node.absolute(key='sys-memory', value=float(systemStats.get("mem")))


Anybody an idea how to do that?
2 REPLIES 2

TomásSeroteRoos
Dynatrace Advisor
Dynatrace Advisor

In Extension Framework 2 the way to define topology changed completely. You now need to define your topology in the extension.yaml file to match the metrics you are sending from your code.

Have a look at this thread for an example and explanation on how you could do it.

jannick_deturck
Organizer

Thanks for this example,  but I was already aware that we need to add a topology in the extension.yaml file.

My question is HOW I can do this?

topology:
  types:
    - enabled: true
      name:
      displayName:
      rules:
        - idPattern:
          instanceNamePattern:
          iconPattern:
          sources:
            - sourceType: Metrics
              condition: ()
          role: default

Featured Posts