Skip to content

Instantly share code, notes, and snippets.

@jadell
Last active December 16, 2015 13:19
Show Gist options
  • Save jadell/5440543 to your computer and use it in GitHub Desktop.
Save jadell/5440543 to your computer and use it in GitHub Desktop.
Puppet manifests and templates for configuring an instance to talk to Loggly
class base_node {
loggly::device { "application_log": }
loggly::device { "apache_access": }
loggly::device { "apache_error": }
}
# Register a device to a loggly input
#
define loggly::device (
$deviceName = $hostname,
$deviceIp = $ipaddress,
) {
$input = $loggly::inputs[$name]
$inputId = $input[id]
$user = $loggly::API_USER
$pass = $loggly::API_PASS
$url = "https://$loggly::DOMAIN/api/devices/"
$response = "/var/lib/loggly.$inputId.response"
$command = "curl -X POST -u $user:$pass -H \"content-type:text/plain\" -d input_id=$inputId -d ip=$deviceIp -d name=$deviceDns \"$url\" > $response 2>&1"
# Register the device with loggly
exec {"$command":
path => ["/usr/bin", "/bin"],
creates => $response
}
# Setup an rsyslog conf file for this input
file { "/etc/rsyslog.d/60-loggly-$name.conf" :
ensure => present,
owner => "root",
group => "root",
mode => 0644,
content => template($input[template]),
notify => Service["rsyslog"]
}
}
# Loggly dependencies and API configuration
#
class loggly {
include rsyslog
$DOMAIN = 'example.loggly.com'
$API_USER = 'our_api_username'
$API_PASS = 'our_api_password'
$inputs = {
application_log => {
id => 1234,
port => 4321,
file => "/var/log/application.log",
tag => "application",
severity => "info"
},
apache_access => {
id => 4567,
port => 7654,
file => "/var/log/httpd/access.log",
tag => "apache-access",
severity => "info"
},
apache_error => {
id => 6789,
port => 9876,
file => "/var/log/httpd/error.log",
tag => "apache-error",
severity => "error"
}
}
}
# ###############################
# Loggly rules: <%= @name %>
# ###############################
$InputFileName <%= @input['file'] %>
$InputFileTag <%= @input['tag'] %>:
$InputFileStateFile stat-<%= @input['tag'] %>
$InputFileSeverity <%= @input['severity'] %>
$InputRunFileMonitor
if $programname == '<%= @input['tag'] %>' then @@logs.loggly.com:<%= @input['port'] %>
& ~
# provides support for monitoring log files
$ModLoad imfile
# How often should monitored input files be polled?
$InputFilePollInterval 5
# Include all config files in /etc/rsyslog.d/
$IncludeConfig /etc/rsyslog.d/*.conf
# Install and set up some defaults for rsyslog
#
class rsyslog {
package {'rsyslog':
ensure => installed
}
file {'/etc/rsyslog.conf':
ensure => present,
mode => 0644,
owner => 'root',
group => 'root',
source => 'puppet:///modules/rsyslog/rsyslog.conf',
notify => Service['rsyslog']
}
file {'/etc/rsyslog.d':
ensure => directory,
mode => 0755,
owner => 'root',
group => 'root',
notify => Service['rsyslog']
}
service { 'rsyslog':
ensure => true,
enable => true,
require => [ Package['rsyslog'], File['/etc/rsyslog.conf'], File['/etc/rsyslog.d'] ]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment