Class: WavefrontCli::Event
- Includes:
- Wavefront::Mixins
- Defined in:
- lib/wavefront-cli/event.rb
Overview
CLI coverage for the v2 ‘event’ API.
Instance Attribute Summary collapse
-
#state_dir ⇒ Object
readonly
Returns the value of attribute state_dir.
Attributes inherited from Base
#klass, #klass_word, #options, #wf
Instance Method Summary collapse
-
#do_close ⇒ Object
The user doesn’t have to give us an event ID.
- #do_create ⇒ Object
- #do_list ⇒ Object
- #do_show ⇒ Object
- #do_update ⇒ Object
- #post_initialize(_options) ⇒ Object
Methods inherited from Base
#check_status, #dispatch, #display, #do_delete, #do_describe, #do_import, #do_tag_add, #do_tag_clear, #do_tag_delete, #do_tag_set, #do_tags, #do_undelete, #format_var, #handle_error, #handle_response, #import_to_create, #initialize, #load_display_class, #load_file, #mk_creds, #mk_opts, #run, #validate_id, #validate_opts, #validate_tags, #validator_exception, #validator_method
Constructor Details
This class inherits a constructor from WavefrontCli::Base
Instance Attribute Details
#state_dir ⇒ Object (readonly)
Returns the value of attribute state_dir.
12 13 14 |
# File 'lib/wavefront-cli/event.rb', line 12 def state_dir @state_dir end |
Instance Method Details
#do_close ⇒ Object
The user doesn’t have to give us an event ID. If no event name is given, we’ll pop the last event off the stack. If an event name is given and it doesn’t look like a full WF event name, we’ll look for something on the stack. If it does look like a real event, we’ll make and API call straight away.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/wavefront-cli/event.rb', line 74 def do_close ev_file = nil ev = if [:'<id>'] == false pop_event elsif [:'<id>'] =~ /^\d{13}:.+/ ev_file = state_dir + [:'<id>'] [:'<id>'] else pop_event([:'<id>']) end abort "No locally stored event matches '#{options[:'<id>']}'." unless ev res = wf.close(ev) ev_file.unlink if ev_file && ev_file.exist? && res.status.code == 200 res end |
#do_create ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/wavefront-cli/event.rb', line 37 def do_create [:start] = Time.now unless [:start] t_start = parse_time([:start], true) id = [t_start, [:'<event>']].join(':') body = { name: [:'<event>'], startTime: t_start, id: id, annotations: {} } body[:annotations][:details] = [:desc] if [:desc] body[:annotations][:severity] = [:severity] if [:severity] body[:annotations][:type] = [:type] if [:type] body[:hosts] = [:host] if [:host] if [:instant] body[:endTime] = t_start + 1 elsif [:end] body[:endTime] = parse_time([:end], true) end resp = wf.create(body) unless [:nostate] || [:end] || [:instant] create_state_file(id, [:host]) end resp end |
#do_list ⇒ Object
25 26 27 28 29 30 |
# File 'lib/wavefront-cli/event.rb', line 25 def do_list [:start] = Time.now - 600 unless [:start] [:end] = Time.now unless [:end] wf.list([:start], [:end], [:limit] || 100, [:offset] || nil) end |
#do_show ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/wavefront-cli/event.rb', line 93 def do_show begin events = state_dir.children rescue Errno::ENOENT raise 'There is no event state directory on this host.' end if events.size.zero? puts 'No open events.' else events.sort.reverse.each { |e| puts e.basename } end exit end |
#do_update ⇒ Object
32 33 34 35 |
# File 'lib/wavefront-cli/event.rb', line 32 def do_update k, v = [:'<key=value>'].split('=') wf.update([:'<id>'], k => v) end |
#post_initialize(_options) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/wavefront-cli/event.rb', line 15 def post_initialize() begin @state_dir = EVENT_STATE_DIR + Etc.getlogin rescue @state_dir = EVENT_STATE_DIR + 'notty' end create_state_dir end |