2010-03-04 Sancho Lerena <slerena@artica.es>
* conf/pandora_server.conf: Several typos and better formating. * util/change_remoteconfig.pl: Tool to massive edit the server IP in remote configuration files. Could be modified to alter any other fixed field. * util/gpx2pandora_agent_data.pl: Transform a standard GPX GIS data file in several Pandora FMS XML data server compatible files with GIS data. * util/gis.README: Small "documentation" on how to start to using GIS in the Server. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2474 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
3770fd48a7
commit
3bf7f1594a
|
@ -1,3 +1,19 @@
|
|||
2010-03-04 Sancho Lerena <slerena@artica.es>
|
||||
|
||||
* conf/pandora_server.conf: Several typos and better formating.
|
||||
|
||||
* util/change_remoteconfig.pl: Tool to massive edit the server IP
|
||||
in remote configuration files. Could be modified to alter any other
|
||||
fixed field.
|
||||
|
||||
* util/gpx2pandora_agent_data.pl: Transform a standard GPX GIS data
|
||||
file in several Pandora FMS XML data server compatible files with GIS
|
||||
data.
|
||||
|
||||
* util/gis.README: Small "documentation" on how to start to using GIS
|
||||
in the Server.
|
||||
|
||||
|
||||
2010-03-04 Pablo de la Concepción <pablo.concepcion@artica.es>
|
||||
|
||||
* conf/pandora_server.conf: Corrected typo
|
||||
|
|
|
@ -233,32 +233,35 @@ max_queue_files 250
|
|||
# restart 0
|
||||
# restart_delay 60
|
||||
|
||||
# More information about GIS Setup in /usr/share/pandora_server/util/gis.README
|
||||
# Flag to activate GIS (positional information for agents and maps)
|
||||
# by default it is desactivated
|
||||
#activate_gis 0
|
||||
|
||||
# Flag to activate GIS (positional information for agents and maps) by default it is desactivated
|
||||
# activate_gis 0
|
||||
|
||||
# Radius of the Error in meters to consider two gis locations as the same location.
|
||||
# location_error 50
|
||||
# Radius of error in meters to consider two gis locations as the same location.
|
||||
#location_error 50
|
||||
|
||||
# Recon reverse geolocation mode [disabled, sql, file]
|
||||
# * disabled: The recon task doesn't try to geolocate the ip discovered.
|
||||
# * sql: The recon task trys to query the SQL database to geolocate the ip discovered
|
||||
# * file: The recon task trys to find the geolocation information of the ip discovered in
|
||||
# the file indicated in the recon_reverse_geolocation_file parameter
|
||||
# disabled The recon task doesn't try to geolocate the ip discovered.
|
||||
# sql The recon task trys to query the SQL database to geolocate the
|
||||
# ip discovered
|
||||
# file The recon task trys to find the geolocation information of the
|
||||
# ip discovered in the file indicated in the
|
||||
# recon_reverse_geolocation_file parameter
|
||||
|
||||
# recon_reverse_geolocation_mode disabled
|
||||
|
||||
# Recon reverse geolocation file (databases with the reverse geolocation information using
|
||||
# MaxMind GPL GeoLiteCity.dat format).
|
||||
|
||||
# Recon reverse geolocation file. This is the database with the reverse
|
||||
# geolocation information using MaxMind GPL GeoLiteCity.dat format).
|
||||
#recon_reverse_geolocation_file /usr/local/share/GeoIP/GeoIPCity.dat
|
||||
|
||||
# Radius (in meters) of the circle in where the agents will be place randomly when finded by a recon task
|
||||
# The center of the cicle is guessed by geolocating the IP.
|
||||
# Radius (in meters) of the circle in where the agents will be place randomly
|
||||
# when finded by a recon task. Center of the circle is guessed
|
||||
# by geolocating the IP.
|
||||
#recon_location_scatter_radius 1000
|
||||
|
||||
|
||||
# Pandora Server self-monitoring (embedded agent) (by default disabled)
|
||||
# self_monitoring 1
|
||||
#self_monitoring 1
|
||||
|
||||
# Update parent from the agent xml
|
||||
#update_parent 1
|
||||
|
|
|
@ -0,0 +1,180 @@
|
|||
#!/usr/bin/perl
|
||||
# (c) Artica Soluciones Tecnologicas 2010
|
||||
# This script is licensed under GPL v2 licence.
|
||||
|
||||
use strict;
|
||||
use POSIX qw(floor);
|
||||
|
||||
|
||||
# TODO: Let more massive changes (fields) to be changed.
|
||||
|
||||
# Used to calculate the MD5 checksum of a string
|
||||
use constant MOD232 => 2**32;
|
||||
if ($#ARGV != 1) {
|
||||
print "This tool is used to do a massive change in all remote configuration\n";
|
||||
print "files for the remote agents, and change a list of files, given it's \n";
|
||||
print "agent name (case sensisitive)\n\n";
|
||||
print "Usage: change_remoteconfig.pl <file_with_server_names> <server_ip>\n\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
my $fichero_nombres = $ARGV[0];
|
||||
my $servidor_destino = $ARGV[1];
|
||||
|
||||
# Ruta al directorio data_in
|
||||
my $data_in = "/var/spool/pandora/data_in";
|
||||
print "Massive changes are set. Ready to modify files at $data_in/conf and the MD5 hashes in $data_in/md5\n";
|
||||
|
||||
md5_init();
|
||||
open (NOMBRES, $fichero_nombres) or die ("File $fichero_nombres not readable : $!");
|
||||
my @servidores = <NOMBRES>;
|
||||
close (NOMBRES);
|
||||
print "Server IP address '$servidor_destino' is about to be changed in these agents:\n";
|
||||
print "Total agents: ". scalar(@servidores)."\n";
|
||||
print @servidores;
|
||||
|
||||
print "Waiting 10 seconds. Press ^C to cancel.n\n";
|
||||
sleep (10);
|
||||
|
||||
foreach (@servidores) {
|
||||
my $servidor = $_;
|
||||
chomp ($servidor);
|
||||
print "Procesing: $servidor " ;
|
||||
my $nombre_md5 = md5($servidor);
|
||||
my $fichero_conf = "$data_in/conf/$nombre_md5.conf";
|
||||
# Se lee el fichero y se cambia la linea correspondiente
|
||||
open (CONF_FILE, $fichero_conf)or print ("Could not open file '$fichero_conf': $!.");
|
||||
open (NEW_CONF_FILE, '>', "$fichero_conf.new")or print ("Could not open file '$fichero_conf.new': $!.");
|
||||
while (my $linea = <CONF_FILE>) {
|
||||
if ($linea =~ m/^\s*server_ip.*/) {
|
||||
$linea = "server_ip\t$servidor_destino\n";
|
||||
}
|
||||
print NEW_CONF_FILE $linea;
|
||||
}
|
||||
close (CONF_FILE);
|
||||
close (NEW_CONF_FILE);
|
||||
`mv $fichero_conf.new $fichero_conf`;
|
||||
|
||||
# Calculate the new configuration file MD5 digest
|
||||
open (CONF_FILE, $fichero_conf)or print ("Could not open file '$fichero_conf': $!.");
|
||||
binmode(CONF_FILE);
|
||||
my $conf_md5 = md5 (join ('', <CONF_FILE>));
|
||||
close (CONF_FILE);
|
||||
print "Nuevo MD5 : $conf_md5\t";
|
||||
my $fichero_md5 = "$data_in/md5/$nombre_md5.md5";
|
||||
`echo -n "$conf_md5" > $fichero_md5`;
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
# MD5 leftrotate function. See http://en.wikipedia.org/wiki/MD5#Pseudocode.
|
||||
###############################################################################
|
||||
sub leftrotate ($$) {
|
||||
my ($x, $c) = @_;
|
||||
|
||||
return (0xFFFFFFFF & ($x << $c)) | ($x >> (32 - $c));
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
# Initialize some variables needed by the MD5 algorithm.
|
||||
# See http://en.wikipedia.org/wiki/MD5#Pseudocode.
|
||||
###############################################################################
|
||||
my (@R, @K);
|
||||
sub md5_init () {
|
||||
|
||||
# R specifies the per-round shift amounts
|
||||
@R = (7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
|
||||
5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
|
||||
4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
|
||||
6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21);
|
||||
|
||||
# Use binary integer part of the sines of integers (radians) as constants
|
||||
for (my $i = 0; $i < 64; $i++) {
|
||||
$K[$i] = floor(abs(sin($i + 1)) * MOD232);
|
||||
}
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
# Return the MD5 checksum of the given string.
|
||||
# Pseudocode from http://en.wikipedia.org/wiki/MD5#Pseudocode.
|
||||
###############################################################################
|
||||
sub md5 ($) {
|
||||
my $str = shift;
|
||||
|
||||
# Note: All variables are unsigned 32 bits and wrap modulo 2^32 when calculating
|
||||
|
||||
# Initialize variables
|
||||
my $h0 = 0x67452301;
|
||||
my $h1 = 0xEFCDAB89;
|
||||
my $h2 = 0x98BADCFE;
|
||||
my $h3 = 0x10325476;
|
||||
|
||||
# Pre-processing
|
||||
my $msg = unpack ("B*", pack ("A*", $str));
|
||||
my $bit_len = length ($msg);
|
||||
|
||||
# Append "1" bit to message
|
||||
$msg .= '1';
|
||||
|
||||
# Append "0" bits until message length in bits â¡ 448 (mod 512)
|
||||
$msg .= '0' while ((length ($msg) % 512) != 448);
|
||||
|
||||
# Append bit /* bit, not byte */ length of unpadded message as 64-bit little-endian integer to message
|
||||
$msg .= unpack ("B64", pack ("VV", $bit_len));
|
||||
|
||||
# Process the message in successive 512-bit chunks
|
||||
for (my $i = 0; $i < length ($msg); $i += 512) {
|
||||
|
||||
my @w;
|
||||
my $chunk = substr ($msg, $i, 512);
|
||||
|
||||
# Break chunk into sixteen 32-bit little-endian words w[i], 0 <= i <= 15
|
||||
for (my $j = 0; $j < length ($chunk); $j += 32) {
|
||||
push (@w, unpack ("V", pack ("B32", substr ($chunk, $j, 32))));
|
||||
}
|
||||
|
||||
# Initialize hash value for this chunk
|
||||
my $a = $h0;
|
||||
my $b = $h1;
|
||||
my $c = $h2;
|
||||
my $d = $h3;
|
||||
my $f;
|
||||
my $g;
|
||||
|
||||
# Main loop
|
||||
for (my $y = 0; $y < 64; $y++) {
|
||||
if ($y <= 15) {
|
||||
$f = $d ^ ($b & ($c ^ $d));
|
||||
$g = $y;
|
||||
}
|
||||
elsif ($y <= 31) {
|
||||
$f = $c ^ ($d & ($b ^ $c));
|
||||
$g = (5 * $y + 1) % 16;
|
||||
}
|
||||
elsif ($y <= 47) {
|
||||
$f = $b ^ $c ^ $d;
|
||||
$g = (3 * $y + 5) % 16;
|
||||
}
|
||||
else {
|
||||
$f = $c ^ ($b | (0xFFFFFFFF & (~ $d)));
|
||||
$g = (7 * $y) % 16;
|
||||
}
|
||||
|
||||
my $temp = $d;
|
||||
$d = $c;
|
||||
$c = $b;
|
||||
$b = ($b + leftrotate (($a + $f + $K[$y] + $w[$g]) % MOD232, $R[$y])) % MOD232;
|
||||
$a = $temp;
|
||||
}
|
||||
|
||||
# Add this chunk's hash to result so far
|
||||
$h0 = ($h0 + $a) % MOD232;
|
||||
$h1 = ($h1 + $b) % MOD232;
|
||||
$h2 = ($h2 + $c) % MOD232;
|
||||
$h3 = ($h3 + $d) % MOD232;
|
||||
}
|
||||
|
||||
# Digest := h0 append h1 append h2 append h3 #(expressed as little-endian)
|
||||
return unpack ("H*", pack ("V", $h0)) . unpack ("H*", pack ("V", $h1)) . unpack ("H*", pack ("V", $h2)) . unpack ("H*", pack ("V", $h3));
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
Pandora FMS uses the MaxMind GeoIP API to map IP address to it's GPS coordinates. This is a GPL library included in Pandora FMS libraries.
|
||||
|
||||
In order to be able to use GeoIP/GIS features of the Pandora FMS reconserver, you need to download and install a GeoLiteCite maps. You can download from maxmind site or from Pandora FMS download site. For more information about MaxMind and GeoIP database, check this URLs:
|
||||
|
||||
http://www.maxmind.com/app/geoip_resources
|
||||
http://www.maxmind.com/app/installation
|
||||
http://www.maxmind.com/app/geolitecity
|
||||
|
||||
Install manually Geo-IP-PurePerl-1.24.tar.gz
|
||||
|
||||
This database will be used with Pandora FMS recon server for positioning detected host Systems. Check Pandora FMS documentacion for more information.
|
||||
|
||||
Prior to use this database you need to decompress it with gzip -d and edit your /etc/pandora/pandora_server.conf file and point the GeoLiteCity GeoLiteCity.dat file with Pandora FMS configuration token 'recon_reverse_geolocation_file', like:
|
||||
|
||||
activate_gis 1
|
||||
recon_reverse_geolocation_file /usr/share/pandora_server/util/GeoLiteCity.dat
|
||||
location_error 50
|
||||
recon_reverse_geolocation_mode file
|
||||
recon_location_scatter_radius 1000
|
||||
|
||||
Get a new version at:
|
||||
|
||||
http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
|
||||
|
|
@ -0,0 +1,116 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use XML::Simple;
|
||||
use PandoraFMS::Tools;
|
||||
use Data::Dumper;
|
||||
use Sys::Hostname;
|
||||
use POSIX qw(strftime);
|
||||
|
||||
use constant AGENT_VERSION => '3.1';
|
||||
|
||||
|
||||
# Check parameters
|
||||
|
||||
if ($#ARGV != 1) {
|
||||
print "Pandora FMS GIS tool to produce XML files from a standard GPX file\n";
|
||||
print "This will put all the XML files in /var/spool/pandora/data_in directory \n";
|
||||
print "\n";
|
||||
print "Usage: $0 <filename.gpx> <agent_name>\n\n";
|
||||
exit 1;
|
||||
}
|
||||
|
||||
# Configuration tokens
|
||||
my %Conf = (
|
||||
'server_path' => '/var/spool/pandora/data_in',
|
||||
'interval' => 300,
|
||||
'agent_name' => hostname (),
|
||||
'description' => 'Data from GPX',
|
||||
'group' => '',
|
||||
'encoding' => 'ISO-8859-1',
|
||||
);
|
||||
|
||||
|
||||
my $file_name = shift;
|
||||
my $agent_name = shift;
|
||||
if (defined($agent_name)) {
|
||||
print "agent_name: $agent_name\n";
|
||||
$Conf{'agent_name'} = $agent_name;
|
||||
}
|
||||
|
||||
my $xml_data = XMLin ($file_name, forcearray => 1 );
|
||||
|
||||
# Invalid XML
|
||||
if ($@) {
|
||||
print "Invalid XML";
|
||||
rename($file_name, $file_name . '_BADXML');
|
||||
exit -1;
|
||||
}
|
||||
|
||||
# Debug, code commented
|
||||
print "Printing XML DATA\n";
|
||||
#print Dumper ($xml_data);
|
||||
#print "Finish Printing XML DATA\n";
|
||||
# 'rte' => [
|
||||
# {
|
||||
# 'rtept' => [
|
||||
# {
|
||||
# 'ele' => [
|
||||
# '728'
|
||||
# ],
|
||||
# 'speed' => [
|
||||
# '0'
|
||||
# ],
|
||||
# 'time' => [
|
||||
# '2010-02-19T10:45:08Z'
|
||||
# ],
|
||||
# 'lat' => '40.4327545166',
|
||||
# 'lon' => '-3.7009150982'
|
||||
# },
|
||||
#
|
||||
my $posiciones = $xml_data->{'rte'}[0];
|
||||
|
||||
# Process positions
|
||||
foreach my $position (@{$posiciones->{'rtept'}}) {
|
||||
my $longitude= $position->{'lon'};
|
||||
my $latitude= $position->{'lat'};
|
||||
my $altitude= $position->{'ele'}[0];
|
||||
my $timestamp= $position->{'time'}[0];
|
||||
|
||||
$timestamp =~ s/Z$//;
|
||||
$timestamp =~ s/T/ /;
|
||||
$timestamp =~ s/02/31/;
|
||||
# Use the current time
|
||||
$timestamp= strftime ('%Y/%m/%d %H:%M:%S', localtime ());
|
||||
|
||||
print "Longitude: $longitude, Latitude: $latitude, Altitude: $altitude, Timestamp: $timestamp\n";
|
||||
|
||||
my $OS = $^O;
|
||||
|
||||
my $xml = "<?xml version='1.0' encoding='" . $Conf{'encoding'} . "'?>\n" .
|
||||
"<agent_data description='" . $Conf{'description'} ."' group='11".
|
||||
"' os_name='$OS' os_version='1' interval='" . $Conf{'interval'} .
|
||||
"' version='" . AGENT_VERSION . "' timestamp='" . $timestamp.
|
||||
"' agent_name='" . $Conf{'agent_name'} . "' timezone_offset='0' longitude='" .$longitude.
|
||||
"' latitude='" .$latitude."' altitude='".$altitude."'>\n";
|
||||
$xml .= "<module>";
|
||||
$xml .= " <name><![CDATA[gps_data]]></name>";
|
||||
$xml .= " <description><![CDATA[GPS Data export from GPX source]]></description>";
|
||||
$xml .= " <type>generic_proc</type>";
|
||||
$xml .= " <data><![CDATA[1]]></data>";
|
||||
$xml .= "</module>";
|
||||
$xml .= "</agent_data>";
|
||||
|
||||
# print $xml;
|
||||
|
||||
# Save XML data file
|
||||
|
||||
my $temp_file = $Conf{'server_path'} . '/' . $Conf{'agent_name'} . '.' . time () . '.data';
|
||||
open (TEMP_FILE, "> $temp_file") ||print ("Could not write XML data file: $!");
|
||||
print TEMP_FILE $xml;
|
||||
close (TEMP_FILE);
|
||||
sleep(1);
|
||||
}
|
||||
|
Loading…
Reference in New Issue