diff options
-rw-r--r-- | README.md | 61 | ||||
-rw-r--r-- | manifests/database.pp | 32 | ||||
-rw-r--r-- | manifests/params.pp | 10 | ||||
-rw-r--r-- | manifests/snippet.pp | 15 | ||||
-rw-r--r-- | templates/database.conf.erb | 6 | ||||
-rw-r--r-- | tests/database.pp | 9 |
6 files changed, 112 insertions, 21 deletions
@@ -30,6 +30,23 @@ Manage rsyslog client and server via Puppet } ``` +#### Logging to a MySQL or PostgreSQL database + +Events can also be logged to a MySQL or PostgreSQL database. The database needs to be deployed separately, either locally or remotely. Schema are available from the `rsyslog` source: + + * [MySQL schema](http://git.adiscon.com/?p=rsyslog.git;a=blob_plain;f=plugins/ommysql/createDB.sql) + * [PostgreSQL schema](http://git.adiscon.com/?p=rsyslog.git;a=blob_plain;f=plugins/ompgsql/createDB.sql) + +Declare the following to configure the connection: +```` + class { 'rsyslog::database': + backend => 'mysql', + server => 'localhost', + database => 'Syslog', + username => 'rsyslog', + password => 'secret', + } +```` ### Server #### Using default values @@ -51,29 +68,35 @@ Manage rsyslog client and server via Puppet Both can be installed at the same time. - ## PARAMETERS The following lists all the class parameters this module accepts. - RSYSLOG::SERVER CLASS PARAMETERS VALUES DESCRIPTION - -------------------------------------------------------------- - enable_tcp true,false Enable TCP listener. Defaults to true. - enable_udp true,false Enable UDP listener. Defaults to true. - enable_onefile true,false Only one logfile per remote host. Defaults to false. - server_dir STRING Folder where logs will be stored on the server. Defaults to '/srv/log/' - custom_config STRING Specify your own template to use for server config. Defaults to undef. Example usage: custom_config => 'rsyslog/my_config.erb' - high_precision_timestamps true,false Whether or not to use high precision timestamps. - - RSYSLOG::CLIENT CLASS PARAMETERS VALUES DESCRIPTION - -------------------------------------------------------------- - log_remote true,false Log Remotely. Defaults to true. - remote_type 'tcp','udp' Which protocol to use when logging remotely. Defaults to 'tcp'. - log_local true,false Log locally. Defualts to false. - log_auth_local true,false Just log auth facility locally. Defaults to false. - custom_config STRING Specify your own template to use for client config. Defaults to undef. Example usage: custom_config => 'rsyslog/my_config.erb - server STRING Rsyslog server to log to. Will be used in the client configuration file. - + RSYSLOG::SERVER CLASS PARAMETERS VALUES DESCRIPTION + ------------------------------------------------------------------- + enable_tcp true,false Enable TCP listener. Defaults to true. + enable_udp true,false Enable UDP listener. Defaults to true. + enable_onefile true,false Only one logfile per remote host. Defaults to false. + server_dir STRING Folder where logs will be stored on the server. Defaults to '/srv/log/' + custom_config STRING Specify your own template to use for server config. Defaults to undef. Example usage: custom_config => 'rsyslog/my_config.erb' + high_precision_timestamps true,false Whether or not to use high precision timestamps. + + RSYSLOG::CLIENT CLASS PARAMETERS VALUES DESCRIPTION + ------------------------------------------------------------------- + log_remote true,false Log Remotely. Defaults to true. + remote_type 'tcp','udp' Which protocol to use when logging remotely. Defaults to 'tcp'. + log_local true,false Log locally. Defualts to false. + log_auth_local true,false Just log auth facility locally. Defaults to false. + custom_config STRING Specify your own template to use for client config. Defaults to undef. Example usage: custom_config => 'rsyslog/my_config.erb + server STRING Rsyslog server to log to. Will be used in the client configuration file. + + RSYSLOG::DATABASE CLASS PARAMETERS VALUES DESCRIPTION + ------------------------------------------------------------------- + backend 'mysql','pgsql' Database backend (MySQL or PostgreSQL). + server STRING Database server. + database STRING Database name. + username STRING Database username. + password STRING Database password. ### Other notes diff --git a/manifests/database.pp b/manifests/database.pp new file mode 100644 index 0000000..183c870 --- /dev/null +++ b/manifests/database.pp @@ -0,0 +1,32 @@ +class rsyslog::database ( + $backend, + $server, + $database, + $username, + $password, +) inherits rsyslog { + + $db_module = "om${backend}" + $db_conf = "${rsyslog::params::rsyslog_d}${backend}.conf" + + case $backend { + mysql: { $db_package = $rsyslog::params::mysql_package_name } + pgsql: { $db_package = $rsyslog::params::pgsql_package_name } + default: { fail("Unsupported backend: ${backend}. Only MySQL (mysql) and PostgreSQL (pgsql) are supported.") } + } + + package { $db_package: + ensure => $rsyslog::params::package_status, + before => File[$db_conf], + } + + file { $db_conf: + ensure => present, + owner => root, + group => $rsyslog::params::run_group, + mode => '0600', + content => template("${module_name}/database.conf.erb"), + require => Class['rsyslog::config'], + notify => Class['rsyslog::service'], + } +} diff --git a/manifests/params.pp b/manifests/params.pp index edf0bc1..96c0b27 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -3,6 +3,8 @@ class rsyslog::params { debian: { $rsyslog_package_name = 'rsyslog' $relp_package_name = 'rsyslog-relp' + $mysql_package_name = 'rsyslog-mysql' + $pgsql_package_name = 'rsyslog-pgsql' $package_status = 'latest' $rsyslog_d = '/etc/rsyslog.d/' $rsyslog_conf = '/etc/rsyslog.conf' @@ -22,6 +24,8 @@ class rsyslog::params { redhat: { $rsyslog_package_name = 'rsyslog' $relp_package_name = 'rsyslog-relp' + $mysql_package_name = 'rsyslog-mysql' + $pgsql_package_name = 'rsyslog-pgsql' $package_status = 'latest' $rsyslog_d = '/etc/rsyslog.d/' $rsyslog_conf = '/etc/rsyslog.conf' @@ -39,8 +43,10 @@ class rsyslog::params { $server_conf = "${rsyslog_d}server.conf" } freebsd: { - $rsyslog_package_name = 'rsyslog5' - $relp_package_name = 'rsyslog5-relp' + $rsyslog_package_name = 'sysutils/rsyslog5' + $relp_package_name = 'sysutils/rsyslog5-relp' + $mysql_package_name = 'sysutils/rsyslog5-mysql' + $pgsql_package_name = 'sysutils/rsyslog5-pgsql' $package_status = 'present' $rsyslog_d = '/etc/syslog.d/' $rsyslog_conf = '/etc/syslog.conf' diff --git a/manifests/snippet.pp b/manifests/snippet.pp new file mode 100644 index 0000000..d59a829 --- /dev/null +++ b/manifests/snippet.pp @@ -0,0 +1,15 @@ +define rsyslog::snippet( + $content, + $ensure = 'present' +) { + include rsyslog + + file { "${rsyslog::params::rsyslog_d}${name}.conf": + ensure => $ensure, + owner => $rsyslog::params::run_user, + group => $rsyslog::params::run_group, + content => "${content}\n", + require => Class['rsyslog::config'], + notify => Class['rsyslog::service'], + } +} diff --git a/templates/database.conf.erb b/templates/database.conf.erb new file mode 100644 index 0000000..174cef2 --- /dev/null +++ b/templates/database.conf.erb @@ -0,0 +1,6 @@ +# File is managed by Puppet + +## Configuration file for rsyslog-<%= backend %> + +$ModLoad <%= db_module %> +*.* :<%= db_module -%>:<%= server -%>,<%= database -%>,<%= username -%>,<%= password %> diff --git a/tests/database.pp b/tests/database.pp new file mode 100644 index 0000000..269be69 --- /dev/null +++ b/tests/database.pp @@ -0,0 +1,9 @@ +include rsyslog + +class { 'rsyslog::database': + backend => 'mysql', + server => 'localhost', + database => 'Syslog', + username => 'rsyslog', + password => 'secret', +} |