[Xymon] your device on a openstreet map
Olivier AUDRY
olivier at audry.fr
Wed Dec 21 12:49:43 CET 2011
hello
here is a quick script to show your device on an openstreet map. Just add a geo:(latitude,longitude) tag run the script and it's ok. If someone know how to draw a ligne between two point let me know :)
#!/usr/bin/perl -w
use strict;
use LWP::Simple;
# utopia = new Marker(new LatLonPoint(43.60394,1.44679))
# utopia.setInfoBubble('Cinéma Utopia Toulouse');
# mapstraction.addMarker(utopia);
#Hobbit tag : geo:(48.8859778,2.2191631)
my $hobbit_url = "http://xymon-gdf.fr.colt.net";
my $itraw = `xymongrep geo:* | grep CPE | awk '{print \$2" "\$4}'`;
my @raw = split /\n/, $itraw;
my %bbhosts;
my %res;
my %page_value;
foreach my $var (@raw) {
my ($host, $geo) = split /\s+/, $var;
$bbhosts{$host} = $geo;
}
open FD,">/opt/xymon/server/www/map.html";
print FD '
<div id="map" ></div>
<p><a href="http://www.openstreetmap.org/?lat=48&lon=2.5&zoom=7"
hreflang="en" title="Site du projet OpenStreetMap">
Voir la carte sur OpenStreetMap.
</a></p>
<script
type="text/javascript"
src="http://openlayers.org/api/OpenLayers.js"
></script>
<script
type="text/javascript"
src="http://mapstraction.com/svn/source/mapstraction.js"
></script>
<script type="text/javascript">
// Initialisation de la carte.
var mapstraction = new Mapstraction(\'map\',\'openlayers\');
mapstraction.addControls({
pan: true,
zoom: \'large\',
map_type: true
});
var center = new LatLonPoint(48,2.5);
mapstraction.setCenterAndZoom(center, 7);
';
foreach my $host (keys %bbhosts) {
my $icons = "http://openlayers.org/dev/img/marker-green.png";
$bbhosts{$host} =~ s/geo:\(//;
$bbhosts{$host} =~ s/\)//;
my $label = "$host ";
my ($lon, $lat) = split /,/, $bbhosts{$host} ;
print FD "$host = new Marker(new LatLonPoint($lon,$lat))\n";
my $tcolor = `xymon 0 "xymondboard fields=hostname,testname,color host=$host color=red" | grep "$host|"`;
if (length($tcolor)) {
my ($t, $service, $color) = split /\|/, $tcolor;
print $tcolor;
$icons = "http://openlayers.org/dev/img/marker.png";
$label .= "<br><a href=\"http://$hobbit_url/xymon-cgi/svcstatus.sh?HOST=$host&SERVICE=$service\">$service</a> is red";
}
print FD "$host.setInfoBubble('$label');\n";
print FD "$host.setIcon('$icons');\n";
print FD "mapstraction.addMarker($host);\n";
print FD "\n";
}
print FD " </script>
";
More information about the Xymon
mailing list