2
0
mirror of https://github.com/munin-monitoring/contrib.git synced 2018-11-08 00:59:34 +01:00
contrib-munin/plugins/other/earthquakes

92 lines
2.0 KiB
Plaintext
Raw Normal View History

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;
# place locations here separated by commas
2008-11-05 07:04:03 +01:00
# names must match Region from the link below
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";
} else {
print "yes\n";
}
exit 0;
2008-11-05 07:04:03 +01:00
}
if (defined $ARGV[0] and $ARGV[0] eq "config")
{
print "graph_title Earthquakes by region\n";
print "graph_args --base 1000\n";
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";
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