2008-11-05 07:04:03 +01:00
|
|
|
#!/usr/bin/perl -w
|
|
|
|
#
|
|
|
|
# Author: Jesse Waite
|
|
|
|
# Plugin: earthquakes
|
|
|
|
# License: GPL v2
|
|
|
|
# Version: 1.0
|
|
|
|
#
|
|
|
|
# Plugin to retrieve earthquake data from earthquake.usgs.gov
|
|
|
|
#
|
|
|
|
# Parameters supported:
|
|
|
|
# config
|
|
|
|
# autoconf
|
|
|
|
#
|
|
|
|
# Requirements:
|
|
|
|
# LWP::Simple
|
|
|
|
#
|
|
|
|
# $Log$
|
|
|
|
# v. 1.0 11/04/2008 Initial release.
|
|
|
|
# v. 1.1 11/08/2008 Fixed misspelling of GAUGE.
|
|
|
|
#
|
|
|
|
# Magic markers:
|
|
|
|
#%# family=auto
|
|
|
|
#%# capabilities=autoconf
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
2014-12-05 00:37:42 +01:00
|
|
|
# place locations here separated by commas
|
2008-11-05 07:04:03 +01:00
|
|
|
# names must match Region from the link below
|
2018-08-02 02:03:42 +02:00
|
|
|
my @regions = ("Southern California",
|
|
|
|
"Central California",
|
|
|
|
"Northern California",
|
2008-11-05 07:04:03 +01:00
|
|
|
"Greater Los Angeles area");
|
|
|
|
|
|
|
|
my $url = "http://earthquake.usgs.gov/eqcenter/catalogs/eqs1hour-M1.txt";
|
|
|
|
|
|
|
|
# checks if LWP::Simple is installed
|
|
|
|
my $ret = undef;
|
|
|
|
eval { use LWP::Simple };
|
|
|
|
if ($@) {
|
|
|
|
my $ret = "LWP::Simple not installed.";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (defined $ARGV[0] and $ARGV[0] eq "autoconf")
|
|
|
|
{
|
|
|
|
if (defined $ret)
|
|
|
|
{
|
|
|
|
print "no ($ret)\n";
|
|
|
|
exit 1;
|
|
|
|
} else {
|
|
|
|
print "yes\n";
|
|
|
|
exit 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (defined $ARGV[0] and $ARGV[0] eq "config")
|
|
|
|
{
|
|
|
|
print "graph_title Earthquakes by region\n";
|
|
|
|
print "graph_args --base 1000\n";
|
2018-08-01 23:56:56 +02:00
|
|
|
print "graph_category other\n";
|
2008-11-05 07:04:03 +01:00
|
|
|
print "graph_info This graph shows earthquakes by region of magnitude 1.0 or greater.\n";
|
2018-08-02 02:03:42 +02:00
|
|
|
print "graph_vlabel Number of Earthquakes\n";
|
2008-11-05 07:04:03 +01:00
|
|
|
|
|
|
|
for my $locale (@regions) {
|
|
|
|
$locale =~ s/\s/_/g; # replace whitespace with underscores
|
|
|
|
print "$locale.label $locale\n";
|
|
|
|
print "$locale.type GAUGE\n";
|
|
|
|
print "$locale.draw LINE2\n";
|
|
|
|
print "$locale.warning 4\n";
|
|
|
|
print "$locale.critical 6\n";
|
|
|
|
} # end for loop
|
|
|
|
exit 0;
|
|
|
|
} # end if
|
|
|
|
|
|
|
|
# fetch the most recent earthquakes
|
|
|
|
my $content = get($url);
|
|
|
|
|
|
|
|
# pull the regions and count how many times they are mentioned
|
|
|
|
for my $locale (@regions) {
|
|
|
|
|
|
|
|
my $i = 0;
|
|
|
|
|
|
|
|
foreach my $key (split(/[,|\n\r]/, $content)) {
|
|
|
|
$key =~ s/"//g; # remove quotes
|
|
|
|
if ($key eq $locale) {
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
} # end foreach loop
|
|
|
|
$locale =~ s/\s/_/g; # replace whitespace with underscore
|
|
|
|
print "$locale.value $i\n";
|
|
|
|
} # end if
|
|
|
|
|