Difference between revisions of "Netband Project - Ubuntu server"
From Teknologisk videncenter
(→Perl Scripts) |
m (→Perl Scripts) |
||
Line 82: | Line 82: | ||
If you want a index page to show all the mrtg graphs in one page create a new textfile and name it index.pl in your mrtg root folder. | If you want a index page to show all the mrtg graphs in one page create a new textfile and name it index.pl in your mrtg root folder. | ||
The indexfile should look like this | The indexfile should look like this | ||
− | <pre> | + | <pre>#!/usr/bin/perl -w |
− | #!/usr/bin/perl -w | ||
############################################# | ############################################# | ||
# This script is copyrighted Rasmus Elmholt # | # This script is copyrighted Rasmus Elmholt # | ||
Line 127: | Line 126: | ||
} | } | ||
close(MRTGFILE); | close(MRTGFILE); | ||
+ | |||
print "</body></html>\n"; | print "</body></html>\n"; |
Revision as of 13:25, 20 April 2009
<accesscontrol>NetBand</accesscontrol> This page is part of the Netband Project
Contents
OS version:
Applications:
FreeNac
- Dynamic Virtual LAN management and assignment per end-device
- LAN Access control (authentication, authorization)
MRTG
- Network monitoring
1. Install the MRTG package
$ sudo aptitude install mrtg
2. Create the initial config file and poll a device
sudo cfgmaker --output /home/mrtg/mrtg.cfg ciscodisco@10.0.0.21
# Created by # /usr/bin/cfgmaker --output /home/mrtg/10.0.0.21.cfg ciscodisco@10.0.0.21 ### Global Config Options # for UNIX # WorkDir: /home/http/mrtg # for Debian WorkDir: /var/www/mrtg # or for NT # WorkDir: c:\mrtgdata ### Global Defaults # to get bits instead of bytes and graphs growing to the right # Options[_]: growright, bits EnableIPv6: no Include: /home/mrtg/10.0.0.21
For more information see cfgmaker
3. Either create additional cfg files for other devices, and copy/paste the relevant parts to the mrtg.cfg file or add them manually
4. Start MRTG
$ sudo env LANG=C /usr/bin/mrtg /home/mrtg/mrtg.cfg
5. Make MRTG run every 5 minutes
$sudo crontab -e # m h dom mon dow command */5 * * * * env LANG=C /usr/bin/mrtg /home/mrtg/mrtg.cfg --logging /var/log/mrtg/mrtg.log
Make apache run perl script
This will install perl module in apache
$ aptitude install libapache2-mod-perl2
This addition in /etc/apache2/apache2.conf configuration file will allow cgi and perl script to be run in every directory, not just cgi-bin/.
AddHandler cgi-script .cgi .pl <Files ~ "\.pl$"> Options +ExecCGI </Files> <Files ~ "\.cgi$"> Options +ExecCGI </Files>
Perl Scripts
If you want a index page to show all the mrtg graphs in one page create a new textfile and name it index.pl in your mrtg root folder. The indexfile should look like this
#!/usr/bin/perl -w ############################################# # This script is copyrighted Rasmus Elmholt # ############################################# use strict; use CGI::Carp qw(fatalsToBrowser); print "Content-type: text/html\n\n"; print '<?xml version="1.0" encoding="iso-8859-1"?>' , "\n"; print '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"' , "\n"; print '"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">' , "\n"; print '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="da">' , "\n"; print "<head><title>MRTG Network Monitoring</title></head><body>\n"; open(MRTGFILE, "/home/mrtg/mrtg.cfg"); while(my $line = <MRTGFILE>) { if($line =~ /^Include:/) { $line =~ /^Include:\s(.*)/; open(MRTGFILE1, $1); #print "Found Include file"; while(my $line1 = <MRTGFILE1>) { #print "line in Include: $line1<br>"; if($line1 =~ /^PageTop/) { $line1 =~ /^PageTop\[(.*)\]:\s(.*)/; my $url = lc($1); print "<a href=\"$url.html\">$2</a><img src=\"$url-day.png\" /><img src=\"$url-week.png\" /><br /><br />"; } } } if($line =~ /^PageTop/) { $line =~ /^PageTop\[(.*)\]:\s(.*)/; my $url = lc($1); print "<a href=\"$url.html\">$2</a><img src=\"$url-day.png\" /><img src=\"$url-week.png\" /><br /><br />"; } } close(MRTGFILE); print "</body></html>\n";