WeatherBug script & templates version 3.0 (weatherbug AP

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

Moderators: Developers, Moderators

Jason.S
Posts: 35
Joined: Thu Jun 11, 2009 9:28 am

Post by Jason.S »

How in the world do I change the WeatherBug API key and zip that the author placed in? I can not find it anywhere but in the XML.



Never mind.......found it. :oops:
pironic
Posts: 4
Joined: Tue Mar 02, 2010 1:40 pm

Post by pironic »

after reading the entire thread from start to end searching for a solution or indication that it might be something that i'm doing that is causing my issue i finally decided to ask for help myself. I dont think it's been answered previously.

i have the graphs and device and all set up correctly (i think) but when troubleshooting i think i have found the source of the issue to be with the way the perl script is parsing the xml from weatherbug.

Depending on the location code i use, the amount of information that is scrummed up is different, but my location is always minimal.
I am attempting to use the metric script with cacti 0.8.7e and RRDTool 1.2.x.

When running the script from command line i get:

Code: Select all

[pi@bluebox scripts]$ perl weatherbug_api_metric.pl A345xxx 54107
Humidity:86 Rain:0.00
[pi@bluebox scripts]$ perl weatherbug_api_metric.pl A435xxx W48564
DewPoint:24 Humidity:83 Temp:27.0 Rain:0.00
ultimatley i want to get location code 54107 working, but its only returning at most 3 of the variables. Thoughts?
pironic
Posts: 4
Joined: Tue Mar 02, 2010 1:40 pm

Post by pironic »

seems i found the reason for the error. it was actually 2 things that needed updating within the script... seems that weatherbug has changed their measurments so the regex was blown to pieces, and the regex wasn't coded to allow for minimum values. Here is the new script:

this is only for metric people:

Code: Select all

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

my $httpaddr = "http://$ARGV[0].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";
istein001
Cacti User
Posts: 54
Joined: Fri Feb 22, 2008 4:44 pm
Location: Houston

Same issue

Post by istein001 »

I've found the same issue... but rain-rate was the only one that got broke. Seems matching with \d+? (digit, 1 or more times, 1 or 0 times) isn't very effective.

I've changed it to be \d* (digit, 0 or more times).

(modified code below)
!/usr/bin/perl
use warnings;
use strict;
use LWP::Simple;

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

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

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

for (keys %data) {
printf "%s:%s ", $_, $data{$_};
}
print "\n";
selmoc
Posts: 2
Joined: Fri Aug 20, 2010 3:23 am

no units shown in Pressure Graph

Post by selmoc »

Hi I am using cacti_host_template_weatherbug_metric.xml and weatherbug_api_metric.pl to track the weather in some locations
within the pressure graph there are no used unit visible as long the pressure is higher than 1000 mbar.
Attachments
graph_image_1.php.png
graph_image_1.php.png (15.75 KiB) Viewed 4970 times
graph_image_2.php.png
graph_image_2.php.png (14.34 KiB) Viewed 4970 times
selmoc
Posts: 2
Joined: Fri Aug 20, 2010 3:23 am

no units shown in Pressure Graph

Post by selmoc »

can anyone help on this issue
emuman100
Posts: 2
Joined: Mon Oct 18, 2010 11:50 am

Re: WeatherBug script & templates version 3.0 (weatherbug AP

Post by emuman100 »

I had a bunch of issues getting this working, but the script works great, and gets the right values. The template gave me an XML parse error so I had to use the modified one. It seems to be getting the data but the graph won't draw. I'm running 0.8.7e on FreeBSD. This is what RRDTool says:

Code: Select all

RRDTool Command:

/usr/local/bin/rrdtool graph - \
--imgformat=PNG \
--start=-86400 \
--end=-300 \
--title="Weatherbug - Humidity" \
--rigid \
--base=1000 \
--height=120 \
--width=500 \
--upper-limit=100 \
--lower-limit=0 \
--vertical-label="%" \
--slope-mode \
--font TITLE:12: \
--font AXIS:8: \
--font LEGEND:10: \
--font UNIT:8: \
DEF:a="/usr/local/share/cacti/rra/weatherbug_dewpoint_70.rrd":Humidity:LAST \
AREA:a#157419FF:"Humidity\n"  \
GPRINT:a:LAST:"Current\:%8.2lf %s"  \
GPRINT:a:MIN:"Minimum\:%8.2lf %s"  \
GPRINT:a:AVERAGE:"Average\:%8.2lf %s"  \
GPRINT:a:MAX:"Maximum\:%8.2lf %s\n" 

RRDTool Says:

ERROR: the RRD does not contain an RRA matching the chosen CF
I think here I have to change LAST to AVERAGE, but won't that mess up the graphs? And I have to do that for all the graphs because none of them will draw.

Thanks.

Jonathan
emuman100
Posts: 2
Joined: Mon Oct 18, 2010 11:50 am

Re: WeatherBug script & templates version 3.0 (weatherbug AP

Post by emuman100 »

Thanks gandalf and mcutting for your previous posts, as I have figured out the issue with your help. You need to go into Data Sources, then RRAs, go into each RRA and also select LAST, and save. Then you delete the existing graphs and recreate them.

Thanks again.

Jonathan
limaunion
Posts: 20
Joined: Tue Jul 05, 2005 10:44 am

Re: WeatherBug script & templates version 3.0 (weatherbug AP

Post by limaunion »

hi! I've just setup this script and it's working fine. I realized that weatherbug also provides the Gust speed which is not included in the script. I've tried to modify it but had no success.

This is what I currently have (other variable options were tried):

if ($_ =~ /<aws:gust-wind-speed units="km\/h">(\d+?)<\/aws:gust-speed>/g) { $data{Gusts} = $1; }

Can anyone enlightenment me?

TIA!
LU
Alekc
Posts: 2
Joined: Sat Apr 21, 2007 9:02 am

Re: WeatherBug script & templates version 3.0 (weatherbug AP

Post by Alekc »

I've done some small changes in the script.

[*]Added Guts Direction (degrees)
[*]Added Guts Speed
[*]Added Light Info
[*]Rendered script less unit dependent (it should be enough vary &unittype=x in order to change from metric in imperial and back)

Code: Select all

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

my $httpaddr = "http://$ARGV[0].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=".*?">(-*\d+?)<\/aws:dew-point>/g)     { $data{DewPoint} = $1; }
if ($_ =~ /<aws:feels-like units=".*?">(-*\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=".*?">(-*\d+?\.\d+?)<\/aws:temp>/g)         { $data{Temp} = $1; }
if ($_ =~ /<aws:wind-speed units=".*?">(\d+?)<\/aws:wind-speed>/g)        { $data{Wind} = $1; }
if ($_ =~ /<aws:gust-direction-degrees>(\d+?)<\/aws:gust-direction-degrees>/)        { $data{GutsDirection} = $1; }
if ($_ =~ /<aws:gust-speed units=".*?">(\d+?)<\/aws:gust-speed>/)        {$data{GutsSpeed} = $1; }
if ($_ =~ /<aws:light>(\d+?)<\/aws:light>/)                                { $data{Light} = $1; }

for (keys %data) {
  printf "%s:%s ", $_, $data{$_};
  }

  print "\n";
synes
Posts: 1
Joined: Wed Dec 01, 2010 7:04 am

Re: WeatherBug script & templates version 3.0 (weatherbug AP

Post by synes »

New version of the script for external of US countries, there was a little bug in pressure regexp.

EDIT : Corrected spelling error for "gust", be careful with your data input method and templates

Code: Select all

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

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

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

# regex in html source order
if ($_ =~ /<aws:dew-point units=".*?">(-*\d+?)<\/aws:dew-point>/g)     { $data{DewPoint} = $1; }
if ($_ =~ /<aws:feels-like units=".*?">(-*\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=".*?">(-*\d+?\.\d+?)<\/aws:temp>/g)         { $data{Temp} = $1; }
if ($_ =~ /<aws:wind-speed units=".*?">(\d+?)<\/aws:wind-speed>/g)        { $data{Wind} = $1; }
if ($_ =~ /<aws:gust-direction-degrees>(\d+?)<\/aws:gust-direction-degrees>/)        { $data{GustDirection} = $1; }
if ($_ =~ /<aws:gust-speed units=".*?">(\d+?)<\/aws:gust-speed>/)        {$data{GustSpeed} = $1; }
if ($_ =~ /<aws:light>(\d+?)<\/aws:light>/)                                { $data{Light} = $1; }

for (keys %data) {
  printf "%s:%s ", $_, $data{$_};
  }

print "\n";
cjolly3053
Posts: 48
Joined: Thu Jan 06, 2011 9:30 am
Location: Nashville, TN
Contact:

Re: WeatherBug script & templates version 3.0 (weatherbug AP

Post by cjolly3053 »

Ok for you Windows guys having issues I will try and explain how I got mine running.

I am running Windows 7 w/cacti 0.8.7.g and used a exe I found that installed cacti but that may not be as important.

First things first actually getting the script and importing the XML
1. put the weatherbug_api.pl in the C:\inetpub\wwwroot\cacti\scripts directory
2. tried to import the XML but had issues that is was not formatted correctly so had to save the XML from firefox to get it to download correctly.

So now I have the XML imported and script in the proper locations... And guess what does not work. Well of course not this was made for unix.

I made sure to request my API code and responded to the email and received my API code

Next I downloaded the windows msi of ActivePerl at http://www.activestate.com/activeperl/downloads

This installed perl in the default location of C:\Perl\bin

So now at this point I have my weatherbug_api.pl installed and template imported along with perl actually installed on the windows machine. At this point you should be able to verify everything is working by running the api as follows:
- C:\Perl\bin\perl.exe C:\inetpub\wwwroot\cacti\scripts\weatherbug_api.pl <API CODE> <ZIP CODE>

Ok now that we can get data via command line we need to create a device.
Just add a device with a Description of whatever you want and for the hostname just use localhost. I personally turned off both the detection and snmp.

Now click on the data template on the left and make sure at the bottom you put in your API code and zip code you want to use and save it. This should fill in for all the data templates but check them to make sure.

OK now for the very important part that probably kept most from getting this to work. We need to tell cacti how to run the perl script since windows is a little different.
1-Click on Data Input Methods in the left column
2- In the Input String box place this:
- C:\Perl\bin\perl.exe <path_cacti>/scripts/weatherbug_api.pl <api_code> <zipcode>
3- Save
This tells cacti how to run the perl script and get the data.

You should now create graphs for the device by clicking Devices and your weatherbug device and click the link at the top to create graphs and select all the graphs.

Sorry if I jumped around a little and some steps may not be in the best order but I think the two things that were most important for us windows users was the fact we need to install perl and we must tell cacti how to run the script.

Hope this helps you guys out... I know I felt I wasted a lot of time reading all the posts and seeing no help for windows users so felt I wanted to share how I got mine to work.

Good luck and if I missed anything just msg me and I will help how I can.

-Chris Jolly-
bonj87
Cacti User
Posts: 92
Joined: Fri Mar 26, 2010 7:42 am

Re: WeatherBug script & templates version 3.0 (weatherbug AP

Post by bonj87 »

ok i got this working.. but my precipitation graph is showing 'in' on the axis.. for inches.. but is displaying in mm instead.
how can i adjust this so it shows the true value in inches?
jhollon
Cacti User
Posts: 51
Joined: Mon Jan 24, 2011 1:30 pm

Re: WeatherBug script & templates version 3.0 (weatherbug AP

Post by jhollon »

i updated the weatherbug_api.pl file with the latest one in this thread and now, i get this when i run it from command line.

root@SLS-Cacti:/var/www/cacti/scripts# perl weatherbug_api.pl A53482xxx 36602

root@SLS-Cacti:/var/www/cacti/scripts#


as you can see, it returns no errors, as well as (most importantly) no data whatsoever.

no i tried to go back to the old one and it does the same exact thing. It is executable and perms are correct. i am not sure where to go from here, but i updated in hopes that it would fix my Precipitation graphs that showed 200mm rather than inches.

thanks for the help in advance.

Jeff
cybrk
Posts: 2
Joined: Mon Feb 07, 2011 12:58 pm

Re: WeatherBug script & templates version 3.0 (weatherbug AP

Post by cybrk »

Greetings all,

I have looked at this most recent script and see that it includes Gust data and Wind direction data. I hope this is not a stupid question, but does not the template also need to be edited to accomidate these new variables?

I found a "°F" in line 362 of the Template that was causing XML Parse errors for me, but after removal, cacti likes it.

I would be very interested in the best strategic method for reporting on the prevailing wind and gust direction variables.

Does a radial graph or compass graph exist yet within Cacti? or are wind directions commonly translated to best guess compass degrees and graphed with y= 0-360 ?

Just curious how everyone else is approaching this.

Also when using Cacti for Temperature and other weather metrics has anyone else explored GPRINT Presets to make sure we are using the best option? I am only just learning this tool, but this numerical notation is a little confusing.

P.S. Jeff I have the same problem with the new script, it no worky, it does not return data. Previous working script still works, so I am trying to solve it now.



I recently had some help from a Perl wizard whom has shown me a very effecient new script method that uses the "wget" command and this uses much less overhead on Cacti.

I have included it here:

Code: Select all

#!/usr/bin/perl 
my %data; 
my $CMD = "/usr/bin/wget --quiet -O - ";
my $URL = "http:\/\/$ARGV[0]\.api\.wxbug\.net\/getLiveWeatherRSS\.aspx?ACode=$ARGV[0]&stationid=$ARGV[1]&unittype=0";
my $c   = "$CMD" . "\"$URL\"";
my $o   = qx/$c/;
# regex in html source order 
if ($o =~ /<aws:dew-point units="&deg;F">(\d*)<\/aws:dew-point>/g) { $data{DewPoint} = $1; } 
if ($o =~ /<aws:feels-like units="&deg;F">(\d*)<\/aws:feels-like>/g) { $data{FeelsLike} = $1; } 
if ($o =~ /<aws:humidity units="%">(\d*)<\/aws:humidity>/g) { $data{Humidity} = $1; } 
if ($o =~ /<aws:pressure units=""">(\d*\.\d*)<\/aws:pressure>/g) { $data{Pressure} = $1; } 
if ($o =~ /<aws:rain-rate units=""\/h">(\d*\.?\d*)<\/aws:rain-rate>/g) { $data{Rain} = $1; } 
if ($o =~ /<aws:temp units="&deg;F">(\d*\.\d*)<\/aws:temp>/g) { $data{Temp} = $1; } 
if ($o =~ /<aws:wind-speed units="mph">(\d*)<\/aws:wind-speed>/g) { $data{Wind} = $1; } 

for (keys %data) { 
    printf "%s:%s ", $_, $data{$_}; 
} 
print "\n";


Please let me know any comments. This script assumes API code and Station ID but can be modified for API code and Zipcode, or possibly CityCode...not sure on that one.

I am still interested on comments regarding wind and prevailing wind trend graphs as they show "direction" as well as speed. Has anyone any good ideas on how best to graph this?

I would like to also add this link/thread :

y-axis scale labels in auto-scale mode

http://forums.cacti.net/viewtopic.php?t=31970

It will explain needed modifications for y-axis scale for pressure's low standard deviation depending on your Cacti version.

Best regards,
cybrk
Last edited by cybrk on Tue Apr 19, 2011 8:06 pm, edited 2 times in total.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests