summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2015-02-09 18:54:32 -0700
committermo khan <mo@mokhan.ca>2015-02-09 18:54:32 -0700
commit72a1483c8f546fae6c93dcdf91cfd47c37bc2f90 (patch)
tree942080f10dc317737b454a75a159265925663582
parentf004d81d3be9ff40830efb66c200a7a6552d72d0 (diff)
use agent registration to endpoint for registering fake agent.
-rw-r--r--lib/fake_agent.rb11
-rw-r--r--lib/tasks/agent.rake12
2 files changed, 15 insertions, 8 deletions
diff --git a/lib/fake_agent.rb b/lib/fake_agent.rb
index a3b4002..f5ce3db 100644
--- a/lib/fake_agent.rb
+++ b/lib/fake_agent.rb
@@ -2,13 +2,20 @@ require 'socket'
class FakeAgent
include PacketFu
+ DEFAULT_ENDPOINT='http://localhost:3000'
attr_reader :id, :endpoint
- def initialize(id, endpoint)
- @id = id
+ def initialize(endpoint = DEFAULT_ENDPOINT)
@endpoint = endpoint
end
+ def register
+ url = "#{endpoint}/agents.json"
+ response = Typhoeus.post(url, body: { agent: { hostname: Socket.gethostname } })
+ json = JSON.parse(response.body)
+ @id = json["id"]
+ end
+
def watch(directory)
listener = Listen.to(directory, debug: true) do |modified, added, removed|
publish_event(:modified, modified)
diff --git a/lib/tasks/agent.rake b/lib/tasks/agent.rake
index 1857454..482cd77 100644
--- a/lib/tasks/agent.rake
+++ b/lib/tasks/agent.rake
@@ -1,24 +1,24 @@
namespace :agent do
require 'fake_agent'
- ENDPOINT='http://localhost:3000'
desc "watch all files"
task watch: :environment do
- agent = FakeAgent.new(Agent.first.id, ENDPOINT)
+ agent = FakeAgent.new
+ agent.register
agent.watch(Dir.pwd)
end
desc "scan directory"
task scan: :environment do
- agent = FakeAgent.new(Agent.first.id, ENDPOINT)
+ agent = FakeAgent.new
+ agent.register
agent.scan(Dir.pwd)
end
desc "scan network traffic"
task :nfm do
- id = Agent.first.id
- agent = FakeAgent.new(id, ENDPOINT)
-
+ agent = FakeAgent.new
+ agent.register
agent.packet_capture('eth0')
end
end