<commit_before>module Sensu
  module Settings
    module Validators
      module Check
        # Validate check execution.
        # Validates: name, command, extension, timeout
        #
        # @param check [Hash] sensu check definition.
        def validate_check_execution(check)
          must_be_a_string(check[:name]) ||
            invalid(check, "check name must be a string")
          must_match_regex(/^[\w\.-]+$/, check[:name]) ||
            invalid(check, "check name cannot contain spaces or special characters")
          must_be_a_string_if_set(check[:command]) ||
            invalid(check, "check command must be a string")
          must_be_a_string_if_set(check[:extension]) ||
            invalid(check, "check extension must be a string")
          (!check[:command].nil? ^ !check[:extension].nil?) ||
            invalid(check, "either check command or extension must be set")
          must_be_a_numeric_if_set(check[:timeout]) ||
            invalid(check, "check timeout must be numeric")
        end

        # Validate check source.
        # Validates: source
        #
        # @param check [Hash] sensu check definition.
        def validate_check_source(check)
          if is_a_string?(check[:source])
            must_match_regex(/^[\w\.-]+$/, check[:source]) ||
              invalid(check, "check source cannot contain spaces or special characters")
          else
            invalid(check, "check source must be a string")
          end
        end

        # Validate check scheduling.
        # Validates: interval, standalone, subscribers
        #
        # @param check [Hash] sensu check definition.
        def validate_check_scheduling(check)
          must_be_boolean_if_set(check[:publish]) ||
            invalid(check, "check publish must be boolean")
          unless check[:publish] == false
            (must_be_an_integer(check[:interval]) && check[:interval] > 0) ||
              invalid(check, "check interval must be an integer")
          end
          must_be_boolean_if_set(check[:standalone]) ||
            invalid(check, "check standalone must be boolean")
          unless check[:standalone]
            if is_an_array?(check[:subscribers])
              items_must_be_strings(check[:subscribers]) ||
                invalid(check, "check subscribers must each be a string")
            else
              invalid(check, "check subscribers must be an array")
            end
          end
        end

        # Validate check handling.
        # Validates: handler, handlers
        #
        # @param check [Hash] sensu check definition.
        def validate_check_handling(check)
          must_be_a_string_if_set(check[:handler]) ||
            invalid(check, "check handler must be a string")
          must_be_an_array_if_set(check[:handlers]) ||
            invalid(check, "check handlers must be an array")
          if is_an_array?(check[:handlers])
            items_must_be_strings(check[:handlers]) ||
              invalid(check, "check handlers must each be a string")
          end
        end

        # Validate check ttl.
        # Validates: ttl
        #
        # @param check [Hash] sensu check definition.
        def validate_check_ttl(check)
          if is_an_integer?(check[:ttl])
            check[:ttl] > 0 ||
              invalid(check, "check ttl must be greater than 0")
          else
            invalid(check, "check ttl must be an integer")
          end
        end

        # Validate check flap detection.
        # Validates: low_flap_threshold, high_flap_threshold
        #
        # @param check [Hash] sensu check definition.
        def validate_check_flap_detection(check)
          if either_are_set?(check[:low_flap_threshold], check[:high_flap_threshold])
            must_be_an_integer(check[:low_flap_threshold]) ||
              invalid(check, "check low flap threshold must be an integer")
            must_be_an_integer(check[:high_flap_threshold]) ||
              invalid(check, "check high flap threshold must be an integer")
          end
        end

        # Validate a Sensu check definition.
        #
        # @param check [Hash] sensu check definition.
        def validate_check(check)
          validate_check_execution(check)
          validate_check_source(check) if check[:source]
          validate_check_scheduling(check)
          validate_check_handling(check)
          validate_check_ttl(check) if check[:ttl]
          validate_check_flap_detection(check)
          validate_subdue(check) if check[:subdue]
        end
      end
    end<commit_msg>[check-ttl] validate_check_name() for further cleanup<commit_after>module Sensu
  module Settings
    module Validators
      module Check
        # Validate check name.
        # Validates: name
        #
        # @param check [Hash] sensu check definition.
        def validate_check_name(check)
          must_be_a_string(check[:name]) ||
            invalid(check, "check name must be a string")
          must_match_regex(/^[\w\.-]+$/, check[:name]) ||
            invalid(check, "check name cannot contain spaces or special characters")
        end

        # Validate check execution.
        # Validates: command, extension, timeout
        #
        # @param check [Hash] sensu check definition.
        def validate_check_execution(check)
          must_be_a_string_if_set(check[:command]) ||
            invalid(check, "check command must be a string")
          must_be_a_string_if_set(check[:extension]) ||
            invalid(check, "check extension must be a string")
          (!check[:command].nil? ^ !check[:extension].nil?) ||
            invalid(check, "either check command or extension must be set")
          must_be_a_numeric_if_set(check[:timeout]) ||
            invalid(check, "check timeout must be numeric")
        end

        # Validate check source.
        # Validates: source
        #
        # @param check [Hash] sensu check definition.
        def validate_check_source(check)
          if is_a_string?(check[:source])
            must_match_regex(/^[\w\.-]+$/, check[:source]) ||
              invalid(check, "check source cannot contain spaces or special characters")
          else
            invalid(check, "check source must be a string")
          end
        end

        # Validate check scheduling.
        # Validates: interval, standalone, subscribers
        #
        # @param check [Hash] sensu check definition.
        def validate_check_scheduling(check)
          must_be_boolean_if_set(check[:publish]) ||
            invalid(check, "check publish must be boolean")
          unless check[:publish] == false
            (must_be_an_integer(check[:interval]) && check[:interval] > 0) ||
              invalid(check, "check interval must be an integer")
          end
          must_be_boolean_if_set(check[:standalone]) ||
            invalid(check, "check standalone must be boolean")
          unless check[:standalone]
            if is_an_array?(check[:subscribers])
              items_must_be_strings(check[:subscribers]) ||
                invalid(check, "check subscribers must each be a string")
            else
              invalid(check, "check subscribers must be an array")
            end
          end
        end

        # Validate check handling.
        # Validates: handler, handlers
        #
        # @param check [Hash] sensu check definition.
        def validate_check_handling(check)
          must_be_a_string_if_set(check[:handler]) ||
            invalid(check, "check handler must be a string")
          must_be_an_array_if_set(check[:handlers]) ||
            invalid(check, "check handlers must be an array")
          if is_an_array?(check[:handlers])
            items_must_be_strings(check[:handlers]) ||
              invalid(check, "check handlers must each be a string")
          end
        end

        # Validate check ttl.
        # Validates: ttl
        #
        # @param check [Hash] sensu check definition.
        def validate_check_ttl(check)
          if is_an_integer?(check[:ttl])
            check[:ttl] > 0 ||
              invalid(check, "check ttl must be greater than 0")
          else
            invalid(check, "check ttl must be an integer")
          end
        end

        # Validate check flap detection.
        # Validates: low_flap_threshold, high_flap_threshold
        #
        # @param check [Hash] sensu check definition.
        def validate_check_flap_detection(check)
          if either_are_set?(check[:low_flap_threshold], check[:high_flap_threshold])
            must_be_an_integer(check[:low_flap_threshold]) ||
              invalid(check, "check low flap threshold must be an integer")
            must_be_an_integer(check[:high_flap_threshold]) ||
              invalid(check, "check high flap threshold must be an integer")
          end
        end

        # Validate a Sensu check definition.
        #
        # @param check [Hash] sensu check definition.
        def validate_check(check)
          validate_check_name(check)
          validate_check_execution(check)
          validate_check_source(check) if check[:source]
          validate_check_scheduling(check)
          validate_check_handling(check)
          validate_check_ttl(check) if check[:ttl]
          validate_check_flap_detection(check)
          validate_subdue(check) if check[:subdue]
        end
      end
    end
{'fraction_non_alphanumeric': 0.09027336300063572, 'fraction_numerical': 0.0006357279084551812, 'mean_word_length': 2.16214405360134, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '2873709', 'n_tokens_mistral': 2537, 'n_tokens_neox': 2489, 'n_words': 677}