2012-08-17 Sergio Martin <sergio.martin@artica.es>

* 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
This commit is contained in:
zarzuelo 2012-08-17 12:12:52 +00:00
parent 2694f6bd73
commit 67913c1fb9
3 changed files with 97 additions and 1 deletions

View File

@ -1,3 +1,10 @@
2012-08-17 Sergio Martin <sergio.martin@artica.es>
* 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 <vanessa.gil@artica.es>
* util/recon_scripts/snmpdevices.pl: Added several networks and ips

View File

@ -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;

View File

@ -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 version='1.0' encoding='ISO-8859-1' ?>";
$xml_output .= "<agent_data os_name='Linux' agent_name='".$agent_name."' interval='300' timestamp='".$timestamp."' >";
foreach my $k (keys(%codes)) {
my $code = $codes{$k};
my $spread = get_10yspread($code)*100;
$xml_output .=" <module>";
$xml_output .=" <name><![CDATA[$k]]></name>";
$xml_output .=" <type>generic_data</type>";
$xml_output .=" <data>$spread</data>";
$xml_output .=" <min_warning>250</min_warning>";
$xml_output .=" <max_warning>0</max_warning>";
$xml_output .=" <min_critical>500</min_critical>";
$xml_output .=" <max_critical>0</max_critical>";
$xml_output .=" </module>";
}
$xml_output .= "</agent_data>";
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 =~ /.*<h3.*$code.*<\/h3>/gi) {
$start_parse = 1;
}
}
if($spread =~ /.*<span.*>\s*(\S+)\s*<\/span>/i) {
return $1;
}
}
main();