<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>iWebDev&#039;s blog &#187; destination</title>
	<atom:link href="http://www.iwebdev.it/blog/?feed=rss2&#038;tag=destination" rel="self" type="application/rss+xml" />
	<link>http://www.iwebdev.it/blog</link>
	<description>and everything goes around</description>
	<lastBuildDate>Sat, 06 Aug 2011 23:08:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Collect syslog events to database (second part)</title>
		<link>http://www.iwebdev.it/blog/?p=163</link>
		<comments>http://www.iwebdev.it/blog/?p=163#comments</comments>
		<pubDate>Thu, 10 Mar 2011 22:31:36 +0000</pubDate>
		<dc:creator>to</dc:creator>
				<category><![CDATA[Log event]]></category>
		<category><![CDATA[Unix]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[destination]]></category>
		<category><![CDATA[log]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[postgres]]></category>
		<category><![CDATA[source]]></category>
		<category><![CDATA[syslog-ng]]></category>
		<category><![CDATA[syslog-ng.conf]]></category>

		<guid isPermaLink="false">http://www.iwebdev.it/blog/?p=163</guid>
		<description><![CDATA[In the previous post you installed the syslog-ng 3.2.2. Now you have to configure our syslog-ng daemon to collect events to database; for this tutorial we choosed a MySQL and Postgres databases. First of all you have to configure the syslog-ng configuration file. nano /opt/syslog-ng/etc/syslog-ng.conf Syslog-ng receives log messages from a source. To define a [...]]]></description>
			<content:encoded><![CDATA[<p>In the previous post you installed the syslog-ng 3.2.2. Now you have to <strong>configure our syslog-ng daemon to collect events to database</strong>; for this tutorial we choosed a <strong>MySQL</strong> and <strong>Postgres</strong> databases. First of all you have to configure the syslog-ng configuration file.</p>
<blockquote><p>nano /opt/syslog-ng/etc/syslog-ng.conf</p></blockquote>
<p>Syslog-ng receives log messages from a <strong>source</strong>. To define a source you should follow the following syntax:</p>
<blockquote><p>source &lt;identifier&gt; { source-driver(params); source-driver(params); &#8230; };</p></blockquote>
<p>For example you have to define the following source:</p>
<blockquote>
<div>source my_source{ tcp ( port ( 614 ) ); };</div>
</blockquote>
<p>In syslog-ng log messages are sent to files. The <strong>destination</strong> syntax is very similar to sources:</p>
<blockquote><p>destination &lt;identifier&gt; {destination-driver(params); destination-driver(params); &#8230; };</p></blockquote>
<p>You will be normally logging to a file, but you could log to a different destination-driver: pipe, unix socket, TCP-UDP ports, terminals or to specific programs.</p>
<blockquote>
<div>destination my_dest{ file(&#8220;/var/log/mylog.txt&#8221;); };</div>
</blockquote>
<div>If you want to collect syslog to database you have to create mysql database and table</div>
<blockquote><p>CREATE DATABASE `syslog` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;</p>
<p>USE `syslog`;</p>
<p>CREATE TABLE IF NOT EXISTS `logs` (<br />
`id` bigint(20) unsigned NOT NULL auto_increment,<br />
`host` varchar(128) collate utf8_unicode_ci default NULL,<br />
`facility` varchar(10) collate utf8_unicode_ci default NULL,<br />
`priority` varchar(10) collate utf8_unicode_ci default NULL,<br />
`level` varchar(10) collate utf8_unicode_ci default NULL,<br />
`tag` varchar(10) collate utf8_unicode_ci default NULL,<br />
`datetime` datetime default NULL,<br />
`program` varchar(15) collate utf8_unicode_ci default NULL,<br />
`msg` text collate utf8_unicode_ci,<br />
`seq` bigint(20) unsigned NOT NULL default &#8217;0&#8242;,<br />
`counter` int(11) NOT NULL default &#8217;1&#8242;,<br />
`fo` datetime default NULL,<br />
`lo` datetime default NULL,<br />
PRIMARY KEY  (`id`),<br />
KEY `datetime` (`datetime`),<br />
KEY `sequence` (`seq`),<br />
KEY `priority` (`priority`),<br />
KEY `facility` (`facility`),<br />
KEY `program` (`program`),<br />
KEY `host` (`host`) )<br />
ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;</p>
<p>GRANT SELECT , INSERT , UPDATE , DELETE , CREATE , DROP , INDEX , ALTER ON `syslog` . * TO &#8216;syslog&#8217;@'localhost&#8217;;</p>
<p>SET PASSWORD FOR &#8216;syslog&#8217;@'localhost&#8217; = PASSWORD( &#8216;syslog&#8217; )</p></blockquote>
<p>Edit syslog-ng config appropriately; add these rows in the destination section (if you want to use Postgres you have to change mysql to pgsql):</p>
<blockquote><p>sql(type(mysql)<br />
host(&#8220;localhost&#8221;)<br />
username(&#8220;syslog&#8221;)<br />
password(&#8220;syslog&#8221;)<br />
database(&#8220;syslog&#8221;)<br />
table(&#8220;logs&#8221;)<br />
columns(&#8220;host&#8221;, &#8220;facility&#8221;, &#8220;priority&#8221;, &#8220;level&#8221;, &#8220;tag&#8221;, &#8220;datetime&#8221;, &#8220;program&#8221;, &#8220;msg&#8221;, &#8220;seq&#8221;)<br />
values(&#8220;$HOST_FROM&#8221;, &#8220;$FACILITY&#8221;, &#8220;$PRIORITY&#8221;, &#8220;$LEVEL&#8221;, &#8220;$TAG&#8221;, &#8220;$YEAR-$MONTH-$DAY $HOUR:$MIN:$SEC&#8221;, &#8220;$PROGRAM&#8221;, &#8220;$MSG&#8221;, &#8220;$SEQNUM&#8221;)<br />
indexes(&#8220;host&#8221;, &#8220;facility&#8221;, &#8220;priority&#8221;, &#8220;datetime&#8221;, &#8220;program&#8221;, &#8220;seq&#8221;));</p></blockquote>
<p>Syslog-ng connects sources, filters and destinations with <strong>log</strong> statements. The syntax is:</p>
<blockquote><p>log { source(src); filter(f_mail); filter(f_info); destination(mailinfo); };</p></blockquote>
<p>So you have to connect my_source with my_dest:</p>
<blockquote>
<div>log { source( my_source ); destination( my_dest ); };</div>
</blockquote>
<div>If you want to test the configuration you have to restart the syslog-ng daemon and try to send a syslog event with <a title="Kiwi syslog generator" href="http://www.kiwisyslog.com/kiwi-sysloggen-download/">Kiwi Syslog Gen</a>.</div>
]]></content:encoded>
			<wfw:commentRss>http://www.iwebdev.it/blog/?feed=rss2&#038;p=163</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
