<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Configuration Analysis Python Automation in Code Exchange</title>
    <link>https://community.cisco.com/t5/code-exchange/configuration-analysis-python-automation/m-p/5327262#M197</link>
    <description>&lt;P&gt;Great stuff&amp;nbsp;&lt;a href="https://community.cisco.com/t5/user/viewprofilepage/user-id/1915992"&gt;@kkowalczyk&lt;/a&gt;!&amp;nbsp;Configuration validation/network analysis is a good use-case for automation. Thank you for sharing.&lt;/P&gt;</description>
    <pubDate>Thu, 04 Sep 2025 19:59:43 GMT</pubDate>
    <dc:creator>Torbjørn</dc:creator>
    <dc:date>2025-09-04T19:59:43Z</dc:date>
    <item>
      <title>Configuration Analysis Python Automation</title>
      <link>https://community.cisco.com/t5/code-exchange/configuration-analysis-python-automation/m-p/5327242#M196</link>
      <description>&lt;P&gt;I wanted to share a version of a script I recently used to analyze configuration for routers across my network. I found a route map attached to a BGP neighbor that was not defined and caused the advertisements of prefixes to be blocked, I was curious if any of the other several hundred routers in my network had this same issue, turns out there was a total of 14 route maps that were applied to neighbors but not defined. This script is written to read in configuration files, my production script SSH'd to each router concurrently and gathered the running config that way, due to the nature of that script I made this version to share.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;PRE&gt;&lt;SPAN&gt;from &lt;/SPAN&gt;CiscoAutomationFramework.Parsers.ConfigParser &lt;SPAN&gt;import &lt;/SPAN&gt;ConfigParser&lt;BR /&gt;&lt;SPAN&gt;from &lt;/SPAN&gt;CiscoAutomationFramework.util &lt;SPAN&gt;import &lt;/SPAN&gt;extract_line_from_tree&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;def &lt;/SPAN&gt;&lt;SPAN&gt;extract_route_map_names&lt;/SPAN&gt;(rm_definition_lines):&lt;BR /&gt;    &lt;SPAN&gt;"""Helper function to extract the route map name from the route map definition&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;    ex. neighbor 192.168.10.5 route-map TEST in || will extract "TEST"&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;    """&lt;BR /&gt;&lt;/SPAN&gt;    map_names = []&lt;BR /&gt;    &lt;SPAN&gt;for &lt;/SPAN&gt;map_statement &lt;SPAN&gt;in &lt;/SPAN&gt;rm_definition_lines:&lt;BR /&gt;        &lt;SPAN&gt;for &lt;/SPAN&gt;idx, word &lt;SPAN&gt;in &lt;/SPAN&gt;&lt;SPAN&gt;enumerate&lt;/SPAN&gt;(map_statement.split()):&lt;BR /&gt;            &lt;SPAN&gt;if &lt;/SPAN&gt;word == &lt;SPAN&gt;'route-map'&lt;/SPAN&gt;:&lt;BR /&gt;                map_names.append(map_statement.split()[idx + &lt;SPAN&gt;1&lt;/SPAN&gt;])&lt;BR /&gt;    &lt;SPAN&gt;return &lt;/SPAN&gt;map_names&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# add path to config files here&lt;BR /&gt;&lt;/SPAN&gt;config_files = []&lt;BR /&gt;total_undefined_route_maps = &lt;SPAN&gt;0&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;for &lt;/SPAN&gt;file &lt;SPAN&gt;in &lt;/SPAN&gt;config_files:&lt;BR /&gt;    &lt;SPAN&gt;# read in config file&lt;BR /&gt;&lt;/SPAN&gt;    &lt;SPAN&gt;with &lt;/SPAN&gt;&lt;SPAN&gt;open&lt;/SPAN&gt;(file, &lt;SPAN&gt;'r'&lt;/SPAN&gt;) &lt;SPAN&gt;as &lt;/SPAN&gt;f:&lt;BR /&gt;        configuration = f.read()&lt;BR /&gt;    &lt;SPAN&gt;print&lt;/SPAN&gt;(file)&lt;BR /&gt;&lt;BR /&gt;    parser = ConfigParser(configuration)&lt;BR /&gt;    &lt;SPAN&gt;# extract only BGP config&lt;BR /&gt;&lt;/SPAN&gt;    bgp_config = parser.search_config_tree(&lt;SPAN&gt;'router bgp'&lt;/SPAN&gt;)&lt;BR /&gt;    &lt;SPAN&gt;# From BGP config extract all lines that contain the text "route-map"&lt;BR /&gt;&lt;/SPAN&gt;    maps = extract_line_from_tree(bgp_config.config_tree, &lt;SPAN&gt;'route-map'&lt;/SPAN&gt;, &lt;SPAN&gt;find_all&lt;/SPAN&gt;=&lt;SPAN&gt;True&lt;/SPAN&gt;)&lt;BR /&gt;    &lt;SPAN&gt;# use helper function to extract the name of the route map from all references&lt;BR /&gt;&lt;/SPAN&gt;    configured_route_maps = extract_route_map_names(maps)&lt;BR /&gt;&lt;BR /&gt;    &lt;SPAN&gt;# Iterate over each route map name, try and get the route map definition from the config, printing out the name&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;    # if not found&lt;BR /&gt;&lt;/SPAN&gt;    &lt;SPAN&gt;for &lt;/SPAN&gt;route_map &lt;SPAN&gt;in &lt;/SPAN&gt;configured_route_maps:&lt;BR /&gt;        &lt;SPAN&gt;if not &lt;/SPAN&gt;parser.get_route_map(route_map):&lt;BR /&gt;            &lt;SPAN&gt;print&lt;/SPAN&gt;(&lt;SPAN&gt;f'Route map &lt;/SPAN&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;route_map&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;SPAN&gt; is referenced but not configured!'&lt;/SPAN&gt;)&lt;BR /&gt;            total_undefined_route_maps += &lt;SPAN&gt;1&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;print&lt;/SPAN&gt;(&lt;SPAN&gt;f'Total undefined route maps: &lt;/SPAN&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;total_undefined_route_maps&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;SPAN&gt;'&lt;/SPAN&gt;)&lt;/PRE&gt;&lt;P&gt;More information about the package used here can be found here&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/superadm1n/CiscoAutomationFramework" target="_blank" rel="noopener"&gt;https://github.com/superadm1n/CiscoAutomationFramework&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://ciscoautomationframework.readthedocs.io/en/latest/?badge=latest" target="_blank" rel="noopener"&gt;https://ciscoautomationframework.readthedocs.io/en/latest/?badge=latest&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 04 Sep 2025 18:43:09 GMT</pubDate>
      <guid>https://community.cisco.com/t5/code-exchange/configuration-analysis-python-automation/m-p/5327242#M196</guid>
      <dc:creator>kkowalczyk</dc:creator>
      <dc:date>2025-09-04T18:43:09Z</dc:date>
    </item>
    <item>
      <title>Re: Configuration Analysis Python Automation</title>
      <link>https://community.cisco.com/t5/code-exchange/configuration-analysis-python-automation/m-p/5327262#M197</link>
      <description>&lt;P&gt;Great stuff&amp;nbsp;&lt;a href="https://community.cisco.com/t5/user/viewprofilepage/user-id/1915992"&gt;@kkowalczyk&lt;/a&gt;!&amp;nbsp;Configuration validation/network analysis is a good use-case for automation. Thank you for sharing.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Sep 2025 19:59:43 GMT</pubDate>
      <guid>https://community.cisco.com/t5/code-exchange/configuration-analysis-python-automation/m-p/5327262#M197</guid>
      <dc:creator>Torbjørn</dc:creator>
      <dc:date>2025-09-04T19:59:43Z</dc:date>
    </item>
  </channel>
</rss>

