<commit_before>#!/usr/bin/env ruby
# check-beanstalk-watchers.rb
# ===
# Author: <NAME> <<EMAIL>>
#
# Released under the same terms as Sensu (the MIT license); see LICENSE
# for details.

require 'rubygems' if RUBY_VERSION < '1.9.0'
require 'sensu-plugin/check/cli'
require 'beanstalk-client'

class CheckBeanstalkWatchers < Sensu::Plugin::Check::CLI
  option :host,
    :short   => '-H HOST',
    :default => 'localhost'
  option :port,
    :short   => '-p PORT',
    :default => '11300'
  option :tube,
    :short   => '-t TUBE'
  option :crit,
    :short   => '-c CRIT_THRESHOLD',
    :proc    => proc { |a| a.to_i },
    :default => false
  option :warn,
    :short   => '-w WARN_THRESHOLD',
    :proc    => proc { |a| a.to_i },
    :default => false

  def run
    unknown "Tube was not set" unless config[:tube]
    begin
      beanstalk = Beanstalk::Connection.new(
        "#{config[:host]}:#{config[:port]}"
      )
    rescue Exception => e
      critical "Failed to connect: (#{e})"
    end

    begin
      stats = beanstalk.stats_tube(config[:tube])
      watchers = stats['current-watching'].to_i
    rescue Beanstalk::NotFoundError
      warning "Tube #{config[:tube]} not found"
    end
    if not watchers
      watchers = 0
    end
    if config[:crit] && watchers < config[:crit]
      critical "Required at least #{config[:crit]} watchers but have #{watchers}"
    elsif config[:warn] && watchers < config[:warn]<commit_msg>make travis happy<commit_after>#!/usr/bin/env ruby
# check-beanstalk-watchers.rb
# ===
# Author: <NAME> <<EMAIL>>
#
# Released under the same terms as Sensu (the MIT license); see LICENSE
# for details.

require 'rubygems' if RUBY_VERSION < '1.9.0'
require 'sensu-plugin/check/cli'
require 'beanstalk-client'

class CheckBeanstalkWatchers < Sensu::Plugin::Check::CLI
  option :host,
    :short   => '-H HOST',
    :default => 'localhost'
  option :port,
    :short   => '-p PORT',
    :default => '11300'
  option :tube,
    :short   => '-t TUBE'
  option :crit,
    :short   => '-c CRIT_THRESHOLD',
    :proc    => proc { |a| a.to_i },
    :default => false
  option :warn,
    :short   => '-w WARN_THRESHOLD',
    :proc    => proc { |a| a.to_i },
    :default => false

  def run
    unknown "Tube was not set" unless config[:tube]
    begin
      beanstalk = Beanstalk::Connection.new(
        "#{config[:host]}:#{config[:port]}"
      )
    rescue Exception => e
      critical "Failed to connect: (#{e})"
    end

    begin
      stats = beanstalk.stats_tube(config[:tube])
      watchers = stats['current-watching'].to_i
    rescue Beanstalk::NotFoundError
      warning "Tube #{config[:tube]} not found"
    end
    unless watchers
      watchers = 0
    end
    if config[:crit] && watchers < config[:crit]
      critical "Required at least #{config[:crit]} watchers but have #{watchers}"
    elsif config[:warn] && watchers < config[:warn]
{'fraction_non_alphanumeric': 0.15283540802213003, 'fraction_numerical': 0.006224066390041493, 'mean_word_length': 2.963013698630137, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 33, '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': '2757777', 'n_tokens_mistral': 1008, 'n_tokens_neox': 969, 'n_words': 262}