Class: RightScale::AuditProxy
Overview
Provides access to core agents audit operation through helper methods that take care of formatting the audits appropriately Audit requests to audit recipes output are buffered as follows:
* Start a timer after each call to audit output
* Reset the timer if a new call to audit output is made
* Actually send the output audit if the total size exceeds
MAX_AUDIT_SIZE or the timer reaches MAX_AUDIT_DELAY
* Audit of any other kind triggers a request and flushes the buffer
Constant Summary collapse
- MAX_AUDIT_SIZE =
Maximum size for accumulated output before sending audit request in characters
5 * 1024
- MAX_AUDIT_DELAY =
Maximum amount of time to wait before sending audit request in seconds
2
Instance Attribute Summary collapse
-
#audit_id ⇒ Object
readonly
(Fixnum) Underlying audit id.
Class Method Summary collapse
-
.create(agent_identity, summary) ⇒ Object
Create a new audit and calls given block back asynchronously with it.
Instance Method Summary collapse
-
#append_error(text, options = {}) ⇒ Object
Append error message to current audit section.
-
#append_info(text, options = {}) ⇒ Object
Append info text to current audit section.
-
#append_output(text) ⇒ Object
Append output to current audit section.
-
#create_new_section(title, options = {}) ⇒ Object
Start new audit section.
-
#initialize(audit_id) ⇒ AuditProxy
constructor
Initialize audit from pre-existing id.
-
#update_status(status, options = {}) ⇒ Object
Update audit summary.
Constructor Details
#initialize(audit_id) ⇒ AuditProxy
Initialize audit from pre-existing id
Parameters
- audit_id(Fixnum)
-
Associated audit id
52 53 54 55 56 57 |
# File 'lib/instance/audit_proxy.rb', line 52 def initialize(audit_id) @audit_id = audit_id @size = 0 @buffer = '' @mutex = Mutex.new end |
Instance Attribute Details
#audit_id ⇒ Object (readonly)
(Fixnum) Underlying audit id
46 47 48 |
# File 'lib/instance/audit_proxy.rb', line 46 def audit_id @audit_id end |
Class Method Details
.create(agent_identity, summary) ⇒ Object
Create a new audit and calls given block back asynchronously with it
Parameters
- agent_identity(AgentIdentity)
-
Agent identity used by core agent to retrieve corresponding account
- summary(String)
-
Summary to be used for newly created audit
Return
- true
-
Always return true
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/instance/audit_proxy.rb', line 67 def self.create(agent_identity, summary) payload = {:agent_identity => agent_identity, :summary => summary, :category => RightScale::EventCategories::NONE} Sender.instance.send_persistent_request("/auditor/create_entry", payload) do |r| res = RightScale::OperationResult.from_results(r) if res.success? audit = new(res.content) yield audit else Log.warning("Failed to create new audit entry with summary '#{summary}': #{res.content}, aborting...") end true end end |
Instance Method Details
#append_error(text, options = {}) ⇒ Object
Append error message to current audit section. A special marker will be prepended to each line of audit to indicate that error message is not some output. Message will be line-wrapped.
Parameters
- text(String)
-
Error text to append to audit entry
- options(String)
-
Optional, must be one of RightScale::EventCategories::CATEGORIES
Return
- true
-
Always return true
129 130 131 |
# File 'lib/instance/audit_proxy.rb', line 129 def append_error(text, ={}) send_audit(:kind => :error, :text => text, :category => [:category]) end |
#append_info(text, options = {}) ⇒ Object
Append info text to current audit section. A special marker will be prepended to each line of audit to indicate that text is not some output. Text will be line-wrapped.
Parameters
- text(String)
-
Informational text to append to audit entry
- options(String)
-
Optional, must be one of RightScale::EventCategories::CATEGORIES
Return
- true
-
Always return true
116 117 118 |
# File 'lib/instance/audit_proxy.rb', line 116 def append_info(text, ={}) send_audit(:kind => :info, :text => text, :category => [:category]) end |
#append_output(text) ⇒ Object
Append output to current audit section
Parameters
- text(String)
-
Output to append to audit entry
Return
- true
-
Always return true
Raise
- ApplicationError
-
If audit id is missing from passed-in options
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/instance/audit_proxy.rb', line 143 def append_output(text) @mutex.synchronize do @buffer << text end EM.next_tick do buffer_size = nil @mutex.synchronize do buffer_size = @buffer.size end if buffer_size > MAX_AUDIT_SIZE flush_buffer else reset_timer end end end |
#create_new_section(title, options = {}) ⇒ Object
Start new audit section
Parameters
- title(String)
-
Title of new audit section, will replace audit status as well
- options(String)
-
Optional, must be one of RightScale::EventCategories::CATEGORIES
Return
- true
-
Always return true
103 104 105 |
# File 'lib/instance/audit_proxy.rb', line 103 def create_new_section(title, ={}) send_audit(:kind => :new_section, :text => title, :category => [:category]) end |
#update_status(status, options = {}) ⇒ Object
Update audit summary
Parameters
- status(String)
-
New audit entry status
- options(String)
-
Optional, must be one of RightScale::EventCategories::CATEGORIES
Return
- true
-
Always return true
91 92 93 |
# File 'lib/instance/audit_proxy.rb', line 91 def update_status(status, ={}) send_audit(:kind => :status, :text => status, :category => [:category]) end |