我正在puppet中使用.erb来管理apacheflume配置文件(flume将把原木运送到elasticsearch,以便在kibana中进行搜索和排序。)
一些背景知识:它从一个名为logpath的自定义事实真相生成器获取这些信息,它将我的日志路径保持为以下格式:
>MysqlBlah;/var/logs/mysql/error.log:/var/logs/mysql/slow_query.log
>TomcatBlah;/var/logs/tomcat/catalina.out:/var/logs/tomcat/error.log
因此,每个服务都以一个>开头,日志列表以一个;,日志路径用一个分隔符分隔。
我想让我的erb读取它,遍历每个日志文件,得到可以放入flume配置文件的文本。
所有这些似乎都没问题,但我遇到了一个无法追踪的错误:
-:58: syntax error, unexpected $end, expecting ')'
我似乎没有任何未闭合的括号,所以我不知道如何寻找是什么原因造成这一点。
编辑1:
根据@daiku,我在所有变量周围添加了双引号,现在它正在通过语法检查。但是,puppet现在出现以下错误:
Could not find value for 'sourcenamelist'
这是范围问题吗?在 %>
?
编辑2:
我应该看看电话号码的。事实证明,我可以按原来的方式插入变量,导致问题的行号是我附加到列表中的行号(这很有意义,因为我在开始附加到列表之前没有声明该变量)。我现在回到正轨了;一旦我解决了剩下的bug,我就会发布完成的代码。
我的代码如下:
<%
# split on > to get each service
services = @logpaths.split(">")
services.each do |serviceline|
# split on semicolon
service = serviceline.split(";")
servicename = service[0]
# split into logs on colon
logs = service[1].string.split(":")
lognumber = 0
logs.each do |log|
# sourcelist is a space-delimited list of names for each logfile (eg mysql3311-1)
lognumber += 1
sourcename = servicename + "-" + lognumber.to_s + " "
sourcenamelist << sourcename
# sourceconfigs assigns each source to channel, exec path
sourceconfig = "a1.sources.#{sourcename}.type = exec\na1.sources.#{sourcename}.command = tail -F #{log}\na1.sources.#{sourcename}.channels = c1"
sourceconfiglist << sourceconfig
# sourceinterceptors appends sourcename, path, and servicename (you know, for search)
sourceinterceptors = "a1.sources.#{sourcename}.interceptors = i1 i2 i3 i4\na1.sources.#{sourcename}.interceptors.i1.type = timestamp"
sourceinterceptorlist << sourceinterceptors
end
end
-%>
# Name the components on this agent
a1.sources = <%= #{sourcenamelist} -%>
a1.sinks = k1
a1.channels = c1
# Describe/configure the source
<%= #{sourceconfiglist} -%>
# Describe the sink
a1.sinks.k1.type = elasticsearch
a1.sinks.k1.hostNames = (my elasticsearch host):9300
a1.sinks.k1.indexName = flume
a1.sinks.k1.indexType = flume_logs
a1.sinks.k1.clusterName = elasticsearch
a1.sinks.k1.batchSize = 1000
a1.sinks.k1.ttl = 2
a1.sinks.k1.serializer = org.apache.flume.sink.elasticsearch.ElasticSearchLogStashEventSerializer
# Use a channel which buffers events in memory
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100
# Bind the source and sink to the channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1
# interceptor
<%= #{sourceinterceptorlist} -%>
1条答案
按热度按时间z4bn682m1#
你需要用双引号括起来:
a1.sources = <%= "#{sourcenamelist}" -%>
等。