SAM API Examples

Posted by Sam

Since the release of SAM 0.3.0 has hot and fresh API support baked in I thought I should put up examples so that somebody besides me could use them. Here's a taste of what it might look like to use the API to get the Threat Index.

require 'rubygems'
require 'active_resource'

class Threat < ActiveResource::Base
  self.site = 'http://127.0.0.1:3000/'
end

start = ARGV[0].to_i.hours.ago.strftime('%Y-%m-%d %H:%M')
threats = Threat.find(:all,
  :from => "/dashboard/threat_indexes.xml",
  :params => { :start_date => start, :limit => 5 })
puts "Source\t\tThreat Index" 
puts "------------------------------" 
for threat in threats
  puts "#{threat.formatted_source_address}\t\t#{threat.threat_index}" 
end

Check out the rest of the API examples.

Tags: sam

Comments

Be the first to leave a comment.

Add a comment