rrdweather/0000755000175000017500000000000010707062526011076 5ustar swswrrdweather/install.sh0000755000175000017500000000147510704634127013111 0ustar swsw#!/bin/sh PATH=/usr/bin:/bin CURDIR=`pwd` echo " " echo "RRDWeather installer" echo "--------------------" echo " " echo "Make sure you have edited rrdweather.conf and rrdweather_cron before continuing" echo -n "Do you want to (c)ontinue or (q)uit ? : " read CONTINUE if [ $CONTINUE != "c" ] then exit 1 else # *.sh if [ ! -d /usr/share/rrdweather ] then echo "Making directory /usr/share/rrdweather ..." mkdir /usr/share/rrdweather fi echo "Copying script files..." cp $CURDIR/files/*.sh /usr/share/rrdweather # rrdweather.conf echo "Copying config file..." cp $CURDIR/files/rrdweather.conf /etc # rrdweather_cron echo "Copying cron file..." cp $CURDIR/files/rrdweather_cron /etc/cron.d/rrdweather # weather.cgi echo "Copy weather.cgi in a cgi-bin enabled directory of the webserver." fi rrdweather/TODO0000644000175000017500000000011310701412656011556 0ustar swswTodo : - tabs for daily/weekly/... graphs instead of everything on 1 page rrdweather/README0000644000175000017500000000473110705501306011753 0ustar swswRRDWeather Released under the GNU General Public License http://www.wains.be/projects/rrdweather/ What is RRDWeather ? RRDWeather is a set of scripts working with RRDtool and weather.com. It collects weather info from the web on a regular basis and puts it in RRDtool graphs. Installation See INSTALL Contributors - Lionel Porcheron - Gregory Bittan - Gregory Guthrie - Heikki Hokkanen Changelog Version 0.42 - October 2007 : - weather.cgi * header titles now link to their section. Patch by Heikki Hokkanen * click on graphs to go to the next section (click on daily graphs to reach weekly graphs and so on) * no longer necessary to have several weather.cgi files to display different cities, zip passed as argument. Idea by Gregory Guthrie * city name fetched from the XML source * made XHTML 1.1 and CSS 2.1 compliant (again) Version 0.41 - October 2007 : - applied the patches made available by Lionel Porcheron in Ubuntu Universe repository * configuration file in /etc instead of editing script files * remove interactions and read informations from configuration file * change database location in cgi script * db_builder.sh and db_update.sh scripts now go in /usr/share/rrdweather and no more in /usr/lib/rrdweather * call rrdweather_cron.sh which creates rrd database if necessary (no need to run db_builder.sh first) - lower and upper limit variables for pressure graphs in cgi script - speed variable for wind graphs in cgi script - reduced size of graphs and changed general layout of graph page - removed the average label for pressure, which was kind of pointless, and due to the smaller graphs, the labels for pressure were too large, so I needed to get rid of one - new install script Version 0.40 - December 2006 : - Gregory Bittan reported an issue when the web connection is down. The script would still feed the RRD databases with a value of 0, messing up the average figures. - The update script can now handle the monitoring of several cities - Lionel Porcheron made RRDweather available to the Ubuntu Community trough the Universe repository - To achieve the goal of monitoring several cities from a single script, RRDWeather had to use a new directory structure in order to store database files - Better indenting - Improved bash code - Improved debugging mode - ... Version 0.36 - January 2006: - Lionel Porcheron made weather.cgi fully w3c XHTML 1.1 et CSS 2.1 compliant rrdweather/files/0000755000175000017500000000000010707062526012200 5ustar swswrrdweather/files/rrdweather.conf0000644000175000017500000000137110701231770015211 0ustar swsw# RRDWeather configuration file # The unit should be either "m" for metric units or "e" for english units # If you monitor several cities, each will be monitored using the unit specified here UNIT=m # The cities you want to monitor # Their ZIP/Intl code separated by a space ZIPS="BEXX0014 28412" # The web server user and group # Check your web server configuration to know these WWWUSER=www-data WWWGROUP=www-data # Where the images will be stored. NO TRAILING SLASH TMPDIR=/var/tmp/rrdweather # Where the DB's will be stored. NO TRAILING SLASH RRDDIR=/var/lib/rrdweather/db # Enable debug mode (y/n). When debug mode is enabled, the DB's are not updated DEBUG=n rrdweather/files/rrdweather_cron.sh0000755000175000017500000000044010701174441015717 0ustar swsw#!/bin/sh . /etc/rrdweather.conf PATH=/usr/bin:/bin # on each run, check if we need to build a RRD database for city in $ZIPS do if [ ! -d ${RRDDIR}/${city} ] then /usr/share/rrdweather/db_builder.sh ${city} fi done /usr/share/rrdweather/db_update.sh rrdweather/files/weather.cgi0000755000175000017500000003327210705073535014335 0ustar swsw#!/usr/bin/perl -w # RRDWeather # Released under the GNU General Public License # http://www.wains.be/projects/rrdweather/ use CGI (); #use CGI::Carp qw(fatalsToBrowser warningsToBrowser); use POSIX qw(strftime); use RRDs; use XML::Simple; my $VERSION = "0.42"; ############################################################ ############## EDIT THESE VALUES BELOW ##################### ############################################################ my $xpoints = 350; # Graphs width my $ypoints = 150; # Graphs height my $db_dir = '/var/lib/rrdweather/db'; # DB files directory my $tmp_dir = '/var/tmp/rrdweather'; # Images directory my $system = 'm'; # m : metric units / e : english units my $scriptname = 'weather.cgi'; # if you want to rename the script ############################################################ ### YOU SHOULD NOT HAVE TO EDIT ANYTHING BELOW THIS LINE ### ############################################################ # Fetching ZIP code passed as argument my $cgi = CGI->new(); my $zip = $cgi->param("zip"); my $uri = $ENV{SCRIPT_URI}; if ( ! $zip ) { print "Content-Type: text/html\n\n"; print "
RRDWeather $VERSION\n---------------\n\n";	
	print "Please specify a city to display.\n\n";
	print "Example : $uri?zip=12345";
	exit 1;
}

# Fetching city name from XML file
my $xml = new XML::Simple;
my $xmlfile = "$tmp_dir/$zip.xml";

# If XML is not available, wait 3 seconds and try again
# If still not available, display the error message which will try to reload the page after 5 seconds
if ( ! -r $xmlfile) { 
	sleep 3;
	if ( ! -r $xmlfile) {
		print "Content-Type: text/html\n\n";
		print "";
		print "";
		print "";
		print "";
		print "";
		print "
RRDWeather $VERSION\n---------------\n\n";	
		print "XML source cannot be read !\n\n";	
		print "Make sure you are trying to display a city monitored by RRDWeather.\n\n";
		print "The XML source may temporarily be unavailable. The page will reload within 5 seconds.\n\n";
		print "If the problem persists, there's a problem with this configuration.";
		exit 1;
	}
}

my $xmldata = $xml->XMLin("$xmlfile");
my $city = $xmldata->{loc}->{dnam};

# Variables
my $date = strftime "%a %b %e %Y %I.%M%p", localtime;
my $points_per_sample = 3;
my $ypoints_err = 96;
my $db_real = "$db_dir/$zip/real.rrd";
my $db_dew = "$db_dir/$zip/dew.rrd";
my $db_felt = "$db_dir/$zip/felt.rrd";
my $db_humidity = "$db_dir/$zip/humidity.rrd";
my $db_wind = "$db_dir/$zip/wind.rrd";
my $db_pressure = "$db_dir/$zip/pressure.rrd";
my $db_uv = "$db_dir/$zip/uv.rrd";

if($system eq "m") {
	$speed = 'kph';		
	$pressurelowlimit = '980';	
	$pressureuplimit = '1100';
}
elsif($system eq "e") {
	$speed = 'mph';
	$pressurelowlimit = '20';	
	$pressureuplimit = '40';
}

my @graphs = (
	{ title => 'Daily Graphs',   seconds => 3600*24,        },
	{ title => 'Weekly Graphs',  seconds => 3600*24*7,      },
	{ title => 'Monthly Graphs', seconds => 3600*24*31,     },
	{ title => 'Yearly Graphs',  seconds => 3600*24*365, 	},
);

sub graph_temperature($$$)
{
	my $range = shift;
	my $file = shift;
	my $title = shift;
	my $step = $range*$points_per_sample/$xpoints;
	
	my ($graphret,$xs,$ys) = RRDs::graph($file,
		'--imgformat', 'PNG',
		'--width', $xpoints,
		'--height', $ypoints,
		'--start', "-$range",
		"--title= Real & felt temp. in $city",
		'--vertical-label', 'Real & felt temp.',
		'--units-exponent', 0,
		'--lazy',
		'-Y',
		
		"DEF:real_c=$db_real:real:AVERAGE",
		"DEF:felt_c=$db_felt:felt:AVERAGE",
		"DEF:dew_c=$db_dew:dew:AVERAGE",
		"COMMENT:           Min       Max       Ave       Last\\n",
		'LINE2:real_c#DD3F4A:Real', 'GPRINT:real_c:MIN: %5.2lf C',
		'GPRINT:real_c:MAX: %5.2lf C', 'GPRINT:real_c:AVERAGE: %5.2lf C',
		'GPRINT:real_c:LAST: %5.2lf C\\n',
		'LINE1:felt_c#3F4ADD:Felt', , 'GPRINT:felt_c:MIN: %5.2lf C',
		'GPRINT:felt_c:MAX: %5.2lf C', 'GPRINT:felt_c:AVERAGE: %5.2lf C',
		'GPRINT:felt_c:LAST: %5.2lf C\\n',	
		'LINE1:dew_c#4ADD3F:Dew ', , 'GPRINT:dew_c:MIN: %5.2lf C',
		'GPRINT:dew_c:MAX: %5.2lf C', 'GPRINT:dew_c:AVERAGE: %5.2lf C',
		'GPRINT:dew_c:LAST: %5.2lf C\\n',
		"COMMENT: \\n",
		"COMMENT:RRDWeather $VERSION - $date",
	);

	my $ERR=RRDs::error;
	die "ERROR : $ERR\n" if $ERR;
}

sub graph_humidity($$$)
{
        my $range = shift;
        my $file = shift;
        my $title = shift;
        my $step = $range*$points_per_sample/$xpoints;

        my ($graphret,$xs,$ys) = RRDs::graph($file,
                '--imgformat', 'PNG',
                '--width', $xpoints,
                '--height', $ypoints,
                '--start', "-$range",
		"--title= Humidity in $city",
                '--vertical-label', 'Humidity',
                '--lower-limit', 0,
		'--upper-limit', 100,
                '--units-exponent', 0,
		'--lazy',
		'-Y',

                "DEF:humidity_pc=$db_humidity:humidity:AVERAGE",
                'COMMENT:        ', "COMMENT:     Min        Max        Ave        Last\\n",
                'LINE1:humidity_pc#4DD34A:Humidity', 'GPRINT:humidity_pc:MIN: %5.2lf pc',
                'GPRINT:humidity_pc:MAX: %5.2lf pc', 'GPRINT:humidity_pc:AVERAGE: %5.2lf pc',
                'GPRINT:humidity_pc:LAST: %5.2lf pc\\n',
		"COMMENT: \\n",
		"COMMENT: \\n",
		"COMMENT: \\n",
		"COMMENT:RRDWeather $VERSION - $date",
	);

        my $ERR=RRDs::error;
        die "ERROR : $ERR\n" if $ERR;
}

sub graph_wind($$$)
{
        my $range = shift;
        my $file = shift;
        my $title = shift;
        my $step = $range*$points_per_sample/$xpoints;

        my ($graphret,$xs,$ys) = RRDs::graph($file,
                '--imgformat', 'PNG',
                '--width', $xpoints,
                '--height', $ypoints,
                '--start', "-$range",
                "--title= Wind in $city",
                '--vertical-label', 'Wind',
                '--units-exponent', 0,
		'--lazy',
                '-Y',

                "DEF:wind_s=$db_wind:wind:AVERAGE",
                "COMMENT:            Min        Max         Ave         Last\\n",
                'LINE2:wind_s#DD3F4A:Wind', "GPRINT:wind_s:MIN: %5.2lf $speed",
                "GPRINT:wind_s:MAX: %5.2lf $speed", "GPRINT:wind_s:AVERAGE: %5.2lf $speed",
                "GPRINT:wind_s:LAST: %5.2lf $speed\\n",
		"COMMENT: \\n",
		"COMMENT:RRDWeather $VERSION - $date",
        );

        my $ERR=RRDs::error;
        die "ERROR : $ERR\n" if $ERR;
}

