root / plugins / other / earthquakes @ 83159620
Historique | Voir | Annoter | Télécharger (2,05 ko)
| 1 |
#!/usr/bin/perl -w |
|---|---|
| 2 |
# |
| 3 |
# Author: Jesse Waite |
| 4 |
# Plugin: earthquakes |
| 5 |
# License: GPL v2 |
| 6 |
# Version: 1.0 |
| 7 |
# |
| 8 |
# Plugin to retrieve earthquake data from earthquake.usgs.gov |
| 9 |
# |
| 10 |
# Parameters supported: |
| 11 |
# config |
| 12 |
# autoconf |
| 13 |
# |
| 14 |
# Requirements: |
| 15 |
# LWP::Simple |
| 16 |
# |
| 17 |
# $Log$ |
| 18 |
# v. 1.0 11/04/2008 Initial release. |
| 19 |
# v. 1.1 11/08/2008 Fixed misspelling of GAUGE. |
| 20 |
# |
| 21 |
# Magic markers: |
| 22 |
#%# family=auto |
| 23 |
#%# capabilities=autoconf |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
|
| 28 |
# place locations here seperated by commas |
| 29 |
# names must match Region from the link below |
| 30 |
my @regions = ("Southern California",
|
| 31 |
"Central California", |
| 32 |
"Northern California", |
| 33 |
"Greater Los Angeles area"); |
| 34 |
|
| 35 |
my $url = "http://earthquake.usgs.gov/eqcenter/catalogs/eqs1hour-M1.txt"; |
| 36 |
|
| 37 |
# checks if LWP::Simple is installed |
| 38 |
my $ret = undef; |
| 39 |
eval { use LWP::Simple };
|
| 40 |
if ($@) {
|
| 41 |
my $ret = "LWP::Simple not installed."; |
| 42 |
} |
| 43 |
|
| 44 |
if (defined $ARGV[0] and $ARGV[0] eq "autoconf") |
| 45 |
{
|
| 46 |
if (defined $ret) |
| 47 |
{
|
| 48 |
print "no ($ret)\n"; |
| 49 |
exit 1; |
| 50 |
} else {
|
| 51 |
print "yes\n"; |
| 52 |
exit 0; |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
if (defined $ARGV[0] and $ARGV[0] eq "config") |
| 57 |
{
|
| 58 |
print "graph_title Earthquakes by region\n"; |
| 59 |
print "graph_args --base 1000\n"; |
| 60 |
print "graph_category Other\n"; |
| 61 |
print "graph_info This graph shows earthquakes by region of magnitude 1.0 or greater.\n"; |
| 62 |
print "graph_vlabel Number of Earthquakes\n"; |
| 63 |
|
| 64 |
for my $locale (@regions) {
|
| 65 |
$locale =~ s/\s/_/g; # replace whitespace with underscores |
| 66 |
print "$locale.label $locale\n"; |
| 67 |
print "$locale.type GAUGE\n"; |
| 68 |
print "$locale.draw LINE2\n"; |
| 69 |
print "$locale.warning 4\n"; |
| 70 |
print "$locale.critical 6\n"; |
| 71 |
} # end for loop |
| 72 |
exit 0; |
| 73 |
} # end if |
| 74 |
|
| 75 |
# fetch the most recent earthquakes |
| 76 |
my $content = get($url); |
| 77 |
|
| 78 |
# pull the regions and count how many times they are mentioned |
| 79 |
for my $locale (@regions) {
|
| 80 |
|
| 81 |
my $i = 0; |
| 82 |
|
| 83 |
foreach my $key (split(/[,|\n\r]/, $content)) {
|
| 84 |
$key =~ s/"//g; # remove quotes |
| 85 |
if ($key eq $locale) {
|
| 86 |
$i++; |
| 87 |
} |
| 88 |
} # end foreach loop |
| 89 |
$locale =~ s/\s/_/g; # replace whitespace with underscore |
| 90 |
print "$locale.value $i\n"; |
| 91 |
} # end if |
| 92 |
|
