Sha256: bd27330497225cfc574a8d35bbd82f69a502126deddd5d24938b2aed14be1066

Contents?: true

Size: 1.07 KB

Versions: 11

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

module Mihari
  class Status
    def check
      statuses
    end

    def self.check
      new.check
    end

    private

    #
    # Statuses of analyzers and emitters
    #
    # @return [Array<Hash>]
    #
    def statuses
      (Mihari.analyzers + Mihari.emitters).map do |klass|
        name = klass.to_s.split("::").last.to_s

        [name, build_status(klass)]
      end.to_h.compact
    end

    #
    # Build a status of a class
    #
    # @param [Class<Mihari::Analyzers::Base>, Class<Mihari::Emitters::Base>] klass
    #
    # @return [Hash, nil]
    #
    def build_status(klass)
      return nil if klass == Mihari::Analyzers::Rule

      is_analyzer = klass.ancestors.include?(Mihari::Analyzers::Base)

      instance = is_analyzer ? klass.new("dummy") : klass.new
      is_configured = instance.configured?
      values = instance.configuration_values
      type = is_analyzer ? "Analyzer" : "Emitter"

      values ? { is_configured: is_configured, values: values, type: type } : nil
    rescue ArgumentError => _e
      nil
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
mihari-3.7.0 lib/mihari/status.rb
mihari-3.6.1 lib/mihari/status.rb
mihari-3.6.0 lib/mihari/status.rb
mihari-3.5.0 lib/mihari/status.rb
mihari-3.4.1 lib/mihari/status.rb
mihari-3.4.0 lib/mihari/status.rb
mihari-3.3.0 lib/mihari/status.rb
mihari-3.2.0 lib/mihari/status.rb
mihari-3.1.0 lib/mihari/status.rb
mihari-3.0.1 lib/mihari/status.rb
mihari-3.0.0 lib/mihari/status.rb