Helping to fix Wall Street
Posted by broseJul 28
This combines two of my favorite things!! Ok, maybe not FAVORITE persay, but recently, I’ve been writing a lot of nagios plugins. And recently, I’ve been hearing a lot about how the economy has been doing rather poorly. It’s as if the people running the economy need something to monitor it and make sure it’s doing okay.
And thus it was born: [the nagios check_economy plugin].
Right now it just monitors the Dow Jones Industrial Average and reports back on a range that you provide to it. My range at the current moment is warning if <=9000, critical if <=8500. The script will break if the people I'm mooching the stock data from redesign their website. Actually, you could probably even modify this script such that it checks other stock symbols besides DJI. The possibilities are endless! Dependencies include the curl package, an internet connection, and some time to waste. @mstarr, you may wish to file this one under humor. 🙂
2 comments
Comment by Donald Ade on July 28, 2009 at 11:56 am
Neat! 🙂
Comment by us3r on July 29, 2009 at 3:28 am
nice 🙂 but if smb want to use this script without curl:
#!/usr/bin/perl
# usage
# ./script warn_level critical_level
use strict;
use warnings;
use LWP::Simple;
my ($WARNING_LOW,$CRITICAL_LOW) = @ARGV;
sub state {
my ($msg,$status) = @_;
print $msg; exit $status;
}
my $url = “http://www.marketwatch.com/m/quotes/INDU”;
my $content = get($url) or die $!;
if ($content =~ m/lasttrade number\”\>\$(\w,\w{3})\.\w{2}/){
my $dj = $1; $dj =~ s/[,.]//;
($dj < $WARNING_LOW) ? ($dj < $CRITICAL_LOW) ? state("Critical: $dj", "2") : state("Warning: $dj","1") : state("OK: $dj","0") ;
} else {
print "Unknown problem…" ; exit 4;
}