Using Perl and Graphviz to simplify your busy life

We all have to create topology diagrams, high level visual representations of our thoughts or environments (or software solutions etc) from time to time, for as they say – “A picture is worth a thousand words”.

The Graphviz software (http://www.graphviz.org/) provides us a simple and elegant way to do so, which with a little bit of practice can make a huge difference in time saved. It also lets us take safe shortcuts, where in we bypass the entire cumbersome process of creating visio diagrams ( or some other tool). And do this instead:

Input Configuration file:

# START_TOPO
#cluster:tier:node:dc
cluster01:web:web1:Chicago
cluster02:middleware:mid1:Chicago
cluster03:db:db1:Chicago
cluster11:web:web2:New York
cluster12:middleware:mid2:New York
cluster13:db:db2:New York
# END_TOPO
# START_EDGE
#nodes:dir:style:label
web1:web2:both:invis:UNDEF
mid1:mid2:both:invis:UNDEF
db1:db2:both:invis:UNDEF
web1,web2:mid1,mid2:::p9099
db1,db2:DBSID:both::Database
mid1,mid2:db1,db2:::p1514
# END_EDGE

Having prepared this type of configuration file (which should take a few minutes), run the script given below to generate the “dot” code needed to generate the diagrams. If you use a wiki (which should be all but ubiquitous in IT by now), most modern wikis (eg: mediawiki, dokuwiki) come with plugins for graphviz. The “dot” code generated by the script can then be pasted into your wiki page and an associated graphviz image will be displayed.

Run the script as follows:

 $ ./graph.pl –cfg=”./graphit.cfg” –output=/tmp/foo.dot

This will generate the necessary framework for your diagram. You do still need to know the “Dot” language in order to edit/modify/improve on the code, but this script will do the bulk of your work for you.  However, that is provided you are drawing topology diagrams (as shown here, in a similar format).

Feel free to pull the script from the git repo here and use/modify it as you deem fit:

https://github.com/implicateorder/sysadmin-tools/blob/master/graph.pl

 

The script:

 

The Dot code:

 

And the diagram looks like this (needs to tweaked further), provided my graphviz plugin works :

wpg_div_wp_graphviz_1

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.