Created
July 29, 2023 23:35
-
-
Save itsecworks/c4a80f0867331a4a5226fbacb22543b5 to your computer and use it in GitHub Desktop.
chord graph
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import xml.etree.ElementTree as ET | |
# Load d3blocks | |
from d3blocks import D3Blocks | |
import pandas as pd | |
filename = 'C:\\temp\\running-config.xml' | |
tree = ET.parse(filename) | |
root = tree.getroot() | |
for dg in root.findall("./devices/entry/device-group/entry"): | |
fromto = {} | |
dg_name = dg.attrib["name"] | |
print(dg_name) | |
for rule in dg.findall("./pre-rulebase/security/rules/entry"): | |
rule_name = rule.attrib["name"] | |
for fromzone in rule.findall("./from/member"): | |
#if fromzone.text != 'any': | |
for tozone in rule.findall("./to/member"): | |
#if tozone.text != 'any': | |
key = fromzone.text + '_to_' + tozone.text | |
if key in fromto: | |
fromto[key] += 1 | |
else: | |
fromto[key] = 1 | |
if fromto: | |
source = [] | |
target = [] | |
weight = [] | |
for key in fromto: | |
source.append(key.split('_to_')[0]) | |
target.append(key.split('_to_')[1]) | |
weight.append(fromto[key]) | |
data = {'source': source, | |
'target': target, | |
'weight': weight | |
} | |
df = pd.DataFrame(data) | |
# Initialize | |
d3 = D3Blocks() | |
# specify the output path and plot | |
file = 'c:/temp/chord_' + dg_name + '.html' | |
d3.chord(df, filepath=file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment