Weatherbug XML API script and templates

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

Moderators: Moderators, Developers

Author
Message
Mondo1287
Posts: 15
Joined: Wed Oct 11, 2006 8:08 am

Weatherbug XML API script and templates

#1 Post by Mondo1287 » Tue Feb 06, 2007 10:18 pm

The following is a simple implementation of WeatherBug's API, and Cacti to create some basic weather graphs. You'll need to register with WeatherBug to receive an "API Code". http://apireg.weatherbug.com/defaultAPI.aspx

This is probably not bug free, but seems to work well. Future updates will likely include more data from WeatherBug's API calls, such as adding predicted highs and lows to the temperature graph.

Note: I am in no way affiliated with WeatherBug.

Open the README file for further instructions.

I was hoping to create something a little easier to work with than the other cacti weather graphing solutions. Comments and criticisms are welcome.

Edit: You may need to edit php.ini and set allow_url_fopen = on
e.g. /etc/php/cli-php5/php.ini

I updated the graph templates and data template to handle negative numbers.

Edit: Added in TheWitness's modified polling script.
Attachments
wbugapi.zip
(17.08 KiB) Downloaded 1340 times
Last edited by Mondo1287 on Mon May 21, 2007 10:00 am, edited 3 times in total.

Mondo1287
Posts: 15
Joined: Wed Oct 11, 2006 8:08 am

#2 Post by Mondo1287 » Wed Feb 07, 2007 3:56 pm

I updated the templates to handle negative numbers. If you already downloaded them, import the updated templates (it will just update the existing ones). Then navigate to <cacti path>/rra/ and run

rrdtool tune <rrd filename> --minimum DewPoint:-200
rrdtool tune <rrd filename> --minimum Temperature:-200

You can find the rrd filename by clicking Data Sources, then choose WeatherBug API DS.

MaffooClock
Posts: 17
Joined: Wed Jul 12, 2006 11:25 pm

#3 Post by MaffooClock » Tue Mar 13, 2007 9:28 pm

I like this better than the other Weatherbug script, especially since this uses an XML API.

Cuerrently, I have the dreaded 'nan' issue with this, however, running the wbugxml.php script at the command-line produced values.

Regardless, once I figure out what my problem is, I'd like to tweak this more and get as much data from the API graphed as possible (as long as you don't mind, of course).

I'll post more feedback as I come across new issues/ideas...

MaffooClock
Posts: 17
Joined: Wed Jul 12, 2006 11:25 pm

#4 Post by MaffooClock » Wed Mar 14, 2007 10:05 am

I spent HOURS troubleshooting the 'nan' issue and I didn't get anywhere. (By the way, I should mention that I am very proficient with Linux, PHP, MySQL, and Cacti.)

I noticed that I had not followed your instructions for installing the templates, so I removed ALL associated graph templates, data templates, data sources, graphs -- everything. I then re-installed all of this by following your instructions precisely. At that point, the graphs weren't being drawn at all. I found that because they are not associated with any hosts, they are never placed in the poller cache. Am I right about this? When I created a dummy host and re-associated all of the data sources and graphs to the new dummy host, the poller cache showed an entry, and the graphs were being generated (but still showing 'nan values').

I should mention that I created a test database for cacti aside from my operational cacti database so that I could tinker with this more. So, essentially, I have a brand new cacti installation, so all of these symptoms cannot be attributed to database corruption or any other misconfiguration.

As the author of these script/templates, I'm certain they work for you. But there's something you're missing (I think), especially when you wrote the README. I hope you'll have some time to help me with this, and I'll be happy to contribute any way I can to making this work for everyone.

But, hopefully I am just stupid and have missed something, and someone will point it out, call me an idiot, and then all will be well.
Last edited by MaffooClock on Wed Mar 14, 2007 4:56 pm, edited 1 time in total.

MaffooClock
Posts: 17
Joined: Wed Jul 12, 2006 11:25 pm

#5 Post by MaffooClock » Wed Mar 14, 2007 1:26 pm

Well, at this point, it seems that I have fixed my graphs. I removed all graphs, data sources, input methods, and everything else. Then, I installed everything according to the README, but then created a dummy host and assigned the data sources and graphs to that host. Now I have data in my graphs.

apperrault
Cacti User
Posts: 372
Joined: Fri Feb 16, 2007 11:37 am
Location: Emeryville, CA
Contact:

#6 Post by apperrault » Tue Mar 20, 2007 3:37 pm

Question, is there a way to setup multiple locations? I have 5 across the country, and one in Canada, and I would love to be able to add all of my sites to my Weather graph group.

Thanks much

app
[b]Cacti Version[/b] - 0.8.7b
[b]Plugin Architecture[/b] - 2.2 Beta
[b]Poller Type[/b] - CMD.php
[b]Server Info[/b] - Linux 2.6.9-78.0.1.ELsmp
[b]Web Server[/b] - Apache/2.0.52 (Red Hat)
[b]PHP[/b] - 4.3.9
[b]MySQL[/b] - 4.1.22
[b]RRDTool[/b] - 1.2.23
[b]SNMP[/b] - 5.1.2
[b]Plugins[/b][list]Global Plugin Settings (settings - v0.5)
SuperLinks (superlinks - v0.72)
Host Info (hostinfo - v0.2)
Report Creator (reports - v0.3)
Update Checker (update - v0.4)
Realtime for Cacti (realtime - v0.35)
Cacti Log View (clog - v1.1)
RRD File Cleaner (rrdclean - v0.36)
Network Discovery (discovery - v0.9)
Uptime (uptime - v0.4)[/list]

