Skip to content

Instantly share code, notes, and snippets.

@b10m
Created August 26, 2013 13:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save b10m/6341194 to your computer and use it in GitHub Desktop.
Save b10m/6341194 to your computer and use it in GitHub Desktop.
To monitor flights from AMS to CGK I decided to let Nagios do that for me. It now alerts me when prices drop to the wanted 799 EUR. It also spits the metric to a graphite box running on localhost to please @ainmosni.
#!/usr/bin/perl
use strict;
use LWP::Simple qw( get );
use XML::Simple qw( XMLin );
use Nagios::Plugin;
use Net::Graphite;
my $np = Nagios::Plugin->new;
$np->set_thresholds(ok => '~:900', warning => '@800:900', critical => '799:');
my $fare;
my $feed = get ( 'http://vakantie.klm.com/cmsdata/fares.xml' )
or $np->nagios_exit( UNKNOWN, "Could not retrieve feed" );
my $xml = XMLin( $feed )
or $np->nagios_exit( UNKNOWN, "Could not parse feed" );
if( ref $xml eq 'HASH' && exists $xml->{flight} ) {
$fare = join ", ", map { $_->{price} } grep {
$_->{destination} eq 'CGK' and
$_->{origin} eq 'AMS'
} @{ $xml->{flight} };
} else {
$np->nagios_exit( UNKNOWN, "Don't understand the feed" );
}
Net::Graphite->new(
host => 'localhost',
port => 2003,
fire_and_forget => 0,
)->send(
path => 'price.klm.amscgk',
value => $fare
);
$np->nagios_exit(
return_code => $np->check_threshold($fare),
message => "$fare EUR"
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment