Sha256: 062749b2f5139115d1277643d45fc233e21963456f91f9724aa75dc029d61b90

Contents?: true

Size: 1.15 KB

Versions: 2

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

module Mihari
  module Commands
    module Search
      include Mixins::Database
      include Mixins::Rule
      include Mixins::ErrorNotification

      def self.included(thor)
        thor.class_eval do
          desc "search [RULE]", "Search by a rule"
          def search_by_rule(path_or_id)
            rule = load_rule(path_or_id)

            # validate
            begin
              validate_rule! rule
            rescue RuleValidationError => e
              raise e
            end

            analyzer = rule.to_analyzer

            with_error_notification do
              alert = analyzer.run

              if alert
                data = Mihari::Entities::Alert.represent(alert)
                puts JSON.pretty_generate(data.as_json)
              else
                Mihari.logger.info "There is no new artifact"
              end

              # record a rule
              with_db_connection do
                model = rule.to_model
                model.save
              rescue ActiveRecord::RecordNotUnique
                nil
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mihari-4.3.0 lib/mihari/commands/search.rb
mihari-4.2.0 lib/mihari/commands/search.rb