#!/usr/bin/perl
use strict;
use warnings;
use LWP::Simple;
use POSIX qw(strftime);
sub main
{
my $agent_name = "EU_10yrspread";
my $incoming_dir = "/var/spool/pandora/data_in";
my $utimestamp = time ();
my $timestamp = strftime ("%Y-%m-%d %H:%M:%S", localtime());
my $germany_spread = get_10yspread('GDBR10:IND')*100;
my %codes;
$codes{'United Kingdom'} = 'GUKG10:IND';
$codes{'Spain'} = 'GSPG10YR:IND';
$codes{'Greece'} = 'GGGB10YR:IND';
$codes{'Italy'} = 'GBTPGR10:IND';
$codes{'Portugal'} = 'GSPT10YR:IND';
#$codes{'Ireland'} = '.IRGERSP:IND';
$codes{'France'} = 'GFRN10:IND';
$codes{'Netherlands'} = 'GNTH10YR:IND';
$codes{'Switzerland'} = 'GSWISS10:IND';
#$codes{'Belgium'} = '.BELGER10:IND';
my $xml_output = "";
$xml_output .= "";
foreach my $k (keys(%codes)) {
my $code = $codes{$k};
my $spread = get_10yspread($code)*100-$germany_spread;
$xml_output .=" ";
$xml_output .=" ";
$xml_output .=" generic_data";
$xml_output .=" $spread";
$xml_output .=" 250";
$xml_output .=" 0";
$xml_output .=" 500";
$xml_output .=" 0";
$xml_output .=" ";
}
$xml_output .= "";
my $filename = $incoming_dir."/".$agent_name.".".$utimestamp.".data";
open (XMLFILE, ">> $filename") or die "[FATAL] Could not open internal monitoring XML file for deploying monitorization at '$filename'";
print XMLFILE $xml_output;
close (XMLFILE);
# return OK when the execution is complete
print "OK";
}
sub get_10yspread($) {
my $code = shift;
my $data = get("http://www.bloomberg.com/quote/".$code);
my @lines = split(/\n/,$data);
my $start_parse = 0;
my $stop_parse = 0;
my $spread = '';
foreach my $line (@lines) {
if($start_parse == 1) {
$spread .= $line;
if($line =~ /<\/span>/gi) {
last;
}
}
if($line =~ /.*
/gi) {
$start_parse = 1;
}
}
if($spread =~ /.*\s*(\S+)\s*<\/span>/i) {
return $1;
}
}
main();