我正在尝试使用Puppet来自动configurationSplunk监控。 这涉及将文件path列表添加到Splunkconfiguration文件(inputs.conf)。
我们应用程序中的每个angular色(networking服务器,数据库等)都有自己的Puppet模块,其中包含了所有angular色共有的一些基本模块。
受监控的文件在不同angular色之间会有所不同 – 对于我们要监控的/var/log/nginx/error.log的Web服务器。 对于db服务器,/ var / log / postgresql / postgresql.log。 应该为每个angular色监视一些文件(/ var / log / syslog)。
我使用EBR模板填充inputs.conf文件,例如:
# $files is actually a parameter to the logging class $files = ['/var/log/syslog', '/var/log/nginx/error.log'] file {"/opt/splunkforwarder/etc/apps/search/local/inputs.conf": ensure => "present", content => template("logging/splunk_inputs.conf.erb"), require => Package["splunkforwarder"], } # splunk_inputs.conf.erb: <% files.each do |file| %> [monitor://<%= file %>] disabled = false <% end -%>
理想情况下,我想在每个类中包含一个“日志logging”模块,并逐步build立一个应该被监视的文件列表。 该列表应该合并,并在模板中使用$ filesvariables。
像这样的东西:
class base { class {'logging': files => ['fileA', 'fileB'] } } class webserver { require base class {'logging': files => ['file1', 'file2'] } }
…会导致以下文件被监视:fileA,fileB,file1,file2。
一旦最后一行被添加,Splunk将需要重新启动。 我有一位高pipe可以做到这一点,但我不确定最好的时机来运行它。 我希望避免每增加一行后重新启动Splunk。
我有困难devise一个干净的模块布局,支持这一点。 我已经尝试了几种不同的布局,但不幸的是迄今为止没有成功。 虚拟资源可能是一个很好的解决scheme,但我不认为有可能在文件模板中使用之前就已经实现了一个“虚拟variables”。 Augeas似乎也不是正确的解决scheme,虽然也许我在这里错过了一些东西。
有没有人有任何build议,我怎么能做到这一点?
您可以尝试使用concat模块来从不同类中声明的片段构build您的configuration文件
取决于你想要的东西 , puppet-stdlib中的file_line资源可能对你有用:
你可以用两种方法做到这一点。 使用木偶concat或使用导出的资源。 看看使用导出的资源自动添加nagios检查的教程。 类似的东西应该为splunk工作。