Mondo1287
Posts: 15
Joined: Wed Oct 11, 2006 8:08 am

#7 Post by Mondo1287 » Mon Mar 26, 2007 9:19 am

MaffooClock, sorry for the late reply. Have you checked to ensure the script is working? Try running wbugxml.php from a shell prompt and make sure there are no errors. It should just output the weather values. I haven't looked at this in quite some time, so I'll try and do a clean install following my instructions and see if there's something I left out.

Mondo1287
Posts: 15
Joined: Wed Oct 11, 2006 8:08 am

#8 Post by Mondo1287 » Mon Mar 26, 2007 3:04 pm

I just did a fresh install of Cacti and I didn't have any issues with my script or templates. I did, however, run into a couple of problems I seem to usually have when installing Cacti. Permission problems with the rra and log folders are common. For testing purposes just do

Code: Select all

chmod -R 777 rra/ log/
from the cacti folder. If you are having nan problems on a fresh install, make sure that cacti is functioning correctly. Create a standard snmp graph for example just to make sure the poller and everything is functioning properly.

Mondo1287
Posts: 15
Joined: Wed Oct 11, 2006 8:08 am

#9 Post by Mondo1287 » Mon Mar 26, 2007 3:18 pm

apperrault wrote:Question, is there a way to setup multiple locations? I have 5 across the country, and one in Canada, and I would love to be able to add all of my sites to my Weather graph group.

Thanks much

app
I can't think of a simple solution for this. I wouldn't mind being able to graph multiple locations myself, so if I get around to it I'll post a write up and probably some updated templates and a script.

cacti_user_md
Posts: 2
Joined: Thu Apr 19, 2007 11:31 am

Gaps in graphs?

#10 Post by cacti_user_md » Tue May 01, 2007 3:14 pm

Has anyone else had any problems with gaps in the Weatherbug graphs? The problem seems to be with the Weatherbug server and not Cacti. The gaps appear much more frequently during the day than at night, so it might be caused by heavy traffic to Weatherbug. Just looking for ideas.
Attachments
weatherbug.jpg
weatherbug.jpg (151.71 KiB) Viewed 25809 times

Mondo1287
Posts: 15
Joined: Wed Oct 11, 2006 8:08 am

#11 Post by Mondo1287 » Wed May 02, 2007 6:01 am

I have the same gaps in my graphs so it must be their server. There is usually an occasional gap but this week there seems to be a ton of them.

tstrathdee
Posts: 3
Joined: Thu May 17, 2007 9:57 pm

Fatal Error on wbugxml.php from command line

#12 Post by tstrathdee » Thu May 17, 2007 10:09 pm

After installing, I wasn't getting any data on my graphs so I tried to run wbugxml.php from the command line. I am getting the following error message

Fatal error: Call to a member function children() on a non-object in /var/www/cacti/scripts/wbugxml.php on line 10

Any ideas on what might be causing this?
Thanks.

Mondo1287
Posts: 15
Joined: Wed Oct 11, 2006 8:08 am

#13 Post by Mondo1287 » Fri May 18, 2007 10:32 am

It may be a problem with PHP not having simplexml support compiled in, but I would assume it would fail on line 7 if that was the case. It sounds like it's not loading the xml data from their website. Comment out lines 10-24, and then add

Code: Select all

echo $url;
Run it from the command line and it should give you the URL it is using, paste that in your browser and you should see the xml. If you get some kind of error then something is probably wrong with your api code, station id, or zipcode.

tstrathdee
Posts: 3
Joined: Thu May 17, 2007 9:57 pm

You were right!

#14 Post by tstrathdee » Sun May 20, 2007 9:32 pm

Mondo1287 wrote:It may be a problem with PHP not having simplexml support compiled in, but I would assume it would fail on line 7 if that was the case. It sounds like it's not loading the xml data from their website. Comment out lines 10-24, and then add

Code: Select all

echo $url;
Run it from the command line and it should give you the URL it is using, paste that in your browser and you should see the xml. If you get some kind of error then something is probably wrong with your api code, station id, or zipcode.
Thanks, I am embarrassed to say it was a typo in the Site ID... Thanks for your help!

User avatar
TheWitness
Developer
Posts: 14855
Joined: Tue May 14, 2002 5:08 pm
Location: MI, USA
Contact:

#15 Post by TheWitness » Mon May 21, 2007 6:05 am

All,

Reviewing Mondo1287's script, I noted an issue relative to the outputing of the script results. The method chosen will cause problems with Cactid. Therefore, I have revised the code attached.

TheWitness
Attachments
wbugxml.zip
(521 Bytes) Downloaded 878 times
True understanding begins only when we realize how little we truly understand...

Life is an adventure, let yours begin with Cacti!

Author of MacTrack, Boost, CLog, SpikeKill, Platform RTM, DSStats, maintainer of Spine, lot's of unpublished work and most of Cacti's bugs.
_________________
Official Cacti Documentation
GitHub Repository with Supported Plugins
Central Plugin Repository
Central Templates Repository


I'm still out there people. Getting excited for Cacti 1.2. I think it will be a great release.

Post Reply