#!/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