Skip to content

Commit a397360

Browse files
committedMay 5, 2012
netweathermap 1.1.1
1 parent e0912e2 commit a397360

12 files changed

+1401
-0
lines changed
 

‎CHANGELOG

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
v1.1.1: 3 Apr 2004
2+
Added -c and -o options.
3+
4+
v1.1.0: 1 Feb 2004
5+
Initial public release.
6+
7+
--
8+
p.christias@noc.ntua.gr

‎INSTALL

+146
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
Network Weathermap
2+
version 1.1.1 (20040422)
3+
Panagiotis Christias, p.christias@noc.ntua.gr
4+
5+
6+
1. Description
7+
8+
The network weathermap displays in a visual way the utilization of
9+
network links. The required data are acquired from graphs created
10+
arrows on a map representing the logical topology of the network.
11+
The resulted image is presented in a web page using extra DHTML and
12+
JavaScript code for web-over pop-ups, based on the OverLib JavaScript
13+
library. The image can be automatically generated via cron.
14+
15+
16+
2. Required software
17+
18+
The network weathermap is written in Perl programming language. It is
19+
using the GD perl module for opening, manipulating and writing image
20+
files. The GD module requires the Gd Graphics Library (libgd). The Gd
21+
Graphics Library requires several libraries like freetype, libjpeg,
22+
libpng and libz.
23+
24+
The current version of the network weathermap does not do any SNMP data
25+
acquisition but relies on MRTG for that task since MRTG does it in a
26+
simple and effective way. MRTG stores the values of the last SNMP query
27+
as HTML comments within the HTML file that creates for each network link:
28+
29+
<!-- maxin d 128563 --> <!-- maxout d 29795 -->
30+
<!-- avin d 17219 --> <!-- avout d 18115 -->
31+
<!-- cuin d 11369 --> <!-- cuout d 19663 -->
32+
<!-- avmxin d 23106 --> <!-- avmxout d 18598 -->
33+
34+
The network weathermap retrieves the HTML files directly from the file
35+
system or remotely from a specified web server using GNU wget, parses
36+
them and uses the current in and out values (cuin d and cuout d values)
37+
to generate the map.
38+
39+
40+
3. Installation and configuration
41+
42+
Perl, libgd and the GD perl modules, optionally wget too, should be
43+
installed and be available in the system that will host the network
44+
weathermap. MRTG should be installed, configured and run regularly for
45+
the network links that will be displayed on the network weathermap.
46+
The MRTG setup is not required to run on the same system with the
47+
network weathermap. Nevertheless, the network weathermap should have
48+
access the HTML files generated by MRTG. That can be direct file
49+
system access or any network method supported by wget (HTTP, HTTPS,
50+
FTP etc.).
51+
52+
The network weathermap is a single Perl script. There are 6 parameters
53+
that are defined in the first lines of the script:
54+
55+
1. the full path of the wget utility with its arguments:
56+
$WGET="/usr/local/bin/wget -qO -";
57+
58+
2. the full path of the default configuration file, which can also be
59+
defined through the "-c" command line option:
60+
$CONFIG = "weathermap.conf";
61+
62+
3. the full path of the output image file, which can also be defined
63+
through the "-o" command line option:
64+
$OUTPUT = "weathermap.png";
65+
66+
4. the debug parameter, which can be accessed through the "-v"
67+
command line option:
68+
$DEBUG = 0;
69+
70+
5. the default wight and height of the output image in case no
71+
background image is defined in the configuration file:
72+
$WIDTH = 880;
73+
$HEIGHT = 750;
74+
75+
The configuration of the network weathermap is defined in a single text
76+
file (weathermap.conf). It includes the definition of:
77+
78+
* nodes: name (NODE xxx), position on the image (POSITION x y) and
79+
label (LABEL zzz)
80+
81+
* links: name (LINK xxx), start and end nodes (NODES xxx yyy), HTML
82+
file from MRTG (TARGET /xxx/yyy/zzz.hmtl or TARGET http://xxx/zzz.html
83+
etc). and bandwidth of the link (BANDWIDTH y) in Kbps.
84+
85+
* image used as background (BACKGROUND /xxx/yyy/zzz.gif) or
86+
alternatively the size of the resulted image (WIDTH x and HEIGHT y).
87+
88+
* position of the key in the image (KEYPOS x y )
89+
90+
* color scale used for the link utilization (SCALE low hight rrr ggg bbb)
91+
92+
White spaces and empty lines are ignored. Shell-like comments (#...) are
93+
supported.
94+
95+
See example/ directory for a sample configuration.
96+
97+
A HTML page can be written to host the network weathermap image. This
98+
page can use HTML, DHTML and JavaScript features in order to create an
99+
"interactive" version of the network weathermap using imagemaps and
100+
web-over pop-ups displaying the MRTG graphs and linking to the MRTG pages.
101+
102+
Again, see example/ directory for such HTML files (weathermap.html and
103+
weathermap-overlib.html).
104+
105+
The network weathermap can be executed via cron with a crontab entry
106+
like:
107+
108+
*/5 * * * * /path/to/weathermap > /tmp/weathermap.out 2>&1
109+
110+
111+
4. Links to used software
112+
113+
Perl programming language:
114+
http://www.perl.org/
115+
116+
GD Graphics Library:
117+
http://www.boutell.com/gd/
118+
119+
GD perl module:
120+
http://stein.cshl.org/WWW/software/GD/
121+
or http://www.cpan.org/
122+
123+
MRTG, The Multi Router Traffic Grapher:
124+
http://people.ee.ethz.ch/~oetiker/webtools/mrtg/
125+
126+
GNU wget:
127+
http://www.gnu.org/software/wget/wget.html
128+
129+
overLIB:
130+
http://www.bosrup.com/web/overlib/
131+
132+
133+
5. Usage examples:
134+
135+
6NET:
136+
http://netmon.grnet.gr/6net.html
137+
138+
GRNET:
139+
http://netmon.grnet.gr/map.shtml
140+
141+
GRNET Athens MAN:
142+
http://netmon.grnet.gr/map-man.shtml
143+
144+
SEEREN:
145+
http://netmon.grnet.gr/seeren.shtml
146+

‎LICENSE

+340
Large diffs are not rendered by default.

‎README

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Network Weathermap
2+
version 1.1.1 (20040422)
3+
4+
A perl tool that displays in a visual way the utilization of the
5+
network links of your network. The required data are acquired from
6+
graphs created by the MRTG package and are displayed as two ways
7+
colored arrows on a map representing the logical topology
8+
of the network.
9+
10+
See INSTALL file for the installation and configuration guide.
11+
12+
See http://netmon.grnet.gr/weathermap/ for updates.
13+
14+
The Network Weathermap is developed by Panagiotis Christias
15+
<p.christias@noc.ntua.gr>. It may be used, modified and redistributed
16+
only under the terms of the GNU General Public License, found in the
17+
file LICENSE in this distribution, or at
18+
19+
http://www.fsf.org/licenses/gpl.html

‎example/overlib_mini.js

+328
Large diffs are not rendered by default.

‎example/weathermap-background.png

49.5 KB
Loading

‎example/weathermap-overlib.html

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<HTML>
2+
<HEAD>
3+
<TITLE>weathermap</TITLE>
4+
</HEAD>
5+
<BODY BGCOLOR=#FFFFFF LEFTMARGIN=0 TOPMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0>
6+
7+
<DIV id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></DIV>
8+
<SCRIPT language="JavaScript" src="overlib_mini.js"><!-- overLIB (c) Erik Bosrup --></SCRIPT>
9+
10+
11+
12+
<IMG SRC="weathermap.png" WIDTH=750 HEIGHT=660 BORDER=0 ALT="" USEMAP="#weathermap_Map">
13+
<MAP NAME="weathermap_Map">
14+
<AREA
15+
SHAPE="poly"
16+
COORDS="231,215, 217,209, 223,177, 237,131, 254,110, 264,113, 261,139, 248,188"
17+
ONMOUSEOVER="return overlib('<img src=http://netmon.grnet.gr/traffic/larissa/larissa-athens-atm.grnet.gr-day.png>', CAPTION, 'Backbone Thessaloniki - Larissa', CENTER, FIXX, 120);" onmouseout="return nd();"
18+
HREF="http://netmon.grnet.gr/traffic/larissa/larissa-athens-atm.grnet.gr.html">
19+
<AREA
20+
SHAPE="poly"
21+
COORDS="400,67, 379,190, 367,243, 331,357, 321,352, 336,234, 349,181, 387,65"
22+
ONMOUSEOVER="return overlib('<img src=http://netmon.grnet.gr/traffic/athens/xanthi-duth-atm.grnet.gr-day.png>', CAPTION, '[GRNET-ATH-XAN-1] Backbone Athens - Xanthi', CENTER, FIXX, 120);" onmouseout="return nd();"
23+
HREF="http://netmon.grnet.gr/traffic/athens/xanthi-duth-atm.grnet.gr.html">
24+
<AREA
25+
SHAPE="poly"
26+
COORDS="324,357, 311,257, 300,205, 271,113, 261,115, 272,212, 285,265, 314,358"
27+
ONMOUSEOVER="return overlib('<img src=http://netmon.grnet.gr/traffic/athens/athens-thessaloniki-atm.grnet.gr-day.png>', CAPTION, '[GRNET-ATH-THE-1] Backbone Athens - Thessaloniki ATM', CENTER, FIXX, 120);" onmouseout="return nd();"
28+
HREF="http://netmon.grnet.gr/traffic/athens/athens-thessaloniki-atm.grnet.gr.html">
29+
<AREA
30+
SHAPE="poly"
31+
COORDS="105,213, 116,202, 201,258, 244,289, 316,353, 310,361, 228,313, 180,281"
32+
ONMOUSEOVER="return overlib('<img src=http://netmon.grnet.gr/traffic/athens/athens-uoi.grnet.gr-day.png>', CAPTION, '[GRNET-ATH-IOA-1] Backbone Athens - Ioannina', CENTER, FIXX, 120);" onmouseout="return nd();"
33+
HREF="http://netmon.grnet.gr/traffic/athens/athens-uoi.grnet.gr.html">
34+
<AREA
35+
SHAPE="poly"
36+
COORDS="181,332, 187,318, 229,324, 280,340, 316,357, 309,369, 273,365, 220,351"
37+
ONMOUSEOVER="return overlib('<img src=http://netmon.grnet.gr/traffic/athens/athens-patra-atm.grnet.gr-day.png>', CAPTION, '[GRNET-ATH-PAT-1] Backbone Athens - Patra', CENTER, FIXX, 120);" onmouseout="return nd();"
38+
HREF="http://netmon.grnet.gr/traffic/athens/athens-patra-atm.grnet.gr.html">
39+
<AREA
40+
SHAPE="poly"
41+
COORDS="311,375, 304,364, 226,384, 174,402, 98,441, 104,452, 188,429, 238,410"
42+
ONMOUSEOVER="return overlib('<img src=http://netmon.grnet.gr/traffic/athens-3/grnet-gw.gr1.gr.geant.net-day.png>', CAPTION, '[GRNET-ATH-GEANT-3] POS GEANT', CENTER, FIXX, 120);" onmouseout="return nd();"
43+
HREF="http://netmon.grnet.gr/traffic/athens-3/grnet-gw.gr1.gr.geant.net.html">
44+
<AREA
45+
SHAPE="poly"
46+
COORDS="317,376, 330,373, 374,455, 396,507, 424,603, 412,606, 367,518, 347,468"
47+
ONMOUSEOVER="return overlib('<img src=http://netmon.grnet.gr/traffic/athens/athens-heraklio-atm.grnet.gr-day.png>', CAPTION, '[GRNET-ATH-HER-1] Backbone Athens - Heraklio ATM', CENTER, FIXX, 120);" onmouseout="return nd();"
48+
HREF="http://netmon.grnet.gr/traffic/athens/athens-heraklio-atm.grnet.gr.html">
49+
<AREA
50+
SHAPE="poly"
51+
COORDS="336,358, 374,350, 430,350, 470,357, 470,373, 430,380, 375,380, 336,372"
52+
ONMOUSEOVER="return overlib('<img src=http://netmon.grnet.gr/traffic/athens-3/grnet.aix.gr-day.png>', CAPTION, '[GRNET-ATH-AIX-2] Athens Internet EXchange', CENTER, FIXX, 120);" onmouseout="return nd();"
53+
HREF="http://netmon.grnet.gr/traffic/athens-3/grnet.aix.gr.html">
54+
</MAP>
55+
56+
</BODY>
57+
</HTML>

‎example/weathermap.conf

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
BACKGROUND weathermap-background.png
2+
3+
KEYPOS 1 520
4+
5+
# low high red green blue
6+
SCALE 1 10 140 0 255
7+
SCALE 10 25 32 32 255
8+
SCALE 25 40 0 192 255
9+
SCALE 40 55 0 240 0
10+
SCALE 55 70 240 240 0
11+
SCALE 70 85 255 192 0
12+
SCALE 85 100 255 0 0
13+
14+
15+
NODE athens3
16+
POSITION 320 365
17+
LABEL ATH
18+
19+
NODE athens2
20+
POSITION 320 365
21+
LABEL ATH
22+
23+
NODE athens
24+
POSITION 320 365
25+
LABEL ATH
26+
27+
NODE thessaloniki
28+
POSITION 262 105
29+
LABEL THE
30+
31+
NODE heraklio
32+
POSITION 420 612
33+
LABEL HER
34+
35+
NODE patra
36+
POSITION 180 325
37+
LABEL PAT
38+
39+
NODE ioannina
40+
POSITION 105 206
41+
LABEL IOA
42+
43+
NODE xanthi
44+
POSITION 395 60
45+
LABEL XAN
46+
47+
NODE larissa
48+
POSITION 225 210
49+
LABEL LAR
50+
51+
NODE aix
52+
POSITION 485 365
53+
LABEL AIX
54+
55+
NODE geant
56+
POSITION 90 450
57+
LABEL GEANT
58+
59+
LINK ath-the
60+
NODES athens thessaloniki
61+
TARGET http://netmon.grnet.gr/traffic/athens/athens-thessaloniki-atm.grnet.gr.html
62+
BANDWIDTH 70656
63+
64+
LINK ath-pat
65+
NODES athens patra
66+
TARGET http://netmon.grnet.gr/traffic/athens/athens-patra-atm.grnet.gr.html
67+
BANDWIDTH 46080
68+
69+
LINK ath-her
70+
NODES athens heraklio
71+
TARGET http://netmon.grnet.gr/traffic/athens/athens-heraklio-atm.grnet.gr.html
72+
BANDWIDTH 61440
73+
74+
LINK ath-ioa
75+
NODES athens ioannina
76+
TARGET http://netmon.grnet.gr/traffic/athens/athens-uoi.grnet.gr.html
77+
BANDWIDTH 22528
78+
79+
LINK ath-xan
80+
NODES athens xanthi
81+
TARGET http://netmon.grnet.gr/traffic/athens/xanthi-duth-atm.grnet.gr.html
82+
BANDWIDTH 21094
83+
84+
LINK lar-the
85+
NODES larissa thessaloniki
86+
TARGET http://netmon.grnet.gr/traffic/larissa/larissa-athens-atm.grnet.gr.html
87+
BANDWIDTH 18432
88+
89+
LINK ath-aix
90+
NODES athens3 aix
91+
TARGET http://netmon.grnet.gr/traffic/athens-3/grnet.aix.gr.html
92+
BANDWIDTH 97656
93+
94+
LINK ath-geant
95+
NODES athens3 geant
96+
TARGET http://netmon.grnet.gr/traffic/athens-3/grnet-gw.gr1.gr.geant.net.html
97+
BANDWIDTH 1214843

‎example/weathermap.html

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<HTML>
2+
<HEAD>
3+
<TITLE>weathermap</TITLE>
4+
</HEAD>
5+
<BODY BGCOLOR=#FFFFFF LEFTMARGIN=0 TOPMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0>
6+
7+
<IMG SRC="weathermap.png" WIDTH=750 HEIGHT=660 BORDER=0 ALT="" USEMAP="#weathermap_Map">
8+
<MAP NAME="weathermap_Map">
9+
<AREA SHAPE="poly" COORDS="231,215, 217,209, 223,177, 237,131, 254,110, 264,113, 261,139, 248,188" HREF="http://netmon.grnet.gr/traffic/larissa/larissa-athens-atm.grnet.gr.html">
10+
<AREA SHAPE="poly" COORDS="400,67, 379,190, 367,243, 331,357, 321,352, 336,234, 349,181, 387,65" HREF="http://netmon.grnet.gr/traffic/athens/xanthi-duth-atm.grnet.gr.html">
11+
<AREA SHAPE="poly" COORDS="324,357, 311,257, 300,205, 271,113, 261,115, 272,212, 285,265, 314,358" HREF="http://netmon.grnet.gr/traffic/athens/athens-thessaloniki-atm.grnet.gr.html">
12+
<AREA SHAPE="poly" COORDS="105,213, 116,202, 201,258, 244,289, 316,353, 310,361, 228,313, 180,281" HREF="http://netmon.grnet.gr/traffic/athens/athens-uoi.grnet.gr.html">
13+
<AREA SHAPE="poly" COORDS="181,332, 187,318, 229,324, 280,340, 316,357, 309,369, 273,365, 220,351" HREF="http://netmon.grnet.gr/traffic/athens/athens-patra-atm.grnet.gr.html">
14+
<AREA SHAPE="poly" COORDS="311,375, 304,364, 226,384, 174,402, 98,441, 104,452, 188,429, 238,410" HREF="http://netmon.grnet.gr/traffic/athens-3/grnet-gw.gr1.gr.geant.net.html">
15+
<AREA SHAPE="poly" COORDS="317,376, 330,373, 374,455, 396,507, 424,603, 412,606, 367,518, 347,468" HREF="http://netmon.grnet.gr/traffic/athens/athens-heraklio-atm.grnet.gr.html">
16+
<AREA SHAPE="poly" COORDS="336,358, 374,350, 430,350, 470,357, 470,373, 430,380, 375,380, 336,372" HREF="http://netmon.grnet.gr/traffic/athens-3/grnet.aix.gr.html">
17+
</MAP>
18+
19+
</BODY>
20+
</HTML>

‎example/weathermap.png

41.1 KB
Loading

‎weathermap

+386
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,386 @@
1+
#!/usr/bin/perl
2+
# Network Wearthermap - version 1.1.1 (20040422)
3+
# http://netmon.grnet.gr/weathermap/
4+
# Panagiotis Christias, <christias@noc.ntua.gr>
5+
6+
$VERSION = "1.1.1";
7+
8+
use Getopt::Long;
9+
use GD;
10+
11+
################################################################
12+
#
13+
# Configuration parameters
14+
#
15+
$WGET = "/usr/local/bin/wget -qO -";
16+
$CONFIG = "weathermap.conf";
17+
$OUTPUT = "weathermap.png";
18+
$DEBUG = 0;
19+
$WIDTH = 880;
20+
$HEIGHT = 750;
21+
#
22+
################################################################
23+
24+
25+
%optctl=();
26+
GetOptions(\%optctl, "config:s", "output:s", "version", "help", "debug", "") || exit(1);
27+
28+
if($optctl{"config"}) { $CONFIG = $optctl{"config"} };
29+
30+
if($optctl{"output"}) { $OUTPUT = $optctl{"output"} };
31+
32+
if($optctl{"version"}) { &version; exit; }
33+
34+
if($optctl{"help"}) { &usage; exit; }
35+
36+
if($optctl{"debug"}) { $DEBUG=1; }
37+
38+
&read_config($CONFIG);
39+
40+
if($background){
41+
open (PNG,"$background") || die "$background: $!\n";
42+
$map = newFromPng GD::Image(PNG) || die "newFromPng failed.";
43+
close PNG;
44+
} else {
45+
$map=new GD::Image($WIDTH,$HEIGHT)
46+
}
47+
48+
&alloc_colors;
49+
50+
print "Opening log files...\n\n" if($DEBUG);
51+
foreach $link (keys %target){
52+
53+
$data = $target{$link};
54+
print "FILE: $data\n" if($DEBUG);
55+
56+
if(($data =~ /^https?:\/\//i) || ($data =~ /^ftp:\/\//i) ) {
57+
open(LOG, "$WGET $data |") or warn "$data: $!\n";
58+
} else {
59+
open(LOG, "$data") or warn "data file $data: $!\n";
60+
}
61+
62+
while(<LOG>){
63+
# <!-- cuin d 5585966 -->
64+
# <!-- cuout d 10589424 -->
65+
if(/<\!-- cuin d (\d+) -->/){
66+
$input{$link}=$1;
67+
print "LINK: $link, Input: $input{$link}\n" if($DEBUG);
68+
}
69+
if(/<\!-- cuout d (\d+) -->/){
70+
$output{$link}=$1;
71+
print "LINK: $link, Output: $output{$link}\n" if($DEBUG);
72+
}
73+
}
74+
close(LOG);
75+
}
76+
77+
print "\nCalculating rates...\n\n" if($DEBUG);
78+
79+
foreach $link (keys %target){
80+
$outrate=(int(($output{$link}/$maxbytes{$link}+0.005)*100)>100) ? 100:int(($output{$link}/$maxbytes{$link}+0.005)*100);
81+
$inrate=(int(($input{$link}/$maxbytes{$link}+0.005)*100)>100) ? 100:int(($input{$link}/$maxbytes{$link}+0.005)*100);
82+
83+
if($output{$link} != 0 && $outrate == 0) { $outrate=1 }
84+
if($input{$link} != 0 && $inrate == 0) { $inrate=1 }
85+
86+
print "$target{$link}: outrate=$outrate%, inrate=$inrate%\n" if($DEBUG);
87+
88+
# draw lines...
89+
90+
$width=7;
91+
92+
&draw_arrow(
93+
$xpos{$nodea{$link}},
94+
$ypos{$nodea{$link}},
95+
&middle($xpos{$nodea{$link}},$xpos{$nodeb{$link}}),
96+
&middle($ypos{$nodea{$link}},$ypos{$nodeb{$link}}),
97+
$width, 1, &select_color($outrate));
98+
&draw_arrow(
99+
$xpos{$nodea{$link}},
100+
$ypos{$nodea{$link}},
101+
&middle($xpos{$nodea{$link}},$xpos{$nodeb{$link}}),
102+
&middle($ypos{$nodea{$link}},$ypos{$nodeb{$link}}),
103+
$width, 0, $black);
104+
105+
&label(&middle($xpos{$nodea{$link}},&middle($xpos{$nodea{$link}},$xpos{$nodeb{$link}})),
106+
&middle($ypos{$nodea{$link}},&middle($ypos{$nodea{$link}},$ypos{$nodeb{$link}})),
107+
$outrate . "%", 0);
108+
109+
&draw_arrow(
110+
$xpos{$nodeb{$link}},
111+
$ypos{$nodeb{$link}},
112+
&middle($xpos{$nodea{$link}},$xpos{$nodeb{$link}}),
113+
&middle($ypos{$nodea{$link}},$ypos{$nodeb{$link}}),
114+
$width, 1, &select_color($inrate));
115+
&draw_arrow(
116+
$xpos{$nodeb{$link}},
117+
$ypos{$nodeb{$link}},
118+
&middle($xpos{$nodea{$link}},$xpos{$nodeb{$link}}),
119+
&middle($ypos{$nodea{$link}},$ypos{$nodeb{$link}}),
120+
$width, 0, $black);
121+
122+
&label(&middle($xpos{$nodeb{$link}},&middle($xpos{$nodea{$link}},$xpos{$nodeb{$link}})),
123+
&middle($ypos{$nodeb{$link}},&middle($ypos{$nodea{$link}},$ypos{$nodeb{$link}})),
124+
$inrate . "%", 0);
125+
}
126+
print "\n" if($DEBUG);
127+
128+
foreach(keys %xpos){
129+
&label($xpos{$_},$ypos{$_},$label{$_}, 3);
130+
}
131+
132+
133+
&annotation;
134+
135+
# print image...
136+
print "Generating image file $OUTPUT...\n\n" if($DEBUG);
137+
open(PNG,">$OUTPUT")||die("$OUTPUT: $!\n");
138+
print PNG $map->png;
139+
close PNG;
140+
141+
# hint, resizing the image could make it look better
142+
143+
exit;
144+
145+
146+
# print labels
147+
sub label{
148+
my($xpos,$ypos,$label,$pad)=@_;
149+
my($strwidth)=gdLargeFont->width*length($label);
150+
my($strheight)=gdLargeFont->height;
151+
$map->filledRectangle(
152+
$xpos-$strwidth/2-$pad-2, $ypos-$strheight/2-$pad+1,
153+
$xpos+$strwidth/2+$pad+1, $ypos+$strheight/2+$pad,
154+
$black);
155+
$map->filledRectangle(
156+
$xpos-$strwidth/2-$pad-1, $ypos-$strheight/2-$pad+2,
157+
$xpos+$strwidth/2+$pad, $ypos+$strheight/2+$pad-1,
158+
$white);
159+
$map->string(gdLargeFont,
160+
$xpos-$strwidth/2, $ypos-$strheight/2+1,
161+
$label, $black)
162+
}
163+
164+
165+
# print annotation
166+
sub annotation{
167+
my($title)="Traffic load";
168+
$strwidth=gdLargeFont->width*length($label{$_});
169+
$strheight=gdLargeFont->height;
170+
171+
# $t=localtime(time);
172+
$t=gmtime(time);
173+
$map->string(gdSmallFont, 0, 785, "Last update on $t UTC", $black);
174+
175+
$map->filledRectangle($keyxpos,$keyypos,
176+
$keyxpos+gdLargeFont->width*length($title)+10,
177+
$keyypos+gdLargeFont->height*($scales+1)+10,
178+
$gray);
179+
$map->rectangle($keyxpos,$keyypos,
180+
$keyxpos+gdLargeFont->width*length($title)+10,
181+
$keyypos+gdLargeFont->height*($scales+1)+10,
182+
$black);
183+
$map->string(gdLargeFont,
184+
$keyxpos+4,
185+
$keyypos+4,
186+
"Traffic load", $black);
187+
188+
my($i)=1;
189+
foreach(sort {$scale_low{$a}<=>$scale_low{$b}} keys %scale_low){
190+
$map->filledRectangle(
191+
$keyxpos+6,
192+
$keyypos+gdLargeFont->height*$i+8,
193+
$keyxpos+6+16,
194+
$keyypos+gdLargeFont->height*$i+gdLargeFont->height+6,
195+
$color{$_});
196+
$map->string(gdLargeFont,
197+
$keyxpos+6+20,
198+
$keyypos+gdLargeFont->height*$i+8,
199+
"$scale_low{$_}-$scale_high{$_}%", $black);
200+
$i++
201+
}
202+
}
203+
204+
sub select_color {
205+
my($rate)=($_[0]>100) ? 100:$_[0];
206+
if($rate=="0"){return($darkgray)}
207+
foreach(sort {$scale_high{$a}<=>$scale_high{$b}} keys %scale_high){
208+
if($scale_low{$_}<=$rate && $rate<=$scale_high{$_}){
209+
return($color{$_});
210+
}
211+
}
212+
}
213+
214+
sub alloc_colors {
215+
$white=$map->colorAllocate(255,255,255);
216+
$gray=$map->colorAllocate(248,248,248);
217+
$black=$map->colorAllocate(0,0,0);
218+
$darkgray=$map->colorAllocate(128,128,128);
219+
220+
foreach(keys %scale_red){
221+
$color{$_} = $map->colorAllocate($scale_red{$_},$scale_green{$_},$scale_blue{$_});
222+
}
223+
}
224+
225+
226+
sub read_config {
227+
my($config)=shift;
228+
my($node,$link);
229+
230+
print "\nReading configuration file...\n\n" if($DEBUG);
231+
232+
$scales=0;
233+
open(CONF,$config) or die "$config: $!\n";
234+
while(<CONF>){
235+
if(/^\s*BACKGROUND\s+(\S+)/i){
236+
if(-s "$1"){
237+
$background=$1;
238+
print "found BACKGROUND: $background\n" if($DEBUG);
239+
}
240+
}
241+
if(/^\s*WIDTH\s+(\d+)/i){
242+
if("$1" ne ""){
243+
$WIDTH=$1;
244+
print "found WIDTH: $WIDTH\n" if($DEBUG);
245+
}
246+
}
247+
if(/^\s*HEIGHT\s+(\d+)/i){
248+
if("$1" ne ""){
249+
$HEIGHT=$1;
250+
print "found HEIGHT: $HEIGHT\n" if($DEBUG);
251+
}
252+
}
253+
if(/^\s*NODE\s+(\w+)/i){
254+
$node=$1;
255+
print "found NODE: $node\n" if($DEBUG);
256+
}
257+
if(/^\s*POSITION\s+(\d+)\s+(\d+)/i){
258+
$xpos{$node}=$1;
259+
$ypos{$node}=$2;
260+
print "found NODE: $node XPOS: $xpos{$node} YPOS: $xpos{$node}\n" if($DEBUG);
261+
}
262+
if(/^\s*LABEL\s+(\S+)/i){
263+
$label{$node}=$1;
264+
print "found NODE: $node LABEL: $label{$node}\n" if($DEBUG);
265+
}
266+
267+
if(/^\s*LINK\s+(\S+)/i){
268+
$link=$1;
269+
print "found LINK: $link\n" if($DEBUG);
270+
}
271+
if(/^\s*NODES\s+(\S+)\s+(\S+)/i){
272+
$nodea{$link}=$1;
273+
$nodeb{$link}=$2;
274+
print "found LINK: $link NODEA: $nodea{$link} NODEB: $nodeb{$link}\n" if($DEBUG);
275+
}
276+
if(/^\s*TARGET\s+(\S+)/i){
277+
$target{$link}=$1;
278+
print "found LINK: $link TARGET: $target{$link}\n" if($DEBUG);
279+
}
280+
if(/^\s*BANDWIDTH\s+(\d+)/i){
281+
$bandwidth{$link}=$1;
282+
$maxbytes{$link}=$bandwidth{$link}*1024/8;
283+
print "found LINK: $link BANDWIDTH: $bandwidth{$link}\n" if($DEBUG);
284+
}
285+
if(/^\s*KEYPOS\s+(\d+)\s+(\d+)/i){
286+
$keyxpos=$1;
287+
$keyypos=$2;
288+
print "found KEY POSITION: $keyxpos $keyypos\n" if($DEBUG);
289+
}
290+
if(/^\s*SCALE\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/i){
291+
$scale_low{"$1:$2"}=$1;
292+
$scale_high{"$1:$2"}=$2;
293+
$scale_red{"$1:$2"}=$3;
294+
$scale_green{"$1:$2"}=$4;
295+
$scale_blue{"$1:$2"}=$5;
296+
$scales++;
297+
print "found SCALE DATA: $1:$2 $3:$4:$5\n" if($DEBUG);
298+
}
299+
}
300+
print "\n" if($DEBUG);
301+
}
302+
303+
304+
sub middle{
305+
return int( $_[0] + ($_[1]-$_[0])/2 )
306+
}
307+
308+
sub dist{
309+
return int( sqrt( $_[0]*$_[0] + $_[1]*$_[1] ) )
310+
}
311+
312+
sub newx{
313+
my($a,$b,$x,$y)=@_;
314+
return int( cos( atan2($y,$x) + atan2($b,$a) ) * sqrt( $x*$x + $y*$y ) );
315+
}
316+
317+
sub newy{
318+
my($a,$b,$x,$y)=@_;
319+
return int( sin( atan2($y,$x) + atan2($b,$a) ) * sqrt( $x*$x + $y*$y ) );
320+
}
321+
322+
323+
324+
sub draw_arrow {
325+
my($x1,$y1,$x2,$y2,$w,$solid,$color)=($_[0],$_[1],$_[2],$_[3],$_[4],$_[5],$_[6]);
326+
my($arrow)=new GD::Polygon;
327+
328+
$arrow->addPt(
329+
$x1 + &newx($x2-$x1, $y2-$y1, 0, $w),
330+
$y1 + &newy($x2-$x1, $y2-$y1, 0, $w)
331+
);
332+
333+
$arrow->addPt(
334+
$x2 + &newx($x2-$x1, $y2-$y1, -4*$w, $w),
335+
$y2 + &newy($x2-$x1, $y2-$y1, -4*$w, $w)
336+
);
337+
338+
$arrow->addPt(
339+
$x2 + &newx($x2-$x1, $y2-$y1, -4*$w, 2*$w),
340+
$y2 + &newy($x2-$x1, $y2-$y1, -4*$w, 2*$w)
341+
);
342+
343+
$arrow->addPt( $x2, $y2);
344+
345+
$arrow->addPt(
346+
$x2 + &newx($x2-$x1, $y2-$y1, -4*$w, -2*$w),
347+
$y2 + &newy($x2-$x1, $y2-$y1, -4*$w, -2*$w)
348+
);
349+
350+
$arrow->addPt(
351+
$x2 + &newx($x2-$x1, $y2-$y1, -4*$w, -$w),
352+
$y2 + &newy($x2-$x1, $y2-$y1, -4*$w, -$w)
353+
);
354+
355+
$arrow->addPt(
356+
$x1 + &newx($x2-$x1, $y2-$y1, 0, -$w),
357+
$y1 + &newy($x2-$x1, $y2-$y1, 0, -$w)
358+
);
359+
360+
if($solid){
361+
$map->filledPolygon($arrow,$color);
362+
}else{
363+
$map->polygon($arrow,$color);
364+
}
365+
}
366+
367+
368+
sub version {
369+
print <<EOM;
370+
Network Wearthermap v$VERSION - http://netmon.grnet.gr/weathermap/
371+
EOM
372+
}
373+
374+
sub usage {
375+
print <<EOM;
376+
Network Wearthermap v$VERSION - http://netmon.grnet.gr/weathermap/
377+
Usage: $0 [OPTION]...
378+
379+
-c, --config=FILE configuration file (default $CONFIG)
380+
-o, --output=FILE output image file default (default $OUTPUT)
381+
-v, --version print version
382+
-h, --help print this text
383+
-d, --debug enable debug output
384+
385+
EOM
386+
}

‎weathermap-1.1.1.tar.gz

-115 KB
Binary file not shown.

0 commit comments

Comments
 (0)
Please sign in to comment.