diff options
| author | mo khan <mo@mokhan.ca> | 2015-02-04 22:04:58 -0700 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2015-02-04 22:04:58 -0700 |
| commit | 1af4f1858830afb079e912e1be0c46f5c3ce6186 (patch) | |
| tree | 5426c7c9c00f4e7fb7bb1411f851257187cf2f93 | |
| parent | b3971b05ce551c219a26c8f876c9a7126ebeb4a7 (diff) | |
post file system changes to event intake.
| -rw-r--r-- | app/controllers/agents/events_controller.rb | 2 | ||||
| -rw-r--r-- | app/controllers/application_controller.rb | 3 | ||||
| -rw-r--r-- | lib/fake_agent.rb | 24 |
3 files changed, 18 insertions, 11 deletions
diff --git a/app/controllers/agents/events_controller.rb b/app/controllers/agents/events_controller.rb index 9912393..630f4df 100644 --- a/app/controllers/agents/events_controller.rb +++ b/app/controllers/agents/events_controller.rb @@ -24,7 +24,7 @@ module Agents private def event_params - params.require(:event).permit(:name, :data) + params[:event] end def load_agent diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d83690e..84e9c93 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,5 +1,6 @@ class ApplicationController < ActionController::Base # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. - protect_from_forgery with: :exception + #protect_from_forgery with: :exception + protect_from_forgery with: :null_session end diff --git a/lib/fake_agent.rb b/lib/fake_agent.rb index 68a2bb5..d23ed03 100644 --- a/lib/fake_agent.rb +++ b/lib/fake_agent.rb @@ -22,20 +22,26 @@ class FakeAgent def publish_event(event, files) files.each do |file| fingerprint = fingerprint_for(file) - url = "#{endpoint}/agents/#{id}/files/#{fingerprint}" - puts url - Typhoeus.get(url, body: { - agent_id: id, - name: event, - data: { - fingerprint: fingerprint, - full_path: file, + url = "#{endpoint}/agents/#{id}/events/" + body = { + event: { + agent_id: id, + name: event, + data: { + fingerprint: fingerprint, + full_path: file, + } } - }) + } + puts [url, body].inspect + Typhoeus.post(url, body: body) end + rescue => e + puts "#{e.message} #{e.backtrace.join(' ')}" end def fingerprint_for(file) + return nil unless File.exist?(file) result = `shasum -a 256 #{file}` sha, * = result.split(' ') sha |
