mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-28 08:14:38 +02:00
2008-08-05 Sancho Lerena <slerena@gmail.com>
* bin/pandora_recon: New functional recon server. It implements different recon tasks based on OS type. Uses a production/consumer thread model, detec OS typew and assign automatically network profiles (including new WMI components) and WMI, Plugin, Network and Prediction servers, taken the first master server that could found. Uses xprobe2 external tool to detect remote OS. * Makefile.PL: Added new dependencies (HTML::Entities), and new binary tool for controlled time executing (pandora_exec), used now by pandora_wmi and pandora_plugin. * Config.pm: Fixed problem parsing xprobe2 command. * DB.pm: Functions pandora_create_agent() and pandora_event() moved from Tools.pm to here. Removed some old DEBUG messages. * Tools.pm: Moved pandora_create_agent() and pandora_event() to DB.pm git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1002 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
c6716bb41a
commit
9238172819
@ -1,3 +1,23 @@
|
|||||||
|
2008-08-05 Sancho Lerena <slerena@gmail.com>
|
||||||
|
|
||||||
|
* bin/pandora_recon: New functional recon server. It implements
|
||||||
|
different recon tasks based on OS type. Uses a production/consumer
|
||||||
|
thread model, detec OS typew and assign automatically network profiles
|
||||||
|
(including new WMI components) and WMI, Plugin, Network and Prediction
|
||||||
|
servers, taken the first master server that could found. Uses xprobe2
|
||||||
|
external tool to detect remote OS.
|
||||||
|
|
||||||
|
* Makefile.PL: Added new dependencies (HTML::Entities), and new
|
||||||
|
binary tool for controlled time executing (pandora_exec), used now
|
||||||
|
by pandora_wmi and pandora_plugin.
|
||||||
|
|
||||||
|
* Config.pm: Fixed problem parsing xprobe2 command.
|
||||||
|
|
||||||
|
* DB.pm: Functions pandora_create_agent() and pandora_event() moved
|
||||||
|
from Tools.pm to here. Removed some old DEBUG messages.
|
||||||
|
|
||||||
|
* Tools.pm: Moved pandora_create_agent() and pandora_event() to DB.pm
|
||||||
|
|
||||||
2008-08-01 Ramon Novoa <rnovoa@artica.es>
|
2008-08-01 Ramon Novoa <rnovoa@artica.es>
|
||||||
|
|
||||||
* bin/pandora_wmi: Removed the timeout mechanism.
|
* bin/pandora_wmi: Removed the timeout mechanism.
|
||||||
|
@ -19,10 +19,11 @@ WriteMakefile(
|
|||||||
IO::Socket => 0,
|
IO::Socket => 0,
|
||||||
Mail::Sendmail => 0,
|
Mail::Sendmail => 0,
|
||||||
Net::Traceroute::PurePerl => 0,
|
Net::Traceroute::PurePerl => 0,
|
||||||
|
HTML::Entities => 0,
|
||||||
SNMP => 0
|
SNMP => 0
|
||||||
},
|
},
|
||||||
EXE_FILES =>
|
EXE_FILES =>
|
||||||
[ 'bin/pandora_server', 'bin/pandora_network', 'bin/pandora_recon', 'bin/pandora_snmpconsole' , 'bin/pandora_plugin', 'bin/pandora_prediction'],
|
[ 'bin/pandora_server', 'bin/pandora_network', 'bin/pandora_recon', 'bin/pandora_snmpconsole' , 'bin/pandora_plugin', 'bin/pandora_prediction', 'util/pandora_exec'],
|
||||||
PMLIBDIRS => [ 'lib' ],
|
PMLIBDIRS => [ 'lib' ],
|
||||||
'dist' => { 'TAR' => 'tar', 'TARFLAGS' => 'cvfz', 'SUFFIX'
|
'dist' => { 'TAR' => 'tar', 'TARFLAGS' => 'cvfz', 'SUFFIX'
|
||||||
=> '.gz', 'COMPRESS' => 'gzip'}
|
=> '.gz', 'COMPRESS' => 'gzip'}
|
||||||
|
@ -29,7 +29,7 @@ use Date::Manip; # Needed to manipulate DateTime formats
|
|||||||
use Net::Ping;
|
use Net::Ping;
|
||||||
use Time::Local; # DateTime basic manipulation
|
use Time::Local; # DateTime basic manipulation
|
||||||
use NetAddr::IP; # To manage IP Addresses
|
use NetAddr::IP; # To manage IP Addresses
|
||||||
use Net::Traceroute::PurePerl; # Traceroute in rawsockets (need root)
|
use Net::Traceroute::PurePerl; # Traceroute needs traceroute command
|
||||||
use POSIX; # to use ceil() function
|
use POSIX; # to use ceil() function
|
||||||
use Socket; # to resolve address
|
use Socket; # to resolve address
|
||||||
use threads;
|
use threads;
|
||||||
@ -45,7 +45,7 @@ my @pending_task : shared;
|
|||||||
my %pending_task_hash : shared;
|
my %pending_task_hash : shared;
|
||||||
my %current_task_hash : shared;
|
my %current_task_hash : shared;
|
||||||
my $queue_lock : shared;
|
my $queue_lock : shared;
|
||||||
|
my $icmp_lock : shared;
|
||||||
|
|
||||||
# FLUSH in each IO (only for debug, very slooow)
|
# FLUSH in each IO (only for debug, very slooow)
|
||||||
# ENABLED in DEBUGMODE
|
# ENABLED in DEBUGMODE
|
||||||
@ -57,7 +57,6 @@ my %pa_config;
|
|||||||
$SIG{'TERM'} = 'pandora_shutdown';
|
$SIG{'TERM'} = 'pandora_shutdown';
|
||||||
$SIG{'INT'} = 'pandora_shutdown';
|
$SIG{'INT'} = 'pandora_shutdown';
|
||||||
|
|
||||||
|
|
||||||
# Inicio del bucle principal de programa
|
# Inicio del bucle principal de programa
|
||||||
pandora_init(\%pa_config, "Pandora FMS Recon server");
|
pandora_init(\%pa_config, "Pandora FMS Recon server");
|
||||||
|
|
||||||
@ -67,6 +66,16 @@ pandora_loadconfig (\%pa_config, 3);
|
|||||||
# Audit server starting
|
# Audit server starting
|
||||||
pandora_audit (\%pa_config, "Pandora FMS Recon Daemon starting", "SYSTEM", "System");
|
pandora_audit (\%pa_config, "Pandora FMS Recon Daemon starting", "SYSTEM", "System");
|
||||||
|
|
||||||
|
# Check for xprobe2
|
||||||
|
my $xprobe2 = $pa_config{"xprobe2"};
|
||||||
|
|
||||||
|
if (! -e $xprobe2) {
|
||||||
|
print " [E] $xprobe2 not found. Pandora FMS Recon cannot detect OS types without it.\n\n";
|
||||||
|
exit;
|
||||||
|
} else {
|
||||||
|
print " [*] $xprobe2 Detected.\n\n";
|
||||||
|
}
|
||||||
|
|
||||||
sleep(1);
|
sleep(1);
|
||||||
|
|
||||||
# Daemonize and put in background
|
# Daemonize and put in background
|
||||||
@ -129,11 +138,12 @@ sub pandora_recon_producer ($) {
|
|||||||
while (1) {
|
while (1) {
|
||||||
$query_sql = "SELECT * FROM trecon_task
|
$query_sql = "SELECT * FROM trecon_task
|
||||||
WHERE
|
WHERE
|
||||||
id_network_server = $server_id
|
id_recon_server = $server_id
|
||||||
AND
|
AND (
|
||||||
status = 1
|
status = 1
|
||||||
AND
|
OR
|
||||||
(utimestamp + interval_sweep) < UNIX_TIMESTAMP()
|
(utimestamp + interval_sweep) < UNIX_TIMESTAMP()
|
||||||
|
)
|
||||||
";
|
";
|
||||||
|
|
||||||
$exec_sql1 = $dbh->prepare($query_sql);
|
$exec_sql1 = $dbh->prepare($query_sql);
|
||||||
@ -233,13 +243,15 @@ sub pandora_detect_os {
|
|||||||
}
|
}
|
||||||
my $command= "";
|
my $command= "";
|
||||||
eval {
|
eval {
|
||||||
$command = `$xprobe2 $host 2> /dev/null | grep "Running OS" | head -1`;
|
$command = `$xprobe2 $host 2> /dev/null | grep "Running OS" 2> /dev/null | head -1 2> /dev/null`;
|
||||||
};
|
};
|
||||||
if ($@){
|
if ($@){
|
||||||
return 10;
|
return 10;
|
||||||
}
|
}
|
||||||
return pandora_get_os ($command);
|
return pandora_get_os ($command);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
##########################################################################
|
##########################################################################
|
||||||
# SUB pandora_exec_task (pa_config, id_task)
|
# SUB pandora_exec_task (pa_config, id_task)
|
||||||
# Execute task
|
# Execute task
|
||||||
@ -254,7 +266,7 @@ sub pandora_recon_exec_task {
|
|||||||
my $space; # temp var to store space of ip's for netaddr::ip
|
my $space; # temp var to store space of ip's for netaddr::ip
|
||||||
my $query_sql; # for use in SQL
|
my $query_sql; # for use in SQL
|
||||||
my $exec_sql; # for use in SQL
|
my $exec_sql; # for use in SQL
|
||||||
my @sql_data; # for use in SQL
|
my $sql_data; # for use in SQL
|
||||||
|
|
||||||
$query_sql = "SELECT * FROM trecon_task WHERE id_rt = $id_task";
|
$query_sql = "SELECT * FROM trecon_task WHERE id_rt = $id_task";
|
||||||
$exec_sql = $dbh->prepare($query_sql);
|
$exec_sql = $dbh->prepare($query_sql);
|
||||||
@ -263,24 +275,24 @@ sub pandora_recon_exec_task {
|
|||||||
# something wrong..
|
# something wrong..
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@sql_data = $exec_sql->fetchrow_array();
|
|
||||||
my $status = $sql_data[10];
|
$sql_data = $exec_sql->fetchrow_hashref();
|
||||||
my $interval = $sql_data[11];
|
my $status = $sql_data->{"status"};
|
||||||
my $network_server_assigned = $sql_data[12];
|
my $interval = $sql_data->{"interval"};
|
||||||
my $extended_info = $sql_data[13];
|
my $target_network = $sql_data->{"subnet"};
|
||||||
my $extended_value = $sql_data[14];
|
my $task_name = $sql_data->{"name"};
|
||||||
my $target_network = $sql_data[4];
|
my $task_ncprofile = $sql_data->{"id_network_profile"};
|
||||||
my $task_name = $sql_data[1];
|
my $task_group = $sql_data->{"id_group"};
|
||||||
|
my $task_create_incident = $sql_data->{"create_incident"};
|
||||||
|
my $task_id_os = $sql_data->{"id_os"};
|
||||||
|
|
||||||
my $position = 0;
|
my $position = 0;
|
||||||
my $task_type = $sql_data[3];
|
|
||||||
my $task_ncprofile = $sql_data[6];
|
|
||||||
my $task_group = $sql_data[8];
|
|
||||||
my $task_create_incident = $sql_data[7];
|
|
||||||
my $list_ip = "";
|
my $list_ip = "";
|
||||||
my $list_host = "";
|
my $list_host = "";
|
||||||
my $host_found = 0;
|
my $host_found = 0;
|
||||||
my $add_host = 0;
|
my $add_host = 0;
|
||||||
my $id_parent = 0;
|
my $id_parent = 0;
|
||||||
|
my $id_os = 0;
|
||||||
|
|
||||||
# Asign target dir to netaddr object "space"
|
# Asign target dir to netaddr object "space"
|
||||||
$space = new NetAddr::IP $target_network;
|
$space = new NetAddr::IP $target_network;
|
||||||
@ -296,19 +308,18 @@ sub pandora_recon_exec_task {
|
|||||||
do {
|
do {
|
||||||
@ip2 = split(/\//,$space);
|
@ip2 = split(/\//,$space);
|
||||||
$target_ip = $ip2[0];
|
$target_ip = $ip2[0];
|
||||||
$space++; $position++;
|
$space++;
|
||||||
|
$position++;
|
||||||
|
|
||||||
$add_host = 0;
|
$add_host = 0;
|
||||||
# Is this IP listed for any agent ?
|
# Is this IP listed for any agent ?
|
||||||
if (pandora_check_ip ($pa_config, $dbh, $target_ip) == 0){
|
if (pandora_check_ip ($pa_config, $dbh, $target_ip) == 0){
|
||||||
|
|
||||||
# Check ICMP for this IP
|
# Check ICMP for this IP
|
||||||
if (($task_type == 1) && (scan_icmp ($target_ip, $pa_config->{'networktimeout'}) == 1)){
|
if ( scan_icmp ($target_ip, $pa_config->{'networktimeout'}) == 1) {
|
||||||
|
$id_os = pandora_detect_os ($pa_config, $target_ip);
|
||||||
|
if ($task_id_os == -1){
|
||||||
$add_host = 1;
|
$add_host = 1;
|
||||||
}
|
} elsif ($id_os == $task_id_os){
|
||||||
# Check TCP port for this IP
|
|
||||||
elsif (($task_type == 2) && (scan_icmp ($target_ip, $pa_config->{'networktimeout'}) == 1)) {
|
|
||||||
if (scan_tcp ($target_ip, $pa_config->{'networktimeout'}, $extended_value) == 1){
|
|
||||||
$add_host = 1;
|
$add_host = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -316,8 +327,8 @@ sub pandora_recon_exec_task {
|
|||||||
if ($add_host == 1){
|
if ($add_host == 1){
|
||||||
$host_found ++;
|
$host_found ++;
|
||||||
my $target_ip_resolved = resolv_ip2name($target_ip);
|
my $target_ip_resolved = resolv_ip2name($target_ip);
|
||||||
$list_ip = $list_ip." ".$target_ip;
|
$list_ip = $list_ip . " " . $target_ip;
|
||||||
$list_host = $list_host." ".resolv_ip2name($target_ip_resolved);
|
$list_host = $list_host . " " . $target_ip_resolved;
|
||||||
$id_parent = pandora_getparent ($pa_config, $target_ip, $dbh);
|
$id_parent = pandora_getparent ($pa_config, $target_ip, $dbh);
|
||||||
|
|
||||||
# If has a network profile, create agent and modules
|
# If has a network profile, create agent and modules
|
||||||
@ -325,12 +336,11 @@ sub pandora_recon_exec_task {
|
|||||||
if ($task_ncprofile > 0){
|
if ($task_ncprofile > 0){
|
||||||
# Create address, agent and more...
|
# Create address, agent and more...
|
||||||
my $target_ip_id = pandora_task_create_address ($pa_config, $dbh, $id_task, $target_ip);
|
my $target_ip_id = pandora_task_create_address ($pa_config, $dbh, $id_task, $target_ip);
|
||||||
$agent_id = pandora_task_create_agent($pa_config, $dbh, $target_ip, $target_ip_id, $task_group, $network_server_assigned, $target_ip_resolved, $id_parent);
|
$agent_id = pandora_task_create_agent ($pa_config, $dbh, $target_ip, $target_ip_id, $task_group, $target_ip_resolved, $id_parent, $id_os);
|
||||||
pandora_task_create_agentmodules($pa_config, $dbh, $agent_id, $task_ncprofile, $target_ip);
|
pandora_task_create_agentmodules ($pa_config, $dbh, $agent_id, $task_ncprofile, $target_ip);
|
||||||
} else {
|
} else {
|
||||||
my $target_ip_id = pandora_task_create_address ($pa_config, $dbh, $id_task, $target_ip);
|
my $target_ip_id = pandora_task_create_address ($pa_config, $dbh, $id_task, $target_ip);
|
||||||
$agent_id = pandora_task_create_agent($pa_config, $dbh, $target_ip, $target_ip_id, $task_group,
|
$agent_id = pandora_task_create_agent($pa_config, $dbh, $target_ip, $target_ip_id, $task_group, $target_ip_resolved, $id_parent, $id_os);
|
||||||
$network_server_assigned, $target_ip_resolved, $id_parent);
|
|
||||||
}
|
}
|
||||||
my $title = "[RECON] New host [$target_ip_resolved] detected on network [$target_network]";
|
my $title = "[RECON] New host [$target_ip_resolved] detected on network [$target_network]";
|
||||||
# Always create event about this detected IP
|
# Always create event about this detected IP
|
||||||
@ -366,33 +376,25 @@ sub pandora_recon_exec_task {
|
|||||||
sub scan_icmp {
|
sub scan_icmp {
|
||||||
my $dest = $_[0];
|
my $dest = $_[0];
|
||||||
my $l_timeout = $_[1];
|
my $l_timeout = $_[1];
|
||||||
# temporal vars.
|
|
||||||
|
# Temp vars.
|
||||||
my $result = 0;
|
my $result = 0;
|
||||||
my $p;
|
my $p;
|
||||||
|
|
||||||
# Check for valid destination
|
# Check for valid destination
|
||||||
if (!defined($dest)) {
|
if (!defined($dest)){
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
# Thread safe
|
|
||||||
# Some hosts don't accept ICMP with too small payload. Use 16 Bytes
|
|
||||||
{
|
{
|
||||||
$p = Net::Ping->new("icmp",$l_timeout,16);
|
lock $icmp_lock;
|
||||||
$p->source_verify(1);
|
$p = Net::Ping->new();
|
||||||
$result = $p->ping($dest);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check for valid result
|
if ($p->ping($dest)){
|
||||||
if (!defined($result)) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
# Lets see the result
|
|
||||||
if ($result == 1) {
|
|
||||||
$p->close();
|
$p->close();
|
||||||
|
undef ($p);
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
$p->close();
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -524,7 +526,7 @@ sub pandora_task_create_address {
|
|||||||
|
|
||||||
##########################################################################
|
##########################################################################
|
||||||
# SUB pandora_task_create_agent (pa_config, dbh, target_ip, target_ip_id,
|
# SUB pandora_task_create_agent (pa_config, dbh, target_ip, target_ip_id,
|
||||||
# id_group, network_server_assigned, name)
|
# id_group, name, id_parent)
|
||||||
# Create agent, and associate address to agent in taddress_agent table.
|
# Create agent, and associate address to agent in taddress_agent table.
|
||||||
# it returns created id_agent.
|
# it returns created id_agent.
|
||||||
##########################################################################
|
##########################################################################
|
||||||
@ -534,12 +536,11 @@ sub pandora_task_create_agent {
|
|||||||
my $target_ip = $_[2];
|
my $target_ip = $_[2];
|
||||||
my $target_ip_id = $_[3];
|
my $target_ip_id = $_[3];
|
||||||
my $id_group = $_[4];
|
my $id_group = $_[4];
|
||||||
my $id_server = $_[5];
|
my $name = $_[5];
|
||||||
my $name = $_[6];
|
my $id_parent = $_[6];
|
||||||
my $id_parent = $_[7];
|
my $id_os = $_[7];
|
||||||
|
|
||||||
my $id_os = pandora_detect_os ($pa_config, $target_ip);
|
return pandora_create_agent ($pa_config, $dbh, $target_ip, $target_ip_id, $id_group, 0, $name, $id_parent, $id_os);
|
||||||
return pandora_create_agent ($pa_config, $dbh, $target_ip, $target_ip_id, $id_group, $id_server, $name, $id_parent, $id_os);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
##########################################################################
|
##########################################################################
|
||||||
@ -564,38 +565,66 @@ sub pandora_task_create_agentmodules {
|
|||||||
my $exec_sql2 = $dbh->prepare($query_sql2);
|
my $exec_sql2 = $dbh->prepare($query_sql2);
|
||||||
$exec_sql2 ->execute;
|
$exec_sql2 ->execute;
|
||||||
if ($exec_sql2->rows != 0) {
|
if ($exec_sql2->rows != 0) {
|
||||||
my @sql_data2 = $exec_sql2->fetchrow_array();
|
my $sql_data2 = $exec_sql2->fetchrow_hashref();
|
||||||
my $name = "";
|
|
||||||
$name = $sql_data2[1];
|
my $name = "";
|
||||||
my $description = "Autocreated by Pandora FMS Recon Server";
|
$name = $sql_data2->{"name"};
|
||||||
$description = $sql_data2[2];
|
|
||||||
my $type = "1";
|
my $description = "";
|
||||||
$type = $sql_data2[4];
|
$description = $sql_data2->{"description"};
|
||||||
my $max = 0;
|
|
||||||
$max = $sql_data2[5];
|
my $type = "1";
|
||||||
my $min = 0;
|
$type = $sql_data2->{"type"};
|
||||||
$min = $sql_data2[6];
|
|
||||||
my $interval = 300;
|
my $max = 0;
|
||||||
$interval = $sql_data2[7];
|
$max = $sql_data2->{"max"};
|
||||||
my $tcp_port = "";
|
|
||||||
$tcp_port = $sql_data2[8];
|
my $min = 0;
|
||||||
my $tcp_send = "";
|
$min = $sql_data2->{"min"};
|
||||||
$tcp_send = $sql_data2[9];
|
|
||||||
my $tcp_rcv = "";
|
my $interval = 300;
|
||||||
$tcp_rcv = $sql_data2[10];
|
$interval = $sql_data2->{"module_interval"};
|
||||||
my $snmp_community = "public";
|
|
||||||
$snmp_community = $sql_data2[11];
|
my $tcp_port = "";
|
||||||
my $snmp_oid = "";
|
$tcp_port = $sql_data2->{"tcp_port"};
|
||||||
$snmp_oid = $sql_data2[12];
|
|
||||||
my $id_module_group = 0;
|
my $tcp_send = "";
|
||||||
$id_module_group = $sql_data2[13];
|
$tcp_send = $sql_data2->{"tcp_send"};
|
||||||
|
|
||||||
|
my $tcp_rcv = "";
|
||||||
|
$tcp_rcv = $sql_data2->{"tcp_rcv"};
|
||||||
|
|
||||||
|
my $snmp_community = "public";
|
||||||
|
$snmp_community = $sql_data2->{"snmp_community"};
|
||||||
|
|
||||||
|
my $snmp_oid = "";
|
||||||
|
$snmp_oid = $sql_data2->{"snmp_oid"};
|
||||||
|
|
||||||
|
my $id_module_group = 0;
|
||||||
|
$id_module_group = $sql_data2->{"id_module_group"};
|
||||||
|
|
||||||
|
my $id_module = 0;
|
||||||
|
$id_module = $sql_data2->{"id_modulo"};
|
||||||
|
|
||||||
|
my $plugin_user = "";
|
||||||
|
$plugin_user = $dbh->quote($sql_data2->{"plugin_user"});
|
||||||
|
|
||||||
|
my $plugin_pass = "";
|
||||||
|
$plugin_pass = $dbh->quote($sql_data2->{"plugin_pass"});
|
||||||
|
|
||||||
|
my $plugin_parameter = "";
|
||||||
|
$plugin_parameter = $dbh->quote($sql_data2->{"plugin_parameter"});
|
||||||
|
|
||||||
|
my $max_timeout = "30";
|
||||||
|
$max_timeout = $sql_data2->{"max_timeout"};
|
||||||
|
|
||||||
|
my $query_sql3 = "INSERT INTO tagente_modulo (id_agente, id_tipo_modulo, descripcion, nombre, max, min, module_interval, tcp_port, tcp_send, tcp_rcv, snmp_community, snmp_oid, ip_target, id_module_group, flag, disabled, plugin_user, plugin_pass, plugin_parameter, max_timeout, id_modulo ) VALUES ( $agent_id, $type, '$description', '$name', $max, $min, $interval, $tcp_port, '$tcp_send', '$tcp_rcv', '$snmp_community', '$snmp_oid', '$ip_adress', $id_module_group, 1, 0, $plugin_user, $plugin_pass, $plugin_parameter, $max_timeout, $id_module)";
|
||||||
|
|
||||||
my $query_sql3 = "INSERT INTO tagente_modulo (id_agente, id_tipo_modulo, descripcion, nombre, max, min, module_interval, tcp_port, tcp_send, tcp_rcv, snmp_community, snmp_oid, ip_target, id_module_group, flag ) VALUES ( $agent_id, $type, '$description', '$name', $max, $min, $interval, $tcp_port, '$tcp_send', '$tcp_rcv', '$snmp_community', '$snmp_oid', '$ip_adress', $id_module_group, 1)";
|
|
||||||
$dbh->do($query_sql3);
|
$dbh->do($query_sql3);
|
||||||
my $last_id_agente_modulo = $dbh->{'mysql_insertid'};
|
my $last_id_agente_modulo = $dbh->{'mysql_insertid'};
|
||||||
logger($pa_config,"Recon Server: Creating module $name for agent $ip_adress",3);
|
logger($pa_config,"Recon Server: Creating module $name for agent $ip_adress",3);
|
||||||
my $query_sql4;
|
my $query_sql4;
|
||||||
if (($type == 2) || ($type == 6) || ($type == 9) || ($type == 18)) {
|
if (($type == 2) || ($type == 6) || ($type == 21) || ($type == 9) || ($type == 18)) {
|
||||||
# for monitors
|
# for monitors
|
||||||
$query_sql4 = "INSERT INTO tagente_estado (id_agente_modulo, datos, timestamp, cambio, estado, id_agente, last_try, utimestamp, current_interval, running_by) VALUES ($last_id_agente_modulo, '', '0000-00-00 00:00:00', 0, 0, $agent_id, '0000-00-00 00:00:00', 0, $interval, 0)";
|
$query_sql4 = "INSERT INTO tagente_estado (id_agente_modulo, datos, timestamp, cambio, estado, id_agente, last_try, utimestamp, current_interval, running_by) VALUES ($last_id_agente_modulo, '', '0000-00-00 00:00:00', 0, 0, $agent_id, '0000-00-00 00:00:00', 0, $interval, 0)";
|
||||||
} else {
|
} else {
|
||||||
@ -615,7 +644,7 @@ sub pandora_getparent ($$){
|
|||||||
my $dbh = $_[2];
|
my $dbh = $_[2];
|
||||||
|
|
||||||
my $t = new Net::Traceroute::PurePerl(
|
my $t = new Net::Traceroute::PurePerl(
|
||||||
backend => 'PurePerl', # this optional
|
backend => 'PurePerl',
|
||||||
host => $destination,
|
host => $destination,
|
||||||
debug => 0,
|
debug => 0,
|
||||||
max_ttl => 15,
|
max_ttl => 15,
|
||||||
@ -624,6 +653,7 @@ sub pandora_getparent ($$){
|
|||||||
protocol => 'icmp', # udp or icmp
|
protocol => 'icmp', # udp or icmp
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
my $success = 0;
|
my $success = 0;
|
||||||
$success = $t->traceroute();
|
$success = $t->traceroute();
|
||||||
if ($t->hops > 1){
|
if ($t->hops > 1){
|
||||||
@ -632,6 +662,7 @@ sub pandora_getparent ($$){
|
|||||||
return pandora_get_agent_from_ip ($pa_config, $dbh, $parent_ip);
|
return pandora_get_agent_from_ip ($pa_config, $dbh, $parent_ip);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -394,7 +394,7 @@ sub pandora_loadconfig {
|
|||||||
$pa_config->{"keepalive"} = clean_blank($1);
|
$pa_config->{"keepalive"} = clean_blank($1);
|
||||||
$pa_config->{"keepalive_orig"} = clean_blank($1);
|
$pa_config->{"keepalive_orig"} = clean_blank($1);
|
||||||
}
|
}
|
||||||
elsif ($parametro =~ m/^xprobe2\s([.*]*)/i) {
|
elsif ($parametro =~ m/^xprobe2\s(.*)/i) {
|
||||||
$pa_config->{'xprobe2'}= clean_blank($1);
|
$pa_config->{'xprobe2'}= clean_blank($1);
|
||||||
}
|
}
|
||||||
elsif ($parametro =~ m/^autocreate\s([0-9*]*)/i) {
|
elsif ($parametro =~ m/^autocreate\s([0-9*]*)/i) {
|
||||||
@ -541,7 +541,7 @@ sub pandora_startlog ($){
|
|||||||
open STDERR, ">>$pa_config->{'errorlogfile'}" or die " [ERROR] Pandora FMS can't write to Errorlog. Aborting : \n $! \n";
|
open STDERR, ">>$pa_config->{'errorlogfile'}" or die " [ERROR] Pandora FMS can't write to Errorlog. Aborting : \n $! \n";
|
||||||
my $time_now = &UnixDate("today","%Y/%m/%d %H:%M:%S");
|
my $time_now = &UnixDate("today","%Y/%m/%d %H:%M:%S");
|
||||||
print STDERR "$time_now - ".$pa_config->{'servername'}.$pa_config->{"servermode"}." Starting Pandora FMS Server. Error logging activated \n";
|
print STDERR "$time_now - ".$pa_config->{'servername'}.$pa_config->{"servermode"}." Starting Pandora FMS Server. Error logging activated \n";
|
||||||
# This redirect ANY output to errorlog. Not a good idea for real usage !
|
# This redirect ANY output to errorlog.
|
||||||
# open STDOUT, ">>$pa_config->{'errorlogfile'}"
|
# open STDOUT, ">>$pa_config->{'errorlogfile'}"
|
||||||
}
|
}
|
||||||
# End of function declaration
|
# End of function declaration
|
||||||
|
@ -64,6 +64,8 @@ our @EXPORT = qw(
|
|||||||
pandora_generate_compound_alerts
|
pandora_generate_compound_alerts
|
||||||
pandora_process_alert
|
pandora_process_alert
|
||||||
pandora_planned_downtime
|
pandora_planned_downtime
|
||||||
|
pandora_create_agent
|
||||||
|
pandora_event
|
||||||
module_generic_proc
|
module_generic_proc
|
||||||
module_generic_data
|
module_generic_data
|
||||||
module_generic_data_inc
|
module_generic_data_inc
|
||||||
@ -849,7 +851,6 @@ sub module_generic_proc (%$$$$$) {
|
|||||||
} else {
|
} else {
|
||||||
$estado = 1;
|
$estado = 1;
|
||||||
}
|
}
|
||||||
print "Checkpoint Proc prev. writestate #1 \n";
|
|
||||||
pandora_writestate ($pa_config, $agent_name, $module_type, $a_name, $a_datos, $estado, $dbh, $bUpdateDatos);
|
pandora_writestate ($pa_config, $agent_name, $module_type, $a_name, $a_datos, $estado, $dbh, $bUpdateDatos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2125,6 +2126,99 @@ sub get_db_free_row ($$) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
##########################################################################
|
||||||
|
# SUB pandora_create_agent (pa_config, dbh, target_ip, target_ip_id,
|
||||||
|
# id_group, network_server_assigned, name, id_os)
|
||||||
|
# Create agent, and associate address to agent in taddress_agent table.
|
||||||
|
# it returns created id_agent.
|
||||||
|
##########################################################################
|
||||||
|
sub pandora_create_agent {
|
||||||
|
my $pa_config = $_[0];
|
||||||
|
my $dbh = $_[1];
|
||||||
|
my $target_ip = $_[2];
|
||||||
|
my $target_ip_id = $_[3];
|
||||||
|
my $id_group = $_[4];
|
||||||
|
my $id_server= $_[5];
|
||||||
|
my $name = $_[6];
|
||||||
|
my $id_parent = $_[7];
|
||||||
|
my $id_os = $_[8];
|
||||||
|
|
||||||
|
my $prediction;
|
||||||
|
my $wmi;
|
||||||
|
my $plugin;
|
||||||
|
|
||||||
|
if ((!is_numeric($id_server)) || ($id_server == 0)){
|
||||||
|
$id_server = get_db_free_field ("SELECT id_server FROM tserver WHERE network_server = 1 AND master = 1 LIMIT 1", $dbh);
|
||||||
|
}
|
||||||
|
|
||||||
|
$prediction = get_db_free_field ("SELECT id_server FROM tserver WHERE prediction_server = 1 AND master = 1 LIMIT 1", $dbh);
|
||||||
|
$wmi = get_db_free_field ("SELECT id_server FROM tserver WHERE wmi_server = 1 AND master = 1 LIMIT 1", $dbh);
|
||||||
|
$plugin = get_db_free_field ("SELECT id_server FROM tserver WHERE plugin_server = 1 AND master = 1 LIMIT 1", $dbh);
|
||||||
|
|
||||||
|
if ($wmi < 0){
|
||||||
|
$wmi = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($plugin < 0){
|
||||||
|
$plugin = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($prediction < 0){
|
||||||
|
$prediction = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($id_server < 0){
|
||||||
|
$id_server = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
my $server = $pa_config->{'servername'}.$pa_config->{"servermode"};
|
||||||
|
logger ($pa_config,"$server: Creating agent $name $target_ip ", 1);
|
||||||
|
|
||||||
|
my $query_sql2 = "INSERT INTO tagente (nombre, direccion, comentarios, id_grupo, id_os, id_network_server, intervalo, id_parent, modo, id_prediction_server, id_wmi_server, id_plugin_server) VALUES ('$name', '$target_ip', 'Created by $server', $id_group, $id_os, $id_server, 300, $id_parent, 1, $prediction, $wmi, $plugin)";
|
||||||
|
|
||||||
|
$dbh->do ($query_sql2);
|
||||||
|
|
||||||
|
my $lastid = $dbh->{'mysql_insertid'};
|
||||||
|
|
||||||
|
pandora_event ($pa_config, "Agent '$name' created by ".$pa_config->{'servername'}.$pa_config->{"servermode"}, $pa_config->{'autocreate_group'}, $lastid, 2, 0, 0, 'new_agent', $dbh);
|
||||||
|
|
||||||
|
if ($target_ip_id > 0){
|
||||||
|
my $query_sql3 = "INSERT INTO taddress_agent (id_a, id_agent) values ($target_ip_id, $lastid)";
|
||||||
|
$dbh->do($query_sql3);
|
||||||
|
}
|
||||||
|
return $lastid;
|
||||||
|
}
|
||||||
|
|
||||||
|
##########################################################################
|
||||||
|
## SUB pandora_event
|
||||||
|
## Write in internal audit system an entry.
|
||||||
|
## Params: config_hash, event_title, group, agent_id, severity, id_alertam
|
||||||
|
## id_agentmodule, event_type (from a set, as string), db_handle
|
||||||
|
##########################################################################
|
||||||
|
|
||||||
|
sub pandora_event (%$$$$$$$$) {
|
||||||
|
my $pa_config = $_[0];
|
||||||
|
my $evento = $_[1];
|
||||||
|
my $id_grupo = $_[2];
|
||||||
|
my $id_agente = $_[3];
|
||||||
|
my $severity = $_[4]; # new in 2.0
|
||||||
|
my $id_alert_am = $_[5]; # new in 2.0
|
||||||
|
my $id_agentmodule = $_[6]; # new in 2.0
|
||||||
|
my $event_type = $_[7]; # new in 2.0
|
||||||
|
my $dbh = $_[8];
|
||||||
|
my $timestamp = &UnixDate("today","%Y-%m-%d %H:%M:%S");
|
||||||
|
my $utimestamp; # integer version of timestamp
|
||||||
|
|
||||||
|
$utimestamp = &UnixDate($timestamp,"%s"); # convert from human to integer
|
||||||
|
$evento = $dbh->quote($evento);
|
||||||
|
$event_type = $dbh->quote($event_type);
|
||||||
|
$timestamp = $dbh->quote($timestamp);
|
||||||
|
my $query = "INSERT INTO tevento (id_agente, id_grupo, evento, timestamp, estado, utimestamp, event_type, id_agentmodule, id_alert_am, criticity) VALUES ($id_agente, $id_grupo, $evento, $timestamp, 0, $utimestamp, $event_type, $id_agentmodule, $id_alert_am, $severity)";
|
||||||
|
$dbh->do($query);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# End of function declaration
|
# End of function declaration
|
||||||
# End of defined Code
|
# End of defined Code
|
||||||
|
|
||||||
|
@ -39,9 +39,7 @@ our @EXPORT = qw(
|
|||||||
is_numeric
|
is_numeric
|
||||||
clean_blank
|
clean_blank
|
||||||
pandora_sendmail
|
pandora_sendmail
|
||||||
pandora_create_agent
|
|
||||||
pandora_get_os
|
pandora_get_os
|
||||||
pandora_event
|
|
||||||
pandora_trash_ascii
|
pandora_trash_ascii
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -61,33 +59,6 @@ sub pandora_trash_ascii {
|
|||||||
return $output
|
return $output
|
||||||
}
|
}
|
||||||
|
|
||||||
##########################################################################
|
|
||||||
## SUB pandora_event
|
|
||||||
## Write in internal audit system an entry.
|
|
||||||
## Params: config_hash, event_title, group, agent_id, severity, id_alertam
|
|
||||||
## id_agentmodule, event_type (from a set, as string), db_handle
|
|
||||||
##########################################################################
|
|
||||||
|
|
||||||
sub pandora_event (%$$$$$$$$) {
|
|
||||||
my $pa_config = $_[0];
|
|
||||||
my $evento = $_[1];
|
|
||||||
my $id_grupo = $_[2];
|
|
||||||
my $id_agente = $_[3];
|
|
||||||
my $severity = $_[4]; # new in 2.0
|
|
||||||
my $id_alert_am = $_[5]; # new in 2.0
|
|
||||||
my $id_agentmodule = $_[6]; # new in 2.0
|
|
||||||
my $event_type = $_[7]; # new in 2.0
|
|
||||||
my $dbh = $_[8];
|
|
||||||
my $timestamp = &UnixDate("today","%Y-%m-%d %H:%M:%S");
|
|
||||||
my $utimestamp; # integer version of timestamp
|
|
||||||
|
|
||||||
$utimestamp = &UnixDate($timestamp,"%s"); # convert from human to integer
|
|
||||||
$evento = $dbh->quote($evento);
|
|
||||||
$event_type = $dbh->quote($event_type);
|
|
||||||
$timestamp = $dbh->quote($timestamp);
|
|
||||||
my $query = "INSERT INTO tevento (id_agente, id_grupo, evento, timestamp, estado, utimestamp, event_type, id_agentmodule, id_alert_am, criticity) VALUES ($id_agente, $id_grupo, $evento, $timestamp, 0, $utimestamp, $event_type, $id_agentmodule, $id_alert_am, $severity)";
|
|
||||||
$dbh->do($query);
|
|
||||||
}
|
|
||||||
|
|
||||||
##########################################################################
|
##########################################################################
|
||||||
# SUB pandora_get_os (string)
|
# SUB pandora_get_os (string)
|
||||||
@ -158,37 +129,6 @@ sub pandora_daemonize {
|
|||||||
# Pandora other General functions |
|
# Pandora other General functions |
|
||||||
# -------------------------------------------+
|
# -------------------------------------------+
|
||||||
|
|
||||||
##########################################################################
|
|
||||||
# SUB pandora_create_agent (pa_config, dbh, target_ip, target_ip_id,
|
|
||||||
# id_group, network_server_assigned, name, id_os)
|
|
||||||
# Create agent, and associate address to agent in taddress_agent table.
|
|
||||||
# it returns created id_agent.
|
|
||||||
##########################################################################
|
|
||||||
sub pandora_create_agent {
|
|
||||||
my $pa_config = $_[0];
|
|
||||||
my $dbh = $_[1];
|
|
||||||
my $target_ip = $_[2];
|
|
||||||
my $target_ip_id = $_[3];
|
|
||||||
my $id_group = $_[4];
|
|
||||||
my $id_server= $_[5];
|
|
||||||
my $name = $_[6];
|
|
||||||
my $id_parent = $_[7];
|
|
||||||
my $id_os = $_[8];
|
|
||||||
|
|
||||||
my $server = $pa_config->{'servername'}.$pa_config->{"servermode"};
|
|
||||||
logger($pa_config,"$server: Creating agent $name $target_ip ", 1);
|
|
||||||
my $query_sql2 = "INSERT INTO tagente (nombre, direccion, comentarios, id_grupo, id_os, id_network_server, intervalo, id_parent, modo) VALUES ('$name', '$target_ip', 'Created by $server', $id_group, $id_os, $id_server, 300, $id_parent, 1)";
|
|
||||||
$dbh->do ($query_sql2);
|
|
||||||
my $lastid = $dbh->{'mysql_insertid'};
|
|
||||||
|
|
||||||
pandora_event ($pa_config, "Agent '$name' created by ".$pa_config->{'servername'}.$pa_config->{"servermode"}, $pa_config->{'autocreate_group'}, $lastid, 2, 0, 0, 'new_agent', $dbh);
|
|
||||||
|
|
||||||
if ($target_ip_id > 0){
|
|
||||||
my $query_sql3 = "INSERT INTO taddress_agent (id_a, id_agent) values ($target_ip_id, $lastid)";
|
|
||||||
$dbh->do($query_sql3);
|
|
||||||
}
|
|
||||||
return $lastid;
|
|
||||||
}
|
|
||||||
|
|
||||||
##########################################################################
|
##########################################################################
|
||||||
# SUB pandora_sendmail
|
# SUB pandora_sendmail
|
||||||
|
Loading…
x
Reference in New Issue
Block a user