summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 64ad914)
raw | patch | inline | side by side (parent: 64ad914)
author | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Fri, 18 Dec 2009 10:59:05 +0000 (10:59 +0000) | ||
committer | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Fri, 18 Dec 2009 10:59:05 +0000 (10:59 +0000) |
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@14908 594d385d-05f5-0310-b6e9-bd551577e9d8
gosa-plugins/rsyslog/addons/rsyslog/class_rsyslog.inc | patch | blob | history | |
gosa-plugins/rsyslog/addons/rsyslog/rSyslog.tpl | patch | blob | history |
diff --git a/gosa-plugins/rsyslog/addons/rsyslog/class_rsyslog.inc b/gosa-plugins/rsyslog/addons/rsyslog/class_rsyslog.inc
index 1f7bd8a59468d8136530db6c444bf96d381a649f..40d9c7e9ad8d6a572697f8326acf7129e93073d5 100644 (file)
var $plDescription= "View system logs";
var $servers = array();
+ var $selected_server = "";
+ var $selected_host = "";
function rsyslog (&$config, $dn= NULL)
{
$this->config= &$config;
$this->ui = get_userinfo();
+ // Get list of rsyslog servers
$ldap = $this->config->get_ldap_link();
$ldap->cd($this->config->current['BASE']);
- $ldap->search("objectClass=rSyslogServer",array("rSyslogUser","rSyslogDatabase","rSyslogPassword"));
+ $ldap->search("objectClass=rSyslogServer",array("cn","rSyslogUser","rSyslogDatabase","rSyslogPassword"));
while($attrs = $ldap->fetch()){
- $this->servers[] = $attrs;
+ if(empty($this->selected_server)) $this->selected_server = $attrs['cn'][0];
+ $s = array('cn' => $attrs['cn'][0], 'dn' => $attrs['dn'], 'Password' => '', 'status' => 'ok');
+ $s['User'] = $attrs['rSyslogUser'][0];
+ $s['Database'] = $attrs['rSyslogDatabase'][0];
+ $s['Hosts'] = array();
+ $s['ACL'] = "";
+ if(isset($attrs['rSyslogPassword'])) $s['Password'] = $attrs['rSyslogPassword'][0];
+ $this->servers[$attrs['cn'][0]] = $s;
+ }
+
+ // Check for installed mysql extension, if missing abort
+ $this->mysql_extension_installed = is_callable("mysql_connect");
+ if(!$this->mysql_extension_installed) return;
+
+ // Test server connetivity
+ $ui = get_userinfo();
+ foreach($this->servers as $name => $server)
+ {
+ $link = @mysql_pconnect($server['cn'], $server['User'], $server['Password']);
+ if ($link === FALSE){
+ new log("debug","gosa_logging","dbconnect",array(),@mysql_error());
+ $this->servers[$name]['status'] = "connectfailed";
+ $this->servers[$name]['error'] = @mysql_error();
+ continue;
+ }elseif (! @mysql_select_db($server['Database'])){
+ new log("debug","gosa_logging","selectdb",array(),@mysql_error());
+ $this->servers[$name]['status'] = "dbmissing";
+ $this->servers[$name]['error'] = @mysql_error();
+ continue;
+ }else{
+ $this->servers[$name]['status'] = "ok";
+ $this->servers[$name]['error'] = "";
+
+ // Detect ACLs
+ $this->servers[$name]['ACL'] = $ui->get_permissions($server['dn'], 'server/rsyslog','viewEntries');
+
+ // Get list of Hosts using this log server..
+ if(preg_match('/r/', $this->servers[$name]['ACL'])){
+ $query = "SELECT distinct(FromHost) FROM SystemEvents;";
+ $res = @mysql_query($query, $link);
+ if($res){
+ while($attrs = @mysql_fetch_assoc($res)){
+ $this->servers[$name]['Hosts'][$attrs['FromHost']] = $attrs['FromHost'];
+ }
+ }else{
+ $this->servers[$name]['status'] = "query_failed";
+ $this->servers[$name]['error'] = @mysql_error();
+ }
+ }
+ }
}
}
{
$smarty = get_smarty();
$ui = get_userinfo();
- foreach($this->servers as $server){
- echo "<b>".$server['dn']."</b><br>";
- echo $ui->get_permissions($server['dn'], 'server/rsyslog','viewEntries')."<br>";
+
+ if(!isset($this->servers[$this->selected_server]) || !count($this->servers[$this->selected_server]['Hosts'])){
+ $hosts = array('-' => _("-"));
+ }else{
+ $hosts = array('all' => _("All"));
+ $hosts = array_merge($hosts,$this->servers[$this->selected_server]['Hosts']);
}
+ $smarty->assign("servers",$this->servers);
+ $smarty->assign("hosts",$hosts);
+ $smarty->assign("selected_server",$this->selected_server);
+ $smarty->assign("selected_host",$this->selected_host);
+ $smarty->assign("result", $this->get_result());
return($smarty->fetch(get_template_path("rSyslog.tpl", TRUE)));
}
+
+ function get_result()
+ {
+ $result = array();
+ $result['entries'] = array();
+ $result['status'] = "ok";
+ $result['error'] = "";
+
+ // Check whether the selected server exists.
+ if(!isset($this->servers[$this->selected_server])){
+ $this->servers[$name]['status'] = sprintf(_("The selected server '%s' does not exists!"),$this->selected_server);
+ $this->servers[$name]['error'] = $this->servers[$this->selected_server]['error'];
+ return($result);
+ }
+
+ // Check database connectivity
+ $name = $this->selected_server;
+ $server = $this->servers[$name];
+ $link = @mysql_pconnect($server['cn'], $server['User'], $server['Password']);
+ if ($link === FALSE){
+ new log("debug","gosa_logging","dbconnect",array(),@mysql_error());
+ $this->servers[$name]['status'] = "connectfailed";
+ $this->servers[$name]['error'] = @mysql_error();
+ }elseif (! @mysql_select_db($server['Database'])){
+ new log("debug","gosa_logging","selectdb",array(),@mysql_error());
+ $this->servers[$name]['status'] = "dbmissing";
+ $this->servers[$name]['error'] = @mysql_error();
+ }else{
+ $this->servers[$name]['status'] = "ok";
+ $this->servers[$name]['error'] = "";
+ }
+
+ // Get log entries matching the selected filter
+ if(preg_match('/r/', $this->servers[$name]['ACL'])){
+ $query = "SELECT * FROM SystemEvents LIMIT 10;";
+ $res = @mysql_query($query, $link);
+ if($res){
+ while($attrs = @mysql_fetch_assoc($res)){
+ $result['entries'][] = $attrs;
+ }
+ $this->servers[$name]['status'] = "ok";
+ $this->servers[$name]['error'] = "";
+ }else{
+ $this->servers[$name]['status'] = "query_failed";
+ $this->servers[$name]['error'] = @mysql_error();
+ }
+ }
+ $result['status'] =$this->servers[$name]['status'];
+ $result['error'] =$this->servers[$name]['error'];
+ return($result);
+ }
+
+
+ function save_object()
+ {
+ foreach(array("selected_host","selected_server") as $attr){
+ if(isset($_POST[$attr])) $this->$attr = get_post($attr);
+ }
+ }
}
// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
?>
diff --git a/gosa-plugins/rsyslog/addons/rsyslog/rSyslog.tpl b/gosa-plugins/rsyslog/addons/rsyslog/rSyslog.tpl
index 8bd6648ed130ac9ece0f89cd9a8fbbfd2608427a..1049f613c24eb29038ff8b1703bd4cce177fc3ed 100644 (file)
-asdf
+
+<select name='selected_server' onChange='document.mainform.submit();'>
+ {foreach from=$servers item=item key=key}
+ <option value='{$key}' {if $key == $selected_server} selected {/if}>{$item.cn}</option>
+ {/foreach}
+</select>
+
+<select name='selected_host' onChange='document.mainform.submit();'>
+ {foreach from=$hosts item=item key=key}
+ <option value='{$key}' {if $key == $selected_host} selected {/if}>{$item}</option>
+ {/foreach}
+</select>
+
+<p class="separator"> </p>
+{if $result.status != 'ok'}
+ <b>{t}Error{/t}: {$result.status}</b><br>
+ {$result.error}<br>
+{else}
+ <b>{t}Results{/t}:</b>
+ <table>
+ {foreach from=$result.entries item=item key=key}
+ <tr>
+ <td>
+ {$item.FromHost};
+ </td>
+ </tr>
+ {/foreach}
+ </table>
+{/if}
+