<commit_before># DataDog webhook handler
#   -- bridges datadog events into hipchat room
#
# Author::    <NAME>  (mailto:<EMAIL>)
# Copyright:: Copyright (c) 2015 <NAME>
# License::   MIT

Hippie::App.controllers :datadog, conditions: {:protect => true} do

  post '/notify/:room/:auth_token' do
    request_payload = convert_json_body(request)
    title           = request_payload["title"]
    event_type      = request_payload["event_type"]
    body            = request_payload["body"]
    link            = request_payload["link"]
    snapshot        = request_payload["snapshot"]
    room            = params['room']
    token           = request_payload['token'] || Hippie::App.room_keys[room]

    halt 500, 'missing room' unless room
    halt 500, 'missing room token' unless token

    color = 'purple'
    color = 'yellow' if title.match(/^\[Triggered\]/)
    color = 'green'  if title.match(/^\[Recovered\]/)

    text_opts = { color: color, token: token }
    html_opts = { color: color, token: token, format: 'html' }

    # post to room
    post_to_room(room, title, text_opts) unless title.length < 4
    post_to_room(room, markdown.render(body.gsub('%%%', '')), html_opts)
    post_to_room(room, "<img src='#{snapshot}'/>", html_opts) unless snapshot.empty? || title.match(/^\[Triggered\]/)
    post_to_room(room, link, text_opts)
  end

end<commit_msg>fix error with datadog when missing snapshot<commit_after># DataDog webhook handler
#   -- bridges datadog events into hipchat room
#
# Author::    <NAME>  (mailto:<EMAIL>)
# Copyright:: Copyright (c) 2015 <NAME>
# License::   MIT

Hippie::App.controllers :datadog, conditions: {:protect => true} do

  post '/notify/:room/:auth_token' do
    request_payload = convert_json_body(request)
    title           = request_payload["title"]
    event_type      = request_payload["event_type"]
    body            = request_payload["body"]
    link            = request_payload["link"]
    snapshot        = request_payload["snapshot"] || ""
    room            = params['room']
    token           = request_payload['token'] || Hippie::App.room_keys[room]

    halt 500, 'missing room' unless room
    halt 500, 'missing room token' unless token

    color = 'purple'
    color = 'yellow' if title.match(/^\[Triggered\]/)
    color = 'green'  if title.match(/^\[Recovered\]/)

    text_opts = { color: color, token: token }
    html_opts = { color: color, token: token, format: 'html' }

    # post to room
    post_to_room(room, title, text_opts) unless title.length < 4
    post_to_room(room, markdown.render(body.gsub('%%%', '')), html_opts)
    post_to_room(room, "<img src='#{snapshot}'/>", html_opts) unless snapshot.empty? || title.match(/^\[Triggered\]/)
    post_to_room(room, link, text_opts)
  end

end
{'fraction_non_alphanumeric': 0.14548073460568958, 'fraction_numerical': 0.00792221822110191, 'mean_word_length': 3.215477996965099, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6928520', 'n_tokens_mistral': 911, 'n_tokens_neox': 880, 'n_words': 215}