Ad Widget

Collapse

Is there facility to contain syslogs from hosts?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • krusty
    Senior Member
    • Oct 2005
    • 222

    #1

    Is there facility to contain syslogs from hosts?

    Hello,

    i´ve the next question. I want to contain syslog messages to the web frontend. I ´ve found a way to insert syslogs into the mysql database. Know i want to export syslogs for every host into the web frontend. Is there any tutorial to adding this feature to zabbix? Or have anyone the same problem and find a way to fix it?

    Greez
  • krusty
    Senior Member
    • Oct 2005
    • 222

    #2
    I have fix my problem by creating a new table in database where the syslogs from syslog-ng is write in. Then i made a new php Script syslog.php, that checks the table for syslogs and print the logs to the browser. Everything works fine, but i the table of logs is very big there is maybe a performance problem. The following code shows you the syslog.php. This is always a alpha version.

    Code:
    <?php
    /* 
    ** ZABBIX
    ** Copyright (C) 2000-2005 SIA Zabbix
    **
    ** This program is free software; you can redistribute it and/or modify
    ** it under the terms of the GNU General Public License as published by
    ** the Free Software Foundation; either version 2 of the License, or
    ** (at your option) any later version.
    **
    ** This program is distributed in the hope that it will be useful,
    ** but WITHOUT ANY WARRANTY; without even the implied warranty of
    ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    ** GNU General Public License for more details.
    **
    ** You should have received a copy of the GNU General Public License
    ** along with this program; if not, write to the Free Software
    ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    **/
    ?>
    <?php
    	include "include/config.inc.php";
    	$page["title"] = "S_SYSLOG";
    	$page["file"] = "syslog.php";
    	show_header($page["title"],30,0);
    ?>
    
    <?php
    	if(isset($_GET["start"])&&isset($_GET["do"])&&($_GET["do"]=="<< Prev 100"))
    	{
    		$_GET["start"]-=100;
    	}
    	if(isset($_GET["do"])&&($_GET["do"]=="Next 100 >>"))
    	{
    		if(isset($_GET["start"]))
    		{
    			$_GET["start"]+=100;
    		}
    		else
    		{
    			$_GET["start"]=100;
    		}
    	}
    	if(isset($_GET["start"])&&($_GET["start"]<=0))
    	{
    		unset($_GET["start"]);
    	}
    	if(isset($_GET["groupid"])&&($_GET["groupid"]==0))
    	{
    		unset($_GET{"groupid"});
    	}
    ?>
    
    <?php
    	update_profile("web.menu.view.last",$page["file"]);
    ?>
    
    <?php
    	$h1="&nbsp;".S_HISTORY_OF_EVENTS_BIG;
    
    	$h2=S_GROUP."&nbsp;";
    	$h2=$h2."<select class=\"biginput\" name=\"groupid\" onChange=\"submit()\">";
    	$h2=$h2.form_select("groupid",0,S_ALL_SMALL);
    	$result=DBselect("select groupid,name from groups order by name");
    	while($row=DBfetch($result))
    	{
    // Check if at least one host with read permission exists for this group
    		$result2=DBselect("select h.hostid,h.host from hosts h,items i,hosts_groups hg where h.status=".HOST_STATUS_MONITORED." and h.hostid=i.hostid and hg.groupid=".$row["groupid"]." and hg.hostid=h.hostid group by h.hostid,h.host order by h.host");
    		$cnt=0;
    		while($row2=DBfetch($result2))
    		{
    			if(!check_right("Host","R",$row2["hostid"]))
    			{
    				continue;
    			}
    			$cnt=1; break;
    		}
    		if($cnt!=0)
    		{
    			$h2=$h2.form_select("groupid",$row["groupid"],$row["name"]);
    		}
    	}
    	$h2=$h2."</select>";
    
    	$h2=$h2."&nbsp;".S_HOST."&nbsp;";
    	$h2=$h2."<select class=\"biginput\" name=\"hostid\" onChange=\"submit()\">";
    	$h2=$h2.form_select("hostid",0,S_SELECT_HOST_DOT_DOT_DOT);
    
    	if(isset($_GET["groupid"]))
    	{
    		$sql="select h.hostid,h.host from hosts h,items i,hosts_groups hg where h.status=".HOST_STATUS_MONITORED." and h.hostid=i.hostid and hg.groupid=".$_GET["groupid"]." and hg.hostid=h.hostid group by h.hostid,h.host order by h.host";
    	}
    	else
    	{
    		$sql="select h.hostid,h.host from hosts h,items i where h.status=".HOST_STATUS_MONITORED." and h.hostid=i.hostid group by h.hostid,h.host order by h.host";
    	}
    
    	$result=DBselect($sql);
    	
    	//Überprüft ob Rechte vorliegen um die Informationen angezeigt zu bekommen.
    	while($row=DBfetch($result))
    	{
    		if(!check_right("Host","R",$row["hostid"]))
    		{
    			continue;
    		}
    		$h2=$h2.form_select("hostid",$row["hostid"],$row["host"]);
    	}
    	$h2=$h2."</select>&nbsp;";
    	
    	//Verschiedene Prioritäten anzeigen.
    	$h2=$h2."&nbsp;".S_PRIORITY."&nbsp;";
    	$h2=$h2."<select class=\"biginput\" name=\"priority\" onChange=\"submit()\">";
    	$h2=$h2.form_select("priority",0,S_PRIORITY_CHOOOSE);
    	$sql="select distinct(priority) from logs";
    	$result=DBselect($sql);
    	
    	while($row=DBfetch($result))
    	{
    		$h2=$h2.form_select("priority",$row["priority"],$row["0"]);
    	}
    	$h2=$h2."</select>&nbsp;";
    	
    	if(isset($_GET["start"]))
    	{
    		$h2=$h2."<input class=\"biginput\" name=\"start\" type=hidden value=".$_GET["start"]." size=8>";
      		$h2=$h2."<input class=\"button\" type=\"submit\" name=\"do\" value=\"<< Prev 100\">";
    	}
    	else
    	{
      		$h2=$h2."<input class=\"button\" type=\"submit\" disabled name=\"do\" value=\"<< Prev 100\">";
    	}
      	$h2=$h2."<input class=\"button\" type=\"submit\" name=\"do\" value=\"Next 100 >>\">";
    
    	show_header2($h1,$h2,"<form name=\"form2\" method=\"get\" action=\"syslog.php\">","</form>");
    ?>
    
    <?php
    	if(!isset($_GET["start"])) 
    	{
    		$_GET["start"]=0;
    	}
    	if(isset($_GET["hostid"])&&($_GET["hostid"] == 0))
    	{
    		unset($_GET["hostid"]); 
    	}
    
    	
    	$sql="select max(seq) as max from logs"; //gibt die anzahl wieder
    	$result=DBselect($sql);
    	$row=DBfetch($result);
    	$maxalarmid=@iif(DBnum_rows($result)>0,$row["max"],0);
    
    	if(isset($_GET["hostid"]))
    	{
    
    		if($_GET["priority"]=="warning")
    		{
    			$sql="select h.host, l.date, l.time, l.program, l.host, l.priority, l.msg from logs l, hosts h where h.hostid=".$_GET["hostid"]." and h.host=l.program and l.priority like '%".$_GET["priority"]."%' order by l.date desc, l.time desc limit ".($_GET["start"]+200); //and l.seq>$maxalarmid-".($_GET["start"]+200)." 
    			echo $sql;
    		}
    		elseif($_GET["priority"]=="notice")
    		{
    			$sql="select h.host, l.date, l.time, l.program, l.host, l.priority, l.msg from logs l, hosts h where h.hostid=".$_GET["hostid"]." and h.host=l.program and l.priority like '%".$_GET["priority"]."%' order by l.date desc, l.time desc limit ".($_GET["start"]+200); //and l.seq>$maxalarmid-".($_GET["start"]+200)." 
    			echo $sql;
    		}
    		elseif($_GET["priority"]=="crit")
    		{
    			$sql="select h.host, l.date, l.time, l.program, l.host, l.priority, l.msg from logs l, hosts h where h.hostid=".$_GET["hostid"]." and h.host=l.program and l.priority like '%".$_GET["priority"]."%' order by l.date desc, l.time desc limit ".($_GET["start"]+200); //and l.seq>$maxalarmid-".($_GET["start"]+200)." 
    			echo $sql;
    		}
    		elseif($_GET["priority"]=="info")
    		{
    			$sql="select h.host, l.date, l.time, l.program, l.host, l.priority, l.msg from logs l, hosts h where h.hostid=".$_GET["hostid"]." and h.host=l.program and l.priority like '%".$_GET["priority"]."%' order by l.date desc, l.time desc limit ".($_GET["start"]+200); //and l.seq>$maxalarmid-".($_GET["start"]+200)." 
    		}
    		else 
    		{
    			$sql="select h.host, l.date, l.time, l.program, l.host, l.priority, l.msg from logs l, hosts h where h.hostid=".$_GET["hostid"]." and h.host=l.program order by l.date desc, l.time desc limit ".($_GET["start"]+200); //and l.seq>$maxalarmid-".($_GET["start"]+200)." 
    		}
    	}
    	else
    	{
    		$sql="select h.host, l.date, l.time, l.program, l.host, l.priority, l.msg from logs l, hosts h where l.seq>$maxalarmid-".($_GET["start"]+200)." order by l.date desc, l.time desc limit ".($_GET["start"]+200);
    	}
    
    	$result=DBselect($sql);
    
    	table_begin();
    	table_header(array(S_TIME,S_DATE,S_PRIORITY,S_HOST,S_MESSAGE));
    	$col=0;
    	$i=0;
    	while($row=DBfetch($result))
    	{        
    		$i++;
    		if(isset($_GET["start"])&&($i<$_GET["start"]))
    		{
    			continue;
    		}
    
    		if($col>100)	break;
    
    		table_row(array(
    			$row[2], //Zeit(Time)
    			$row[1], //Datum(Date)
    			$row[5], //Priorität
    			$row[4], //System (IP-Addresse)
    			$row[6]), //Nachricht (msg)
    			$col++);
    	}
    	table_end();
    ?>
    </TR>
    </TABLE>
    
    <?php
    	show_footer();
    ?>
    For your information i use the alarm.php as template. I´m not really good in programming php. Maybe there is anyone who looks to the code and help me to correct the code.

    Greez

    Comment

    Working...