mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-28 16:24:54 +02:00
2014-07-25 Miguel de Dios <miguel.dedios@artica.es>
* lib/PandoraFMS/GIS.pm, lib/PandoraFMS/DB.pm, lib/PandoraFMS/Core.pm, lib/PandoraFMS/ReconServer.pm, lib/PandoraFMS/DataServer.pm: tiny fixes for to improve the support of PostgreSQL. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@10356 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
8d7541ce56
commit
f679cec04c
@ -1201,8 +1201,10 @@ sub pandora_planned_downtime_disabled_once_stop($$) {
|
|||||||
# Stop executed downtimes (enable agents and disable_agents_alerts)
|
# Stop executed downtimes (enable agents and disable_agents_alerts)
|
||||||
my @downtimes = get_db_rows($dbh, 'SELECT *
|
my @downtimes = get_db_rows($dbh, 'SELECT *
|
||||||
FROM tplanned_downtime
|
FROM tplanned_downtime
|
||||||
WHERE type_downtime != "quiet" AND type_execution="once"
|
WHERE type_downtime != ' . $RDBMS_QUOTE_STRING. 'quiet' . $RDBMS_QUOTE_STRING. '
|
||||||
AND executed = 1 AND date_to <= ?', $utimestamp);
|
AND type_execution = ' . $RDBMS_QUOTE_STRING. 'once' . $RDBMS_QUOTE_STRING. '
|
||||||
|
AND executed = 1
|
||||||
|
AND date_to <= ?', $utimestamp);
|
||||||
|
|
||||||
foreach my $downtime (@downtimes) {
|
foreach my $downtime (@downtimes) {
|
||||||
|
|
||||||
@ -1234,7 +1236,8 @@ sub pandora_planned_downtime_disabled_once_start($$) {
|
|||||||
# Start pending downtimes (disable agents and disable_agents_alerts)
|
# Start pending downtimes (disable agents and disable_agents_alerts)
|
||||||
my @downtimes = get_db_rows($dbh, 'SELECT *
|
my @downtimes = get_db_rows($dbh, 'SELECT *
|
||||||
FROM tplanned_downtime
|
FROM tplanned_downtime
|
||||||
WHERE type_downtime != "quiet" AND type_execution="once"
|
WHERE type_downtime != ' . $RDBMS_QUOTE_STRING . 'quiet' . $RDBMS_QUOTE_STRING . '
|
||||||
|
AND type_execution = ' . $RDBMS_QUOTE_STRING . 'once' . $RDBMS_QUOTE_STRING . '
|
||||||
AND executed = 0 AND date_from <= ?
|
AND executed = 0 AND date_from <= ?
|
||||||
AND date_to >= ?', $utimestamp, $utimestamp);
|
AND date_to >= ?', $utimestamp, $utimestamp);
|
||||||
|
|
||||||
@ -1431,7 +1434,8 @@ sub pandora_planned_downtime_quiet_once_stop($$) {
|
|||||||
# Stop pending downtimes
|
# Stop pending downtimes
|
||||||
my @downtimes = get_db_rows($dbh, 'SELECT *
|
my @downtimes = get_db_rows($dbh, 'SELECT *
|
||||||
FROM tplanned_downtime
|
FROM tplanned_downtime
|
||||||
WHERE type_downtime = "quiet" AND type_execution="once"
|
WHERE type_downtime = ' . $RDBMS_QUOTE_STRING . 'quiet' . $RDBMS_QUOTE_STRING . '
|
||||||
|
AND type_execution = ' . $RDBMS_QUOTE_STRING. 'once' . $RDBMS_QUOTE_STRING . '
|
||||||
AND executed = 1 AND date_to <= ?', $utimestamp);
|
AND executed = 1 AND date_to <= ?', $utimestamp);
|
||||||
|
|
||||||
foreach my $downtime (@downtimes) {
|
foreach my $downtime (@downtimes) {
|
||||||
@ -1471,7 +1475,8 @@ sub pandora_planned_downtime_quiet_once_start($$) {
|
|||||||
# Start pending downtimes
|
# Start pending downtimes
|
||||||
my @downtimes = get_db_rows($dbh, 'SELECT *
|
my @downtimes = get_db_rows($dbh, 'SELECT *
|
||||||
FROM tplanned_downtime
|
FROM tplanned_downtime
|
||||||
WHERE type_downtime = "quiet" AND type_execution="once"
|
WHERE type_downtime = ' . $RDBMS_QUOTE_STRING . 'quiet' . $RDBMS_QUOTE_STRING . '
|
||||||
|
AND type_execution = ' . $RDBMS_QUOTE_STRING . 'once' . $RDBMS_QUOTE_STRING . '
|
||||||
AND executed = 0 AND date_from <= ?
|
AND executed = 0 AND date_from <= ?
|
||||||
AND date_to >= ?', $utimestamp, $utimestamp);
|
AND date_to >= ?', $utimestamp, $utimestamp);
|
||||||
|
|
||||||
@ -1525,7 +1530,7 @@ sub pandora_planned_downtime_monthly_start($$) {
|
|||||||
# Start pending downtimes
|
# Start pending downtimes
|
||||||
my @downtimes = get_db_rows($dbh, 'SELECT *
|
my @downtimes = get_db_rows($dbh, 'SELECT *
|
||||||
FROM tplanned_downtime
|
FROM tplanned_downtime
|
||||||
WHERE type_periodicity="monthly"
|
WHERE type_periodicity = ' . $RDBMS_QUOTE_STRING . 'monthly' . $RDBMS_QUOTE_STRING . '
|
||||||
AND executed = 0
|
AND executed = 0
|
||||||
AND periodically_day_from <= ?
|
AND periodically_day_from <= ?
|
||||||
AND periodically_day_to >= ?',
|
AND periodically_day_to >= ?',
|
||||||
@ -1627,9 +1632,9 @@ sub pandora_planned_downtime_monthly_stop($$) {
|
|||||||
# Start pending downtimes
|
# Start pending downtimes
|
||||||
my @downtimes = get_db_rows($dbh, 'SELECT *
|
my @downtimes = get_db_rows($dbh, 'SELECT *
|
||||||
FROM tplanned_downtime
|
FROM tplanned_downtime
|
||||||
WHERE type_periodicity = "monthly"
|
WHERE type_periodicity = ' . $RDBMS_QUOTE_STRING . 'monthly' . $RDBMS_QUOTE_STRING . '
|
||||||
AND executed = 1
|
AND executed = 1
|
||||||
AND type_execution <> "once"');
|
AND type_execution <> ' . $RDBMS_QUOTE_STRING . 'once' . $RDBMS_QUOTE_STRING);
|
||||||
|
|
||||||
foreach my $downtime (@downtimes) {
|
foreach my $downtime (@downtimes) {
|
||||||
#Convert to identical type.
|
#Convert to identical type.
|
||||||
@ -1703,18 +1708,18 @@ sub pandora_planned_downtime_weekly_start($$) {
|
|||||||
# Start pending downtimes
|
# Start pending downtimes
|
||||||
my @downtimes = get_db_rows($dbh, 'SELECT *
|
my @downtimes = get_db_rows($dbh, 'SELECT *
|
||||||
FROM tplanned_downtime
|
FROM tplanned_downtime
|
||||||
WHERE type_periodicity="weekly"
|
WHERE type_periodicity = ' . $RDBMS_QUOTE_STRING . 'weekly' . $RDBMS_QUOTE_STRING . '
|
||||||
AND executed = 0');
|
AND executed = 0');
|
||||||
|
|
||||||
foreach my $downtime (@downtimes) {
|
foreach my $downtime (@downtimes) {
|
||||||
my $across_date = $downtime->{'periodically_time_from'} gt $downtime->{'periodically_time_to'} ? 1 : 0 ;
|
my $across_date = $downtime->{'periodically_time_from'} gt $downtime->{'periodically_time_to'} ? 1 : 0 ;
|
||||||
$found = 0;
|
$found = 0;
|
||||||
|
|
||||||
if ($across_date && ($time lt $downtime->{'periodically_time_to'})) {
|
if ($across_date && ($time lt $downtime->{'periodically_time_to'})) {
|
||||||
$number_day_week--;
|
$number_day_week--;
|
||||||
$number_day_week = 6 if ($number_day_week == -1);
|
$number_day_week = 6 if ($number_day_week == -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($number_day_week == 1) &&
|
if (($number_day_week == 1) &&
|
||||||
($downtime->{'monday'})) {
|
($downtime->{'monday'})) {
|
||||||
$found = 1;
|
$found = 1;
|
||||||
@ -1825,8 +1830,8 @@ sub pandora_planned_downtime_weekly_stop($$) {
|
|||||||
# Start pending downtimes
|
# Start pending downtimes
|
||||||
my @downtimes = get_db_rows($dbh, 'SELECT *
|
my @downtimes = get_db_rows($dbh, 'SELECT *
|
||||||
FROM tplanned_downtime
|
FROM tplanned_downtime
|
||||||
WHERE type_periodicity = "weekly"
|
WHERE type_periodicity = ' . $RDBMS_QUOTE_STRING . 'weekly' . $RDBMS_QUOTE_STRING . '
|
||||||
AND type_execution <> "once"
|
AND type_execution <> ' . $RDBMS_QUOTE_STRING . 'once' . $RDBMS_QUOTE_STRING . '
|
||||||
AND executed = 1');
|
AND executed = 1');
|
||||||
|
|
||||||
foreach my $downtime (@downtimes) {
|
foreach my $downtime (@downtimes) {
|
||||||
@ -2145,7 +2150,7 @@ sub pandora_update_gis_data ($$$$$$$$$) {
|
|||||||
Create a template module.
|
Create a template module.
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
##########################################################################
|
########################################################################
|
||||||
sub pandora_create_template_module ($$$$;$$$) {
|
sub pandora_create_template_module ($$$$;$$$) {
|
||||||
my ($pa_config, $dbh, $id_agent_module, $id_alert_template, $id_policy_alerts, $disabled, $standby) = @_;
|
my ($pa_config, $dbh, $id_agent_module, $id_alert_template, $id_policy_alerts, $disabled, $standby) = @_;
|
||||||
|
|
||||||
@ -2154,16 +2159,27 @@ sub pandora_create_template_module ($$$$;$$$) {
|
|||||||
$standby = 0 unless defined $standby;
|
$standby = 0 unless defined $standby;
|
||||||
|
|
||||||
my $module_name = get_module_name($dbh, $id_agent_module);
|
my $module_name = get_module_name($dbh, $id_agent_module);
|
||||||
return db_insert ($dbh, 'id', "INSERT INTO talert_template_modules (`id_agent_module`, `id_alert_template`, `id_policy_alerts`, `disabled`, `standby`, `last_reference`) VALUES (?, ?, ?, ?, ?, ?)", $id_agent_module, $id_alert_template, $id_policy_alerts, $disabled, $standby, time);
|
|
||||||
|
return db_insert ($dbh,
|
||||||
|
'id',
|
||||||
|
"INSERT INTO talert_template_modules(
|
||||||
|
" . $RDBMS_QUOTE . "id_agent_module" . $RDBMS_QUOTE . ",
|
||||||
|
" . $RDBMS_QUOTE . "id_alert_template" . $RDBMS_QUOTE . ",
|
||||||
|
" . $RDBMS_QUOTE . "id_policy_alerts" . $RDBMS_QUOTE . ",
|
||||||
|
" . $RDBMS_QUOTE . "disabled" . $RDBMS_QUOTE . ",
|
||||||
|
" . $RDBMS_QUOTE . "standby" . $RDBMS_QUOTE . ",
|
||||||
|
" . $RDBMS_QUOTE . "last_reference" . $RDBMS_QUOTE . ")
|
||||||
|
VALUES (?, ?, ?, ?, ?, ?)",
|
||||||
|
$id_agent_module, $id_alert_template, $id_policy_alerts, $disabled, $standby, time);
|
||||||
}
|
}
|
||||||
|
|
||||||
##########################################################################
|
########################################################################
|
||||||
=head2 C<< pandora_update_template_module(I<$pa_config>, I<$dbh>, I<$id_alert>, I<$id_policy_alerts>, I<$disabled>, I<$standby>) >>
|
=head2 C<< pandora_update_template_module(I<$pa_config>, I<$dbh>, I<$id_alert>, I<$id_policy_alerts>, I<$disabled>, I<$standby>) >>
|
||||||
|
|
||||||
Update a template module.
|
Update a template module.
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
##########################################################################
|
########################################################################
|
||||||
|
|
||||||
sub pandora_update_template_module ($$$;$$$) {
|
sub pandora_update_template_module ($$$;$$$) {
|
||||||
my ($pa_config, $dbh, $id_alert, $id_policy_alerts, $disabled, $standby) = @_;
|
my ($pa_config, $dbh, $id_alert, $id_policy_alerts, $disabled, $standby) = @_;
|
||||||
@ -2172,16 +2188,22 @@ sub pandora_update_template_module ($$$;$$$) {
|
|||||||
$disabled = 0 unless defined $disabled;
|
$disabled = 0 unless defined $disabled;
|
||||||
$standby = 0 unless defined $standby;
|
$standby = 0 unless defined $standby;
|
||||||
|
|
||||||
db_do ($dbh, "UPDATE talert_template_modules SET `id_policy_alerts` = ?, `disabled` = ?, `standby` = ? WHERE id = ?", $id_policy_alerts, $disabled, $standby, $id_alert);
|
db_do ($dbh,
|
||||||
|
"UPDATE talert_template_modules
|
||||||
|
SET " . $RDBMS_QUOTE . "id_policy_alerts" . $RDBMS_QUOTE . " = ?,
|
||||||
|
" . $RDBMS_QUOTE . "disabled" . $RDBMS_QUOTE . " = ?,
|
||||||
|
" . $RDBMS_QUOTE . "standby" . $RDBMS_QUOTE . " = ?
|
||||||
|
WHERE id = ?",
|
||||||
|
$id_policy_alerts, $disabled, $standby, $id_alert);
|
||||||
}
|
}
|
||||||
|
|
||||||
##########################################################################
|
########################################################################
|
||||||
=head2 C<< pandora_create_template_module_action(I<$pa_config>, I<$parameters>, I<$dbh>) >>
|
=head2 C<< pandora_create_template_module_action(I<$pa_config>, I<$parameters>, I<$dbh>) >>
|
||||||
|
|
||||||
Create a template action.
|
Create a template action.
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
##########################################################################
|
########################################################################
|
||||||
sub pandora_create_template_module_action ($$$) {
|
sub pandora_create_template_module_action ($$$) {
|
||||||
my ($pa_config, $parameters, $dbh) = @_;
|
my ($pa_config, $parameters, $dbh) = @_;
|
||||||
|
|
||||||
@ -2192,26 +2214,26 @@ sub pandora_create_template_module_action ($$$) {
|
|||||||
return $action_id;
|
return $action_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
##########################################################################
|
########################################################################
|
||||||
=head2 C<< pandora_delete_all_template_module_actions(I<$dbh>, I<$template_module_id>) >>
|
=head2 C<< pandora_delete_all_template_module_actions(I<$dbh>, I<$template_module_id>) >>
|
||||||
|
|
||||||
Delete all actions of policy template module.
|
Delete all actions of policy template module.
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
##########################################################################
|
########################################################################
|
||||||
sub pandora_delete_all_template_module_actions ($$) {
|
sub pandora_delete_all_template_module_actions ($$) {
|
||||||
my ($dbh, $template_module_id) = @_;
|
my ($dbh, $template_module_id) = @_;
|
||||||
|
|
||||||
return db_do ($dbh, 'DELETE FROM talert_template_module_actions WHERE id_alert_template_module = ?', $template_module_id);
|
return db_do ($dbh, 'DELETE FROM talert_template_module_actions WHERE id_alert_template_module = ?', $template_module_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
##########################################################################
|
########################################################################
|
||||||
=head2 C<< pandora_update_agent_address(I<$pa_config>, I<$agent_id>, I<$address>, I<$dbh>) >>
|
=head2 C<< pandora_update_agent_address(I<$pa_config>, I<$agent_id>, I<$address>, I<$dbh>) >>
|
||||||
|
|
||||||
Update the address of an agent.
|
Update the address of an agent.
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
##########################################################################
|
########################################################################
|
||||||
sub pandora_update_agent_address ($$$$$) {
|
sub pandora_update_agent_address ($$$$$) {
|
||||||
my ($pa_config, $agent_id, $agent_name, $address, $dbh) = @_;
|
my ($pa_config, $agent_id, $agent_name, $address, $dbh) = @_;
|
||||||
|
|
||||||
@ -2306,9 +2328,13 @@ sub pandora_create_module ($$$$$$$$$$) {
|
|||||||
$status = 0;
|
$status = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $module_id = db_insert($dbh, 'id_agente_modulo', 'INSERT INTO tagente_modulo (id_agente, id_tipo_modulo, nombre, max, min, post_process, descripcion, module_interval, id_modulo)
|
my $module_id = db_insert($dbh, 'id_agente_modulo',
|
||||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, 1)', $agent_id, $module_type_id, safe_input($module_name), $max, $min, $post_process, $description, $interval);
|
'INSERT INTO tagente_modulo (id_agente, id_tipo_modulo, nombre, max, min, post_process, descripcion, module_interval, id_modulo)
|
||||||
db_do ($dbh, 'INSERT INTO tagente_estado (id_agente_modulo, id_agente, estado, last_status, last_known_status, last_try) VALUES (?, ?, ?, ?, ?, \'1970-01-01 00:00:00\')', $module_id, $agent_id, $status, $status, $status);
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, 1)',
|
||||||
|
$agent_id, $module_type_id, safe_input($module_name), $max, $min, $post_process, $description, $interval);
|
||||||
|
db_do ($dbh, 'INSERT INTO tagente_estado (id_agente_modulo, id_agente, estado, last_status, last_known_status, last_try)
|
||||||
|
VALUES (?, ?, ?, ?, ?, \'1970-01-01 00:00:00\')',
|
||||||
|
$module_id, $agent_id, $status, $status, $status);
|
||||||
|
|
||||||
# Update the module status count. When the module is created disabled dont do it
|
# Update the module status count. When the module is created disabled dont do it
|
||||||
pandora_mark_agent_for_module_update ($dbh, $agent_id);
|
pandora_mark_agent_for_module_update ($dbh, $agent_id);
|
||||||
@ -2514,8 +2540,16 @@ sub pandora_create_module_tags ($$$$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach my $tag_name (split (',', $serialized_tags)) {
|
foreach my $tag_name (split (',', $serialized_tags)) {
|
||||||
my $tag_id = get_db_value ($dbh, "SELECT id_tag FROM ttag WHERE name = ?", $tag_name);
|
my $tag_id = get_db_value ($dbh,
|
||||||
db_insert ($dbh, 'id_tag', "INSERT INTO ttag_module (`id_tag`, `id_agente_modulo`) VALUES (?, ?)", $tag_id, $id_agent_module);
|
"SELECT id_tag FROM ttag WHERE name = ?", $tag_name);
|
||||||
|
|
||||||
|
db_insert ($dbh,
|
||||||
|
'id_tag',
|
||||||
|
"INSERT INTO ttag_module(
|
||||||
|
" . $RDBMS_QUOTE . "id_tag" . $RDBMS_QUOTE . ",
|
||||||
|
" . $RDBMS_QUOTE . "id_agente_modulo" . $RDBMS_QUOTE . ")
|
||||||
|
VALUES (?, ?)",
|
||||||
|
$tag_id, $id_agent_module);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3987,33 +4021,46 @@ sub pandora_self_monitoring ($$) {
|
|||||||
AND estado = 3");
|
AND estado = 3");
|
||||||
$agents_unknown = 0 if (!defined($agents_unknown));
|
$agents_unknown = 0 if (!defined($agents_unknown));
|
||||||
}
|
}
|
||||||
|
|
||||||
my $queued_modules = get_db_value ($dbh, "SELECT SUM(queued_modules) FROM tserver WHERE name = '".$pa_config->{"servername"}."'");
|
my $queued_modules = get_db_value ($dbh, "SELECT SUM(queued_modules) FROM tserver WHERE name = '".$pa_config->{"servername"}."'");
|
||||||
|
|
||||||
if (!defined($queued_modules)){
|
if (!defined($queued_modules)) {
|
||||||
$queued_modules = 0;
|
$queued_modules = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $dbmaintance = get_db_value ($dbh, "SELECT COUNT(*) FROM tconfig WHERE token = 'db_maintance' AND value > UNIX_TIMESTAMP() - 86400");
|
my $dbmaintance;
|
||||||
|
if ($RDBMS eq 'postgresql') {
|
||||||
|
$dbmaintance = get_db_value ($dbh,
|
||||||
|
"SELECT COUNT(*)
|
||||||
|
FROM tconfig
|
||||||
|
WHERE token = 'db_maintance'
|
||||||
|
AND NULLIF(value, '')::int > UNIX_TIMESTAMP() - 86400");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$dbmaintance = get_db_value ($dbh,
|
||||||
|
"SELECT COUNT(*)
|
||||||
|
FROM tconfig
|
||||||
|
WHERE token = 'db_maintance' AND value > UNIX_TIMESTAMP() - 86400");
|
||||||
|
}
|
||||||
|
|
||||||
$xml_output .=" <module>";
|
$xml_output .=" <module>";
|
||||||
$xml_output .=" <name>Database Maintenance</name>";
|
$xml_output .=" <name>Database Maintenance</name>";
|
||||||
$xml_output .=" <type>generic_proc</type>";
|
$xml_output .=" <type>generic_proc</type>";
|
||||||
$xml_output .=" <data>$dbmaintance</data>";
|
$xml_output .=" <data>$dbmaintance</data>";
|
||||||
$xml_output .=" </module>";
|
$xml_output .=" </module>";
|
||||||
|
|
||||||
$xml_output .=" <module>";
|
$xml_output .=" <module>";
|
||||||
$xml_output .=" <name>Queued_Modules</name>";
|
$xml_output .=" <name>Queued_Modules</name>";
|
||||||
$xml_output .=" <type>generic_data</type>";
|
$xml_output .=" <type>generic_data</type>";
|
||||||
$xml_output .=" <data>$queued_modules</data>";
|
$xml_output .=" <data>$queued_modules</data>";
|
||||||
$xml_output .=" </module>";
|
$xml_output .=" </module>";
|
||||||
|
|
||||||
$xml_output .=" <module>";
|
$xml_output .=" <module>";
|
||||||
$xml_output .=" <name>Agents_Unknown</name>";
|
$xml_output .=" <name>Agents_Unknown</name>";
|
||||||
$xml_output .=" <type>generic_data</type>";
|
$xml_output .=" <type>generic_data</type>";
|
||||||
$xml_output .=" <data>$agents_unknown</data>";
|
$xml_output .=" <data>$agents_unknown</data>";
|
||||||
$xml_output .=" </module>";
|
$xml_output .=" </module>";
|
||||||
|
|
||||||
$xml_output .=" <module>";
|
$xml_output .=" <module>";
|
||||||
$xml_output .=" <name>System_Load_AVG</name>";
|
$xml_output .=" <name>System_Load_AVG</name>";
|
||||||
$xml_output .=" <type>generic_data</type>";
|
$xml_output .=" <type>generic_data</type>";
|
||||||
|
@ -86,14 +86,18 @@ our @EXPORT = qw(
|
|||||||
get_agentmodule_data
|
get_agentmodule_data
|
||||||
$RDBMS
|
$RDBMS
|
||||||
$RDBMS_QUOTE
|
$RDBMS_QUOTE
|
||||||
|
$RDBMS_QUOTE_STRING
|
||||||
);
|
);
|
||||||
|
|
||||||
# Relational database management system in use
|
# Relational database management system in use
|
||||||
our $RDBMS = '';
|
our $RDBMS = '';
|
||||||
|
|
||||||
# Character used to quote reserved words in the current RDBMS
|
# For fields, character used to quote reserved words in the current RDBMS
|
||||||
our $RDBMS_QUOTE = '';
|
our $RDBMS_QUOTE = '';
|
||||||
|
|
||||||
|
# For strings, Character used to quote in the current RDBMS
|
||||||
|
our $RDBMS_QUOTE_STRING = '';
|
||||||
|
|
||||||
##########################################################################
|
##########################################################################
|
||||||
## Connect to the DB.
|
## Connect to the DB.
|
||||||
##########################################################################
|
##########################################################################
|
||||||
@ -103,7 +107,8 @@ sub db_connect ($$$$$$) {
|
|||||||
if ($rdbms eq 'mysql') {
|
if ($rdbms eq 'mysql') {
|
||||||
$RDBMS = 'mysql';
|
$RDBMS = 'mysql';
|
||||||
$RDBMS_QUOTE = '`';
|
$RDBMS_QUOTE = '`';
|
||||||
|
$RDBMS_QUOTE_STRING = '"';
|
||||||
|
|
||||||
# Connect to MySQL
|
# Connect to MySQL
|
||||||
my $dbh = DBI->connect("DBI:mysql:$db_name:$db_host:$db_port", $db_user, $db_pass, { RaiseError => 1, AutoCommit => 1 });
|
my $dbh = DBI->connect("DBI:mysql:$db_name:$db_host:$db_port", $db_user, $db_pass, { RaiseError => 1, AutoCommit => 1 });
|
||||||
return undef unless defined ($dbh);
|
return undef unless defined ($dbh);
|
||||||
@ -119,15 +124,18 @@ sub db_connect ($$$$$$) {
|
|||||||
elsif ($rdbms eq 'postgresql') {
|
elsif ($rdbms eq 'postgresql') {
|
||||||
$RDBMS = 'postgresql';
|
$RDBMS = 'postgresql';
|
||||||
$RDBMS_QUOTE = '"';
|
$RDBMS_QUOTE = '"';
|
||||||
|
$RDBMS_QUOTE_STRING = "'";
|
||||||
|
|
||||||
# Connect to PostgreSQL
|
# Connect to PostgreSQL
|
||||||
my $dbh = DBI->connect("DBI:Pg:dbname=$db_name;host=$db_host;port=$db_port", $db_user, $db_pass, { RaiseError => 1, AutoCommit => 1 });
|
my $dbh = DBI->connect("DBI:Pg:dbname=$db_name;host=$db_host;port=$db_port", $db_user, $db_pass, { RaiseError => 1, AutoCommit => 1 });
|
||||||
return undef unless defined ($dbh);
|
return undef unless defined ($dbh);
|
||||||
|
|
||||||
return $dbh;
|
return $dbh;
|
||||||
} elsif ($rdbms eq 'oracle') {
|
}
|
||||||
|
elsif ($rdbms eq 'oracle') {
|
||||||
$RDBMS = 'oracle';
|
$RDBMS = 'oracle';
|
||||||
$RDBMS_QUOTE = '"';
|
$RDBMS_QUOTE = '"';
|
||||||
|
$RDBMS_QUOTE_STRING = '"';
|
||||||
|
|
||||||
# Connect to Oracle
|
# Connect to Oracle
|
||||||
my $dbh = DBI->connect("DBI:Oracle:dbname=$db_name;host=$db_host;port=$db_port;sid=pandora", $db_user, $db_pass, { RaiseError => 1, AutoCommit => 1 });
|
my $dbh = DBI->connect("DBI:Oracle:dbname=$db_name;host=$db_host;port=$db_port;sid=pandora", $db_user, $db_pass, { RaiseError => 1, AutoCommit => 1 });
|
||||||
@ -641,6 +649,7 @@ sub db_insert ($$$;@) {
|
|||||||
my ($dbh, $index, $query, @values) = @_;
|
my ($dbh, $index, $query, @values) = @_;
|
||||||
my $insert_id = undef;
|
my $insert_id = undef;
|
||||||
|
|
||||||
|
|
||||||
# MySQL
|
# MySQL
|
||||||
if ($RDBMS eq 'mysql') {
|
if ($RDBMS eq 'mysql') {
|
||||||
$dbh->do($query, undef, @values);
|
$dbh->do($query, undef, @values);
|
||||||
@ -684,9 +693,9 @@ sub get_alert_template_module_id ($$$) {
|
|||||||
return defined ($rc) ? $rc : -1;
|
return defined ($rc) ? $rc : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
##########################################################################
|
########################################################################
|
||||||
## SQL insert. Returns the ID of the inserted row.
|
## SQL insert. Returns the ID of the inserted row.
|
||||||
##########################################################################
|
########################################################################
|
||||||
sub db_process_insert($$$$;@) {
|
sub db_process_insert($$$$;@) {
|
||||||
my ($dbh, $index, $table, $parameters, @values) = @_;
|
my ($dbh, $index, $table, $parameters, @values) = @_;
|
||||||
|
|
||||||
@ -711,9 +720,13 @@ sub db_process_insert($$$$;@) {
|
|||||||
}
|
}
|
||||||
$wildcards = '('.$wildcards.')';
|
$wildcards = '('.$wildcards.')';
|
||||||
|
|
||||||
my $columns_string = join('`,`',@columns_array);
|
my $columns_string = join($RDBMS_QUOTE . ',' . $RDBMS_QUOTE,
|
||||||
|
@columns_array);
|
||||||
|
|
||||||
|
my $res = db_insert ($dbh,
|
||||||
|
$index,
|
||||||
|
"INSERT INTO $table (" . $RDBMS_QUOTE . $columns_string . $RDBMS_QUOTE . ") VALUES " . $wildcards, @values_array);
|
||||||
|
|
||||||
my $res = db_insert ($dbh, $index, "INSERT INTO $table (`".$columns_string."`) VALUES ".$wildcards, @values_array);
|
|
||||||
|
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
@ -740,7 +753,8 @@ sub db_process_update($$$$$;@) {
|
|||||||
if ($i > 0 && $i <= $#values_array) {
|
if ($i > 0 && $i <= $#values_array) {
|
||||||
$fields = $fields.',';
|
$fields = $fields.',';
|
||||||
}
|
}
|
||||||
$fields = $fields." `$columns_array[$i]` = ?";
|
$fields = $fields .
|
||||||
|
" " . $RDBMS_QUOTE . "$columns_array[$i]" . $RDBMS_QUOTE . " = ?";
|
||||||
}
|
}
|
||||||
|
|
||||||
push(@values_array, $where_value);
|
push(@values_array, $where_value);
|
||||||
@ -752,28 +766,30 @@ sub db_process_update($$$$$;@) {
|
|||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
##########################################################################
|
########################################################################
|
||||||
# Add the given address to taddress.
|
# Add the given address to taddress.
|
||||||
##########################################################################
|
########################################################################
|
||||||
sub add_address ($$) {
|
sub add_address ($$) {
|
||||||
my ($dbh, $ip_address) = @_;
|
my ($dbh, $ip_address) = @_;
|
||||||
|
|
||||||
return db_insert ($dbh, 'id_a', 'INSERT INTO taddress (ip) VALUES (?)', $ip_address);
|
return db_insert ($dbh, 'id_a', 'INSERT INTO taddress (ip) VALUES (?)', $ip_address);
|
||||||
}
|
}
|
||||||
|
|
||||||
##########################################################################
|
########################################################################
|
||||||
# Assign the new address to the agent
|
# Assign the new address to the agent
|
||||||
##########################################################################
|
########################################################################
|
||||||
sub add_new_address_agent ($$$) {
|
sub add_new_address_agent ($$$) {
|
||||||
my ($dbh, $addr_id, $agent_id) = @_;
|
my ($dbh, $addr_id, $agent_id) = @_;
|
||||||
|
|
||||||
db_do ($dbh, 'INSERT INTO taddress_agent (`id_a`, `id_agent`)
|
db_do ($dbh, 'INSERT INTO taddress_agent (' .
|
||||||
|
$RDBMS_QUOTE . 'id_a' . $RDBMS_QUOTE . ', ' .
|
||||||
|
$RDBMS_QUOTE. 'id_agent' . $RDBMS_QUOTE. ')
|
||||||
VALUES (?, ?)', $addr_id, $agent_id);
|
VALUES (?, ?)', $addr_id, $agent_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
##########################################################################
|
########################################################################
|
||||||
# Return the ID of the given address, -1 if it does not exist.
|
# Return the ID of the given address, -1 if it does not exist.
|
||||||
##########################################################################
|
########################################################################
|
||||||
sub get_addr_id ($$) {
|
sub get_addr_id ($$) {
|
||||||
my ($dbh, $addr) = @_;
|
my ($dbh, $addr) = @_;
|
||||||
|
|
||||||
@ -825,9 +841,9 @@ sub is_agent_address ($$$) {
|
|||||||
return (defined ($id_ag)) ? $id_ag : 0;
|
return (defined ($id_ag)) ? $id_ag : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
##########################################################################
|
########################################################################
|
||||||
## Quote the given string.
|
## Quote the given string.
|
||||||
##########################################################################
|
########################################################################
|
||||||
sub db_string ($) {
|
sub db_string ($) {
|
||||||
my $string = shift;
|
my $string = shift;
|
||||||
|
|
||||||
@ -856,7 +872,10 @@ sub db_text ($) {
|
|||||||
sub get_alert_template_name ($$) {
|
sub get_alert_template_name ($$) {
|
||||||
my ($dbh, $alert_id) = @_;
|
my ($dbh, $alert_id) = @_;
|
||||||
|
|
||||||
return get_db_value ($dbh, "SELECT name FROM talert_templates, talert_template_modules WHERE talert_templates.id = talert_template_modules.id_alert_template AND talert_template_modules.id = ?", $alert_id);
|
return get_db_value ($dbh, "SELECT name
|
||||||
|
FROM talert_templates, talert_template_modules
|
||||||
|
WHERE talert_templates.id = talert_template_modules.id_alert_template
|
||||||
|
AND talert_template_modules.id = ?", $alert_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
########################################################################
|
########################################################################
|
||||||
@ -906,18 +925,18 @@ sub get_priority_name ($) {
|
|||||||
########################################################################
|
########################################################################
|
||||||
sub db_update_get_values ($) {
|
sub db_update_get_values ($) {
|
||||||
my ($set_ref) = @_;
|
my ($set_ref) = @_;
|
||||||
|
|
||||||
my $set = '';
|
my $set = '';
|
||||||
my @values;
|
my @values;
|
||||||
while (my ($key, $value) = each (%{$set_ref})) {
|
while (my ($key, $value) = each (%{$set_ref})) {
|
||||||
|
|
||||||
# Not value for the given column
|
# Not value for the given column
|
||||||
next if (! defined ($value));
|
next if (! defined ($value));
|
||||||
|
|
||||||
$set .= "$key = ?,";
|
$set .= "$key = ?,";
|
||||||
push (@values, $value);
|
push (@values, $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
# Remove the last ,
|
# Remove the last ,
|
||||||
chop ($set);
|
chop ($set);
|
||||||
|
|
||||||
@ -929,34 +948,34 @@ sub db_update_get_values ($) {
|
|||||||
########################################################################
|
########################################################################
|
||||||
sub db_insert_get_values ($) {
|
sub db_insert_get_values ($) {
|
||||||
my ($insert_ref) = @_;
|
my ($insert_ref) = @_;
|
||||||
|
|
||||||
my $columns = '(';
|
my $columns = '(';
|
||||||
my @values;
|
my @values;
|
||||||
while (my ($key, $value) = each (%{$insert_ref})) {
|
while (my ($key, $value) = each (%{$insert_ref})) {
|
||||||
|
|
||||||
# Not value for the given column
|
# Not value for the given column
|
||||||
next if (! defined ($value));
|
next if (! defined ($value));
|
||||||
|
|
||||||
$columns .= $PandoraFMS::DB::RDBMS_QUOTE . "$key" . $PandoraFMS::DB::RDBMS_QUOTE . ",";
|
$columns .= $PandoraFMS::DB::RDBMS_QUOTE . "$key" . $PandoraFMS::DB::RDBMS_QUOTE . ",";
|
||||||
push (@values, $value);
|
push (@values, $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
# Remove the last , and close the parentheses
|
# Remove the last , and close the parentheses
|
||||||
chop ($columns);
|
chop ($columns);
|
||||||
$columns .= ')';
|
$columns .= ')';
|
||||||
|
|
||||||
# No columns
|
# No columns
|
||||||
if ($columns eq '()') {
|
if ($columns eq '()') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Add placeholders for the values
|
# Add placeholders for the values
|
||||||
$columns .= ' VALUES (' . ("?," x ($#values + 1));
|
$columns .= ' VALUES (' . ("?," x ($#values + 1));
|
||||||
|
|
||||||
# Remove the last , and close the parentheses
|
# Remove the last , and close the parentheses
|
||||||
chop ($columns);
|
chop ($columns);
|
||||||
$columns .= ')';
|
$columns .= ')';
|
||||||
|
|
||||||
return ($columns, \@values);
|
return ($columns, \@values);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -973,7 +992,7 @@ sub db_get_lock($$;$) {
|
|||||||
my $sth = $dbh->prepare('SELECT GET_LOCK(?, ?)');
|
my $sth = $dbh->prepare('SELECT GET_LOCK(?, ?)');
|
||||||
$sth->execute($lock_name, $lock_timeout);
|
$sth->execute($lock_name, $lock_timeout);
|
||||||
my ($lock) = $sth->fetchrow;
|
my ($lock) = $sth->fetchrow;
|
||||||
|
|
||||||
# Something went wrong
|
# Something went wrong
|
||||||
return 0 if (! defined ($lock));
|
return 0 if (! defined ($lock));
|
||||||
|
|
||||||
|
@ -528,7 +528,7 @@ sub process_module_data ($$$$$$$$$) {
|
|||||||
'str_warning' => '', 'str_critical' => '', 'critical_instructions' => '', 'warning_instructions' => '',
|
'str_warning' => '', 'str_critical' => '', 'critical_instructions' => '', 'warning_instructions' => '',
|
||||||
'unknown_instructions' => '', 'tags' => '', 'critical_inverse' => 0, 'warning_inverse' => 0, 'quiet' => 0,
|
'unknown_instructions' => '', 'tags' => '', 'critical_inverse' => 0, 'warning_inverse' => 0, 'quiet' => 0,
|
||||||
'module_ff_interval' => 0};
|
'module_ff_interval' => 0};
|
||||||
|
|
||||||
# Other tags will be saved here
|
# Other tags will be saved here
|
||||||
$module_conf->{'extended_info'} = '';
|
$module_conf->{'extended_info'} = '';
|
||||||
|
|
||||||
@ -539,8 +539,8 @@ sub process_module_data ($$$$$$$$$) {
|
|||||||
} else {
|
} else {
|
||||||
$module_conf->{'extended_info'} .= "$tag: " . get_tag_value ($data, $tag, '') . '<br/>';
|
$module_conf->{'extended_info'} .= "$tag: " . get_tag_value ($data, $tag, '') . '<br/>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Description XML tag and column name don't match
|
# Description XML tag and column name don't match
|
||||||
$module_conf->{'descripcion'} = $module_conf->{'description'};
|
$module_conf->{'descripcion'} = $module_conf->{'description'};
|
||||||
$module_conf->{'descripcion'} = '' unless defined ($module_conf->{'descripcion'});
|
$module_conf->{'descripcion'} = '' unless defined ($module_conf->{'descripcion'});
|
||||||
@ -549,14 +549,14 @@ sub process_module_data ($$$$$$$$$) {
|
|||||||
# Name XML tag and column name don't match
|
# Name XML tag and column name don't match
|
||||||
$module_conf->{'nombre'} = safe_input($module_name);
|
$module_conf->{'nombre'} = safe_input($module_name);
|
||||||
delete $module_conf->{'name'};
|
delete $module_conf->{'name'};
|
||||||
|
|
||||||
# Calculate the module interval in seconds
|
# Calculate the module interval in seconds
|
||||||
$module_conf->{'module_interval'} = 1 unless defined ($module_conf->{'module_interval'});
|
$module_conf->{'module_interval'} = 1 unless defined ($module_conf->{'module_interval'});
|
||||||
$module_conf->{'module_interval'} *= $interval if (defined ($module_conf->{'module_interval'}));
|
$module_conf->{'module_interval'} *= $interval if (defined ($module_conf->{'module_interval'}));
|
||||||
|
|
||||||
# Allow , as a decimal separator
|
# Allow , as a decimal separator
|
||||||
$module_conf->{'post_process'} =~ s/,/./ if (defined ($module_conf->{'post_process'}));
|
$module_conf->{'post_process'} =~ s/,/./ if (defined ($module_conf->{'post_process'}));
|
||||||
|
|
||||||
# Get module data or create it if it does not exist
|
# Get module data or create it if it does not exist
|
||||||
$ModuleSem->down ();
|
$ModuleSem->down ();
|
||||||
my $module = get_db_single_row ($dbh, 'SELECT * FROM tagente_modulo WHERE id_agente = ? AND ' . db_text ('nombre') . ' = ?', $agent->{'id_agente'}, safe_input($module_name));
|
my $module = get_db_single_row ($dbh, 'SELECT * FROM tagente_modulo WHERE id_agente = ? AND ' . db_text ('nombre') . ' = ?', $agent->{'id_agente'}, safe_input($module_name));
|
||||||
@ -568,14 +568,14 @@ sub process_module_data ($$$$$$$$$) {
|
|||||||
$ModuleSem->up ();
|
$ModuleSem->up ();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Is the agent learning?
|
# Is the agent learning?
|
||||||
if ($agent->{'modo'} ne '1') {
|
if ($agent->{'modo'} ne '1') {
|
||||||
logger($pa_config, "Learning mode disabled. Skipping module '$module_name' agent '$agent_name'.", 10);
|
logger($pa_config, "Learning mode disabled. Skipping module '$module_name' agent '$agent_name'.", 10);
|
||||||
$ModuleSem->up ();
|
$ModuleSem->up ();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Get the module type
|
# Get the module type
|
||||||
$module_conf->{'id_tipo_modulo'} = get_module_id ($dbh, $module_type);
|
$module_conf->{'id_tipo_modulo'} = get_module_id ($dbh, $module_type);
|
||||||
if ($module_conf->{'id_tipo_modulo'} <= 0) {
|
if ($module_conf->{'id_tipo_modulo'} <= 0) {
|
||||||
@ -583,16 +583,16 @@ sub process_module_data ($$$$$$$$$) {
|
|||||||
$ModuleSem->up ();
|
$ModuleSem->up ();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
# The group name has to be translated to a group ID
|
# The group name has to be translated to a group ID
|
||||||
if (defined $module_conf->{'module_group'}) {
|
if (defined $module_conf->{'module_group'}) {
|
||||||
$module_conf->{'id_module_group'} = get_module_group_id ($dbh, $module_conf->{'module_group'});
|
$module_conf->{'id_module_group'} = get_module_group_id ($dbh, $module_conf->{'module_group'});
|
||||||
delete $module_conf->{'module_group'};
|
delete $module_conf->{'module_group'};
|
||||||
}
|
}
|
||||||
|
|
||||||
$module_conf->{'id_modulo'} = 1;
|
$module_conf->{'id_modulo'} = 1;
|
||||||
$module_conf->{'id_agente'} = $agent->{'id_agente'};
|
$module_conf->{'id_agente'} = $agent->{'id_agente'};
|
||||||
|
|
||||||
my $module_tags = undef;
|
my $module_tags = undef;
|
||||||
if(defined ($module_conf->{'tags'})) {
|
if(defined ($module_conf->{'tags'})) {
|
||||||
$module_tags = $module_conf->{'tags'};
|
$module_tags = $module_conf->{'tags'};
|
||||||
@ -601,7 +601,7 @@ sub process_module_data ($$$$$$$$$) {
|
|||||||
|
|
||||||
# Create the module
|
# Create the module
|
||||||
my $module_id = pandora_create_module_from_hash ($pa_config, $module_conf, $dbh);
|
my $module_id = pandora_create_module_from_hash ($pa_config, $module_conf, $dbh);
|
||||||
|
|
||||||
$module = get_db_single_row ($dbh, 'SELECT * FROM tagente_modulo WHERE id_agente = ? AND ' . db_text('nombre') . ' = ?', $agent->{'id_agente'}, safe_input($module_name));
|
$module = get_db_single_row ($dbh, 'SELECT * FROM tagente_modulo WHERE id_agente = ? AND ' . db_text('nombre') . ' = ?', $agent->{'id_agente'}, safe_input($module_name));
|
||||||
if (! defined ($module)) {
|
if (! defined ($module)) {
|
||||||
logger($pa_config, "Could not create module '$module_name' for agent '$agent_name'.", 3);
|
logger($pa_config, "Could not create module '$module_name' for agent '$agent_name'.", 3);
|
||||||
@ -626,7 +626,8 @@ sub process_module_data ($$$$$$$$$) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
# Control NULL columns
|
# Control NULL columns
|
||||||
$module->{'descripcion'} = '' unless defined ($module->{'descripcion'});
|
$module->{'descripcion'} = '' unless defined ($module->{'descripcion'});
|
||||||
$module->{'extended_info'} = '' unless defined ($module->{'extended_info'});
|
$module->{'extended_info'} = '' unless defined ($module->{'extended_info'});
|
||||||
@ -649,15 +650,15 @@ sub process_module_data ($$$$$$$$$) {
|
|||||||
if ($agent->{'modo'} eq '1' && $policy_linked == 0) {
|
if ($agent->{'modo'} eq '1' && $policy_linked == 0) {
|
||||||
update_module_configuration ($pa_config, $dbh, $module, $module_conf);
|
update_module_configuration ($pa_config, $dbh, $module, $module_conf);
|
||||||
}
|
}
|
||||||
|
|
||||||
$ModuleSem->up ();
|
$ModuleSem->up ();
|
||||||
|
|
||||||
# Module disabled!
|
# Module disabled!
|
||||||
if ($module->{'disabled'} eq '1') {
|
if ($module->{'disabled'} eq '1') {
|
||||||
logger($pa_config, "Skipping disabled module '$module_name' agent '$agent_name'.", 10);
|
logger($pa_config, "Skipping disabled module '$module_name' agent '$agent_name'.", 10);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Parse the timestamp and process the module
|
# Parse the timestamp and process the module
|
||||||
if ($timestamp !~ /(\d+)\/(\d+)\/(\d+) +(\d+):(\d+):(\d+)/ &&
|
if ($timestamp !~ /(\d+)\/(\d+)\/(\d+) +(\d+):(\d+):(\d+)/ &&
|
||||||
$timestamp !~ /(\d+)\-(\d+)\-(\d+) +(\d+):(\d+):(\d+)/) {
|
$timestamp !~ /(\d+)\-(\d+)\-(\d+) +(\d+):(\d+):(\d+)/) {
|
||||||
|
@ -146,12 +146,24 @@ B<Returns>: I<undef> if there is not information available or a B<hash> with:
|
|||||||
##########################################################################
|
##########################################################################
|
||||||
sub get_reverse_geoip_sql($$$) {
|
sub get_reverse_geoip_sql($$$) {
|
||||||
my ($pa_config,$ip_addr, $dbh) = @_;
|
my ($pa_config,$ip_addr, $dbh) = @_;
|
||||||
|
|
||||||
my $id_range = get_db_value($dbh, 'SELECT `id_range` FROM tgis_reverse_geoip_ranges WHERE INET_ATON(?) >= `first_IP_decimal` AND INET_ATON(?) <= `last_IP_decimal` LIMIT 1', $ip_addr, $ip_addr);
|
my $id_range = get_db_value($dbh,
|
||||||
if (defined($id_range)) {
|
'SELECT ' . $RDBMS_QUOTE . 'id_range' . $RDBMS_QUOTE . '
|
||||||
logger($pa_config,"Range id of '$ip_addr' is '$id_range'", 8);
|
FROM tgis_reverse_geoip_ranges
|
||||||
my $region_info = get_db_single_row($dbh, 'SELECT * FROM tgis_reverse_geoip_info WHERE `id_range` = ?',$id_range);
|
WHERE INET_ATON(?) >= ' . $RDBMS_QUOTE . 'first_IP_decimal' . $RDBMS_QUOTE . '
|
||||||
logger($pa_config, "region info of id_range '$id_range' is: country:".$region_info->{'country_name'}." region:".$region_info->{'region'}." city:".$region_info->{'city'}." longitude:".$region_info->{'longitude'}." latitude:".$region_info->{'longitude'}, 8);
|
AND INET_ATON(?) <= ' . $RDBMS_QUOTE . 'last_IP_decimal ' . $RDBMS_QUOTE . '
|
||||||
|
LIMIT 1', $ip_addr, $ip_addr);
|
||||||
|
|
||||||
|
if (defined($id_range)) {
|
||||||
|
logger($pa_config,"Range id of '$ip_addr' is '$id_range'", 8);
|
||||||
|
my $region_info = get_db_single_row($dbh,
|
||||||
|
'SELECT *
|
||||||
|
FROM tgis_reverse_geoip_info
|
||||||
|
WHERE ' . $RDBMS_QUOTE . 'id_range ' . $RDBMS_QUOTE . ' = ?',
|
||||||
|
$id_range);
|
||||||
|
|
||||||
|
logger($pa_config, "region info of id_range '$id_range' is: country:".$region_info->{'country_name'}." region:".$region_info->{'region'}." city:".$region_info->{'city'}." longitude:".$region_info->{'longitude'}." latitude:".$region_info->{'longitude'}, 8);
|
||||||
|
|
||||||
return $region_info;
|
return $region_info;
|
||||||
}
|
}
|
||||||
return undef;
|
return undef;
|
||||||
|
@ -262,7 +262,7 @@ sub data_consumer ($$) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
# End of GIS code -----------------------------
|
# End of GIS code -----------------------------
|
||||||
else {
|
else {
|
||||||
# Create a new agent
|
# Create a new agent
|
||||||
$agent_id = pandora_create_agent ($pa_config, $pa_config->{'servername'},
|
$agent_id = pandora_create_agent ($pa_config, $pa_config->{'servername'},
|
||||||
$host_name, $addr, $task->{'id_group'},
|
$host_name, $addr, $task->{'id_group'},
|
||||||
@ -274,7 +274,7 @@ sub data_consumer ($$) {
|
|||||||
logger($pa_config, "Error creating agent '$host_name'.", 3);
|
logger($pa_config, "Error creating agent '$host_name'.", 3);
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Add the new address if it does not exist
|
# Add the new address if it does not exist
|
||||||
my $addr_id = get_addr_id ($dbh, $addr);
|
my $addr_id = get_addr_id ($dbh, $addr);
|
||||||
$addr_id = add_address ($dbh, $addr) unless ($addr_id > 0);
|
$addr_id = add_address ($dbh, $addr) unless ($addr_id > 0);
|
||||||
@ -282,14 +282,15 @@ sub data_consumer ($$) {
|
|||||||
logger($pa_config, "Could not add address '$addr' for host '$host_name'.", 3);
|
logger($pa_config, "Could not add address '$addr' for host '$host_name'.", 3);
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Assign the new address to the agent
|
# Assign the new address to the agent
|
||||||
my $agent_addr_id = get_agent_addr_id ($dbh, $addr_id, $agent_id);
|
my $agent_addr_id = get_agent_addr_id ($dbh, $addr_id, $agent_id);
|
||||||
if ($agent_addr_id <= 0) {
|
if ($agent_addr_id <= 0) {
|
||||||
db_do ($dbh, 'INSERT INTO taddress_agent (`id_a`, `id_agent`)
|
db_do ($dbh, 'INSERT INTO taddress_agent (' . $RDBMS_QUOTE . 'id_a' . $RDBMS_QUOTE . ', ' .
|
||||||
VALUES (?, ?)', $addr_id, $agent_id);
|
$RDBMS_QUOTE . 'id_agent' . $RDBMS_QUOTE . ')
|
||||||
|
VALUES (?, ?)', $addr_id, $agent_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
# Create network profile modules for the agent
|
# Create network profile modules for the agent
|
||||||
create_network_profile_modules ($pa_config, $dbh, $agent_id, $task->{'id_network_profile'}, $addr, $task->{'snmp_community'});
|
create_network_profile_modules ($pa_config, $dbh, $agent_id, $task->{'id_network_profile'}, $addr, $task->{'snmp_community'});
|
||||||
|
|
||||||
@ -309,9 +310,9 @@ sub data_consumer ($$) {
|
|||||||
$text .= "\n\nThis is the list of IP addresses found: \n\n$added_hosts";
|
$text .= "\n\nThis is the list of IP addresses found: \n\n$added_hosts";
|
||||||
pandora_create_incident ($pa_config, $dbh, "[RECON] New hosts detected", $text, 0, 0, 'Pandora FMS Recon Server', $task->{'id_group'});
|
pandora_create_incident ($pa_config, $dbh, "[RECON] New hosts detected", $text, 0, 0, 'Pandora FMS Recon Server', $task->{'id_group'});
|
||||||
}
|
}
|
||||||
|
|
||||||
logger($pa_config, "Finished recon task for net " . $task->{'subnet'} . ".", 10);
|
logger($pa_config, "Finished recon task for net " . $task->{'subnet'} . ".", 10);
|
||||||
|
|
||||||
# Mark recon task as done
|
# Mark recon task as done
|
||||||
update_recon_task ($dbh, $task_id, -1);
|
update_recon_task ($dbh, $task_id, -1);
|
||||||
}
|
}
|
||||||
@ -388,12 +389,13 @@ sub get_host_parent {
|
|||||||
if ($os_detect == 1) {
|
if ($os_detect == 1) {
|
||||||
$id_os = guess_os ($pa_config, $dbh, $host_addr);
|
$id_os = guess_os ($pa_config, $dbh, $host_addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
# Create the host
|
# Create the host
|
||||||
my $agent_id = pandora_create_agent ($pa_config, $pa_config->{'servername'}, $host_name, $host_addr, $group, $parent_id, $id_os, '', 300, $dbh);
|
my $agent_id = pandora_create_agent ($pa_config, $pa_config->{'servername'}, $host_name, $host_addr, $group, $parent_id, $id_os, '', 300, $dbh);
|
||||||
$agent_id = 0 unless defined ($parent_id);
|
$agent_id = 0 unless defined ($parent_id);
|
||||||
db_do ($dbh, 'INSERT INTO taddress_agent (`id_a`, `id_agent`)
|
db_do ($dbh, 'INSERT INTO taddress_agent (' . $RDBMS_QUOTE . 'id_a' . $RDBMS_QUOTE . ',' .
|
||||||
VALUES (?, ?)', $addr_id, $agent_id);
|
$RDBMS_QUOTE . 'id_agent' . $RDBMS_QUOTE . ')
|
||||||
|
VALUES (?, ?)', $addr_id, $agent_id);
|
||||||
|
|
||||||
# Move to the next host
|
# Move to the next host
|
||||||
$parent_id = $agent_id;
|
$parent_id = $agent_id;
|
||||||
@ -417,9 +419,9 @@ sub tcp_scan ($$$) {
|
|||||||
# Guess OS using xprobe2.
|
# Guess OS using xprobe2.
|
||||||
##########################################################################
|
##########################################################################
|
||||||
sub guess_os {
|
sub guess_os {
|
||||||
my ($pa_config, $dbh, $host) = @_;
|
my ($pa_config, $dbh, $host) = @_;
|
||||||
|
|
||||||
# Use xprobe2 if available
|
# Use xprobe2 if available
|
||||||
my $xprobe = $pa_config->{'xprobe2'};
|
my $xprobe = $pa_config->{'xprobe2'};
|
||||||
if (-e $xprobe){
|
if (-e $xprobe){
|
||||||
my $output = `$xprobe $host 2>$DEVNULL | grep 'Running OS' | head -1`;
|
my $output = `$xprobe $host 2>$DEVNULL | grep 'Running OS' | head -1`;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user