Class: VictorOps::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/victor_ops/client.rb,
lib/victor_ops/client/version.rb,
lib/victor_ops/client/exceptions.rb,
lib/victor_ops/client/persistence.rb

Defined Under Namespace

Classes: Error, MissingMessageType, MissingSettings, NotYetImplemented, PostFailure

Constant Summary collapse

VERSION =
'0.3.0'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Client

Returns a new instance of Client.



15
16
17
18
19
20
21
# File 'lib/victor_ops/client.rb', line 15

def initialize(opts)
  @settings = OpenStruct.new opts
  AwesomePrint.defaults = { indent: -2, plain: true }
  set_default_settings
  configure_data_store unless settings.persist.nil?
  raise VictorOps::Client::MissingSettings unless valid_settings?
end

Instance Attribute Details

#dbObject

Returns the value of attribute db.



5
6
7
# File 'lib/victor_ops/client/persistence.rb', line 5

def db
  @db
end

#settingsObject

Returns the value of attribute settings.



13
14
15
# File 'lib/victor_ops/client.rb', line 13

def settings
  @settings
end

Instance Method Details

#ack(data) ⇒ Object



59
60
61
# File 'lib/victor_ops/client.rb', line 59

def ack(data)
  post ack_payload(data)
end

#configure_data_storeObject



7
8
9
10
11
# File 'lib/victor_ops/client/persistence.rb', line 7

def configure_data_store
  settings.store_file = VictorOps::Defaults::Daybreak::PATH unless settings.store_file
  @db = Daybreak::DB.new settings.store_file
  ObjectSpace.define_finalizer(self, proc { shutdown })
end

#critical(data) ⇒ Object



47
48
49
# File 'lib/victor_ops/client.rb', line 47

def critical(data)
  post critical_payload(data)
end

#delete(key) ⇒ Object



21
22
23
# File 'lib/victor_ops/client/persistence.rb', line 21

def delete(key)
  db.delete! key
end

#entity_display_nameObject



23
24
25
26
27
28
29
# File 'lib/victor_ops/client.rb', line 23

def entity_display_name
  if settings.entity_display_name.nil?
    "#{settings.host}/#{settings.name}"
  else
    settings.entity_display_name
  end
end

#entity_display_name=(str) ⇒ Object



31
32
33
# File 'lib/victor_ops/client.rb', line 31

def entity_display_name=(str)
  settings.entity_display_name = str
end

#info(data) ⇒ Object



55
56
57
# File 'lib/victor_ops/client.rb', line 55

def info(data)
  post info_payload(data)
end

#monitoring_toolObject



35
36
37
38
39
40
41
# File 'lib/victor_ops/client.rb', line 35

def monitoring_tool
  if settings.monitoring_tool.nil?
    "#{settings.routing_key}::#{settings.name}"
  else
    settings.monitoring_tool
  end
end

#monitoring_tool=(str) ⇒ Object



43
44
45
# File 'lib/victor_ops/client.rb', line 43

def monitoring_tool=(str)
  settings.monitoring_tool = str
end

#recovery(data) ⇒ Object



63
64
65
# File 'lib/victor_ops/client.rb', line 63

def recovery(data)
  post recovery_payload(data)
end

#retrieve(key) ⇒ Object



17
18
19
# File 'lib/victor_ops/client/persistence.rb', line 17

def retrieve(key)
  db[key]
end

#set(key, value) ⇒ Object



13
14
15
# File 'lib/victor_ops/client/persistence.rb', line 13

def set(key, value)
  db.set! key, value
end

#shutdownObject



25
26
27
28
29
# File 'lib/victor_ops/client/persistence.rb', line 25

def shutdown
  db.flush
  db.compact
  db.close
end

#warn(data) ⇒ Object



51
52
53
# File 'lib/victor_ops/client.rb', line 51

def warn(data)
  post warn_payload(data)
end