Extensions
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?
3 REPLIES 3

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

Hi Jannick,

I must have somehow missed your original reply, sorry about that.

Not sure if you already figured out how to make this work, but for anyone else who might stumble upon this thread:

This generic topology works by defining entities from metrics and logs, as opposed to the old one which worked by first defining the entity and then the attaching metrics and logs to it.

On the YAML you defined a set a rules. Each rule defines and idPattern which is how the entity ID will be calculated, and sources, which is what metrics/logs are going to create this entity. These are the most important fields. Let's give a very simple example:

topology:
  types:
    - enabled: true
      name: unifi-device
      displayName: Unifi device
      rules:
        - idPattern: unifi_device_{device.name}
          instanceNamePattern: {device.name}
          sources:
            - sourceType: Metrics
              condition: $prefix(unifi.)

With this topology definition, for every metric whose key starts with unifi. which has the dimension device.name (here the dimension is implicitly required because you are using it in the idPattern), Dynatrace will calculate an ID hash from the string unifi_device_{device.name} (where it replaces device.name with the actual value of the dimension in your metric). Then, if no entity with that ID exists in your environment, it will create a new one. Otherwise, it will attach this metric to the existing entity.

You can then enrich this with properties:

topology:
  types:
    - enabled: true
      name: unifi-device
      displayName: Unifi device
      rules:
        - idPattern: unifi_device_{device.name}
          instanceNamePattern: {device.name}
          sources:
            - sourceType: Metrics
              condition: $prefix(unifi.)
          attributes:
            - pattern: '{mac}'
              key: mac
              displayName: MAC address
            - pattern: '{type}'
              key: type
              displayName: Device type
            - pattern: '{adopted}'
              key: adopted
              displayName: Adopted

where the rule will now try to extract as properties the dimensions mac, type and adopted from the matching metrics (if these dimensions exist).

A strategy that we normally use in our extension to populate this attributes, is to have a "dummy" metric like unifi.device.attributes which we populate with all the dimensions that should be attributes, and then have as our first rule something with this source:

sourceType: Metrics
condition: $eq(unifi.device.attributes)

 

Let me know if that was helpful, and once again apologies for the very delayed reply.

Featured Posts