WeatherBug script & templates

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

Moderators: Developers, Moderators

User avatar
lard
Cacti User
Posts: 165
Joined: Wed Jul 20, 2005 10:48 am
Location: UK - Cambridge

Post by lard »

ottomatic wrote:Ok... After much frustration I figured out how this works.

Step 1: Import the template and copy the perl script to the scripts directory

Step 2: Make sure that in your Settings > Poller > Downed Host Detection is set to "Ping and SNMP"

Step 3: Devices and create a new host by clicking Add.

Step 4: Enter your description. Then your hostname... you can add a host that is pingable or 127.0.0.1. Then change the host template to "WeatherBug." then click create.

Step 5: Click on "Create Graphs for this Host"

Step 6: Then click on the types of weather you want to graph. I just checked them all.

Step 7: Now... In all of the blanks that say... "get code from..." Go to that website and search for your code. Once have found the weather for your city. In the address bar there is a "?id=" and then there is a few letters... That is your code. Put that in all the blanks that say "get code from..." then click create at the bottom.

Step 8: Now go to your Graph Trees and add the host (the description is what you should look for) that we created earlier in step 1. Then wait for the poller go get the weather.
Many thanks for the clear and consise instructions - I will give it a go now and hopefully it will be a breeze ( :) )
---- lard007skype ----
User avatar
lard
Cacti User
Posts: 165
Joined: Wed Jul 20, 2005 10:48 am
Location: UK - Cambridge

Post by lard »

o.k. - all fine apart from not being prompted for the code when creating the graphs...can I just change this in the data imput method or is there a better way perhaps?

Thanks,

Lard
---- lard007skype ----
ottomatic
Posts: 10
Joined: Mon Mar 20, 2006 3:29 pm

Post by ottomatic »

You can go to "Data Sources" then look for weatherbug. You should have 5 (if you selected all 5 graphs). Click on one of the weatherbug's and then put the code in the last blank what says "Weather Code."
User avatar
lard
Cacti User
Posts: 165
Joined: Wed Jul 20, 2005 10:48 am
Location: UK - Cambridge

Post by lard »

ottomatic wrote:You can go to "Data Sources" then look for weatherbug. You should have 5 (if you selected all 5 graphs). Click on one of the weatherbug's and then put the code in the last blank what says "Weather Code."
Excellent spotted that one - if you change the data template and select the "ignore this value" checkbox and enter "null" in the code field it will then ask you for them when you create the graphs,

Having an issue with the perl script though as it was on widows 2k - putting it on the centos server and I'm sure it will work fine!

Thanks for the help!

Lard
---- lard007skype ----
User avatar
lard
Cacti User
Posts: 165
Joined: Wed Jul 20, 2005 10:48 am
Location: UK - Cambridge

Post by lard »

Strange but when I run this code I always only get two variables returned - does not seem to matter what code I enter as the METAR:

[root@localhost /]# usr/bin/perl /var/www/html/scripts/weatherbug.pl EGSC
DewPoint:1.2 HeatIndex:1.2


[root@localhost /]# usr/bin/perl /var/www/html/scripts/weatherbug.pl ABCD
DewPoint:1.2 HeatIndex:1.2

The script is:

#!/usr/bin/perl
use warnings;
use strict;

use LWP::Simple;

my $httpaddr = "http://www.aws.com/aws_2001/asp/obsforecast.asp?id=?" . $ARGV[0];

my %data;
my %trash;
my $content = LWP::Simple::get($httpaddr) or die "Couldn't get it!";

# regex in html source order
if ($content =~ /(<b>Temperature<\/b>)/g) { $trash{a} = $1; }
if ($content =~ /<b>(-?\d+\.\d+)<\/b>/g) { $data{Temp} = $1; }

if ($content =~ /(<b>Humidity<\/b>)/g) { $trash{a} = $1; }
if ($content =~ /<b>(\d+\.\d+)<\/b>/g) { $data{Humidity} = $1; }

if ($content =~ /(<b>Wind<\/b>)/g) { $trash{a} = $1; }
if ($content =~ /(\d+\.\d+)<\/b>/g) { $data{Wind} = $1; }

if ($content =~ /(<b>Daily Rain<\/b>)/g) { $trash{a} = $1; }
if ($content =~ /<b>(\d+\.\d+)<\/b>/g) { $data{Rain} = $1; }

if ($content =~ /(<b>Pressure<\/b>)/g) { $trash{a} = $1; }
if ($content =~ /<b>(\d+\.\d+)<\/b>/g) { $data{Pressure} = $1; }

if ($content =~ /(HEAT INDEX|WIND CHILL)/g) { $trash{a} = $1; }
if ($content =~ /(\d+\.\d+)/g) { $data{HeatIndex} = $1; }

if ($content =~ /(DEW POINT:)/g) { $trash{a} = $1; }
if ($content =~ /(\d+\.\d+)/g) { $data{DewPoint} = $1; }

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

I notice that the variables that are returning are in CAPS - could this be the issue?

Thanks,

Lard
---- lard007skype ----
User avatar
lard
Cacti User
Posts: 165
Joined: Wed Jul 20, 2005 10:48 am
Location: UK - Cambridge

Post by lard »

lard wrote:Strange but when I run this code I always only get two variables returned - does not seem to matter what code I enter as the METAR:

[root@localhost /]# usr/bin/perl /var/www/html/scripts/weatherbug.pl EGSC
DewPoint:1.2 HeatIndex:1.2


[root@localhost /]# usr/bin/perl /var/www/html/scripts/weatherbug.pl ABCD
DewPoint:1.2 HeatIndex:1.2

