WeatherBug script & templates version 3.0 (weatherbug AP

Templates, scripts for templates, scripts and requests for templates.

Moderators: Developers, Moderators

darkpixel
Posts: 2
Joined: Sat Feb 19, 2011 2:40 pm

Re: WeatherBug script & templates version 3.0 (weatherbug AP

Post by darkpixel »

Hello,

Im from Spain, and for this to work, i had to modify the perl script to use City Codes instead of Zip Codes. That´s because it seems there are no Zip Codes for spanish City´s.

I debugged my problem searching my city for the the "Zip Code" using the api (example: http://api.wxbug.net/getLocationsXML.as ... ing=copper) and i realized that my City has no "Zip Code" (it whas blank). But it showed a "City Code" instead, so there whas a chance to make a fix. BUT, another funny problem whas, that at first, using the Zip Code for my City that shows this "maintained" (11 Mar 2011) list (http://www.rap.ucar.edu/weather/surface/stations.txt) (which is totally erroneous with the weatherbug stations) posted in the old weatherbug threads, and using the original script, i whas graphing results from some Airport of USA, lol. Finally i have fixed all issues.

So, once i get my City Code, i made a test with the api asking for my City Code (example: http://api.wxbug.net/getLiveWeatherRSS. ... unittype=1) and it worked, i whas getting my City weather. Then i modified the regex of the script to match the new values of the xml.

Later i changed the graphs to use Celtius instead of Fharenheit, creating a new CDEF function "F to Celtius" (cdef=CURRENT_DATA_SOURCE,32,-,0.55555555556,*), (Also modified the graph template and changed "ºF" to "C" (because of XML parse error and also the Fharenheit to Celtius conversion)), and that´s it.

The script looks like this:

Code: Select all

#!/usr/bin/perl
use warnings;
use strict;
use LWP::Simple;

#my $httpaddr = "http://api.wxbug.net/getLiveWeatherRSS.aspx?ACode=$ARGV[0]&zipcode=$ARGV[1]&unittype=0";
my $httpaddr = "http://api.wxbug.net/getLiveWeatherRSS.aspx?ACode=$ARGV[0]&citycode=$ARGV[1]&unittype=1";
my %data;

$_ = LWP::Simple::get($httpaddr);

# regex in html source order
if ($_ =~ /<aws:dew-point units="&deg;C">(\d+?)<\/aws:dew-point>/g)     { $data{DewPoint} = $1; }
if ($_ =~ /<aws:feels-like units="&deg;C">(\d+?)<\/aws:feels-like>/g)   { $data{FeelsLike} = $1; }
if ($_ =~ /<aws:humidity units="%">(\d+?)<\/aws:humidity>/g)                { $data{Humidity} = $1; }
if ($_ =~ /<aws:pressure units="mb">(\d+?\.\d+?)<\/aws:pressure>/g)     { $data{Pressure} = $1; }
if ($_ =~ /<aws:rain-today units="mm">(\d+?\.\d+?)<\/aws:rain-today>/g) { $data{Rain} = $1; }
if ($_ =~ /<aws:temp units="&deg;C">(\d+?\.\d+?)<\/aws:temp>/g)         { $data{Temp} = $1; }
if ($_ =~ /<aws:wind-speed units="km\/h">(\d+?)<\/aws:wind-speed>/g)          { $data{Wind} = $1; }

for (keys %data) {
  printf "%s:%s ", $_, $data{$_};
}
print "\n";
Kind regards, and big respect for all CACTi and his users.
kels0
Posts: 8
Joined: Wed Dec 23, 2009 2:35 pm

Re: WeatherBug script & templates version 3.0 (weatherbug AP

Post by kels0 »

Im having a strange problem since updating cacti recently. I can setup the templates/host/graphs etc, however the graphs never get any data and I dont understand why.

Code: Select all

06/29/2011 01:23:04 PM - SPINE: Poller[0] Host[93] TH[1] DS[2857] SCRIPT: perl /var/www/html/scripts/weatherbug_api.pl A4344085463 33909, output: 0
06/29/2011 01:23:04 PM - SPINE: Poller[0] Host[93] TH[1] DS[2856] SCRIPT: perl /var/www/html/scripts/weatherbug_api.pl A4344085463 33909, output: 0
06/29/2011 01:23:04 PM - SPINE: Poller[0] Host[93] TH[1] DS[2855] SCRIPT: perl /var/www/html/scripts/weatherbug_api.pl A4344085463 33909, output: 0
06/29/2011 01:23:05 PM - SPINE: Poller[0] Host[93] TH[1] DS[2853] SCRIPT: perl /var/www/html/scripts/weatherbug_api.pl A4344085463 33909, output: 0
06/29/2011 01:23:05 PM - SPINE: Poller[0] Host[93] TH[1] DS[2854] SCRIPT: perl /var/www/html/scripts/weatherbug_api.pl A4344085463 33909, output: 0
06/29/2011 01:23:05 PM - POLLER: Poller[0] CACTI2RRD: /usr/bin/rrdtool update /var/www/html/rra/weather_feelslike_2854.rrd --template  1309368183:0
06/29/2011 01:23:05 PM - POLLER: Poller[0] CACTI2RRD: /usr/bin/rrdtool update /var/www/html/rra/weather_feelslike_2853.rrd --template  1309368183:0
06/29/2011 01:23:05 PM - POLLER: Poller[0] CACTI2RRD: /usr/bin/rrdtool update /var/www/html/rra/weather_feelslike_2855.rrd --template  1309368183:0
06/29/2011 01:23:05 PM - POLLER: Poller[0] CACTI2RRD: /usr/bin/rrdtool update /var/www/html/rra/weather_feelslike_2857.rrd --template  1309368183:0
06/29/2011 01:23:05 PM - POLLER: Poller[0] CACTI2RRD: /usr/bin/rrdtool update /var/www/html/rra/weather_feelslike_2856.rrd --template  1309368183:0
The command from above outputs

Code: Select all


 perl /var/www/html/scripts/weatherbug_api.pl A4344085463 33909
DewPoint:71 Temp:82.2 Humidity:69 Wind:4 FeelsLike:87 Pressure:30.06
the graph files never update past the original creation. Any ideas what I can check to resolve this or why it returns 0 in the cacti.log shown above?
User avatar
classen
Cacti User
Posts: 116
Joined: Thu Nov 12, 2009 3:07 pm

Re: WeatherBug script & templates version 3.0 (weatherbug AP

Post by classen »

same problem here:
script runs fine from command line, initial graph gets created, but it never gets updated or populated.
ack :(
semakka
Posts: 20
Joined: Mon Oct 23, 2006 6:37 am

Re: WeatherBug script & templates version 3.0 (weatherbug AP

Post by semakka »

darkpixel wrote:Hello,

Im from Spain, and for this to work, i had to modify the perl script to use City Codes instead of Zip Codes. That´s because it seems there are no Zip Codes for spanish City´s.

I debugged my problem searching my city for the the "Zip Code" using the api (example: http://api.wxbug.net/getLocationsXML.as ... ing=copper) and i realized that my City has no "Zip Code" (it whas blank). But it showed a "City Code" instead, so there whas a chance to make a fix. BUT, another funny problem whas, that at first, using the Zip Code for my City that shows this "maintained" (11 Mar 2011) list (http://www.rap.ucar.edu/weather/surface/stations.txt) (which is totally erroneous with the weatherbug stations) posted in the old weatherbug threads, and using the original script, i whas graphing results from some Airport of USA, lol. Finally i have fixed all issues.

So, once i get my City Code, i made a test with the api asking for my City Code (example: http://api.wxbug.net/getLiveWeatherRSS. ... unittype=1) and it worked, i whas getting my City weather. Then i modified the regex of the script to match the new values of the xml.

Later i changed the graphs to use Celtius instead of Fharenheit, creating a new CDEF function "F to Celtius" (cdef=CURRENT_DATA_SOURCE,32,-,0.55555555556,*), (Also modified the graph template and changed "ºF" to "C" (because of XML parse error and also the Fharenheit to Celtius conversion)), and that´s it.

The script looks like this:

Code: Select all

#!/usr/bin/perl
use warnings;
use strict;
use LWP::Simple;

#my $httpaddr = "http://api.wxbug.net/getLiveWeatherRSS.aspx?ACode=$ARGV[0]&zipcode=$ARGV[1]&unittype=0";
my $httpaddr = "http://api.wxbug.net/getLiveWeatherRSS.aspx?ACode=$ARGV[0]&citycode=$ARGV[1]&unittype=1";
my %data;

$_ = LWP::Simple::get($httpaddr);

# regex in html source order
if ($_ =~ /<aws:dew-point units="&deg;C">(\d+?)<\/aws:dew-point>/g)     { $data{DewPoint} = $1; }
if ($_ =~ /<aws:feels-like units="&deg;C">(\d+?)<\/aws:feels-like>/g)   { $data{FeelsLike} = $1; }
if ($_ =~ /<aws:humidity units="%">(\d+?)<\/aws:humidity>/g)                { $data{Humidity} = $1; }
if ($_ =~ /<aws:pressure units="mb">(\d+?\.\d+?)<\/aws:pressure>/g)     { $data{Pressure} = $1; }
if ($_ =~ /<aws:rain-today units="mm">(\d+?\.\d+?)<\/aws:rain-today>/g) { $data{Rain} = $1; }
if ($_ =~ /<aws:temp units="&deg;C">(\d+?\.\d+?)<\/aws:temp>/g)         { $data{Temp} = $1; }
if ($_ =~ /<aws:wind-speed units="km\/h">(\d+?)<\/aws:wind-speed>/g)          { $data{Wind} = $1; }

for (keys %data) {
  printf "%s:%s ", $_, $data{$_};
}
print "\n";
Kind regards, and big respect for all CACTi and his users.

Thanks mate, I have the same issues here. I'll try and let you know.

Steven
cfoos
Posts: 1
Joined: Sat Dec 10, 2011 5:57 am

Re: WeatherBug script & templates version 3.0 (weatherbug AP

Post by cfoos »

Has anyone got this to work on 0.8.7h? If you have can you please supply the working files and instructions to get it to work? :)
tosage
Cacti User
Posts: 164
Joined: Wed Jul 28, 2010 5:05 am
Location: France

Re: WeatherBug script & templates version 3.0 (weatherbug AP

Post by tosage »

@cfoos : I think you need to modify the hash of the host template to your Cacti Version and go ;)
Cacti Version - 0.8.8a
Plugin Architecture - 3.1
Poller Type - spine
Server Info - Linux
Web Server - Apache/2.2.22 (Ubuntu)
PHP - 5.3.10-1ubuntu3.6 with Suhosin-Patch (cli)
MySQL - 5.5.29-0ubuntu0.12.04.2
RRDTool - 1.4.7
iwhite
Posts: 4
Joined: Mon Mar 05, 2012 6:44 am

Re: WeatherBug script & templates version 3.0 (weatherbug AP

Post by iwhite »

Hello,

I'am trying to get working for me, but I have no success :S

I can't get my code...I registered from here http://weather.weatherbug.com/desktop-w ... &stat=LBSF and there is no code in the confirmation mail... what to do now?

Any ideas thanks in advance!
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests