From: rettenbe Date: Wed, 20 Aug 2008 14:04:46 +0000 (+0000) Subject: update: gosa-si with trigger_reload_syslog_config handling X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=415afb84e3a4050499a81eab25da1e0af95609ff;p=gosa.git update: gosa-si with trigger_reload_syslog_config handling git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@12255 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-si/client/events/corefunctions.pm b/gosa-si/client/events/corefunctions.pm index f74f595d7..acf03be3c 100644 --- a/gosa-si/client/events/corefunctions.pm +++ b/gosa-si/client/events/corefunctions.pm @@ -4,6 +4,7 @@ use Exporter; my @events = ( "get_events", "registered", + 'new_syslog_config', "new_ntp_config", "new_ldap_config", "new_key", @@ -25,6 +26,7 @@ use File::Basename; my ($ldap_enabled, $offline_enabled, $ldap_config, $pam_config, $nss_config, $fai_logpath); my $chrony_file = "/etc/chrony/chrony.conf"; +my $syslog_file = "/etc/syslog.conf"; my %cfg_defaults = ( "client" => { @@ -153,6 +155,63 @@ sub server_leaving { return; } + +## @method new_syslog_config +# Update or add syslog messages forwarding to specified syslog server. +# @param msg - STRING - xml message with tag server +# @param msg_hash - HASHREF - message information parsed into a hash +sub new_syslog_config { + my ($msg, $msg_hash) = @_ ; + + # Sanity check of incoming message + if ((not exists $msg_hash->{'server'}) || (not @{$msg_hash->{'server'}} == 1) ) { + &main::daemon_log("ERROR: 'new_syslog_config'-message does not contain a syslog server: $msg", 1); + return; + } + + # Fetch the new syslog server from incoming message + my $syslog_server = @{$msg_hash->{'server'}}[0]; + &main::daemon_log("INFO: found syslog server: ".join(", ", $syslog_server), 5); + my $found_server_flag = 0; + + # Sanity check of /etc/syslog.conf + if (not -f $syslog_file) { + &main::daemon_log("ERROR: file '$syslog_file' does not exist, cannot do syslog reconfiguration!", 1); + return; + } + + # Substitute existing server with new syslog server + open (FILE, "<$syslog_file"); + my @file = ; + close FILE; + my $syslog_server_line = "*.*\t@".$syslog_server."\n"; + foreach my $line (@file) { + if ($line =~ /^\*\.\*\s+@/) { + $line = $syslog_server_line; + $found_server_flag++; + } + } + + # Append new server if no old server configuration found + if (not $found_server_flag) { + push(@file, "\n#\n# syslog server configuration written by GOsa-si\n#\n"); + push(@file, $syslog_server_line); + } + + # Write changes to file and close it + open (FILE, "+>$syslog_file"); + print FILE join("", @file); + close FILE; + &main::daemon_log("INFO: wrote new configuration file: $syslog_file", 5); + + # Restart syslog deamon + my $res = qx(/etc/init.d/sysklogd restart); + &main::daemon_log("INFO: restart syslog daemon: \n$res", 5); + + return; +} + + ## @method new_ntp_config # Updates the server options in /etc/chrony/chrony.conf and restarts the chrony service # @param msg - STRING - xml message with tag server diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server index 2e362facd..bb6c6e881 100755 --- a/gosa-si/gosa-si-server +++ b/gosa-si/gosa-si-server @@ -1579,8 +1579,12 @@ sub watch_for_opsi_jobs { } } - # Estimate "rough" progress - $result->{'progress'}= int($installed * 100 / $products); + # Estimate "rough" progress, avoid division by zero + if ($products == 0) { + $result->{'progress'}= 0; + } else { + $result->{'progress'}= int($installed * 100 / $products); + } # Set updates in job queue if ((not $error) && (not $installing) && ($installed)) { diff --git a/gosa-si/modules/ClientPackages.pm b/gosa-si/modules/ClientPackages.pm index 270cda8ab..b2a5288d6 100644 --- a/gosa-si/modules/ClientPackages.pm +++ b/gosa-si/modules/ClientPackages.pm @@ -582,6 +582,81 @@ sub who_has_i_do { } +sub new_syslog_config { + my ($mac_address, $session_id) = @_; + my $syslog_msg; + + # Build LDAP connection + my $ldap_handle = &main::get_ldap_handle($session_id); + if( not defined $ldap_handle ) { + &main::daemon_log("$session_id ERROR: cannot connect to ldap: $ldap_uri", 1); + return; + } + + # Perform search + my $ldap_res = $ldap_handle->search( base => $ldap_base, + scope => 'sub', + attrs => ['gotoSyslogServer'], + filter => "(&(objectClass=GOhard)(macaddress=$mac_address))"); + if($ldap_res->code) { + &main::daemon_log("$session_id ".$ldap_res->error, 1); + return; + } + + # Sanity check + if ($ldap_res->count != 1) { + &main::daemon_log("$session_id ERROR: client with mac address $mac_address not found/unique/active - not sending syslog config". + "\n\tbase: $ldap_base". + "\n\tscope: sub". + "\n\tattrs: gotoSyslogServer". + "\n\tfilter: (&(objectClass=GOhard)(macaddress=$mac_address))", 1); + return; + } + + my $entry= $ldap_res->entry(0); + my $dn = &Net::LDAP::Util::escape_dn_value($entry->dn); + my $syslog_server = $entry->get_value("gotoSyslogServer"); + + # If no syslog server is specified at host, just have a look at the object group of the host + # Perform object group search + if (not defined $syslog_server) { + my $ldap_res = $ldap_handle->search( base => $ldap_base, + scope => 'sub', + attrs => ['gotoSyslogServer'], + filter => "(&(objectClass=gosaGroupOfNames)(member=$dn))"); + if($ldap_res->code) { + &main::daemon_log("$session_id ".$ldap_res->error, 1); + return; + } + + # Sanity check + if ($ldap_res->count != 1) { + &main::daemon_log("$session_id ERROR: client with mac address $mac_address not found/unique/active - not sending syslog config". + "\n\tbase: $ldap_base". + "\n\tscope: sub". + "\n\tattrs: gotoSyslogServer". + "\n\tfilter: (&(objectClass=gosaGroupOfNames)(member=$dn))", 1); + return; + } + + my $entry= $ldap_res->entry(0); + $syslog_server= $entry->get_value("gotoSyslogServer"); + } + + # Return if no syslog server specified + if (not defined $syslog_server) { + &main::daemon_log("$session_id WARNING: no syslog server specified for this host '$mac_address'", 3); + return; + } + + # Add syslog server to 'syslog_config' message + my $syslog_msg_hash = &create_xml_hash("new_syslog_config", $server_address, $mac_address); + &add_content2xml_hash($syslog_msg_hash, "server", $syslog_server); + + return &create_xml_string($syslog_msg_hash); +} + + sub new_ntp_config { my ($address, $session_id) = @_; my $ntp_msg; diff --git a/gosa-si/server/events/gosaTriggered.pm b/gosa-si/server/events/gosaTriggered.pm index 2f74dfd76..d4d7ddd9f 100644 --- a/gosa-si/server/events/gosaTriggered.pm +++ b/gosa-si/server/events/gosaTriggered.pm @@ -10,6 +10,7 @@ my @events = ( "get_login_usr_for_client", "get_client_for_login_usr", "gen_smb_hash", + "trigger_reload_syslog_config", "trigger_reload_ntp_config", "trigger_reload_ldap_config", "ping", @@ -404,9 +405,31 @@ sub detect_hardware { } +sub trigger_reload_syslog_config { + my ($msg, $msg_hash, $session_id) = @_ ; + + # Sanity check of macaddress + # TODO + + my $macaddress = @{$msg_hash->{macaddress}}[0]; + + my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0]; + if( defined $jobdb_id) { + my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id"; + &main::daemon_log("$session_id DEBUG: $sql_statement", 7); + my $res = $main::job_db->exec_statement($sql_statement); + } + + my $out_msg = &ClientPackages::new_syslog_config($macaddress, $session_id); + my @out_msg_l = ( $out_msg ); + + return @out_msg_l; + + +} + sub trigger_reload_ntp_config { my ($msg, $msg_hash, $session_id) = @_ ; - my $target = @{$msg_hash->{target}}[0]; # Sanity check of macaddress # TODO diff --git a/gosa-si/server/events/opsi_com.pm b/gosa-si/server/events/opsi_com.pm index 870e54927..105c9b450 100644 --- a/gosa-si/server/events/opsi_com.pm +++ b/gosa-si/server/events/opsi_com.pm @@ -472,7 +472,7 @@ sub opsi_get_netboot_products { my $description= xml_quote($tres->{'description'}); $name=~ s/\//\\\//; $description=~ s/\//\\\//; - $xml_msg=~ s/<\/xxx>/$r<\/productId><\/name>$description<\/description><\/item>$state<\/xxx>/; + $xml_msg=~ s/<\/xxx>/\n$r<\/productId><\/name>$description<\/description><\/item>$state<\/xxx>/; } } } @@ -495,7 +495,7 @@ sub opsi_get_netboot_products { my $description= xml_quote($tres->{'description'}); $name=~ s/\//\\\//; $description=~ s/\//\\\//; - $xml_msg=~ s/<\/xxx>/$r<\/productId><\/name>$description<\/description><\/item><\/xxx>/; + $xml_msg=~ s/<\/xxx>/\n$r<\/productId><\/name>$description<\/description><\/item><\/xxx>/; } } @@ -587,7 +587,7 @@ sub opsi_get_product_properties { if (not &check_opsi_res($res)){ my $r= $res->result; foreach my $key (keys %{$r}) { - my $item= ""; + my $item= "\n"; my $value= $r->{$key}; if (UNIVERSAL::isa( $value, "ARRAY" )){ foreach my $subval (@{$value}){ @@ -768,7 +768,7 @@ sub opsi_get_client_hardware { if (not &check_opsi_res($res)){ my $result= $res->result; foreach my $r (keys %{$result}){ - my $item= "".xml_quote($r).""; + my $item= "\n".xml_quote($r).""; my $value= $result->{$r}; foreach my $sres (@{$value}){ @@ -1009,7 +1009,7 @@ sub opsi_get_local_products { my $description= xml_quote($tres->{'description'}); $name=~ s/\//\\\//; $description=~ s/\//\\\//; - $xml_msg=~ s/<\/xxx>/$r<\/productId><\/name>$description<\/description><\/item>$state<\/xxx>/; + $xml_msg=~ s/<\/xxx>/\n$r<\/productId><\/name>$description<\/description><\/item>$state<\/xxx>/; } } @@ -1033,7 +1033,7 @@ sub opsi_get_local_products { my $description= xml_quote($tres->{'description'}); $name=~ s/\//\\\//; $description=~ s/\//\\\//; - $xml_msg=~ s/<\/xxx>/$r<\/productId><\/name>$description<\/description><\/item><\/xxx>/; + $xml_msg=~ s/<\/xxx>/\n$r<\/productId><\/name>$description<\/description><\/item><\/xxx>/; } } diff --git a/gosa-si/tests/client.php b/gosa-si/tests/client.php index 772cc39f6..8e3179e60 100755 --- a/gosa-si/tests/client.php +++ b/gosa-si/tests/client.php @@ -162,9 +162,16 @@ for($count = 1; $count <= $zahl; $count++) # Add product to Opsi client #$data = "
gosa_opsi_add_product_to_client
GOSA 00:01:6c:9d:b9:fa 00:11:25:4b:8c:e5 linux-cl-2.intranet.gonicus.de winxppro
"; + #$data = "
gosa_opsi_add_product_to_client
GOSA 00:01:6c:9d:b9:fa 00:11:25:4b:8c:e5 linux-cl-2.intranet.gonicus.de preloginloader
"; + #$data = "
gosa_opsi_add_product_to_client
GOSA 00:01:6c:9d:b9:fa 00:11:25:4b:8c:e5 linux-cl-2.intranet.gonicus.de opsi-adminutils
"; + #$data = "
gosa_opsi_add_product_to_client
GOSA 00:01:6c:9d:b9:fa 00:11:25:4b:8c:e5 linux-cl-2.intranet.gonicus.de xpconfig
"; + #$data = "
gosa_opsi_add_product_to_client
GOSA 00:01:6c:9d:b9:fa 00:11:25:4b:8c:e5 linux-cl-2.intranet.gonicus.de hwaudit
"; + #$data = "
gosa_opsi_add_product_to_client
GOSA 00:01:6c:9d:b9:fa 00:11:25:4b:8c:e5 linux-cl-2.intranet.gonicus.de javavm
"; + #$data = "
gosa_opsi_add_product_to_client
GOSA 00:01:6c:9d:b9:fa 00:11:25:4b:8c:e5 linux-cl-2.intranet.gonicus.de firefox
"; + #$data = "
gosa_opsi_add_product_to_client
GOSA 00:01:6c:9d:b9:fa 00:11:25:4b:8c:e5 linux-cl-2.intranet.gonicus.de flashplayer
"; # Delete product from Opsi client - #$data = "
gosa_opsi_del_product_from_client
GOSA 00:01:6c:9d:b9:fa linux-cl-1.intranet.gonicus.de 00:11:25:4b:8c:e5 softprod
"; + #$data = "
gosa_opsi_del_product_from_client
GOSA 00:01:6c:9d:b9:fa linux-cl-1.intranet.gonicus.de 00:11:25:4b:8c:e5 wipedisk
"; ######################### @@ -189,7 +196,11 @@ for($count = 1; $count <= $zahl; $count++) ############################## # NTP reload - $data = "
gosa_trigger_reload_ntp_config
GOSA GOSA 00:11:25:4B:8C:E5
"; + #$data = "
gosa_trigger_reload_ntp_config
GOSA GOSA 00:11:25:4B:8C:E5
"; + + ############################## + # SYSLOG reload + $data = "
gosa_trigger_reload_syslog_config
GOSA GOSA 00:01:6c:9d:b9:fa
"; $sock->write($data); $answer = "nothing";