<commit_before>#!/usr/bin/env ruby

require 'rubygems' if RUBY_VERSION < '1.9.0'
require 'sensu-handler'
require 'socket'
require 'httparty'
require 'json'
require 'timeout'


class Alerta < Sensu::Handler

  def short_name
    @event['client']['name'] + '/' + @event['check']['name']
  end

  def action_to_string
    @event['action'].eql?('resolve') ? "RESOLVED" : "ALERT"
  end

  def status_to_severity
    case @event['check']['status']
      when 0
        "normal"
      when 1
        "warning"
      when 2
        "critical"
      else
        "unknown"
    end
  end

  def handle
    endpoint = settings['alerta']['endpoint'] || 'http://localhost:8080'
    key = settings['alerta']['key'] || nil

    url = endpoint + '/alert'
    puts url
    hostname = Socket.gethostname

    environment = @event['check']['environment'] || 'Production'
    subscribers = @event['check']['subscribers'] || []

    payload = {
      "origin" => "sensu/#{hostname}",
      "resource" => "#{@event['client']['name']}:#{@event['client']['address']}",
      "event" => "#{@event['check']['name']}",
      "group" => "Sensu",
      "severity" => "#{status_to_severity}",
      "environment" => environment,
      "service" => @event['client']['subscriptions'],
      "tags" => [
        "handler=#{@event['check']['handler']}",
      ],
      "text" => "#{@event['check']['output']}",
      "summary" => "#{action_to_string} - #{short_name}",
      "value" => "",
      "type" => "sensuAlert",
      "attributes" => {
        "subscribers" => "subscribers.join(",")}",
        "thresholdInfo" => "#{@event['action']}: #{@event['check']['command']}"
      },
      "rawData" => "#{@event.to_json}"
    }.to_json
    # puts payload

    headers = { 'Content-Type' => 'application/json' }
    if key
      headers['Authorization'] = 'Key ' + key
    end<commit_msg>Fix typo<commit_after>#!/usr/bin/env ruby

require 'rubygems' if RUBY_VERSION < '1.9.0'
require 'sensu-handler'
require 'socket'
require 'httparty'
require 'json'
require 'timeout'


class Alerta < Sensu::Handler

  def short_name
    @event['client']['name'] + '/' + @event['check']['name']
  end

  def action_to_string
    @event['action'].eql?('resolve') ? "RESOLVED" : "ALERT"
  end

  def status_to_severity
    case @event['check']['status']
      when 0
        "normal"
      when 1
        "warning"
      when 2
        "critical"
      else
        "unknown"
    end
  end

  def handle
    endpoint = settings['alerta']['endpoint'] || 'http://localhost:8080'
    key = settings['alerta']['key'] || nil

    url = endpoint + '/alert'
    puts url
    hostname = Socket.gethostname

    environment = @event['check']['environment'] || 'Production'
    subscribers = @event['check']['subscribers'] || []

    payload = {
      "origin" => "sensu/#{hostname}",
      "resource" => "#{@event['client']['name']}:#{@event['client']['address']}",
      "event" => "#{@event['check']['name']}",
      "group" => "Sensu",
      "severity" => "#{status_to_severity}",
      "environment" => environment,
      "service" => @event['client']['subscriptions'],
      "tags" => [
        "handler=#{@event['check']['handler']}",
      ],
      "text" => "#{@event['check']['output']}",
      "summary" => "#{action_to_string} - #{short_name}",
      "value" => "",
      "type" => "sensuAlert",
      "attributes" => {
        "subscribers" => "#{subscribers.join(",")}",
        "thresholdInfo" => "#{@event['action']}: #{@event['check']['command']}"
      },
      "rawData" => "#{@event.to_json}"
    }.to_json
    # puts payload

    headers = { 'Content-Type' => 'application/json' }
    if key
      headers['Authorization'] = 'Key ' + key
    end
{'fraction_non_alphanumeric': 0.2164642375168691, 'fraction_numerical': 0.005398110661268556, 'mean_word_length': 3.0458515283842793, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 37, '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': '2031089', 'n_tokens_mistral': 1242, 'n_tokens_neox': 1203, 'n_words': 226}