Last active
December 16, 2015 13:19
-
-
Save jadell/5440543 to your computer and use it in GitHub Desktop.
Puppet manifests and templates for configuring an instance to talk to Loggly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class base_node { | |
loggly::device { "application_log": } | |
loggly::device { "apache_access": } | |
loggly::device { "apache_error": } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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"] | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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" | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ############################### | |
# 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'] %> | |
& ~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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