summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Reynolds <ferventcoder@gmail.com>2014-07-08 11:37:33 -0500
committerRob Reynolds <ferventcoder@gmail.com>2014-07-08 11:37:33 -0500
commit58799e00a8e1c19f2ebcf386d2feafdee5ae8caf (patch)
tree9f6ed81dbcc298d60281bf16b2b44dd2ee12536b
parent39b1912f81b918f8dbdac24584a81d78ecb9906e (diff)
parent537b0572ddb17c20042d296a6712edf1031e1f9b (diff)
downloadpuppet-58799e00a8e1c19f2ebcf386d2feafdee5ae8caf.tar.gz
Merge branch 'ticket/master/PUP2889-eventlog'
* ticket/master/PUP2889-eventlog: (PUP-2889) Remove dependency on win32-eventlog constants
-rwxr-xr-xext/windows/service/daemon.rb17
-rw-r--r--lib/puppet/util/log/destinations.rb10
-rwxr-xr-xspec/unit/util/log/destinations_spec.rb38
3 files changed, 53 insertions, 12 deletions
diff --git a/ext/windows/service/daemon.rb b/ext/windows/service/daemon.rb
index 718afaf22..70e9caf07 100755
--- a/ext/windows/service/daemon.rb
+++ b/ext/windows/service/daemon.rb
@@ -8,6 +8,9 @@ require 'win32/eventlog'
class WindowsDaemon < Win32::Daemon
CREATE_NEW_CONSOLE = 0x00000010
+ EVENTLOG_ERROR_TYPE = 0x0001
+ EVENTLOG_WARNING_TYPE = 0x0002
+ EVENTLOG_INFORMATION_TYPE = 0x0004
@LOG_TO_FILE = false
LOG_FILE = File.expand_path(File.join(Dir::COMMON_APPDATA, 'PuppetLabs', 'puppet', 'var', 'log', 'windows.log'))
@@ -125,16 +128,12 @@ class WindowsDaemon < Win32::Daemon
end
case level
- when :debug
- report_windows_event(Win32::EventLog::INFO,0x01,msg.to_s)
- when :info
- report_windows_event(Win32::EventLog::INFO,0x01,msg.to_s)
- when :notice
- report_windows_event(Win32::EventLog::INFO,0x01,msg.to_s)
+ when :debug, :info, :notice
+ report_windows_event(EVENTLOG_INFORMATION_TYPE,0x01,msg.to_s)
when :err
- report_windows_event(Win32::EventLog::ERR,0x03,msg.to_s)
+ report_windows_event(EVENTLOG_ERROR_TYPE,0x03,msg.to_s)
else
- report_windows_event(Win32::EventLog::WARN,0x02,msg.to_s)
+ report_windows_event(EVENTLOG_WARNING_TYPE,0x02,msg.to_s)
end
end
end
@@ -145,7 +144,7 @@ class WindowsDaemon < Win32::Daemon
eventlog = Win32::EventLog.open("Application")
eventlog.report_event(
:source => "Puppet",
- :event_type => type, # Win32::EventLog::INFO or WARN, ERROR
+ :event_type => type, # EVENTLOG_ERROR_TYPE, etc
:event_id => id, # 0x01 or 0x02, 0x03 etc.
:data => message # "the message"
)
diff --git a/lib/puppet/util/log/destinations.rb b/lib/puppet/util/log/destinations.rb
index 932007099..6c5cc7f23 100644
--- a/lib/puppet/util/log/destinations.rb
+++ b/lib/puppet/util/log/destinations.rb
@@ -189,6 +189,10 @@ Puppet::Util::Log.newdesttype :array do
end
Puppet::Util::Log.newdesttype :eventlog do
+ Puppet::Util::Log::DestEventlog::EVENTLOG_ERROR_TYPE = 0x0001
+ Puppet::Util::Log::DestEventlog::EVENTLOG_WARNING_TYPE = 0x0002
+ Puppet::Util::Log::DestEventlog::EVENTLOG_INFORMATION_TYPE = 0x0004
+
def self.suitable?(obj)
Puppet.features.eventlog?
end
@@ -200,11 +204,11 @@ Puppet::Util::Log.newdesttype :eventlog do
def to_native(level)
case level
when :debug,:info,:notice
- [Win32::EventLog::INFO, 0x01]
+ [self.class::EVENTLOG_INFORMATION_TYPE, 0x01]
when :warning
- [Win32::EventLog::WARN, 0x02]
+ [self.class::EVENTLOG_WARNING_TYPE, 0x02]
when :err,:alert,:emerg,:crit
- [Win32::EventLog::ERROR, 0x03]
+ [self.class::EVENTLOG_ERROR_TYPE, 0x03]
end
end
diff --git a/spec/unit/util/log/destinations_spec.rb b/spec/unit/util/log/destinations_spec.rb
index a91236dba..82b647647 100755
--- a/spec/unit/util/log/destinations_spec.rb
+++ b/spec/unit/util/log/destinations_spec.rb
@@ -181,3 +181,41 @@ describe Puppet::Util::Log.desttypes[:console] do
end
end
end
+
+
+describe ":eventlog", :if => Puppet::Util::Platform.windows? do
+ let(:klass) { Puppet::Util::Log.desttypes[:eventlog] }
+
+ def expects_message_with_type(klass, level, eventlog_type, eventlog_id)
+ eventlog = stub('eventlog')
+ eventlog.expects(:report_event).with(has_entries(:source => "Puppet", :event_type => eventlog_type, :event_id => eventlog_id, :data => "a hitchhiker: don't panic"))
+ Win32::EventLog.stubs(:open).returns(eventlog)
+
+ msg = Puppet::Util::Log.new(:level => level, :message => "don't panic", :source => "a hitchhiker")
+ dest = klass.new
+ dest.handle(msg)
+ end
+
+ it "supports the eventlog feature" do
+ expect(Puppet.features.eventlog?).to be_true
+ end
+
+ it "logs to the Application event log" do
+ eventlog = stub('eventlog')
+ Win32::EventLog.expects(:open).with('Application').returns(stub('eventlog'))
+
+ klass.new
+ end
+
+ it "logs :debug level as an information type event" do
+ expects_message_with_type(klass, :debug, klass::EVENTLOG_INFORMATION_TYPE, 0x1)
+ end
+
+ it "logs :warning level as an warning type event" do
+ expects_message_with_type(klass, :warning, klass::EVENTLOG_WARNING_TYPE, 0x2)
+ end
+
+ it "logs :err level as an error type event" do
+ expects_message_with_type(klass, :err, klass::EVENTLOG_ERROR_TYPE, 0x3)
+ end
+end