Code

* gosa-si-server
authorrettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 5 Jun 2008 13:43:17 +0000 (13:43 +0000)
committerrettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 5 Jun 2008 13:43:17 +0000 (13:43 +0000)
* under construction

git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@11246 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-si/gosa-si-server
gosa-si/modules/ClientPackages.pm
gosa-si/server/events/clMessages.pm
gosa-si/server/events/server_server_com.pm
gosa-si/server/events/siTriggered.pm

index bfb1619a340ea0bd5c4fd49e21283e51a634a3dc..e40768d456d1abd2ecfe3d11b44d15d4250aef96 100755 (executable)
@@ -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,
index 37942071659adb0d04de2d4c3a7e4f25dcf76c46..77cc61880eb61881eb0c32824115e969e20ddbfd 100644 (file)
@@ -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',
index 0faea11c17d6d95e2007c29dd90fda486c114e95..ad665646a2ef9a9a09b418553cc6f3ddcb7f257b 100644 (file)
@@ -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",
index af7ce1b0c869bdc0303831ff1f9a8d16ddcc8397..1621ad1246be47899dc65dad536c01a2a16863a5 100644 (file)
@@ -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,
index 50d7905152fd3f01e45ee93955dd5ff496690cee..42c5fece1b5975b0a29af9ff372edcf35a50aee6 100644 (file)
@@ -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 ;
 }