Sha256: 2b994c3df8f31b5e6bcdf2ddb97fa4be9215eef56147fd470c0fead4d7af2b59

Contents?: true

Size: 1.45 KB

Versions: 9

Compression:

Stored size: 1.45 KB

Contents

#!/usr/bin/env ruby

$:.push(File.expand_path(File.join('..', '..', 'lib'), __FILE__))

STDOUT.sync = true

require 'optparse'
require 'patronus_fati'

$0 = File.basename(__FILE__)

options = {
  'port'   => 2501,
  'server' => '127.0.0.1'
}

OptionParser.new(nil, 32, '  ') do |opts|
  opts.on('-s', '--server SERVER', 'IP or hostname of running kismet server.') do |srv|
    options['server'] = srv
  end

  opts.on('-p', '--port PORT', 'Port that kismet server is running on.') do |port|
    options['port'] = port.to_i
  end
end.parse(ARGV)

def exception_logger(tag)
  yield
rescue Interrupt
  PatronusFati.logger.info('Quitting...')
rescue => e
  PatronusFati.logger.error("(#{tag}) Rescued from error: #{e.message}")
  e.backtrace.each do |l|
    PatronusFati.logger.error(l)
  end
end

exception_logger('process') do
  connection = PatronusFati.setup(options['server'], options['port'])
  connection.connect

  PatronusFati.event_handler.on(:any) do |asset_type, event_type, msg, diagnostics|
    PatronusFati.logger.info(JSON.generate(
      {
        asset_type: asset_type,
        event_type: event_type,
        data: msg,
        diagnostics: diagnostics,
        timestamp: Time.now.to_i
      }
    ))
  end

  while (line = connection.read_queue.pop)
    next unless (obj = PatronusFati::MessageParser.parse(line))
    responses = PatronusFati::MessageProcessor.handle(obj)

    Array(responses).each { |msg| connection.write(msg) }
  end

  connection.disconnect
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
patronus_fati-1.3.5 bin/patronus_fati
patronus_fati-1.3.4 bin/patronus_fati
patronus_fati-1.3.3 bin/patronus_fati
patronus_fati-1.3.2 bin/patronus_fati
patronus_fati-1.3.1 bin/patronus_fati
patronus_fati-1.3.0 bin/patronus_fati
patronus_fati-1.2.2 bin/patronus_fati
patronus_fati-1.2.1 bin/patronus_fati
patronus_fati-1.2.0 bin/patronus_fati