Class: TestPack1::AlertItem

Inherits:
BaseModel show all
Defined in:
lib/test_pack_1/models/alert_item.rb

Overview

An alert generated for a device based on a rule.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(device_id = nil, rule_id = nil, timestamp_start = nil, timestamp_end = nil, message = nil, comment = nil, description = nil, details = nil) ⇒ AlertItem

Returns a new instance of AlertItem.



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/test_pack_1/models/alert_item.rb', line 59

def initialize(device_id = nil,
               rule_id = nil,
               timestamp_start = nil,
               timestamp_end = nil,
               message = nil,
               comment = nil,
               description = nil,
               details = nil)
  @device_id = device_id
  @rule_id = rule_id
  @timestamp_start = timestamp_start
  @timestamp_end = timestamp_end
  @message = message
  @comment = comment
  @description = description
  @details = details
end

Instance Attribute Details

#commentString

A user comment associated with the alert.

Returns:



34
35
36
# File 'lib/test_pack_1/models/alert_item.rb', line 34

def comment
  @comment
end

#descriptionString

A description explaning the rule the alert is based on.

Returns:



38
39
40
# File 'lib/test_pack_1/models/alert_item.rb', line 38

def description
  @description
end

#detailsString

Additional details for the alert. Note that the structure of this data is subject to change.

Returns:



43
44
45
# File 'lib/test_pack_1/models/alert_item.rb', line 43

def details
  @details
end

#device_idInteger

The id of the device the alert was generated for.

Returns:

  • (Integer)


12
13
14
# File 'lib/test_pack_1/models/alert_item.rb', line 12

def device_id
  @device_id
end

#messageString

The title of the rule the alert is based on.

Returns:



30
31
32
# File 'lib/test_pack_1/models/alert_item.rb', line 30

def message
  @message
end

#rule_idInteger

The id of the rule the alert is based on.

Returns:

  • (Integer)


16
17
18
# File 'lib/test_pack_1/models/alert_item.rb', line 16

def rule_id
  @rule_id
end

#timestamp_endDateTime

The timestamp when the alert ended. The timestamp is in your system-configured time zone without UTC offset.

Returns:

  • (DateTime)


26
27
28
# File 'lib/test_pack_1/models/alert_item.rb', line 26

def timestamp_end
  @timestamp_end
end

#timestamp_startDateTime

The timestamp when the alert began. The timestamp is in your system-configured time zone without UTC offset.

Returns:

  • (DateTime)


21
22
23
# File 'lib/test_pack_1/models/alert_item.rb', line 21

def timestamp_start
  @timestamp_start
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/test_pack_1/models/alert_item.rb', line 78

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.

  device_id = hash['deviceId']
  rule_id = hash['ruleId']
  timestamp_start = APIHelper.rfc3339(hash['timestampStart']) if
    hash['timestampStart']
  timestamp_end = APIHelper.rfc3339(hash['timestampEnd']) if
    hash['timestampEnd']
  message = hash['message']
  comment = hash['comment']
  description = hash['description']
  details = hash['details']

  # Create object from extracted values.

  AlertItem.new(device_id,
                rule_id,
                timestamp_start,
                timestamp_end,
                message,
                comment,
                description,
                details)
end

.namesObject

A mapping from model property names to API property names.



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/test_pack_1/models/alert_item.rb', line 46

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['device_id'] = 'deviceId'
  @_hash['rule_id'] = 'ruleId'
  @_hash['timestamp_start'] = 'timestampStart'
  @_hash['timestamp_end'] = 'timestampEnd'
  @_hash['message'] = 'message'
  @_hash['comment'] = 'comment'
  @_hash['description'] = 'description'
  @_hash['details'] = 'details'
  @_hash
end