A quick and dirty netdisco install on debian with an MRTG integration ===================================================================== From: sylvain.maurin@isc.cnrs.fr ********************************************** ***** Get and install 14all-cgi and mrtg ***** ********************************************** =============== Ddebian help us ============== * use debian sarge packages : * (even for rrdtool) # apt-get -u install mrtg # apt-get -su install rrdtool librrds-perl * will not use debian mrtg conf # mv /etc/mrtg.cfg /etc/mrtg.cfg.debian # mkdir /usr/local/mrtg # mkdir /usr/local/mrtg/bin # mkdir /usr/local/mrtg/etc # addgroup --system mrtg # adduser --system --home /usr/local/mrtg --no-create-home --ingroup mrtg mrtg # chsh -s mrtg /bin/bash # chown -R mrtg.mrtg /usr/local/mrtg # chown -R mrtg.mrtg /var/www/mrtg # chown -R mrtg.mrtg /var/log/mrtg # chown -R mrtg.mrtg /var/lock/mrtg # chown -R mrtg.mrtg /var/lib/mrtg # su mrtg mkdir /var/www/mrtg/images =============== 14all.cgi =============== # wget http://heanet.dl.sourceforge.net/sourceforge/my14all/14all-1.1p25.tar.gz * untar and install stuff ... and : # cp 14all/14all.cgi /usr/lib/cgi-bin * edit /usr/lib/cgi-bin/14all.cgi: $cfgfile = /usr/local/mrtg/etc/14all.cfg * done # cd /usr/local/mrtg/etc/ # ln -s CONF_FILE_MRTG 14all.cfg =============== local stuff =============== cat >/usr/local/mrtg/bin/mrtg-conf-builder <new('icmp'); # define your router switch/router list push @host, "192.168.1.1"; for ($adr=220;$adr<230;$adr++) { push @host, "192.168.1.$adr"; } for ($adr=237;$adr<240;$adr++) { push @host, "192.168.1.$adr"; } for ($adr=50;$adr<80;$adr++) { push @host, "172.18.1.$adr"; } #push @host, "SR0S26"; #push @host, "SR0S24"; #push @host, "SR0S29"; #push @host, "SR0N26"; #push @host, "SR0N24"; #push @host, "SR0N50"; #push @host, "SR1N24"; #push @host, "SR1S26"; #push @host, "SR1S24"; #push @host, "SR1S29"; #push @host, "SR1N29"; #some local path declaration $wwwpath="/var/www/mrtg"; $confpath="/usr/local/mrtg/etc"; $confname="mrtg-script-builded.conf"; $logpath="/var/log/mrtg"; @path=($wwwpath,$confpath,$logpath); foreach $path (@path) { if ( not (-d $path) ) { mkdir $path; print `ls $path/.`; } } #mrtg autoconf declaration $global = " --ifref=eth"; $global.= " --ifdesc=descr"; $global.= " --global 'RunAsDaemon: Yes'"; $global.= " --global 'Interval: 10'"; $global.= " --global 'Refresh: 600'"; $global.= " --global 'WorkDir: $wwwpath'"; #$global.= " --global 'Htmldir: $wwwpath'"; #$global.= " --global 'Imagedir: $wwwpath'"; #$global.= " --global 'Logdir: $logpath'"; $global.= " --global 'LogFormat: rrdtool'"; $global.= " --global 'PathAdd: /usr/bin'"; $global.= " --global 'LibAdd: /usr/share/perl5'"; $global.= " --global 'Forks: 4'"; $global.= " --global 'Options[_]: bits,growright'"; $subdir = " --subdirs=HOSTNAME"; $output = " --output='$confpath/$confname'"; $community = " --community=public"; # ping to verify that an target exist foreach $ip (@host) { if ($p->ping($ip, 0.5)) { printf "Add $ip\n"; $host.= " $ip"; } else { printf "Host $ip not added (no echo)\n"; } } # do mrtg conf printf "************* DO : \n"; $cmd = "/usr/bin/cfgmaker $global $subdir $output $community $host"; $log = "$cmd\n" . `$cmd` . "\nFIN $cmd\n\n"; #$cmd = "/usr/bin/indexmaker --section=title --show=week --columns=2 --output=$wwwpath/index.html $confpath/$confname"; #$log.= "$cmd\n" . `$cmd` . "\nFIN $cmd\n\n"; #$log.= `/usr/bin/indexmaker --section=name --show=week --columns=6 --output=$wwwpath/index.html $confpath/$confname`; printf "\n$log\n************* FIN !\n\n"; $p->close(); EOF_mrtg-conf-builder * And now to build our first mrtg.conf : # chmod +x /usr/local/mrtg/bin/mrtg-enpc-conf-builder # /usr/local/mrtg/bin/mrtg-enpc-conf-builder =============== mrtg init script =============== cat >/etc/init.d/mrtg <>/var/log/mrtg/lance_mrtg.log 2>&1 echo . fi ;; stop) echo -n "Stopping mrtg" if [ -f $PID_FILE ] then /bin/kill `/bin/cat $PID_FILE` echo . fi ;; *) echo "Usage: /etc/init.d/netdisco {start|stop}" exit 1 esac exit 0 EOF * get it at boot : # chmd 755 /etc/init.d/mrtg # update-rc.d mrtg defaults 88 20 * else to start mrtg manualy : # mrtg --user=mrtg --group=mrtg /usr/local/mrtg/etc/mrtg-script-builded.conf =============== daily topology update =============== cat > /etc/cron.daily/mrtg <>/etc/logrotate.d/mrtg <>/usr/local/postgress/data/pg_hba.conf < install GraphViz * done =============== apache =============== # apt-get -u install apache-perl apache-doc libapache-mod-perl-doc libmailtools-perl libhtml-format-perl cat >>/etc/apache-perl/httpd.conf < 'netdiscoISC'] [db_Pg_pw = netdisco_new_passwd] * done # su netdisco $ cd /usr/local/netdisco/sql ; ./pg_run $ cd /usr/local/netdisco/sql ; ./pg_all * Do not care on errors ... * get CISCO mibs # cd /usr/local/src/netdisco ; wget -nH -nd ftp://ftp.cisco.com/pub/mibs/v1/v1.tar.gz # cd /usr/local/src/netdisco ; wget -nH -nd ftp://ftp.cisco.com/pub/mibs/v2/v2.tar.gz # cd /usr/share/snmp/mibs/ ; tar xzvf /usr/local/src/netdisco/v2.tar.gz # cd /usr/share/snmp/mibs/ ; tar xzvf /usr/local/src/netdisco/v1.tar.gz BRIDGE-MIB.my SNMP-REPEATER-MIB.my ESSWITCH-MIB.my TOKEN-RING-RMON-MIB.my * get OUI database (Organizationally Unique Identifier for MAC address) # cd /usr/local/netdisco # wget http://standards.ieee.org/regauth/oui/oui.txt # apt-get -u install libdbi-perl libpg-perl libdbd-pg-perl # su netdisco -c "./netdisco -O" * edit and modify netdisco.conf domain = ... compress = /bin/gzip -f db_Pg_pw = ... node_font = /usr/local/netdisco/lucon.ttf * done * edit and modify netdisco_apache.conf mettre a jour les champs suivants: session_password #session_cookie_domain * done * add netdisco.crontab in netdisco user crontab # crontab -e -u netdisco :r /usr/local/netdisco/netdisco :wq * add netdisco web admin (here with pwd netdisco) # su netdisco -c "/usr/local/netdisco/netdisco -u admin netdisco * first test we need a new mibs BUG ? # /usr/local/netdisco/netdisco -d rgi24 # cd /usr/local/share/snmp/mibs # wget http://www.simpleweb.org/ietf/mibs/modules/IETF/txt/RFC1271-MIB * some manual configuration #cd /usr/local/netdisco #su netdisco -c "./netdisco -r 195.221.109.1" * no more to do : we have a CDP enabled network... =============== netdisco init script =============== cat >/etc/init.d/netdisco </usr/local/src/netdisco/netdisco_html_device.html.patch <{remote_port}; my $remote_id = $port->{remote_id}; my $remote_type = $port->{remote_type}; - my $remote_portm = ''; my $up_admin = $port->{up_admin} || ''; my $stp = $port->{stp} || ''; my $up = $port->{up} || ''; @@ -436,7 +435,7 @@ my $rowclass = (++$odd % 2 ) ? 'match-0': 'match-1'; - <% $port->{portdisp} %> + <% $port->{portdisp} %> <%perl> foreach my $col (sort keys %port_cols){ my $colname = $port_cols{$col}->[0]; @@ -460,7 +459,7 @@ if (defined $remote_ip) { my $name = ''; my $link = ''; - my $remote_dev = sql_hash('device',['ip','dns','name','location'], + my $remote_dev = sql_hash('device',['ip','dns'], {'ip'=>$remote_ip}); my $alias = sql_hash('device_ip',['ip','dns'], {'alias'=>$remote_ip}); @@ -479,7 +478,7 @@ $name = $remote_dev->{'dns'}; $name = defined $name ? $name : $remote_ip; $name =~ s/\Q$domain\E//; - $name .= " ($remote_port) | $remote_dev->{name}\@$remote_dev->{location}"; + $name .= " ($remote_port)"; $name = "$name"; $link = "device.html?ip=$remote_ip&port=$remote_port"; @@ -500,7 +499,7 @@ $link = "node.html?node=$remote_ip"; } - <%$name%> \ + <%$name%> \ <%perl> } $m->out("
\n") if (defined $remote_ip and defined $port->{macs}); @@ -551,18 +550,6 @@ % # Port Control Column \ - -% if ( $port->{port} !~ /vlan|Administrati|Etudiants|Externe|Hertzien|Recherche|Residence|Test/i and $class eq "port-up") { -% my $portm = $port->{mac}; -% $portm =~ tr/A-Z/a-z/; -% $portm =~ tr/_ @:^\//-/; -% $portm =~ s/--/-/g; -% my $image = 'weekly-graph '; - <% $image %> -% } - % if ($device->{dns} =~ /^hub/i and $port_info) { Pinnacles DB Info \ % } EOF___netdisco_html_device.html.patch # cd /usr/local/netdisco/html # patch -b -p0