From 7b9954cc4e86f8fce424d7b0f4d12b4c9cf6e74a Mon Sep 17 00:00:00 2001 From: Fabien Wernli Date: Fri, 21 Aug 2015 16:00:29 +0200 Subject: [PATCH] implement syslog_ng_version fact --- README.md | 5 ++++ lib/facter/syslog_ng_version.rb | 6 +++++ spec/unit/facter/syslog_ng_version_spec.rb | 30 ++++++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 lib/facter/syslog_ng_version.rb create mode 100644 spec/unit/facter/syslog_ng_version_spec.rb diff --git a/README.md b/README.md index 5598d22..dbec2c7 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ * [What syslog_ng affects](#what-syslog_ng-affects) * [Getting started with syslog_ng](#beginning-with-syslog_ng) 4. [Usage - Configuration options and additional functionality](#usage) + * [Facts](#facts) * [Classes and defined types](#classes-and-defined-types) 5. [Implementation details](#implementation-details) 5. [Limitations - OS compatibility, etc.](#limitations) @@ -151,6 +152,10 @@ Before the generated configuration would be applied, it is written to a temporar it overwrites the real configuration file. So you do not have to worry about configuration errors. +### Facts + +The fact `syslog_ng_version` contains the installed version string *e.g.* `3.7.1` + ### Classes and defined types ####Class: `syslog_ng` diff --git a/lib/facter/syslog_ng_version.rb b/lib/facter/syslog_ng_version.rb new file mode 100644 index 0000000..c67af54 --- /dev/null +++ b/lib/facter/syslog_ng_version.rb @@ -0,0 +1,6 @@ +Facter.add(:syslog_ng_version) do + setcode do + Facter::Util::Resolution.exec("/usr/sbin/syslog-ng --version").lines.find { |l| l =~ /^syslog-ng/}.split(' ')[1] + end +end + diff --git a/spec/unit/facter/syslog_ng_version_spec.rb b/spec/unit/facter/syslog_ng_version_spec.rb new file mode 100644 index 0000000..2ebac1e --- /dev/null +++ b/spec/unit/facter/syslog_ng_version_spec.rb @@ -0,0 +1,30 @@ +require "spec_helper" + +describe Facter::Util::Fact do + before { + Facter.clear + } + + describe "syslog_ng" do + context 'returns version' do + it do + output = <<-EOS +syslog-ng 3.7.1 +Installer-Version: 3.7.1 +Revision: +Compile-Date: Aug 17 2015 14:25:00 +Available-Modules: afamqp,basicfuncs,linux-kmsg-format,csvparser,system-source,sdjournal,afsmtp,afmongodb,mod-java,riemann,afsocket,cryptofuncs,trigger-source,afstomp,lua,confgen,rust,rss,afuser,affile,afsql,dbparser,tfgetent,geoip-plugin,graphite,pseudofile,mod-perl,kvformat,grok-parser,json-plugin,afprog,basicfuncs-plus,monitor-source,syslogformat,mod-python,date-parser +Enable-Debug: off +Enable-GProf: off +Enable-Memtrace: off +Enable-IPv6: on +Enable-Spoof-Source: off +Enable-TCP-Wrapper: off +Enable-Linux-Caps: off + EOS + Facter::Util::Resolution.expects(:exec).with("/usr/sbin/syslog-ng --version").returns(output) + Facter.value(:syslog_ng_version).should == "3.7.1" + end + end + end +end