<commit_before>#!/usr/bin/env ruby
#
# check-rancher-service.rb
#
# Author: <NAME> <<EMAIL>>
#

require 'sensu-plugin/check/cli'
require 'net/http'
require 'json'

class CheckRancherService < Sensu::Plugin::Check::CLI
  option :api_url,
         :description => "Rancher Metadata API URL (default: http://rancher-metadata/2015-07-25)",
         :long => "--api-url <URL>",
         :proc => proc { |s| s.gsub(/\/$/, '') },
         :default => "http://rancher-metadata/2015-07-25"

  option :warn,
         :description => "Warn instead of throwing a critical failure",
         :short => "-w",
         :long => "--warn",
         :boolean => true,
         :default => false

  option :dryrun,
         :description => "Do not send events to sensu client socket",
         :long => "--dryrun",
         :boolean => true,
         :default => false

  def initialize()
    super
  end

  def send_client_socket(data)
    if config[:dryrun]
      puts data.inspect
    else
      sock = UDPSocket.new
      sock.send(data + "\n", 0, "127.0.0.1", 3030)
    end
  end

  def send_ok(check_name, source, msg)
    event = {"name" => check_name, "source" => source, "status" => 0, "output" => "OK: #{msg}", "handler" => config[:handler]}
    send_client_socket(event.to_json)
  end

  def send_warning(check_name, source, msg)
    event = {"name" => check_name, "source" => source, "status" => 1, "output" => "WARNING: #{msg}", "handler" => config[:handler]}
    send_client_socket(event.to_json)
  end

  def send_critical(check_name, source, msg)
    event = {"name" => check_name, "source" => source, "status" => 2, "output" => "CRITICAL: #{msg}", "handler" => config[:handler]}
    send_client_socket(event.to_json)
  end

  def send_unknown(check_name, source, msg)
    event = {"name" => check_name, "source" => source, "status" => 3, "output" => "UNKNOWN: #{msg}", "handler" => config[:handler]}
    send_client_socket(event.to_json)
  end

  def is_error?(data):
    if data.is_a?(Hash) and data.has_key?('code') and data['code'] == 404
      return true
    else
      return false
    end
  end<commit_msg>fixed typo<commit_after>#!/usr/bin/env ruby
#
# check-rancher-service.rb
#
# Author: <NAME> <<EMAIL>>
#

require 'sensu-plugin/check/cli'
require 'net/http'
require 'json'

class CheckRancherService < Sensu::Plugin::Check::CLI
  option :api_url,
         :description => "Rancher Metadata API URL (default: http://rancher-metadata/2015-07-25)",
         :long => "--api-url <URL>",
         :proc => proc { |s| s.gsub(/\/$/, '') },
         :default => "http://rancher-metadata/2015-07-25"

  option :warn,
         :description => "Warn instead of throwing a critical failure",
         :short => "-w",
         :long => "--warn",
         :boolean => true,
         :default => false

  option :dryrun,
         :description => "Do not send events to sensu client socket",
         :long => "--dryrun",
         :boolean => true,
         :default => false

  def initialize()
    super
  end

  def send_client_socket(data)
    if config[:dryrun]
      puts data.inspect
    else
      sock = UDPSocket.new
      sock.send(data + "\n", 0, "127.0.0.1", 3030)
    end
  end

  def send_ok(check_name, source, msg)
    event = {"name" => check_name, "source" => source, "status" => 0, "output" => "OK: #{msg}", "handler" => config[:handler]}
    send_client_socket(event.to_json)
  end

  def send_warning(check_name, source, msg)
    event = {"name" => check_name, "source" => source, "status" => 1, "output" => "WARNING: #{msg}", "handler" => config[:handler]}
    send_client_socket(event.to_json)
  end

  def send_critical(check_name, source, msg)
    event = {"name" => check_name, "source" => source, "status" => 2, "output" => "CRITICAL: #{msg}", "handler" => config[:handler]}
    send_client_socket(event.to_json)
  end

  def send_unknown(check_name, source, msg)
    event = {"name" => check_name, "source" => source, "status" => 3, "output" => "UNKNOWN: #{msg}", "handler" => config[:handler]}
    send_client_socket(event.to_json)
  end

  def is_error?(data)
    if data.is_a?(Hash) and data.has_key?('code') and data['code'] == 404
      return true
    else
      return false
    end
  end
{'fraction_non_alphanumeric': 0.17520151730678046, 'fraction_numerical': 0.016121384542437174, 'mean_word_length': 3.018095238095238, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 77, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '4795259', 'n_tokens_mistral': 1491, 'n_tokens_neox': 1422, 'n_words': 352}