Module: RSMP::SiteProxy::Modules::Alarms

Included in:
RSMP::SiteProxy
Defined in:
lib/rsmp/proxy/site/modules/alarms.rb

Overview

Handles alarm messages

Instance Method Summary collapse

Instance Method Details

#process_alarm(message) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/rsmp/proxy/site/modules/alarms.rb', line 6

def process_alarm(message)
  component = find_component message.attribute('cId')
  status = %w[ack aS sS].map { |key| message.attribute(key) }.join(',')
  component.handle_alarm message
  alarm_code = message.attribute('aCId')
  asp = message.attribute('aSp')
  log "Received #{message.type}, #{alarm_code} #{asp} [#{status}]", message: message, level: :log
  acknowledge message
end

#resume_alarm(task, c_id:, a_c_id:, collect: false) ⇒ Object

Send an AlarmResume message and optionally collect the confirming response. When collect: true, returns [message, response]; when collect: false, returns message.



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/rsmp/proxy/site/modules/alarms.rb', line 56

def resume_alarm(task, c_id:, a_c_id:, collect: false)
  message = RSMP::AlarmResume.new(
    'mId' => RSMP::Message.make_m_id,
    'cId' => c_id,
    'aCId' => a_c_id
  )
  if collect
    collect_task = task.async do
      RSMP::AlarmCollector.new(self,
                               m_id: message.m_id,
                               num: 1,
                               matcher: {
                                 'cId' => c_id,
                                 'aCI' => a_c_id,
                                 'aSp' => 'Suspend',
                                 'sS' => /^notSuspended/i
                               },
                               timeout: node.supervisor_settings.dig('default', 'timeouts', 'alarm')).collect!
    end
    send_message message
    [message, collect_task.wait.first]
  else
    send_message message
    message
  end
end

#send_alarm_acknowledgement(component, alarm_code, options = {}) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/rsmp/proxy/site/modules/alarms.rb', line 16

def send_alarm_acknowledgement(component, alarm_code, options = {})
  message = RSMP::AlarmAcknowledged.new({
                                          'cId' => component,
                                          'aCId' => alarm_code
                                        })
  send_message message, validate: options[:validate]
  message
end

#suspend_alarm(task, c_id:, a_c_id:, collect: false) ⇒ Object

Send an AlarmSuspend message and optionally collect the confirming response. When collect: true, returns [message, response]; when collect: false, returns message.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/rsmp/proxy/site/modules/alarms.rb', line 27

def suspend_alarm(task, c_id:, a_c_id:, collect: false)
  message = RSMP::AlarmSuspend.new(
    'mId' => RSMP::Message.make_m_id,
    'cId' => c_id,
    'aCId' => a_c_id
  )
  if collect
    collect_task = task.async do
      RSMP::AlarmCollector.new(self,
                               m_id: message.m_id,
                               num: 1,
                               matcher: {
                                 'cId' => c_id,
                                 'aCI' => a_c_id,
                                 'aSp' => 'Suspend',
                                 'sS' => /^Suspended/i
                               },
                               timeout: node.supervisor_settings.dig('default', 'timeouts', 'alarm')).collect!
    end
    send_message message
    [message, collect_task.wait.first]
  else
    send_message message
    message
  end
end