sub graph_pressure($$$)
{
        my $range = shift;
        my $file = shift;
        my $title = shift;
        my $step = $range*$points_per_sample/$xpoints;

        my ($graphret,$xs,$ys) = RRDs::graph($file,
                '--imgformat', 'PNG',
                '--width', $xpoints,
                '--height', $ypoints,
                '--start', "-$range",
                "--title= Pressure in $city",
                '--vertical-label', 'Pressure',
                '--lower-limit', $pressurelowlimit,
                '--upper-limit', $pressureuplimit,
		'--units-exponent', 0,
		'--lazy',
		'-Y',

        	"DEF:pressure_hpa=$db_pressure:pressure:AVERAGE",
                'COMMENT:        ', "COMMENT:        Min           Max           Last\\n",
                'LINE1:pressure_hpa#DD3F4A:Pressure', 'GPRINT:pressure_hpa:MIN: %5.2lf hPa',
                'GPRINT:pressure_hpa:MAX: %5.2lf hPa', 
                'GPRINT:pressure_hpa:LAST: %5.2lf hPa\\n',
		"COMMENT: \\n",
		"COMMENT:RRDWeather $VERSION - $date",
	);

        my $ERR=RRDs::error;
        die "ERROR : $ERR\n" if $ERR;
}

sub graph_uv($$$)
{
        my $range = shift;
        my $file = shift;
        my $title = shift;
        my $step = $range*$points_per_sample/$xpoints;

        my ($graphret,$xs,$ys) = RRDs::graph($file,
                '--imgformat', 'PNG',
                '--width', $xpoints,
                '--height', $ypoints,
                '--start', "-$range",
                "--title= UV index in $city",
                '--vertical-label', 'UV index',
                '--lower-limit', 0,
	        '--upper-limit', 10,        
		'--units-exponent', 0,
		'--lazy',
		'-y', '1:5',		

                "DEF:uv_index=$db_uv:uv:AVERAGE",
                'COMMENT:        ', "COMMENT:     Min     Max     Ave    Last\\n",
                'AREA:uv_index#DD3F4A:UV index', 'GPRINT:uv_index:MIN: %5.2lf',
                'GPRINT:uv_index:MAX: %5.2lf', 'GPRINT:uv_index:AVERAGE: %5.2lf',
		'GPRINT:uv_index:LAST: %5.2lf\\n',
		"COMMENT: \\n",
		"COMMENT:RRDWeather $VERSION - $date",
	);

        my $ERR=RRDs::error;
        die "ERROR : $ERR\n" if $ERR;
}

sub print_html()
{
	print "Content-Type: application/xhtml+xml\n\n";

	print <



Weather in $city - Generated by RRDWeather






HEADER
	print "

Weather in $city

\n"; print "

According to weather.com

\n"; for my $n (0..$#graphs) { print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
\n"; my $h2_id = $graphs[$n]{title}; my $next_h2_id = $graphs[$n+1]{title}; $h2_id =~ s/ /_/; $next_h2_id =~ s/ /_/; print "\n"; print "
\"Temperature\"\"Humidity\"
\"Wind\"\"Pressure\"
\"UV
\n"; } print < Valid XHTML 1.1

RRDWeather $VERSION by Sebastien Wains
\n\n\n FOOTER } sub send_image($) { my $file = shift; -r $file or do { print "Content-type: text/plain\n\nERROR : can't find $file\n"; exit 1; }; print "Content-type: image/png\n"; print "Content-length: ".((stat($file))[7])."\n"; print "\n"; open(IMG, $file) or die; my $data; print $data while read IMG, $data, 1024; } sub main() { mkdir $tmp_dir, 0777 unless -d $tmp_dir; mkdir "$tmp_dir/$zip", 0777 unless -d "$tmp_dir/$zip"; my $img = $ENV{QUERY_STRING}; if(defined $img and $img =~ /\S/) { if($img =~ /^zip=([a-zA-Z0-9]{5,8})&file=(\d+)-temperature$/) { my $file = "$tmp_dir/$1/RRDWeather_$2_temperature.png"; graph_temperature($graphs[$2]{seconds}, $file, $graphs[$2]{title}); send_image($file); } elsif($img =~ /^zip=([a-zA-Z0-9]{5,8})&file=(\d+)-humidity$/) { my $file = "$tmp_dir/$1/RRDWeather_$2_humidity.png"; graph_humidity($graphs[$2]{seconds}, $file, $graphs[$2]{title}); send_image($file); } elsif($img =~ /^zip=([a-zA-Z0-9]{5,8})&file=(\d+)-wind$/) { my $file = "$tmp_dir/$1/RRDWeather_$2_wind.png"; graph_wind($graphs[$2]{seconds}, $file, $graphs[$2]{title}); send_image($file); } elsif($img =~ /^zip=([a-zA-Z0-9]{5,8})&file=(\d+)-pressure$/) { my $file = "$tmp_dir/$1/RRDWeather_$2_pressure.png"; graph_pressure($graphs[$2]{seconds}, $file, $graphs[$2]{title}); send_image($file); } elsif($img =~ /^zip=([a-zA-Z0-9]{5,8})&file=(\d+)-uv$/) { my $file = "$tmp_dir/$1/RRDWeather_$2_uv.png"; graph_uv($graphs[$2]{seconds}, $file, $graphs[$2]{title}); send_image($file); } else { print_html; } } } main; rrdweather/files/rrdweather_cron0000644000175000017500000000024010701401234015272 0ustar swsw# weather db update for rrdweather # # You may need to change the user executing the script # */5 * * * * www-data /usr/share/rrdweather/rrdweather_cron.sh rrdweather/files/db_builder.sh0000755000175000017500000001043010701231770014621 0ustar swsw#!/bin/sh # RRDWeather # Released under the GNU General Public License # http://www.wains.be/projects/rrdweather/ PATH=/usr/bin:/bin . /etc/rrdweather.conf #################################################################################### # YOU SHOULD NOT EDIT ANYTHING BELOW THIS LINE, UNLESS YOU KNOW WHAT YOU ARE DOING # #################################################################################### clear if [ -z "$1" ] then exit 1 fi CITY=$1 cd if [ ! -d ${RRDDIR}/${CITY} ] then mkdir -p ${RRDDIR}/${CITY} fi rrdtool create ${RRDDIR}/${CITY}/real.rrd \ --start 1127253600 \ DS:real:GAUGE:600:-50:150 \ RRA:AVERAGE:0.5:1:600 \ RRA:AVERAGE:0.5:6:700 \ RRA:AVERAGE:0.5:24:775 \ RRA:AVERAGE:0.5:288:797 \ RRA:MIN:0.5:1:600 \ RRA:MIN:0.5:6:700 \ RRA:MIN:0.5:24:775 \ RRA:MIN:0.5:288:797 \ RRA:MAX:0.5:1:600 \ RRA:MAX:0.5:6:700 \ RRA:MAX:0.5:24:775 \ RRA:MAX:0.5:288:797 rrdtool create ${RRDDIR}/${CITY}/felt.rrd \ --start 1127253600 \ DS:felt:GAUGE:600:-50:150 \ RRA:AVERAGE:0.5:1:600 \ RRA:AVERAGE:0.5:6:700 \ RRA:AVERAGE:0.5:24:775 \ RRA:AVERAGE:0.5:288:797 \ RRA:MIN:0.5:1:600 \ RRA:MIN:0.5:6:700 \ RRA:MIN:0.5:24:775 \ RRA:MIN:0.5:288:797 \ RRA:MAX:0.5:1:600 \ RRA:MAX:0.5:6:700 \ RRA:MAX:0.5:24:775 \ RRA:MAX:0.5:288:797 rrdtool create ${RRDDIR}/${CITY}/dew.rrd \ --start 1127253600 \ DS:dew:GAUGE:600:-50:150 \ RRA:AVERAGE:0.5:1:600 \ RRA:AVERAGE:0.5:6:700 \ RRA:AVERAGE:0.5:24:775 \ RRA:AVERAGE:0.5:288:797 \ RRA:MIN:0.5:1:600 \ RRA:MIN:0.5:6:700 \ RRA:MIN:0.5:24:775 \ RRA:MIN:0.5:288:797 \ RRA:MAX:0.5:1:600 \ RRA:MAX:0.5:6:700 \ RRA:MAX:0.5:24:775 \ RRA:MAX:0.5:288:797 rrdtool create ${RRDDIR}/${CITY}/humidity.rrd \ --start 1127253600 \ DS:humidity:GAUGE:600:0:100 \ RRA:AVERAGE:0.5:1:600 \ RRA:AVERAGE:0.5:6:700 \ RRA:AVERAGE:0.5:24:775 \ RRA:AVERAGE:0.5:288:797 \ RRA:MIN:0.5:1:600 \ RRA:MIN:0.5:6:700 \ RRA:MIN:0.5:24:775 \ RRA:MIN:0.5:288:797 \ RRA:MAX:0.5:1:600 \ RRA:MAX:0.5:6:700 \ RRA:MAX:0.5:24:775 \ RRA:MAX:0.5:288:797 rrdtool create ${RRDDIR}/${CITY}/wind.rrd \ --start 1127253600 \ DS:wind:GAUGE:600:0:150 \ RRA:AVERAGE:0.5:1:600 \ RRA:AVERAGE:0.5:6:700 \ RRA:AVERAGE:0.5:24:775 \ RRA:AVERAGE:0.5:288:797 \ RRA:MIN:0.5:1:600 \ RRA:MIN:0.5:6:700 \ RRA:MIN:0.5:24:775 \ RRA:MIN:0.5:288:797 \ RRA:MAX:0.5:1:600 \ RRA:MAX:0.5:6:700 \ RRA:MAX:0.5:24:775 \ RRA:MAX:0.5:288:797 if [ $UNIT = "m" ] then rrdtool create ${RRDDIR}/${CITY}/pressure.rrd \ --start 1127253600 \ DS:pressure:GAUGE:600:900:1100 \ RRA:AVERAGE:0.5:1:600 \ RRA:AVERAGE:0.5:6:700 \ RRA:AVERAGE:0.5:24:775 \ RRA:AVERAGE:0.5:288:797 \ RRA:MIN:0.5:1:600 \ RRA:MIN:0.5:6:700 \ RRA:MIN:0.5:24:775 \ RRA:MIN:0.5:288:797 \ RRA:MAX:0.5:1:600 \ RRA:MAX:0.5:6:700 \ RRA:MAX:0.5:24:775 \ RRA:MAX:0.5:288:797 else rrdtool create ${RRDDIR}/${CITY}/pressure.rrd \ --start 1127253600 \ DS:pressure:GAUGE:600:20:40 \ RRA:AVERAGE:0.5:1:600 \ RRA:AVERAGE:0.5:6:700 \ RRA:AVERAGE:0.5:24:775 \ RRA:AVERAGE:0.5:288:797 \ RRA:MIN:0.5:1:600 \ RRA:MIN:0.5:6:700 \ RRA:MIN:0.5:24:775 \ RRA:MIN:0.5:288:797 \ RRA:MAX:0.5:1:600 \ RRA:MAX:0.5:6:700 \ RRA:MAX:0.5:24:775 \ RRA:MAX:0.5:288:797 fi rrdtool create ${RRDDIR}/${CITY}/uv.rrd \ --start 1127253600 \ DS:uv:GAUGE:600:0:15 \ RRA:AVERAGE:0.5:1:600 \ RRA:AVERAGE:0.5:6:700 \ RRA:AVERAGE:0.5:24:775 \ RRA:AVERAGE:0.5:288:797 \ RRA:MIN:0.5:1:600 \ RRA:MIN:0.5:6:700 \ RRA:MIN:0.5:24:775 \ RRA:MIN:0.5:288:797 \ RRA:MAX:0.5:1:600 \ RRA:MAX:0.5:6:700 \ RRA:MAX:0.5:24:775 \ RRA:MAX:0.5:288:797 chown -R ${WWWUSER}:${WWWGROUP} ${RRDDIR}/${CITY}/* rrdweather/files/db_update.sh0000755000175000017500000000772010707062404014467 0ustar swsw#!/bin/sh # RRDWeather # Released under the GNU General Public License # http://www.wains.be/projects/rrdweather/ PATH=/usr/bin:/bin . /etc/rrdweather.conf ########################################################################################## ###### YOU SHOULD NOT EDIT ANYTHING BELOW THIS LINE ###################################### ########################################################################################## for ZIP in ${ZIPS} do if [ -d "${TMPDIR}" ]; then cd ${TMPDIR} else mkdir ${TMPDIR} chown ${WWWUSER}:${WWWGROUP} ${TMPDIR} chmod 777 ${TMPDIR} cd ${TMPDIR} fi cd ${TMPDIR} rm ${TMPDIR}/${ZIP}.xml -f if [ $DEBUG = "y" ] then echo "Debug mode" echo "1. Connection test to www.google.com" echo "====================================" ping -c 4 www.google.com echo "" else ping -q -c 2 xoap.weather.com > /dev/null 2>&1 fi sleep 3s if [ $? -eq 0 ] then if [ $DEBUG = "y" ] then echo "2. XML retrieval from xoap.weather.com" echo "======================================" wget "http://xoap.weather.com/weather/local/${ZIP}?cc=*&unit=${UNIT}" echo "" else wget -q "http://xoap.weather.com/weather/local/${ZIP}?cc=*&unit=${UNIT}" fi mv "${ZIP}?cc=*&unit=${UNIT}" "${ZIP}.xml" sleep 5s if [ ${UNIT} = "m" ] then REAL=`cat ${ZIP}.xml | grep "" | awk -F'>' '{print $2}' | awk -F'<' '{print$1}' | sed -re 's/(N|n|A|a|\/)//g'` FELT=`cat ${ZIP}.xml | grep "" | awk -F'>' '{print $2}' | awk -F'<' '{print $1}' | sed -re 's/(N|n|A|a|\/)//g'` DEW=`cat ${ZIP}.xml | grep "" | awk -F'>' '{print $2}' | awk -F'<' '{print $1}' | sed -re 's/(N|n|A|a|\/)//g'` HUMIDITY=`cat ${ZIP}.xml | grep "" | awk -F'>' '{print $2}' | awk -F'<' '{print $1}' | sed -re 's/(N|n|A|a|\/)//g'` WIND=`cat ${ZIP}.xml | grep "" | awk -F'>' '{print $2}' | awk -F'<' '{print $1}' | sed -re 's/(C|c|L|l|M|m|N|n|A|a|\/)//g'` PRESSURE=`cat ${ZIP}.xml | grep "" | awk -F'>' '{print $2}' | awk -F'<' '{print $1}' | sed -re 's/(N|n|A|a|\/)//g;s/\.[0-9]{1,2}//g'` UV=`cat ${ZIP}.xml | grep "" | awk -F'>' '{print $2}' | awk -F'<' '{print $1}' | sed -re 's/(N|n|A|a|\/)//g'` else REAL=`cat ${ZIP}.xml | grep "" | awk -F'>' '{print $2}' | awk -F'<' '{print$1}' | sed -re 's/(N|n|A|a|\/)//g'` FELT=`cat ${ZIP}.xml | grep "" | awk -F'>' '{print $2}' | awk -F'<' '{print $1}' | sed -re 's/(N|n|A|a|\/)//g'` DEW=`cat ${ZIP}.xml | grep "" | awk -F'>' '{print $2}' | awk -F'<' '{print $1}' | sed -re 's/(N|n|A|a|\/)//g'` HUMIDITY=`cat ${ZIP}.xml | grep "" | awk -F'>' '{print $2}' | awk -F'<' '{print $1}' | sed -re 's/(N|n|A|a|\/)//g'` WIND=`cat ${ZIP}.xml | grep "" | awk -F'>' '{print $2}' | awk -F'<' '{print $1}' | sed -re 's/(C|c|L|l|M|m|N|n|A|a|\/)//g'` PRESSURE=`cat ${ZIP}.xml | grep "" | awk -F'>' '{print $2}' | awk -F'<' '{print $1}' | sed -re 's/(N|n|A|a|\/)//g'` UV=`cat ${ZIP}.xml | grep "" | awk -F'>' '{print $2}' | awk -F'<' '{print $1}' | sed -re 's/(N|n|A|a|\/)//g'` fi if [ ${DEBUG} = "y" ] then echo "3. Values found" echo "===============" echo "Real temperature . :" ${REAL} echo "Felt temperature . :" ${FELT} echo "Dew point ........ :" ${DEW} echo "Humidity ......... :" ${HUMIDITY} echo "Wind ............. :" ${WIND} echo "Pressure ......... :" ${PRESSURE} echo "UV index ......... :" ${UV} else rrdtool update ${RRDDIR}/${ZIP}/real.rrd N:${REAL} rrdtool update ${RRDDIR}/${ZIP}/felt.rrd N:${FELT} rrdtool update ${RRDDIR}/${ZIP}/dew.rrd N:${DEW} rrdtool update ${RRDDIR}/${ZIP}/humidity.rrd N:${HUMIDITY} rrdtool update ${RRDDIR}/${ZIP}/wind.rrd N:${WIND} rrdtool update ${RRDDIR}/${ZIP}/pressure.rrd N:${PRESSURE} rrdtool update ${RRDDIR}/${ZIP}/uv.rrd N:${UV} fi else echo "RRDWeather thinks the connection is down." echo "It won't do anything until the connection is back." exit 1 fi done exit 0 rrdweather/INSTALL0000644000175000017500000000460410704634127012132 0ustar swswRRDWeather Released under the GNU General Public License http://www.wains.be/projects/rrdweather/ What do I need ? - a linux or unix machine running 24/7 - awk, sed and wget - apache webserver allowing ExecCGI (or any other webserver) - rrdtool >= 1.2.0 - the following perl libraries : * RRDs * POSIX * perl::XML::Simple * perl::XML::Parser Installation steps - if you want to monitor cities outside of the USA, find the international city code by searching on weather.com By searching for "Mons, Belgium" I'm pointed to this URL : http://www.weather.com/weather/local/BEXX0014?from=search_city The international city code is BEXX0014. - "untar-gz" the files to a temporary directory - edit files/rrdweather.conf to fit the locations you want to monitor, your needs and configuration edit files/rrdweather_cron and change the user that must run the script (by default www-data under Debian, apache under RedHat) - execute install.sh as root, this will copy the config file, cron file and scripts to default locations As soon as the files have been copied, the cron will start doing its job and the RRD databases will start being populated - copy "weather.cgi" to a cgi-bin folder of your webserver. - after a few minutes, you should see graphs at http://yourdomain.tld/cgi-bin/weather.cgi?zip=BEXX0014 Troubleshooting Q : I get a blank page when trying to reach weather.cgi in my web browser OR I get something like this in the error logs of Apache Can't locate RRDs.pm in @INC (@INC contains: /etc/perl /usr/local/lib/perl/5.8.8 /usr/local/share/perl/5.8.8 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.8 /usr/share/perl/5.8 /usr/local/lib/site_perl .) at /usr/lib/cgi-bin/weather.cgi line 7. A : You will probably need to install the missing perl library Under Debian systems : # apt-get install librrds-perl Under RedHat systems : You will need to install the package "perl-rrdtool" provided by several 3rd party repositories. Search for "perl-rrdtool RPM" in Google. Or build from sources. Q : I can reach weather.cgi but no graph is displayed ! A : check the permissions on : - the database directory : directory reachable by your web server ? - the database files must be owned by the web server user/group and writable by the web server. - the temporary directory and its files. These should be owned by the web server user/group.