# Python EF2 topology setting

**URL:** <https://community.dynatrace.com/t/python-ef2-topology-setting/46855>\
**Category:** Extensions\
**Tags:** topology, python, extensions\
**Created:** [July 28, 2024, 11:26am UTC](https://community.dynatrace.com/t/python-ef2-topology-setting/46855 "2024-07-28T11:26:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yosi\_Neuman](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/yosi_neuman/32/9845_2.png) [@Yosi\_Neuman](https://community.dynatrace.com/u/Yosi_Neuman)\
**Post date:** [July 28, 2024, 11:26am UTC](https://community.dynatrace.com/t/python-ef2-topology-setting/46855/1 "2024-07-28T11:26:53Z")

</div>

Hi guys,

We&nbsp; have start to convert python EF1 to EF2, we managed to convert already few of them but and now we are a bit confused on how to create the topology within&nbsp;extension.yaml and how to set the values from \_\_main\_\_.py

We did not found any documentation or example for this kind of change or settings.

Wonder if we missed it or its really not there&nbsp;🤔

Anyhow, can someone please help and show us the equivalence of the follows EF1 code:

```python
for i in range (0,int(data['metaData']['totalHits'])):
            g1 = self.topology_builder.create_group("AlteonCloud", "AlteonCloud")
            e1 = g1.create_element("Alteon Cloud - " + self.group, "Alteon Cloud - " + self.group)
            ip = self.Alteon_url.replace("https://","")
            e1.add_endpoint(ip)

        for i in range (0,10):
            try:
                ip = self.Alteon_ips.split(",")[i]
                e1.add_endpoint(ip)
            except:
                break     

        for i in range (0,int(data['metaData']['totalHits'])):
            e1.absolute(key="blockedHttpTransactions",value=data["data"][i]["row"]['blockedHttpTransactions'])
            e1.absolute(key="passiveHttpTransactions",value=data["data"][i]["row"]['passiveHttpTransactions'])
            e1.absolute(key="cleanHttpTransactions" ,value=data["data"][i]["row"]['cleanHttpTransactions'])

```

In EF2&nbsp;extension.yaml and \_\_main\_\_.py

Thanks in advance

Yos

---

<div class="post-metadata">

**Author:** ![Julius\_Loman](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/julius_loman/32/51_2.png) [@Julius\_Loman](https://community.dynatrace.com/u/Julius_Loman)\
**Post date:** [July 28, 2024, 8:03pm UTC](https://community.dynatrace.com/t/python-ef2-topology-setting/46855/2 "2024-07-28T20:03:07Z")

</div>

Topology is handled differently. You cannot create topology directly from code, you need to send logs/metrics/traces/events and create generic topology types and relations which you can package into extension 2.0. Topology in EF2 has a significant drawback compared to EF+ - you need to send data at least every 5 minutes to keep entities alive. This can result in increased costs depending on your case.

This means you won’t have any continuity in terms of topology and after rewriting your extension to EF2 your devices from EF1 will no longer exist and generic topology from EF2 will create new devices.&nbsp;  
Also the custom topology won’t have any automatically created relations unless you specify it in the custom topology relations. In EF1 you could create custom devices with specific IP addresses and smartscape automatically created relations. For example, if you monitored an appliance and there are outgoing requests from OneAgent monitored services to that appliance a link was established and you could see a service on top of a custom device. This is no longer possible.

---

<div class="post-metadata">

**Author:** ![Tom\_sSeroteRoos](https://avatars.discourse-cdn.com/v4/letter/t/bb73d2/32.png) [@Tom\_sSeroteRoos](https://community.dynatrace.com/u/Tom_sSeroteRoos)\
**Post date:** [July 29, 2024, 6:54am UTC](https://community.dynatrace.com/t/python-ef2-topology-setting/46855/3 "2024-07-29T06:54:07Z")

</div>

As [@Julius\_Loman](https://community.dynatrace.com/user/3364) mentions below, you can no longer create custom devices directly from code. Instead you have to first declare them in your _extension.yaml_ file and then ingest metrics/logs in accordance to the sources you specify.

```auto
extension.yaml

topology:
  types:
    - name: alteon-cloud
      displayName: Alteon Cloud
      enabled: true
      rules:
        - idPattern: alteon_cloud_{ip}
          instanceNamePattern: "Alteon Cloud {ip}"
          sources:
            - sourceType: Metrics
              condition: $prefix(alteonCloud.)
          role: default

```

(the settings here correspond mostly to what you see in the UI under generic topology)

With the snippet above your _extension.yaml_ file you will be creating a generic topology rule in Dynatrace which will attempt to create Altean Cloud entities from any metric with prefix _alteonCloud._ . These metrics should have an _ip_ dimension which will uniquely identify the entity, as indicated by the entity _idPattern_ (meaning you will have a different entity per _ip_ in your metric dimensions).

You would then ingest these metrics in your python code. For example:

```auto
__main__.py<br><br>class ExtensionImpl(Extension):
...
def query(self):<br> ...
    self.report_metric(key=alteonCloud.blockedHttpTransactions, value=data[stuff], dimensions={"ip": "your_ip", **other_dimensions})<br>    ...

```

---

<div class="post-metadata">

**Author:** ![Yosi\_Neuman](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/yosi_neuman/32/9845_2.png) [@Yosi\_Neuman](https://community.dynatrace.com/u/Yosi_Neuman)\
**Post date:** [July 29, 2024, 3:45pm UTC](https://community.dynatrace.com/t/python-ef2-topology-setting/46855/4 "2024-07-29T15:45:11Z")

</div>

Thank you both&nbsp;[@Julius\_Loman](https://community.dynatrace.com/user/3364)&nbsp;&&nbsp;[@TomásSeroteRoos](https://community.dynatrace.com/user/55565)&nbsp; for the detailed explanation and code sample

Apricate it a lot

Yos