The script is:

#!/usr/bin/perl
use warnings;
use strict;

use LWP::Simple;

my $httpaddr = "http://www.aws.com/aws_2001/asp/obsforecast.asp?id=?" . $ARGV[0];

my %data;
my %trash;
my $content = LWP::Simple::get($httpaddr) or die "Couldn't get it!";

# regex in html source order
if ($content =~ /(<b>Temperature<\/b>)/g) { $trash{a} = $1; }
if ($content =~ /<b>(-?\d+\.\d+)<\/b>/g) { $data{Temp} = $1; }

if ($content =~ /(<b>Humidity<\/b>)/g) { $trash{a} = $1; }
if ($content =~ /<b>(\d+\.\d+)<\/b>/g) { $data{Humidity} = $1; }

if ($content =~ /(<b>Wind<\/b>)/g) { $trash{a} = $1; }
if ($content =~ /(\d+\.\d+)<\/b>/g) { $data{Wind} = $1; }

if ($content =~ /(<b>Daily Rain<\/b>)/g) { $trash{a} = $1; }
if ($content =~ /<b>(\d+\.\d+)<\/b>/g) { $data{Rain} = $1; }

if ($content =~ /(<b>Pressure<\/b>)/g) { $trash{a} = $1; }
if ($content =~ /<b>(\d+\.\d+)<\/b>/g) { $data{Pressure} = $1; }

if ($content =~ /(HEAT INDEX|WIND CHILL)/g) { $trash{a} = $1; }
if ($content =~ /(\d+\.\d+)/g) { $data{HeatIndex} = $1; }

if ($content =~ /(DEW POINT:)/g) { $trash{a} = $1; }
if ($content =~ /(\d+\.\d+)/g) { $data{DewPoint} = $1; }

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

I notice that the variables that are returning are in CAPS - could this be the issue?

Thanks,

Lard
Please forgive me for spamming the forums :oops: - I had an errant "?" in the URL!

Best,

Lard
---- lard007skype ----
qwertz
Cacti User
Posts: 98
Joined: Thu Feb 16, 2006 9:20 am

Post by qwertz »

what a beautiful script !!!

The "problem" is that i'm living in Switzerland /Europe ...

Is there a place where i could catch weather info for European countries ?

Thank you very much

Qwertz
User avatar
lard
Cacti User
Posts: 165
Joined: Wed Jul 20, 2005 10:48 am
Location: UK - Cambridge

Post by lard »

qwertz wrote:what a beautiful script !!!

The "problem" is that i'm living in Switzerland /Europe ...

Is there a place where i could catch weather info for European countries ?

Thank you very much

Qwertz
Sure - I'm in the UK and just googled for ICIA or WEBAR weatherstation codes on google.co.uk and hey presto it came out - the weatherstations all have a unique code, it's just that the site it uses to scrape only lets you search for US ones,

Happy weather bugging :)

Cheerio,

Lard
---- lard007skype ----
User avatar
lard
Cacti User
Posts: 165
Joined: Wed Jul 20, 2005 10:48 am
Location: UK - Cambridge

Post by lard »

lard wrote:
qwertz wrote:what a beautiful script !!!

The "problem" is that i'm living in Switzerland /Europe ...

Is there a place where i could catch weather info for European countries ?

Thank you very much

Qwertz
Sure - I'm in the UK and just googled for ICIA or WEBAR weatherstation codes on google.co.uk and hey presto it came out - the weatherstations all have a unique code, it's just that the site it uses to scrape only lets you search for US ones,

Happy weather bugging :)

Cheerio,

Lard
Here's one for Geneva LSGG

Lard
---- lard007skype ----
qwertz
Cacti User
Posts: 98
Joined: Thu Feb 16, 2006 9:20 am

Post by qwertz »

THANK YOU
kegrif
Posts: 1
Joined: Wed Mar 29, 2006 6:42 pm

Post by kegrif »

I still get this error when trying to import the XML file

Error: XML: Hash version does not exist.

I am running on Debian with Cacti Version 0.8.6c

Thanks.
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Post by gandalf »

This seems to be a downlevel cacti. Importing must be performed with at least the same level as exporting. And 0.8.6c is quite outdated
Reinhard
tkdan235
Posts: 17
Joined: Thu Apr 27, 2006 6:46 pm
Location: Sacramento, Ca

Post by tkdan235 »

ottomatic wrote:Ok... After much frustration I figured out how this works.......


Step 7: Now... In all of the blanks that say... "get code from..." Go to that website and search for your code. Once have found the weather for your city. In the address bar there is a "?id=" and then there is a few letters... That is your code. Put that in all the blanks that say "get code from..." then click create at the bottom.
The link I have for my area is =
http://www.aws.com/aws_2001/asp/obsFore ... &srch.y=13

The problem is that in that url there is no "?id=" ... I can't seem to add anything that will work. Is there something else I can put in these fields?
Jeff_Smith
Posts: 14
Joined: Thu May 04, 2006 11:53 am

Post by Jeff_Smith »

Below the stats there is a link to Full Observation. click that link and pull the ID from that URL.
tkdan235
Posts: 17
Joined: Thu Apr 27, 2006 6:46 pm
Location: Sacramento, Ca

Post by tkdan235 »

That is bring up the id, which for me is = KSAC

When I entered this code, it went through, but there is no data in my graphs. I am running 0.8.6g, and the rest of my graphs are working fine. I also tried entering = KSAC&obs=full just in case, but with no avail.

Any suggestions?
Locked

Who is online

Users browsing this forum: No registered users and 0 guests