[sip] Script pour générer un graphe à partir du extentions.conf d'asterisk
This commit is contained in:
parent
a394438780
commit
87cc827335
1 changed files with 72 additions and 0 deletions
72
sip/asterisk-graph.py
Executable file
72
sip/asterisk-graph.py
Executable file
|
@ -0,0 +1,72 @@
|
|||
#!/usr/bin/env python
|
||||
from __future__ import print_function
|
||||
from sh import neato
|
||||
from sh import date
|
||||
from sh import dot
|
||||
|
||||
tmp_file = '/tmp/graph.gv'
|
||||
exten_file = '/etc/asterisk/extensions.conf'
|
||||
start_nodes = ["crans-sip", "crans-from-external", "ovh-sip", "crans-sms" ]
|
||||
|
||||
out = file(tmp_file,'w')
|
||||
arrow={}
|
||||
iarrow={}
|
||||
|
||||
print("""digraph G {
|
||||
rankdir=LR
|
||||
edge [len=2.50, ratio=fill]
|
||||
""", file=out)
|
||||
for node in start_nodes:
|
||||
print('"%s" [style=filled];' % node, file=out)
|
||||
|
||||
file=open(exten_file).read()
|
||||
file=file.split('\n[')
|
||||
del(file[0])
|
||||
for context in file:
|
||||
context=context.split('\n')
|
||||
context_name = context[0].strip()[:-1]
|
||||
arrow[context_name]= arrow.get(context_name, set())
|
||||
iarrow[context_name]= iarrow.get(context_name, set())
|
||||
del(context[0])
|
||||
print('"%s";' % context_name, file=out)
|
||||
for line in context:
|
||||
if line.startswith('include'):
|
||||
dest=line.split('=>', 1)[1].strip()
|
||||
iarrow[context_name].add(dest)
|
||||
line=line.split(',')
|
||||
if len(line)>2 and line[2].strip().startswith('Goto('):
|
||||
dest=line[2].strip()[5:]
|
||||
arrow[context_name].add(dest)
|
||||
|
||||
|
||||
for (context_name, dests) in arrow.items():
|
||||
for dest in dests:
|
||||
print('"%s" -> "%s" [arrowhead=normal];' % (context_name, dest), file=out)
|
||||
for (context_name, dests) in iarrow.items():
|
||||
for dest in dests:
|
||||
print('"%s" -> "%s" [arrowhead=crow, style=dashed];' % (context_name, dest), file=out)
|
||||
|
||||
print("""
|
||||
node [shape=plaintext]
|
||||
subgraph cluster_01 {
|
||||
key [label=<<table border="0" cellpadding="2" cellspacing="0" cellborder="0">
|
||||
<tr><td align="right" port="i1">B inclus dans A : A</td></tr>
|
||||
<tr><td align="right" port="i2">Saut de A vers B : A</td></tr>
|
||||
</table>>];
|
||||
key2 [label=<<table border="0" cellpadding="2" cellspacing="0" cellborder="0">
|
||||
<tr><td port="j1">B</td></tr>
|
||||
<tr><td port="j2">B</td></tr>
|
||||
</table>>];
|
||||
key:i1:e -> key2:j1:e [style=dashed, arrowhead=crow]
|
||||
key:i2:e -> key2:j2:w []
|
||||
}
|
||||
""", file=out)
|
||||
|
||||
print("""
|
||||
label = "\\n\\nAsterisk extensions\\nLes Nounous\\n%s";
|
||||
}""" % str(date())[0:-1], file=out)
|
||||
|
||||
out.close()
|
||||
|
||||
dot("-Tsvg", tmp_file, "-o", "/usr/scripts/var/doc/asterisk/extensions.svg")
|
||||
#neato("-Tsvg", tmp_file, "-o", "/usr/scripts/var/doc/asterisk/extensions.svg")
|
Loading…
Add table
Add a link
Reference in a new issue