Class: PagerDuty::Escalation
- Inherits:
-
Object
- Object
- PagerDuty::Escalation
- Defined in:
- lib/pagerduty_tools/pagerduty.rb
Instance Method Summary collapse
-
#initialize(levels = nil, policy = nil) ⇒ Escalation
constructor
A new instance of Escalation.
- #label_for_level(level) ⇒ Object
- #label_for_person(person) ⇒ Object
- #level_for_person(person) ⇒ Object
- #parse(dashboard_body) ⇒ Object
Constructor Details
#initialize(levels = nil, policy = nil) ⇒ Escalation
Returns a new instance of Escalation.
117 118 119 120 |
# File 'lib/pagerduty_tools/pagerduty.rb', line 117 def initialize(levels=nil, policy = nil) @levels = levels @policy = policy end |
Instance Method Details
#label_for_level(level) ⇒ Object
165 166 167 |
# File 'lib/pagerduty_tools/pagerduty.rb', line 165 def label_for_level(level) @results.find {|result| result['level'] == level }['label'] end |
#label_for_person(person) ⇒ Object
169 170 171 |
# File 'lib/pagerduty_tools/pagerduty.rb', line 169 def label_for_person(person) @results.find {|result| result['person'] == person }['label'] end |
#level_for_person(person) ⇒ Object
173 174 175 |
# File 'lib/pagerduty_tools/pagerduty.rb', line 173 def level_for_person(person) @results.find {|result| result['person'] == person }['level'] end |
#parse(dashboard_body) ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/pagerduty_tools/pagerduty.rb', line 122 def parse(dashboard_body) # Scrape out the on-call list from the Dashboard HTML. policies = Nokogiri::HTML(dashboard_body).css("div.whois_oncall") oncall = if @policy policies.detect do |policy| policy.css('h4 a').text == @policy end else policies.first end @results = [] oncall.css("div").each do |div| level_text = div.css("span > strong").text level_text =~ /Level (\d+)\:/ level = $1 # PagerDuty sometimes adds a comment saying what the rotation is called # for this level. If it's there, use it, or fall back to a generic label. label_text = div.xpath("span/comment()").text label = label_text[/\(<[^>]+>(.+) on-call<\/a>\)/, 1] || "Level #{level}" person = div.css("span > a") start_time, end_time = div.css("span.time").text.split(" - ").map {|text| text.strip } if @levels == nil or @levels.length == 0 or @levels.include?(level) @results << { 'level' => level, 'label' => label, 'person' => person.text, 'person_path' => person.first['href'], 'start_time' => start_time, 'end_time' => end_time } end end return @results end |