Skip to content

Instantly share code, notes, and snippets.

@bryanl
Created January 21, 2009 01:02
Show Gist options
  • Save bryanl/49782 to your computer and use it in GitHub Desktop.
Save bryanl/49782 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'rubygems'
require 'couchrest'
CouchRest::Model.default_database = CouchRest.database!('snort-playground')
class Rule < CouchRest::Model
end
db = CouchRest.database!("snort-playground")
#puts db.view("snort/signature_revision")["rows"].map{|r| r["value"]}.inspect
puts db.view("snort/signature_revision").inspect
#doc = CouchRest::Document.new
#doc["_id"] = "_design/foo"
#doc["language"] = "javascript"
#views = {"signature_revision" => { "map" => "function(doc) {\n if (doc['couchrest-type'] == 'Rule') {\n emit(doc._id, [doc.signature, doc.revision, doc.category])\n\n }\n }\n"} }
#doc["views"] = views
#doc.database = db
#doc.save
#!/usr/bin/env ruby
require 'rubygems'
require 'couchrest'
require 'snort_rule_pak'
require 'tmpdir'
require 'benchmark'
db = CouchRest.database!("snort-playground")
path = "/Users/bryan/Documents/sourcefire/snort/snortrules-snapshot-CURRENT.tar.gz"
rp = SnortRulePak::RulePak.new :location => path
puts Benchmark.measure {
rp.categories.each do |name|
rule_hashes = rp.category(name).rules.map do |rule|
rule.to_h.merge("couchrest-type" => "Rule")
end
db.bulk_save(rule_hashes)
end
rp.close
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment