SNMP::Map - Tool for drawing network map
my $map = new SNMP::Map; $map->get_data(username=> 'user', password =>'pass', ipv3 => ['10.8.255.238','10.8.255.239','10.8.255.244','10.8.255.248'], vlan=>'vlan-224' ); $map->get_output(file => 'map.jpg');
The SNMP::Map module is used for drawing network map of hosts which support SNMP. Spanning Tree root switch can be distinguished by its position and color. Module provides switches and ports on the picture linked by each other.You can get various information about switch and its link. Image map file is also available. So, it can be used to create javascript for popuping additional info.
This is the constructor. It does not accept any attributes.
my $map = new SNMP::Map;
get_data method gets data from switches using SNMP protocol. It starts from the spanning tree root switch, and makes recursive calls to all switches linked to root. By default, it uses SNMP v3, but for switches listed in ipv2 array reference,it uses SNMP v2. If a failure occurs, method returns underfined value, you can use 'error' method to get error. At least, one ip adress must be specified by ipv2 or ipv3 attribute. It is recommended to get more info, list all switches by ipv2 and ipv3 attributes. It was tested on 'WS-C2950','WS-C2960','WS-3750' platforms. 'WS-C2950' switches must be listed in ipv2.
get_data
Attributes:
username for SNMP v3.
password for SNMP v3.
community for SNMP v2.
timeout for SNMP.
array reference consist of list of hosts which is supported SNMP v3.
array reference consist of list of hosts which is supported SNMP v2.
switch on/off debug.can be true or false. Debug information is printed to STDERR.
vlan to draw map.
$map->get_data(username=>'user', community=>'comm', password=>'pass', ipv3=>['10.8.255.115','10.8.255.118','10.8.255.119','10.8.255.111'], ipv2=>['10.8.255.145','10.8.255.133','10.8.255.151','10.8.255.149'], vlan => 'vlan-192');
This method is used for saving image into file. Also you can get an image map file. A color value used in attributes of the method may be "h,s,v" (hue, saturation, brightness) floating point numbers between 0 and 1, or an X11 color name such as 'white', 'black', 'red', 'green', 'blue', 'yellow', 'magenta', 'cyan', or 'burlywood'.
sets the outline color for Spanning Tree root switch, and the default fill color if the 'style' is 'filled' and 'fillcolor' is not specified.
sets the fill color for Spanning Tree root switch when the style is 'filled'. If not specified, the 'fillcolor' when the 'style' is 'filled' defaults to be the same as the outline color.
sets the label text color for Spanning Tree root switch.
sets the outline color for hosts and the default fill color if the 'style' is 'filled' and 'fillcolor' is not specified.
sets the fill color for hosts when the style is 'filled'. If not specified, the 'fillcolor' when the 'style' is 'filled' defaults to be the same as the outline color.
sets the label text color for hosts.
sets hash reference for the host`s shape, the key - regexp for the device platform, value - shape. shape could be: 'record', 'plaintext', 'ellipse', 'circle', 'egg', 'triangle', 'box', 'diamond', 'trapezium', 'parallelogram', 'house', 'hexagon', 'octagon'. unknown key is for hosts for which platform is unknown.
sets array reference for colors of the links between hosts. First element of array reference is the color for the unknown state of link. Last element is the color for link in blocking state. 2-7 elements - colors for hosts depending of its cost. Formula to correspond link color and its cost - log(1/cost)*100 .
log(1/cost)*100
file to output image.
format of image file. Could be: 'ps','hpgl','pcl','mif','pic','gd','gd2','gif','jpg','png','wbmp', 'vrml','vtx,'mp','fig','svg','svgz','plain'.
The layout attribute determines which layout algorithm GraphViz.pm will use. Possible values are: 'dot','neato','twopi','circo','fdp'. 'dot' and 'circo' are recommended.
background color of image.
minimal height/width of image in inches.
host`s label font size.
host`s style. Could be: 'filled', 'solid', 'dashed', 'dotted', 'bold', 'invis'.
style of link. Could be: 'filled', 'solid', 'dashed', 'dotted', 'bold', 'invis'.
file to output client-side/server-side image file. href parameter in the html tags is the ip adress for hosts and number for links. You can change it to nohref and use 'nodes_info' and 'edge_info' methods to create javascript pop up.
$map->get_output(file=>'../map.jpg', root_fillcolor=>'blue', root_fontcolor=>'cyan', fontcolor=>'red', color=>'green', shapes => {unknown => 'record','IP Phone' =>'ellipse'}, edges_colors=>['blue','0,0,0.9','0,0,0.8','0,0,0.7','0,0.5,0.6','0,0,0.5','0,0,0.4','red'], height=>5, width=>9, edge_style=>'dashed', cmap=>'map' );
return last error message.
returns hash reference with information about host.To use this method you must call 'get_data' method first. Keys of the hash reference are the ip address of the hosts.The following information could be obtained:
$info = $map->nodes_info(); print $info->{10.8.255.101}{deviceID}; print $info->{10.8.255.101}{priority}; print $info->{10.8.255.101}{mac}; print $info->{10.8.255.101}{platform}; print $info->{10.8.255.101}{interfaces}{Gi0/1}{cost}; #cost for Gi0/1 port print $info->{10.8.255.101}{interfaces}{Gi0/1}{cost}; #state for Gi0/1 port
take the number of the link as first parameter. To use this method you must call 'get_data' method first.Number correspond to href parameter of the image map file of link. The following information could be obtained:
$info = $map->edge_info(5); print $info->{from_ip}; print $info->{from_interface}; #name of the port print $info->{from_virtual}; #name of the virtual port print $info->{to_ip}; print $info->{to_interface}; #name of the port print $info->{to_virtual}; #name of the virtual port
Module was tested on 'WS-C2950','WS-C2960','WS-3750' platforms. ipv2 option in 'get_data' method is used for WS-C2950.
Krol Alexander <kasha@bigmir.net>
This module is free software; you can redistribute it or modify it under the same terms as Perl itself.
To install SNMP::Map, copy and paste the appropriate command in to your terminal.
cpanm
cpanm SNMP::Map
CPAN shell
perl -MCPAN -e shell install SNMP::Map
For more information on module installation, please visit the detailed CPAN module installation guide.