Code

Removed usePrototype flag, its activated always now.
[gosa.git] / gosa-si / server / events / siTriggered.pm
index 8b9b53b1c4e42720b20b6a68c675df3fd5c66162..f190e15fee6f580d6f3f12b3cf0d184a36562bcb 100644 (file)
@@ -1,22 +1,24 @@
 package siTriggered;
-use Exporter;
-@ISA = qw(Exporter);
-my @events = (
-    "got_ping",
-    "detected_hardware",
-    "trigger_wake",
-    "reload_ldap_config",
-       "get_terminal_server",
-    );
-@EXPORT = @events;
 
 use strict;
 use warnings;
+
+use Exporter;
 use Data::Dumper;
 use GOSA::GosaSupportDaemon;
 use Socket;
 
+our @ISA = qw(Exporter);
 
+my @events = (
+    "got_ping",
+    "detected_hardware",
+    "trigger_wake",
+    "reload_ldap_config",
+    "get_terminal_server",
+    );
+    
+our @EXPORT = @events;
 
 BEGIN {}
 
@@ -54,7 +56,7 @@ sub get_terminal_server
                my $ldap_mesg = $ldap_handle->search(
                                base => $ldap_base,
                                scope => 'sub',
-                               attrs => ['macAddress'],
+                               attrs => ['macAddress', 'cn', 'ipHostNumber'],
                                filter => "objectClass=goTerminalServer",
                                );
                if ($ldap_mesg->count) 
@@ -81,18 +83,39 @@ sub get_terminal_server
                        }
 
 ### JUST FOR DEBUGGING # CAN BE DELETED AT ANY TIME ###########################
-                       my $db_res = $main::foreign_clients_db->select_dbentry("SELECT * FROM $main::foreign_clients_tn WHERE macaddress LIKE '00:01:6c:9d:b9:fa'");
-                       while (($hit, $hash) = each %$db_res) 
+#                      my $db_res = $main::known_clients_db->select_dbentry("SELECT * FROM $main::known_clients_tn WHERE macaddress LIKE '00:01:6c:9d:b9:fa'");
+#                      while (($hit, $hash) = each %$db_res) 
+#                      {
+#                              $out_msg = &create_xml_string(&create_xml_hash('get_load', $source, $hash->{macaddress}));
+#                              push(@out_msg_l, $out_msg);
+#                      }
+### JUST FOR DEBUGGING # CAN BE DELETED AT ANY TIME ###########################
+
+                       # Found terminal server but no running clients on them
+                       if (@out_msg_l == 0) 
                        {
-                               $out_msg = &create_xml_string(&create_xml_hash('get_load', $source, $hash->{macaddress}));
-                               push(@out_msg_l, $out_msg);
+                               &main::daemon_log("$session_id ERROR: Found no running clients (known_clients_db, foreign_clients_db) on the following determined terminal server", 1);
+                               my @entries = $ldap_mesg->entries;
+                               foreach my $ts (@entries) 
+                               {
+                                       my $ip = (defined $ts->get_value("ipHostNumber")) ? "   ip='".$ts->get_value("ipHostNumber")."'" : "" ;
+                                       my $cn = (defined $ts->get_value("cn")) ? "   cn='".$ts->get_value("cn")."'" : "" ;
+                                       my $mac = (defined $ts->get_value("macAddress")) ? "   macAddress='".$ts->get_value("macAddress")."'" : "" ;
+                                       &main::daemon_log("$session_id ERROR: ".$cn.$mac.$ip , 1);
+                               }
                        }
-### JUST FOR DEBUGGING # CAN BE DELETED AT ANY TIME ###########################
+
                }
+               # No terminal server found in LDAP
+               if ($ldap_mesg->count == 0) 
+               {
+                       &main::daemon_log("$session_id ERROR: No terminal server found in LDAP: \n\tbase='$ldap_base'\n\tscope='sub'\n\tattrs='['macAddress']'\n\tfilter='objectClass=goTerminalServer'", 1);
+               }
+
                # Translating errors ?
                if ($ldap_mesg->code) 
                {
-                       &main::daemon_log("0 ERROR: Cannot fetch terminal server from LDAP: \n\tbase='$ldap_base'\n\tscope='sub'\n\tattrs='['macAddress']'\n\tfilter='objectClass=goTerminalServer'", 1);
+                       &main::daemon_log("$session_id ERROR: Cannot fetch terminal server from LDAP: \n\tbase='$ldap_base'\n\tscope='sub'\n\tattrs='['macAddress']'\n\tfilter='objectClass=goTerminalServer'", 1);
                }
        }
        &main::release_ldap_handle($ldap_handle);
@@ -204,9 +227,9 @@ sub detected_hardware {
                #       $dnsname= $heap->{force-hostname}->{$macaddress};
                #       &main::daemon_log("INFO: Using forced hostname $dnsname for client $address", 4);
                if (-e "/var/tmp/$macaddress" ){
-                       open(TFILE, "< /var/tmp/$macaddress");
-                       $dnsname= <TFILE>;
-                       close(TFILE);
+                       open(my $TFILE, "<", "/var/tmp/$macaddress");
+                       $dnsname= <$TFILE>;
+                       close($TFILE);
                } else {
                        $dnsname= gethostbyaddr(inet_aton($ipaddress), AF_INET) || $ipaddress;
                }