From OpenNMS
Contents |
About
Sometimes it is important to know when particular areas of the country or world are experiencing severe weather. Such events are severe enough to cause disruption in power, cooling and network connectivity. All of these dependencies are needed for any device being monitored by Opennms. If power goes out in a remote facility it would be nice to know before the UPS runs out of battery power. I always seem to hold my breath at 3am when performing fsck on a filesystem because of a power event caused by a storm. Cleanly turning remote equipment off would have been the preferred choice. To summarize, severe weather happens and when it does I want to know about it. I want to be able to react fast with enough time to remotely shutdown a system. Because opennms is very flexible I wrote a small python script to basically be my weatherman and send a weather event to opennms. When opennms receives this weather event it will then send out a notification through its normal mechanism.
Requirements
- Opennms
- python 2.4
- python-xml if using SLES 10
- send-event.pl located in /opt/opennms/bin/
- Five minutes of your time.
How it works
- getWeather.py is called manually or via a cron job
- getWeather.py uses the weatherbug API to get a XML encoded result with the weather report
- getWeather.py parses and processes the XML and determines if any weather exists in that area
- getWeather.py also scans the result for certain severe weather types and creates specific opennms events (UEI)
- If severe weather exists it then calls the send-event.pl in /opt/opennms/bin/ with the weather report
- Send-event.pl receives this weather report and displays it in the event stream according to the weather event defination defined in Weather.events.xml
- If notifications are enabled for the specific or general weather events a notification is sent.
- You are alerted by the notification and quickly shutdown your servers as a hurricane is imminent.
How to Install
Download
git clone git://github.com/logicminds/opennms-addons.git
or
wget https://github.com/logicminds/opennms-addons/tarball/master
- Download getWeather.py and put this somewhere on the opennms server (/opt/opennms/bin/ is a good place)
- Download Weather.events.xml and put in /opt/opennms/etc/events/ or copy and paste the following into /opt/opennms/etc/events/Weather.events.xml
<events>
<event>
<uei>uei.opennms.org/vendor/weather/events/WeatherAlert</uei>
<event-label>Weather: General Weather Alert </event-label>
<descr> <p> %parm[title]% </p><br>
<p> %parm[alertmsg]% </p>
<br>
<b>Areas affected:</b> %parm[counties]%
</descr>
<logmsg dest='logndisplay'> General Weather Alert: %parm[title]% for %parm[loc]%</logmsg>
<severity>Normal</severity>
</event>
<event>
<uei>uei.opennms.org/vendor/weather/events/tornadoAlert</uei>
<event-label>Weather: Tornado Weather Alert </event-label>
<descr> <p> %parm[title]% </p><br>
<p> %parm[alertmsg]% </p>
<br>
<b>Areas affected:</b> %parm[counties]%
</descr>
<logmsg dest='logndisplay'> Tornado Weather Alert: %parm[title]% for %parm[loc]%</logmsg>
<severity>Normal</severity>
</event>
<event>
<uei>uei.opennms.org/vendor/weather/events/hurricaneAlert</uei>
<event-label>Weather: Hurricane Weather Alert </event-label>
<descr> <p> %parm[title]% </p><br>
<p> %parm[alertmsg]% </p>
<br>
<b>Areas affected:</b> %parm[counties]%
</descr>
<logmsg dest='logndisplay'> Hurricane Weather Alert: %parm[title]% for %parm[loc]%</logmsg>
<severity>Normal</severity>
</event>
<event>
<uei>uei.opennms.org/vendor/weather/events/blizzardAlert</uei>
<event-label>Weather: Blizzard Weather Alert </event-label>
<descr> <p> %parm[title]% </p><br>
<p> %parm[alertmsg]% </p>
<br>
<b>Areas affected:</b> %parm[counties]%
</descr>
<logmsg dest='logndisplay'> Blizzard Weather Alert: %parm[title]% for %parm[loc]%</logmsg>
<severity>Normal</severity>
</event>
</events>
Setup
- Edit /opt/opennms/etc/eventconf.xml and add the following near the bottom where all the other includes are.
<event-file>events/Weather.events.xml</event-file>
- Either reload the eventd or restart opennms to find the new events.
- Add the weather notifications to your notifications.xml file or use the WebUI to set this up. This is an example.
You can copy and paste this into the notifications.xml and change to something for your environment. You will need a notification for each type of weather event (blizzard, tornado, hurricane, ...). Note: This can also be done through the web UI
<notification name="Blizzard Weather Alert" status="on" writeable="yes">
<uei xmlns="">uei.opennms.org/vendor/weather/events/blizzardAlert</uei>
<description xmlns="">A Blizzard Weather Alert has been received</description>
<rule xmlns="">(IPADDR IPLIKE *.*.*.*)</rule>
<destinationPath xmlns="">test</destinationPath>
<text-message xmlns="">A Blizzard Weather Alert has been received by opennms. %parm[condition]% %parm[summary]% Affected counties: %parm[counties]%</text-message>
<subject xmlns="">%parm[title]% for location : %parm[loc]%</subject>
<numeric-message xmlns="">111-%noticeid%</numeric-message>
</notification>
<notification name="General Weather Alert" status="on" writeable="yes">
<uei xmlns="">uei.opennms.org/vendor/weather/events/WeatherAlert</uei>
<description xmlns="">A General Weather Alert has been received</description>
<rule xmlns="">(IPADDR IPLIKE *.*.*.*)</rule>
<destinationPath xmlns="">test</destinationPath>
<text-message xmlns="">A General Weather Alert has been received by opennms. %parm[condition]% %parm[summary]% Affected counties: %parm[counties]%</text-message>
<subject xmlns="">%parm[title]% for location : %parm[loc]%</subject>
<numeric-message xmlns="">111-%noticeid%</numeric-message>
</notification>
In my example I have "test" which is a test destination path I setup. You will need to change this to suit your environment.
<destinationPath>test</destinationPath>
How to Use
- Manually
bash# python /opt/opennms/bin/getWeather.py 90210
- Automated via Cron job
0 12,23 * * * /usr/bin/python /opt/opennms/bin/getWeather.py 90210 >> /tmp/getWeather.log
Advanced
Note: This is for advanced users but is still pretty simple to understand.
Report Multiple Zip Codes Easily
If would like to report weather for multiple zip codes you can use the "--all" keyword. This will trigger an action to send check weather for all zipcodes you have defined in the getWeather.py file. I have defined a few so far that pertain to job but feel free to change to suit your own needs. Just edit the following.
# The Following list is for a simple lookup if you can't remember zip codes
# If you add more zip codes here they will be included with the --all command
AIRPORT_CODES={'ATL': '30297', 'BWI': '21075', 'BOS': '02081', 'ORD': '60018',
'CVG': '41048', 'TEX': '75050', 'DEN': '80216', 'IND': '46241', 'SFO': '94587',
'SEA': '90002'}
bash# python /opt/opennms/bin/getWeather.py --all
New Extreme Weather Event Types
If you would like to define new weather types you will need to do the following.
- Edit the Weather.events.xml file for the new event
- Modify the getWeather.py file to include the new event type.
All weather events not defined in the extremewords list will be considered a general weather event. The extreme words will only work if that word is in the alert provided by weather bug. If you do this please let me know so I can add these new events.
# Add more extreme words to the following list to trigger new events # These events will need to be defined in the Weather.events.xml file extremewords=['hurricane', 'tornado', 'blizzard']
Notification and Event Variables
- %parm[alertmsg]% (The main alert message)
- %parm[loc]% (The zipcode you input on the command line)
- %parm[type]% (The type of weather alert)
- %parm[title]% (Short description of alert)
- %parm[summary]% (Summary of the message)
- %parm[counties]% (Counties affected in the alert)
Help
For help please join the opennms discussion group and ask.
https://lists.sourceforge.net/lists/listinfo/opennms-discuss
For code updates or other questions please email me






