diff --git a/deployment_scripts/puppet/manifests/compute.pp b/deployment_scripts/puppet/manifests/compute.pp index e501b28b9..5392af7c1 100644 --- a/deployment_scripts/puppet/manifests/compute.pp +++ b/deployment_scripts/puppet/manifests/compute.pp @@ -13,6 +13,8 @@ else { class { 'lma_collector::logs::openstack': } +class { 'lma_collector::logs::libvirt': } + if $enable_notifications { class { 'lma_collector::notifications::compute': topics => $notification_topics, diff --git a/deployment_scripts/puppet/modules/lma_collector/files/plugins/common/patterns.lua b/deployment_scripts/puppet/modules/lma_collector/files/plugins/common/patterns.lua index 68ac0742b..3995f1424 100644 --- a/deployment_scripts/puppet/modules/lma_collector/files/plugins/common/patterns.lua +++ b/deployment_scripts/puppet/modules/lma_collector/files/plugins/common/patterns.lua @@ -48,7 +48,7 @@ Uuid = uuid_nodash + uuid_dash -- -- The datetime string can be formatted as -- 'YYYY-MM-DD( |T)HH:MM:SS(.ssssss)?(offset indicator)?' -TimestampTable = l.Ct(dt.rfc3339_full_date * (sp + l.P"T") * dt.rfc3339_partial_time * dt.rfc3339_time_offset^-1) +TimestampTable = l.Ct(dt.rfc3339_full_date * (sp + l.P"T") * dt.rfc3339_partial_time * (dt.rfc3339_time_offset + dt.timezone_offset)^-1) -- Returns the parsed datetime converted to nanosec Timestamp = TimestampTable / dt.time_to_ns diff --git a/deployment_scripts/puppet/modules/lma_collector/files/plugins/decoders/libvirt_log.lua b/deployment_scripts/puppet/modules/lma_collector/files/plugins/decoders/libvirt_log.lua new file mode 100644 index 000000000..f0863c43b --- /dev/null +++ b/deployment_scripts/puppet/modules/lma_collector/files/plugins/decoders/libvirt_log.lua @@ -0,0 +1,64 @@ +-- Copyright 2015 Mirantis, Inc. +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +local l = require 'lpeg' +l.locale(l) + +local string = require 'string' +local patt = require 'patterns' +local utils = require 'lma_utils' + +local msg = { + Timestamp = nil, + Type = 'log', + Hostname = nil, + Payload = nil, + Pid = nil, + Fields = nil, + Severity = nil, +} + +-- libvirt message logs are formatted like this: +-- +-- 2015-03-26 17:24:52.126+0000: : : Message + +local timestamp = l.Cg(patt.Timestamp, "Timestamp") +local pid = l.Cg(patt.Pid, "Pid") +local severity = l.Cg(l.P"debug" + "info" + "warning" + "error", "Severity") +local message = l.Cg(patt.Message, "Message") + +local grammar = l.Ct(timestamp * ": " * pid * ": " * severity * " : " * message) + +function process_message () + local log = read_message("Payload") + + local m = grammar:match(log) + if not m then + return -1 + end + + m.Severity = string.upper(m.Severity) + + msg.Timestamp = m.Timestamp + msg.Pid = m.Pid + msg.Payload = m.Message + msg.Severity = utils.label_to_severity_map[m.Severity] + + msg.Fields = {} + msg.Fields.severity_label = m.Severity + msg.Fields.programname = 'libvirt' + utils.inject_tags(msg) + + inject_message(msg) + return 0 +end diff --git a/deployment_scripts/puppet/modules/lma_collector/manifests/logs/libvirt.pp b/deployment_scripts/puppet/modules/lma_collector/manifests/logs/libvirt.pp new file mode 100644 index 000000000..f8800c634 --- /dev/null +++ b/deployment_scripts/puppet/modules/lma_collector/manifests/logs/libvirt.pp @@ -0,0 +1,47 @@ +# Class lma_collector::logs::libvirt + +class lma_collector::logs::libvirt { + include lma_collector::params + include lma_collector::service + + $libvirt_dir = '/var/log/libvirt' + $libvirt_log = 'libvirtd.log' + $libvirt_hooks_dir = '/etc/libvirt/hooks' + $libvirt_hook = "${libvirt_hooks_dir}/daemon" + $libvirt_service = $::osfamily ? { + 'debian' => 'libvirt-bin', + default => 'libvirtd' + } + + service {$libvirt_service: } + + file { $libvirt_hooks_dir: + ensure => 'directory', + } + + # libvirt is running as root and by default permission are restricted to + # root user. So we need to enable other users to read this file. + file { $libvirt_hook: + owner => 'root', + group => 'root', + mode => '0700', + content => template('lma_collector/hooks_daemon.erb'), + require => File[$libvirt_hooks_dir], + notify => Service[$libvirt_service], + } + + heka::decoder::sandbox { 'libvirt': + config_dir => $lma_collector::params::config_dir, + filename => "${lma_collector::params::plugins_dir}/decoders/libvirt_log.lua", + } + + heka::input::logstreamer { 'libvirt': + config_dir => $lma_collector::params::config_dir, + log_directory => $libvirt_dir, + file_match => $libvirt_log, + decoder => 'libvirt', + differentiator => '["libvirt"]', + require => Heka::Decoder::Sandbox['libvirt'], + notify => Class['lma_collector::service'], + } +} diff --git a/deployment_scripts/puppet/modules/lma_collector/templates/hooks_daemon.erb b/deployment_scripts/puppet/modules/lma_collector/templates/hooks_daemon.erb new file mode 100644 index 000000000..31683233b --- /dev/null +++ b/deployment_scripts/puppet/modules/lma_collector/templates/hooks_daemon.erb @@ -0,0 +1,3 @@ +#!/bin/bash + +chmod 0644 <%= @libvirt_dir %>/<%= @libvirt_log %>