I was recently at a client site where I met a man named Jeremy Ford. He’s sharp as a knife and even though, at the time, he was new to OpenNMS, he had already hacked a few neat things into the system (open source FTW).
One of those was the addition of a weathermap to the OpenNMS home page. He has graciously put the code up on Github.
The code is a script that will generate a JSP file in the OpenNMS “includes” directory. All you have to do then is to add a reference to it in the main index.jsp file.
For those of you who don’t know or who have never poked around, under the $OPENNMS_HOME
directory should be a directory called jetty-webapps
. That is the web root directory for the Jetty servlet container that ships with OpenNMS.
Under that directory you’ll find a subdirectory for opennms
. When you surf to http://[my OpenNMS Server]:8980/opennms
that is the directory you are visiting. In it is an index.jsp
file that serves as the main page.
If you are familiar with HTML, the JSP file is very similar. It can contain references to Java code, but a lot of it is straight HTML. The file is kept simple on purpose, with each of the three columns on the main page indicated by comments. The part you will need to change is the third column:
<!-- Right Column --> <div class="col-md-3" id="index-contentright"> <!-- weather box --> <jsp:include page="/includes/weather.jsp" flush="false" />
Feel free to look around. If you ever wanted to rearrange the OpenNMS Home page, this is a good place to start.
Now, I used to like poking around with these files since they would update automatically, but later versions of OpenNMS (which contain later versions of Jetty) seem to require a restart. If you get an error, restart OpenNMS and see if it goes away.
Now the weather.jsp
file gets generated by Jeremy’s python script. In order to get that to work you’ll need to do two things. The most important is to get an API key from Weather Underground. It is a pretty easy process, but be aware that you can only do 500 queries a day without paying. The second thing you’ll need to do is edit the three URLs in the script and change the location. It is currently set to “CA/San_Francisco” but I was able to change it to “NC/Pittsboro” and it “just worked”.
Finally, you’ll need to set the script up to run via cron. I’m not sure how frequently Weather Underground updates the data, but a 10 minute interval seems to work well. That’s only 144 queries a day, so you could easily double it and still be within your limit.
[IMPORTANT UPDATE: Jeremy pointed out that the script actually does three queries, not just one, so instead of doing 144 queries a day, it’s 432. Still leaves some room with 10 minute queries but you don’t want to increase the frequency too much.]
Thanks to Jeremy for taking the time to share this. Remember, once you get it working, if you upgrade OpenNMS you’ll need to edit index.jsp
and add it back, but that should be the only change needed.