From d1b757a3f13712f158dd84ff25cbadfe22d41389 Mon Sep 17 00:00:00 2001 From: rettenbe Date: Thu, 5 Jun 2008 13:43:17 +0000 Subject: [PATCH] * gosa-si-server * under construction git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@11246 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-si/gosa-si-server | 8 ++++ gosa-si/modules/ClientPackages.pm | 2 +- gosa-si/server/events/clMessages.pm | 2 +- gosa-si/server/events/server_server_com.pm | 47 ++++++++++++++++++++++ gosa-si/server/events/siTriggered.pm | 7 +++- 5 files changed, 63 insertions(+), 3 deletions(-) diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server index bfb1619a3..e40768d45 100755 --- a/gosa-si/gosa-si-server +++ b/gosa-si/gosa-si-server @@ -2963,6 +2963,14 @@ daemon_log("0 INFO: found foreign server in config file and DNS: $all_foreign_se # add all found foreign servers to known_server my $act_timestamp = &get_time(); foreach my $foreign_server (@foreign_server_list) { + + ####################################### + # TODO for jan + # do not add myself to known_server_db + # work around!!! + if ($foreign_server eq '172.16.2.89:20081') { next; } + ###################################### + my $res = $known_server_db->add_dbentry( {table=>$known_server_tn, primkey=>['hostname'], hostname=>$foreign_server, diff --git a/gosa-si/modules/ClientPackages.pm b/gosa-si/modules/ClientPackages.pm index 379420716..77cc61880 100644 --- a/gosa-si/modules/ClientPackages.pm +++ b/gosa-si/modules/ClientPackages.pm @@ -927,7 +927,7 @@ sub hardware_config { # TODO # resolve plain name for host my $func_dic = {table=>$main::job_queue_tn, - primkey=>[], + primkey=>['macaddress', 'headertag'], timestamp=>&get_time, status=>'processing', result=>'none', diff --git a/gosa-si/server/events/clMessages.pm b/gosa-si/server/events/clMessages.pm index 0faea11c1..ad665646a 100644 --- a/gosa-si/server/events/clMessages.pm +++ b/gosa-si/server/events/clMessages.pm @@ -410,7 +410,7 @@ sub TASKBEGIN { &main::daemon_log("$session_id DEBUG: add job to queue for host '$macaddress'", 7); my $func_dic = {table=>$main::job_queue_tn, - primkey=>[], + primkey=>['macaddress', 'headertag'], timestamp=>&get_time, status=>'processing', result=>"$header $content", diff --git a/gosa-si/server/events/server_server_com.pm b/gosa-si/server/events/server_server_com.pm index af7ce1b0c..1621ad124 100644 --- a/gosa-si/server/events/server_server_com.pm +++ b/gosa-si/server/events/server_server_com.pm @@ -12,6 +12,7 @@ use strict; use warnings; use Data::Dumper; use GOSA::GosaSupportDaemon; +use Time::HiRes qw( usleep); BEGIN {} @@ -149,6 +150,52 @@ sub new_foreign_client { my $hostname = @{$msg_hash->{'client'}}[0]; my $macaddress = @{$msg_hash->{'macaddress'}}[0]; + # if new client is known in known_clients_db + my $check_sql = "SELECT * FROM $main::known_clients_tn WHERE (macaddress LIKE '$macaddress')"; + my $check_res = $main::known_clients_db->select_dbentry($check_sql); + + if( (keys(%$check_res) == 1) ) { + my $host_key = $check_res->{1}->{'hostkey'}; + + # check if new client is still alive + my $client_hash = &create_xml_hash("ping", $main::server_address, $hostname); + &add_content2xml_hash($client_hash, 'session_id', $session_id); + my $client_msg = &create_xml_string($client_hash); + my $error = &main::send_msg_to_target($client_msg, $hostname, $host_key, 'ping', $session_id); + my $message_id; + my $i = 0; + while (1) { + $i++; + my $sql = "SELECT * FROM $main::incoming_tn WHERE headertag='answer_$session_id'"; + my $res = $main::incoming_db->exec_statement($sql); + if (ref @$res[0] eq "ARRAY") { + $message_id = @{@$res[0]}[0]; + last; + } + + # do not run into a endless loop + if ($i > 100) { last; } + usleep(100000); + } + + # client is alive + # -> new_foreign_client will be ignored + if (defined $message_id) { + &main::daemon_log("$session_id ERROR: At new_foreign_clients: host '$hostname' is reported as a new foreign client, ". + "but the host is still registered at this server. So, the new_foreign_client-msg will be ignored: $msg", 1); + } + + } + + + # new client is not found in known_clients_db or + # new client is dead -> new_client-msg from foreign server is valid + # -> client will be deleted from known_clients_db + # -> inserted to foreign_clients_db + + my $del_sql = "SELECT * FROM $main::known_clients_tn WHERE (hostname='$hostname')"; + my $del_res = $main::known_clients_db->exec_statement($del_sql); + my $func_dic = { table => $main::foreign_clients_tn, primkey => ['hostname'], hostname => $hostname, diff --git a/gosa-si/server/events/siTriggered.pm b/gosa-si/server/events/siTriggered.pm index 50d790515..42c5fece1 100644 --- a/gosa-si/server/events/siTriggered.pm +++ b/gosa-si/server/events/siTriggered.pm @@ -125,6 +125,7 @@ sub got_ping { sub detected_hardware { my ($msg, $msg_hash, $session_id) = @_ ; my $address = $msg_hash->{source}[0]; + my $header = $msg_hash->{header}[0]; my $gotoHardwareChecksum= $msg_hash->{detected_hardware}[0]->{gotoHardwareChecksum}; my $sql_statement= "SELECT * FROM known_clients WHERE hostname='$address'"; @@ -238,8 +239,12 @@ sub detected_hardware { } else { &main::daemon_log("INFO: Added Hardware configuration to LDAP", 5); } - } + + # if there is a job in job queue for this host and this macaddress, delete it, cause its no longer used + my $del_sql = "DELETE FROM $main::job_queue_tn WHERE (macaddress='$macaddress' AND headertag='$header')"; + my $del_res = $main::job_db->exec_statement($del_sql); + return ; } -- 2.30.2