<commit_before>#!/usr/bin/ruby
require 'nagiosplugin'
require 'slop'


#TODO need to parse args like anormale nagios plugin
opts = Slop.parse do
  banner 'Usage: foo.rb [options]'

  on 'w', 'warning','threshold for worning'
  on 'c', 'critical', 'threshold for critical'
  on 'v', 'verbose', 'Enable verbose mode'
end

# if ARGV is `--name Lee -v`
opts.verbose?  #=> true
#puts opts.to_hash   #=> {:name=>"Lee", :password=><PASSWORD>, :verbose=>true}

# simple helpers to find if a string is a number
class String
  def is_number?
    true if Float self rescue false
  end
end


class DockerInfo < NagiosPlugin::Plugin
  @critical = false
  @warning = false
  @ok = false
  
  # initialize with a call to docker info
  def initialize
    cmd = 'docker info 2>&1'
    @info = {}
    IO.popen(cmd).each do |line|
      if(line.include?("Cannot connect") || line.include?("permission denied"))
        @critical = true
        @info["CRITICAL"]=line
      else
        l=line.split(':')
        @info[l[0].delete(' ')]=l[1][0..-2]
      end
    end.close
    @ok =  $?.success?
    
    
    #@info.delete("WARNING")# remove for now warning from docker info
    @warning = @info.has_key?("WARNING")
  end

  def critical?
    @msg=@info["CRITICAL"]
    @critical
  end

  def warning?
    @msg=@info["WARNING"]
    @warning 
  end

  def ok?<commit_msg>added performance data on warning<commit_after>#!/usr/bin/ruby
require 'nagiosplugin'
require 'slop'


#TODO need to parse args like anormale nagios plugin
opts = Slop.parse do
  banner 'Usage: foo.rb [options]'

  on 'w', 'warning','threshold for worning'
  on 'c', 'critical', 'threshold for critical'
  on 'v', 'verbose', 'Enable verbose mode'
end

# if ARGV is `--name Lee -v`
opts.verbose?  #=> true
#puts opts.to_hash   #=> {:name=>"Lee", :password=><PASSWORD>, :verbose=>true}

# simple helpers to find if a string is a number
class String
  def is_number?
    true if Float self rescue false
  end
end


class DockerInfo < NagiosPlugin::Plugin
  @critical = false
  @warning = false
  @ok = false
  
  # initialize with a call to docker info
  def initialize
    cmd = 'docker info 2>&1'
    @info = {}
    IO.popen(cmd).each do |line|
      if(line.include?("Cannot connect") || line.include?("permission denied"))
        @critical = true
        @info["CRITICAL"]=line
      else
        l=line.split(':')
        @info[l[0].delete(' ')]=l[1][0..-2]
      end
    end.close
    @ok =  $?.success?
    
    
    #@<EMAIL>.delete("WARNING")# remove for now warning from docker info
    @warning = @info.has_key?("WARNING")
  end

  def critical?
    @msg=@info["CRITICAL"]
    @critical
  end

  def warning?
    @msg=@info["WARNING"]
    perf_data=" |"
    @info.each do |label,val|
      if (val.is_number?)
         perf_data+="#{label}=#{val.delete(' ')} ,"
      end
    end
    @msg=@msg + perf_data[0..-2]  
    @warning 
  end

  def ok?
{'fraction_non_alphanumeric': 0.14974182444061962, 'fraction_numerical': 0.004819277108433735, 'mean_word_length': 2.93234100135318, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 18, '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': '6222730', 'n_tokens_mistral': 1044, 'n_tokens_neox': 999, 'n_words': 290}