From 66786d4cfa86a36eca87cef60d9c0a4a1ee24ba8 Mon Sep 17 00:00:00 2001 From: zarzuelo Date: Fri, 17 Aug 2012 12:12:52 +0000 Subject: [PATCH] 2012-08-17 Sergio Martin * util/plugin/EU_10yrspread.pl util/pandora_migrate_plugins.pl: Add plugin to get the 10 year spread of several european countries and fix some bugs of the plugin migrate tool git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6876 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_server/ChangeLog | 7 ++ .../util/pandora_migrate_plugins.pl | 2 +- pandora_server/util/plugin/EU_10yrspread.pl | 89 +++++++++++++++++++ 3 files changed, 97 insertions(+), 1 deletion(-) create mode 100755 pandora_server/util/plugin/EU_10yrspread.pl diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index e795825bef..3c9f1885a3 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,10 @@ +2012-08-17 Sergio Martin + + * util/plugin/EU_10yrspread.pl + util/pandora_migrate_plugins.pl: Add plugin to + get the 10 year spread of several european countries + and fix some bugs of the plugin migrate tool + 2012-08-16 Vanessa Gil * util/recon_scripts/snmpdevices.pl: Added several networks and ips diff --git a/pandora_server/util/pandora_migrate_plugins.pl b/pandora_server/util/pandora_migrate_plugins.pl index 68b8fae8f6..b76e473974 100755 --- a/pandora_server/util/pandora_migrate_plugins.pl +++ b/pandora_server/util/pandora_migrate_plugins.pl @@ -142,7 +142,7 @@ sub pandora_migrate_plugins_main ($) { print "\n[*] Migrating plugins.\n\n"; - my @plugins = get_db_rows ($dbh, "SELECT * FROM tplugin WHERE macros = ''"); + my @plugins = get_db_rows ($dbh, "SELECT * FROM tplugin WHERE macros = '' OR macros IS NULL"); $migrated_plugins = $#plugins + 1; diff --git a/pandora_server/util/plugin/EU_10yrspread.pl b/pandora_server/util/plugin/EU_10yrspread.pl new file mode 100755 index 0000000000..a8df8d30c4 --- /dev/null +++ b/pandora_server/util/plugin/EU_10yrspread.pl @@ -0,0 +1,89 @@ +#!/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 %codes; + + $codes{'Spain'} = '.SPAINGER10:IND'; + $codes{'Greece'} = '.GRGER10:IND'; + $codes{'Italy'} = '.ITAGER10:IND'; + $codes{'Portugal'} = '.PORGER10:IND'; + $codes{'Ireland'} = '.IRGERSP:IND'; + $codes{'France'} = '.FRAGER10: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; + + $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(); +