iwanthome has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

I want to write a web-based network monitor application. The hard problem for me is how to generate the dynamic network topology. My network is comprised of many cisco router and switch which run cdp . I can get text-based network topology information by cdp.But how to generate the picture?

I read many documention and found 3 possible solution.

1.perl/tk. But I think it can't do the web-based appliction.So I think it is not candidate.

2.GD. But I don't know how to lay out graphs in an aesthetically-pleasing way . So please anyone can give me some clues.

3.cpan module graphviz.Maybe it is a good solution. I am trying to install and test it.

I was wondering if there are better ways. So I would appreciate any ideas and pointers which anyone may have.(before I go sailing off in the wrong direction)

thanks!

  • Comment on How to generate network topology with perl ?

Replies are listed 'Best First'.
Re: How to generate network topology with perl ?
by Fletch (Bishop) on Apr 29, 2004 at 15:41 UTC

    GraphViz is probably the way to go. I used it and Net::Traceroute to generate a picture of the intermediate routers between our colo equipment and field locations at $previous_jobs[-1].

    Update: AH HAH. Knew it was around here somewhere. Code follows.

      I'll definitely be checking this out. A couple style nits:

      Strategy in comments. Tactics in code.
      Don't mention any actual numbers, operators or data types in a comment, and you're less likely to get out of sync.

      use constant TIMEOUT => 5; # seconds, for traceroutes

      Think higher.
      If you think about the problem in strategy terms, you won't micromanage your tactics.

      open(HOST, $file ) or die "Can't open `$file': $!\n"; my @hosts = <HOST>; close(HOST); chomp @hosts;

      --
      [ e d @ h a l l e y . c c ]

        The while loop was that way for a reason because at one time it was going to possibly deal with comments (I just never stuck the next if /^\s*#/; et al in there); other things changed (moved into Postgres) and the list-o-hosts wound up not being commented.

        Guilty as charged on the first count, though. %)

      Fletch,

      thanks for your reply.Could you give me some guide about how to install the grahpviz c module (not cpan module) ? I have spend two days to install and always fail.

      thanks!

        Not particularly. I've always used either the RedHat RPM or the tarball the dot people provide (way back when when dinosaurs roamed the earth and 9600 baud was blazing fast) and never had any problems. Your best bet is to seek the assistance of your friendly neightborhood sysadmin (or more likely your curmudgeonly neighborhood sysadmin).

Re: How to generate network topology with perl ?
by kvale (Monsignor) on Apr 29, 2004 at 15:42 UTC
    You may also want to add Dia to your list. It is a diagram editor that can create network diagrams, among other things. It has an XML storage format which would be easy to generate from perl and exports to several image formats.

    -Mark

Re: How to generate network topology with perl ?
by eXile (Priest) on Apr 30, 2004 at 15:56 UTC
    Not a perl solution (Tcl), but I thing worth a look, is Scotty / Tkinet. A quote from the Tkinet description:
    Network maps can be maintained by using the editing features provided by Tkined or using automated tools. The source distribution contains applications to discover IP networks, to support the network layout process, to troubleshoot IP networks using SNMP in combination with other standard tools (e.g. traceroute) and to monitor network status using SNMP or selected SUN RPCs.
    Might be interesting to use together with Tcl::Tk, if you want to do this in perl.
      thanks,I will try.