Class: Chef::EventLoggers::WindowsEventLogger
- Inherits:
-
EventLoggers::Base
- Object
- EventLoggers::Base
- Chef::EventLoggers::WindowsEventLogger
- Defined in:
- lib/chef/event_loggers/windows_eventlog.rb
Constant Summary collapse
- RUN_START_EVENT_ID =
These must match those that are defined in the manifest file
10000- RUN_STARTED_EVENT_ID =
10001- RUN_COMPLETED_EVENT_ID =
10002- RUN_FAILED_EVENT_ID =
10003- EVENT_CATEGORY_ID =
11000- LOG_CATEGORY_ID =
11001- SOURCE =
Since we must install the event logger, this is not really configurable
ChefUtils::Dist::Infra::SHORT.freeze
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ WindowsEventLogger
constructor
A new instance of WindowsEventLogger.
- #run_completed(node) ⇒ Object
-
#run_failed(e) ⇒ Object
Failed chef-client run %1 in %2 seconds.
- #run_start(version, run_status) ⇒ Object
- #run_started(run_status) ⇒ Object
Constructor Details
#initialize ⇒ WindowsEventLogger
Returns a new instance of WindowsEventLogger.
45 46 47 |
# File 'lib/chef/event_loggers/windows_eventlog.rb', line 45 def initialize @eventlog = ::Win32::EventLog.open("Application") end |
Class Method Details
.available? ⇒ Boolean
41 42 43 |
# File 'lib/chef/event_loggers/windows_eventlog.rb', line 41 def self.available? ChefUtils.windows? end |
Instance Method Details
#run_completed(node) ⇒ Object
68 69 70 71 72 73 74 75 |
# File 'lib/chef/event_loggers/windows_eventlog.rb', line 68 def run_completed(node) @eventlog.report_event( event_type: ::Win32::EventLog::INFO_TYPE, source: SOURCE, event_id: RUN_COMPLETED_EVENT_ID, data: [@run_status.run_id, @run_status.elapsed_time.to_s] ) end |
#run_failed(e) ⇒ Object
Failed chef-client run %1 in %2 seconds. Exception type: %3 Exception message: %4 Exception backtrace: %5
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/chef/event_loggers/windows_eventlog.rb', line 81 def run_failed(e) data = if @run_status [@run_status.run_id, @run_status.elapsed_time.to_s] else %w{UNKNOWN UNKNOWN} end @eventlog.report_event( event_type: ::Win32::EventLog::ERROR_TYPE, source: SOURCE, event_id: RUN_FAILED_EVENT_ID, data: data + [e.class.name, e., e.backtrace.join("\n")] ) end |
#run_start(version, run_status) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/chef/event_loggers/windows_eventlog.rb', line 49 def run_start(version, run_status) @eventlog.report_event( event_type: ::Win32::EventLog::INFO_TYPE, source: SOURCE, event_id: RUN_START_EVENT_ID, data: [version] ) end |
#run_started(run_status) ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/chef/event_loggers/windows_eventlog.rb', line 58 def run_started(run_status) @run_status = run_status @eventlog.report_event( event_type: ::Win32::EventLog::INFO_TYPE, source: SOURCE, event_id: RUN_STARTED_EVENT_ID, data: [run_status.run_id] ) end |