<commit_before>require 'terminal-table'
require 'optparse'
require 'nagiosharder'

class NagiosHarder
  class Cli

    attr_reader :options, :command, :param, :the_rest, :host, :service

    def initialize(argv)
      @options          = parse_connection_options(argv)
      @command, @param  = argv
      @host, @service   = param.split("/") if param
      @the_rest         = argv[2..-1]
    end

    def run
      return_value = case command
      when 'status'
        service_table do
          client.host_status(host).select do |name, s|
            service.nil? || service == name
          end.map { |name, s| s }
        end
        true
      when /^(ack|acknowledged)$/
        if service.nil?
          client.acknowledge_host(host, the_rest.join(' '))
        else
          client.acknowledge_service(host, service, the_rest.join(' '))
        end
      when /^unack/
        client.unacknowledge_service(host, service)
      when /^(mute|disable_notifications)$/
        client.disable_service_notifications(host, service)
      when /^(unmute|enable_notifications)$/
        client.enable_service_notifications(host, service)
      when 'check'
        if service
          client.schedule_service_check(host, service)
        else<commit_msg>[cli] allow status to check multiple hosts<commit_after>require 'terminal-table'
require 'optparse'
require 'nagiosharder'

class NagiosHarder
  class Cli

    attr_reader :options, :command, :param, :the_rest, :host, :service

    def initialize(argv)
      @options          = parse_connection_options(argv)
      @command, @param  = argv
      @host, @service   = param.split("/") if param
      @the_rest         = argv[2..-1]
    end

    def run
      return_value = case command
      when 'status'
        status_checks = {}

        # for each hostname or checkname we got
        param.each do |check|
          host,service = check.split("/")
          check_info = client.host_status(host)

          # If we were asked about a specific service, get rid of the ones
          # that they didn't ask for
          check_info.reject! { |name,s| service and service != name }

          # accumulate our results
          status_checks.merge!(check_info)
        end

        service_table do
          status_checks.map { |name, s| s }
        end
        true
      when /^(ack|acknowledged)$/
        if service.nil?
          client.acknowledge_host(host, the_rest.join(' '))
        else
          client.acknowledge_service(host, service, the_rest.join(' '))
        end
      when /^unack/
        client.unacknowledge_service(host, service)
      when /^(mute|disable_notifications)$/
        client.disable_service_notifications(host, service)
      when /^(unmute|enable_notifications)$/
        client.enable_service_notifications(host, service)
      when 'check'
        if service
          client.schedule_service_check(host, service)
        else
{'fraction_non_alphanumeric': 0.09962470146707608, 'fraction_numerical': 0.001364721937905152, 'mean_word_length': 2.2650334075723833, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '320353', 'n_tokens_mistral': 881, 'n_tokens_neox': 844, 'n_words': 210}