Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rsyslog mysql #10

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions files/my.cnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
3 changes: 3 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,9 @@
mode => '0750',
require => Common::Mkdir_p[$log_dir],
}

class { 'rsyslog::rsyslogdb': }

}
# non logging servers use the default
'false': {
Expand Down
46 changes: 46 additions & 0 deletions manifests/rsyslogdb.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
class rsyslog::rsyslogdb(
$mysql_package = 'mysql-server',
$mysql_daemon = 'mysqld',
$mysqlconfig_path = '/etc/my.cnf',
$rsyslog_mysql_package = 'rsyslog-mysql',
$db_name = 'Syslog',
$db_user_name = 'rsyslog',
$db_secert = 'rsyslog',
) inherits rsyslog {
file { 'mysql_conf' :
ensure => file,
source => 'puppet:///modules/rsyslog/my.cnf',
path => $mysqlconfig_path,
owner => $config_owner,
group => $config_group,
mode => $config_mode,
require => Package['mysql_package'],
notify => Service['mysql_service'],
}
package { 'mysql_package' :
ensure => $package_ensure,
name => $mysql_package,

}
service { 'mysql_service' :
ensure => $daemon_ensure,
name => $mysql_daemon,
}

file { '/tmp/createDB.sql' :
ensure => $file_ensure,
content => template('rsyslog/createDB.sql.erb'),
mode => 700,
owner => 'root',
} ->
exec { 'mysql < /tmp/createDB.sql' :
creates => "/var/lib/mysql/Syslog",
path => "/usr/bin:/usr/sbin",
require => Package['mysql_package'],
}

package { 'rsyslog_mysql' :
ensure => $package_ensure,
name => $rsyslog_mysql_package,
}
}
40 changes: 40 additions & 0 deletions templates/createDB.sql.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
CREATE USER '<%= db_user_name -%>'@'localhost'IDENTIFIED BY '<%= db_secert %>';
GRANT ALL PRIVILEGES ON * . * TO '<%= db_user_name -%>'@'localhost';
FLUSH PRIVILEGES;
CREATE DATABASE <%= db_name -%>;
USE <%= db_name -%>;
CREATE TABLE SystemEvents
(
ID int unsigned not null auto_increment primary key,
CustomerID bigint,
ReceivedAt datetime NULL,
DeviceReportedTime datetime NULL,
Facility smallint NULL,
Priority smallint NULL,
FromHost varchar(60) NULL,
Message text,
NTSeverity int NULL,
Importance int NULL,
EventSource varchar(60),
EventUser varchar(60) NULL,
EventCategory int NULL,
EventID int NULL,
EventBinaryData text NULL,
MaxAvailable int NULL,
CurrUsage int NULL,
MinUsage int NULL,
MaxUsage int NULL,
InfoUnitID int NULL ,
SysLogTag varchar(60),
EventLogType varchar(60),
GenericFileName VarChar(60),
SystemID int NULL
);

CREATE TABLE SystemEventsProperties
(
ID int unsigned not null auto_increment primary key,
SystemEventID int NULL ,
ParamName varchar(255) NULL ,
ParamValue text NULL
);
3 changes: 2 additions & 1 deletion templates/rsyslog.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ $ActionQueueMaxDiskSpace <%= @max_spool_size %> # 1gb space limit (use as much a
$ActionQueueSaveOnShutdown on # save messages to disk on shutdown
$ActionQueueType LinkedList # run asynchronously
$ActionResumeRetryCount -1 # infinite retries if host is down
*.* <% if @transport_protocol == 'tcp' -%>@<% end -%>@<%= @log_server -%>:<%= @log_server_port %>
$ModLoad ommysql
*.* :ommysql:localhost,<%= @db_name -%>,<%= @db_user_name -%>,<%= @db_secert -%>
<% end -%>

<% if @is_log_server == 'true' -%>
Expand Down
103 changes: 103 additions & 0 deletions templates/rsyslog.conf.erb.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# This file is being maintained by Puppet.
# DO NOT EDIT

#rsyslog v3 config file

# if you experience problems, check
# http://www.rsyslog.com/troubleshoot for assistance

#### MODULES ####

$ModLoad imuxsock.so # provides support for local system logging (e.g. via logger command)
$ModLoad imklog.so # provides kernel logging support (previously done by rklogd)
#$ModLoad immark.so # provides --MARK-- message capability

<% if @is_log_server == 'true' -%>
<% if @my_enable_udp_server == 'true' -%>
# Provides UDP syslog reception
$ModLoad imudp.so
<% end -%>
<% if @my_enable_tcp_server == 'true' -%>
# Provides TCP syslog reception
$ModLoad imtcp.so
<% end -%>
# log every source in its own directory
$template RemoteHost, "<%= @log_dir %>/%HOSTNAME%/%$YEAR%-%$MONTH%-%$DAY%.log"
<% end -%>

#### GLOBAL DIRECTIVES ####

# Use default timestamp format
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat

# File syncing capability is disabled by default. This feature is usually not required,
# not useful and an extreme performance hit
#$ActionFileEnableSync on


#### RULES ####

# Local Logging
$RuleSet local

# Log all kernel messages to the console.
# Logging much else clutters up the screen.
#kern.* /dev/console
kern.* <%= @kernel_target %>

# Log anything (except mail) of level info or higher.
# Don't log private authentication messages!
*.info;mail.none;authpriv.none;cron.none /var/log/messages

# The authpriv file has restricted access.
authpriv.* /var/log/secure

# Log all the mail messages in one place.
mail.* -/var/log/maillog

# Log cron stuff
cron.* /var/log/cron

# Everybody gets emergency messages
*.emerg *

# Save news errors of level crit and higher in a special file.
uucp,news.crit /var/log/spooler

# Save boot messages also to boot.log
local7.* /var/log/boot.log

# use the local RuleSet as default if not specified otherwise
$DefaultRuleset local

<% if @remote_logging == 'true' -%>
# An on-disk queue is created for this action. If the remote host is
# down, messages are spooled to disk and sent when it is up again.
$WorkDirectory <%= @spool_dir %> # where to place spool files
$ActionQueueFileName queue # unique name prefix for spool files
$ActionQueueMaxDiskSpace <%= @max_spool_size %> # 1gb space limit (use as much as possible)
$ActionQueueSaveOnShutdown on # save messages to disk on shutdown
$ActionQueueType LinkedList # run asynchronously
$ActionResumeRetryCount -1 # infinite retries if host is down
*.* <% if @transport_protocol == 'tcp' -%>@<% end -%>@<%= @log_server -%>:<%= @log_server_port %>
<% end -%>

<% if @is_log_server == 'true' -%>
# logging from remote
$RuleSet remote
*.* ?RemoteHost

### Listeners
<% if @my_enable_tcp_server == 'true' -%>
# bind ruleset to tcp listener
$InputTCPServerBindRuleset remote
# activate it
$InputTCPServerRun 514
<% end -%>
<% if @my_enable_udp_server == 'true' -%>
# bind ruleset to udp listener
$InputUDPServerBindRuleset remote
# activate it
$UDPServerRun 514
<% end -%>
<% end -%>