root / plugins / weather / buienradar_ @ 0ddf0181
Historique | Voir | Annoter | Télécharger (9,39 ko)
| 1 | b7be0776 | Rowdy Schwach?fer | #!/usr/bin/perl |
|---|---|---|---|
| 2 | # |
||
| 3 | # Munin plugin for graphing the weather information provided by BuienRadar (The Netherlands) |
||
| 4 | # |
||
| 5 | # Copyright (C) 2011 - Rowdy Schwachofer (http://rowdy.nl) |
||
| 6 | # BuienRadar: http://www.buienradar.nl |
||
| 7 | # |
||
| 8 | # |
||
| 9 | # This program is free software: you can redistribute it and/or modify it under the terms of the |
||
| 10 | # GNU General Public License as published by the Free Software Foundation, either version 3 of |
||
| 11 | # the License, or (at your option) any later version. |
||
| 12 | # |
||
| 13 | # This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without |
||
| 14 | # even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||
| 15 | # General Public License for more details. |
||
| 16 | # |
||
| 17 | # You should have received a copy of the GNU General Public License along with this program. |
||
| 18 | # If not, see <http://www.gnu.org/licenses/>. |
||
| 19 | # |
||
| 20 | # |
||
| 21 | ### Requirements |
||
| 22 | # This plugin uses the perl module LibXML. You should have it installed... :) |
||
| 23 | # |
||
| 24 | # |
||
| 25 | # |
||
| 26 | ### Configuration example |
||
| 27 | # Use these settings in your client config in /etc/munin/plugin-conf.d/munin-node |
||
| 28 | # For the language you can use 'nl' (Dutch) or 'en'. O well, everything exept 'nl' will just show |
||
| 29 | # the english version. :) |
||
| 30 | # |
||
| 31 | # [buienradar*] |
||
| 32 | # env.language = 'en' |
||
| 33 | # env.temperature = 'yes' |
||
| 34 | # env.temperature10cm = 'yes' |
||
| 35 | # env.humidity = 'yes' |
||
| 36 | # env.windspeedMS = 'yes' |
||
| 37 | # env.windspeedBF = 'yes' |
||
| 38 | # env.airpressure = 'yes' |
||
| 39 | # env.view = 'yes' |
||
| 40 | # env.gusts = 'yes' |
||
| 41 | # env.rain = 'yes' |
||
| 42 | # |
||
| 43 | # |
||
| 44 | # |
||
| 45 | ### Installation Example |
||
| 46 | # Below is a example to monitor station Venlo (6391). Codes for the station can be seen at the end of |
||
| 47 | # this source or can be show with the command './buienradar_ stations' |
||
| 48 | # |
||
| 49 | # wget -O /usr/lib/munin/plugins/buienradar_ http://exchange.munin-monitoring.org/plugins/buienradar_/version/1/download |
||
| 50 | # chmod a+x /usr/lib/munin/plugins/buienradar |
||
| 51 | # ln -s /usr/lib/munin/plugins/buienradar_ /etc/munin/plugins/buienradar_6391 |
||
| 52 | # /etc/init.d/munin-node restart |
||
| 53 | # |
||
| 54 | |||
| 55 | use strict; |
||
| 56 | use warnings; |
||
| 57 | use XML::LibXML; |
||
| 58 | use Data::Dumper; |
||
| 59 | |||
| 60 | |||
| 61 | # Getting the enviroment variabeles |
||
| 62 | my $LAN = $ENV{language} || "en";
|
||
| 63 | my $TMP = $ENV{temperature} || "yes";
|
||
| 64 | my $TMP10CM = $ENV{temperature10cm} || "yes";
|
||
| 65 | my $HUM = $ENV{humidity} || "yes";
|
||
| 66 | my $WSMS = $ENV{windspeedMS} || "yes";
|
||
| 67 | my $WSBF = $ENV{windspeedBF} || "yes";
|
||
| 68 | my $AP = $ENV{airpressure} || "yes";
|
||
| 69 | my $VIEW = $ENV{view} || "yes";
|
||
| 70 | my $GUSTS = $ENV{gusts} || "yes";
|
||
| 71 | my $RAIN = $ENV{rain} || "yes";
|
||
| 72 | |||
| 73 | |||
| 74 | # Do we need to print the station list? |
||
| 75 | if (defined $ARGV[0] and $ARGV[0] eq "stations") {
|
||
| 76 | die print_stations(); |
||
| 77 | } |
||
| 78 | |||
| 79 | |||
| 80 | # Getting the station |
||
| 81 | my $station = ""; |
||
| 82 | if ($0 =~ /buienradar_(\w+)$/i) {
|
||
| 83 | $station = $1; |
||
| 84 | } elsif (not defined $ARGV[0] or ($ARGV[0] ne "config" and $ARGV[0] ne "stations")) {
|
||
| 85 | # Let's show a nice error message and display the list of stations |
||
| 86 | die "Error:\n" |
||
| 87 | ."We need to know what station you want to monitor. Please set your station this way \n\n" |
||
| 88 | ." ln -s /usr/lib/munin/plugins/buienradar_ /etc/munin/plugins/buienradar_STATIONCODE\n\n" |
||
| 89 | .print_stations(); |
||
| 90 | } |
||
| 91 | |||
| 92 | |||
| 93 | # Let's first try to find the station that is requested |
||
| 94 | my $xml = "http://xml.buienradar.nl"; |
||
| 95 | my $parser = XML::LibXML->new(); |
||
| 96 | my $doc = $parser->parse_file($xml); |
||
| 97 | my $stationNode = "//weerstation[stationcode/text() = '$station']/"; |
||
| 98 | my $stationName = "Regio ".$doc->findvalue($stationNode."/stationnaam/\@regio")." (".$doc->findnodes($stationNode."/stationnaam/text()").")";
|
||
| 99 | |||
| 100 | if($stationName eq "") {
|
||
| 101 | # Darn, no station name found. This means we don't provided a correct id. |
||
| 102 | die "Error:\n" |
||
| 103 | ."You have provided an invalid station code. (".$station.") Please use a correct one.\n\n"
|
||
| 104 | .print_stations(); |
||
| 105 | } |
||
| 106 | |||
| 107 | |||
| 108 | # Output for config |
||
| 109 | if(defined $ARGV[0] && $ARGV[0] eq 'config') {
|
||
| 110 | print "graph_title ".$stationName."\n"; |
||
| 111 | print "graph_category Weather\n"; |
||
| 112 | if($LAN eq "nl") {
|
||
| 113 | # Dutch Language |
||
| 114 | if($TMP eq "yes") { print "tmp.label Temperatuur (C)\n"; }
|
||
| 115 | if($TMP10CM eq "yes") { print "tmp10cm.label Temperatuur op 10cm (C)\n"; }
|
||
| 116 | if($HUM eq "yes") { print "hum.label Luchtvochtigheid\n"; }
|
||
| 117 | if($WSMS eq "yes") { print "wsms.label Windsnelheid (ms)\n"; }
|
||
| 118 | if($WSBF eq "yes") { print "wsbf.label Windsnelheid (Bft)\n"; }
|
||
| 119 | if($AP eq "yes") { print "ap.label Luchtdruk\n"; }
|
||
| 120 | if($VIEW eq "yes") { print "view.label Zichtmeters\n"; }
|
||
| 121 | if($GUSTS eq "yes") { print "gusts.label Windstoten (ms)\n"; }
|
||
| 122 | if($RAIN eq "yes") { print "rain.label Regen (mm p/u)\n"; }
|
||
| 123 | } |
||
| 124 | else {
|
||
| 125 | # All other languages |
||
| 126 | if($TMP eq "yes") { print "tmp.label Temperature (C)\n"; }
|
||
| 127 | if($TMP10CM eq "yes") { print "tmp10cm.label Temperature 10cm (C)\n"; }
|
||
| 128 | if($HUM eq "yes") { print "hum.label Humidity\n"; }
|
||
| 129 | if($WSMS eq "yes") { print "wsms.label Wind speed (ms)\n"; }
|
||
| 130 | if($WSBF eq "yes") { print "wsbf.label Wind Speef (Bft)\n"; }
|
||
| 131 | if($AP eq "yes") { print "ap.label Air pressure\n"; }
|
||
| 132 | if($VIEW eq "yes") { print "view.label View (m)\n"; }
|
||
| 133 | if($GUSTS eq "yes") { print "gusts.label Wind gusts (ms)\n"; }
|
||
| 134 | if($RAIN eq "yes") { print "rain.label Rain (mm p/h)\n"; }
|
||
| 135 | } |
||
| 136 | exit 0; |
||
| 137 | } |
||
| 138 | |||
| 139 | |||
| 140 | # Print the values |
||
| 141 | if($TMP eq "yes") { print "tmp.value ".$doc->findnodes($stationNode."/temperatuurGC/text()")."\n"; }
|
||
| 142 | if($TMP10CM eq "yes") { print "tmp10cm.value ".$doc->findnodes($stationNode."/temperatuur10cm/text()")."\n"; }
|
||
| 143 | if($HUM eq "yes") { print "hum.value ".$doc->findnodes($stationNode."/luchtvochtigheid/text()")."\n"; }
|
||
| 144 | if($WSMS eq "yes") { print "wsms.value ".$doc->findnodes($stationNode."/windsnelheidMS/text()")."\n"; }
|
||
| 145 | if($WSBF eq "yes") { print "wsbf.value ".$doc->findnodes($stationNode."/windsnelheidBF/text()")."\n"; }
|
||
| 146 | if($AP eq "yes") { print "ap.value ".$doc->findnodes($stationNode."/luchtdruk/text()")."\n"; }
|
||
| 147 | if($VIEW eq "yes") { print "view.value ".$doc->findnodes($stationNode."/zichtmeters/text()")."\n"; }
|
||
| 148 | if($GUSTS eq "yes") { print "gusts.value ".$doc->findnodes($stationNode."/windstotenMS/text()")."\n"; }
|
||
| 149 | if($RAIN eq "yes") { print "rain.value ".$doc->findnodes($stationNode."/regenMMPU/text()")."\n"; }
|
||
| 150 | |||
| 151 | |||
| 152 | |||
| 153 | # Station codes |
||
| 154 | # Static, I know I could do this dynamically, but since they don't change reguarly I choose this way |
||
| 155 | # so I could present two nice rows whitout having to write a buncgh of code... :P |
||
| 156 | sub print_stations {
|
||
| 157 | return "Available station codes, updated last on April 4th 2011\n\n" |
||
| 158 | ." [6391] Venlo (Station Arcen) [6275] Arnhem (Station Arnhem)\n" |
||
| 159 | ." [6249] Berkhout (Station Berkhout) [6308] Cadzand (Station Cadzand)\n" |
||
| 160 | ." [6260] Utrecht (Station Utrecht) [6235] Den Helder (Station Den Helder)\n" |
||
| 161 | ." [6370] Eindhoven (Station Eindhoven) [6321] Noordzee (Station Euro platform)\n" |
||
| 162 | ." [6350] Gilze Rijen (Station Gilze Rijen) [6323] Goes (Station Goes)\n" |
||
| 163 | ." [6283] Oost-Overijssel (Station Groenlo-Hupsel) [6280] Groningen (Station Groningen)\n" |
||
| 164 | ." [6315] Oost-Zeeland (Station Hansweert) [6278] Zwolle (Station Heino)\n" |
||
| 165 | ." [6356] Gorinchem (Station Herwijnen) [6330] Hoek van Holland (Station Hoek van Holland)\n" |
||
| 166 | ." [6311] Zuid-Zeeland (Station Hoofdplaat) [6279] Hoogeveen (Station Hoogeveen)\n" |
||
| 167 | ." [6251] Wadden (Station Hoorn Terschelling) [6258] Enkhuizen-Lelystad (Station Houtribdijk)\n" |
||
| 168 | ." [6285] Schiermonnikoog (Station Huibertgat) [6209] IJmond (Station IJmond)\n" |
||
| 169 | ." [6225] IJmuiden (Station IJmuiden) [6210] Katwijk (Station Katwijk)\n" |
||
| 170 | ." [6277] Noord-Groningen (Station Lauwersoog) [6320] Goeree (Station LE Goeree)\n" |
||
| 171 | ." [6270] Leeuwarden (Station Leeuwarden) [6269] Lelystad (Station Lelystad)\n" |
||
| 172 | ." [6348] West-Utrecht (Station Lopik-Cabauw) [6380] Maastricht (Station Maastricht)\n" |
||
| 173 | ." [6273] Noordoostpolder (Station Marknesse) [6286] Oost-Groningen (Station Nieuw Beerta)\n" |
||
| 174 | ." [6312] Oosterschelde (Station Oosterschelde) [6344] Rotterdam (Station Rotterdam)\n" |
||
| 175 | ." [6343] Rotterdam Haven (Station Rotterdam Geulhaven) [6316] Schaar (Station Schaar)\n" |
||
| 176 | ." [6240] Amsterdam (Station Schiphol) [6324] Midden-Zeeland (Station Stavenisse)\n" |
||
| 177 | ." [6267] West-Friesland (Station Stavoren) [6229] Texel (Station Texelhors)\n" |
||
| 178 | ." [6331] Tholen (Station Tholen) [6290] Twente (Station Twente)\n" |
||
| 179 | ." [6313] West-Zeeland (Station Vlakte aan de Raan) [6242] Vlieland (Station Vlieland)\n" |
||
| 180 | ." [6310] Vlissingen (Station Vlissingen) [6375] Uden (Station Volkel)\n" |
||
| 181 | ." [6319] Terneuzen (Station Westdorpe) [6248] Hoorn (Station Wijdenes)\n" |
||
| 182 | ." [6257] Wijk aan Zee (Station Wijk aan Zee) [6340] Woensdrecht (Station Woensdrecht)\n" |
||
| 183 | ." [6239] Noordzee (Station Zeeplatform F-3) [6252] Noordzee (Station Zeeplatform K13)\n"; |
||
| 184 | } |
