hobelar 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +2 -0
- data/README.rdoc +2 -1
- data/hobelar.gemspec +1 -1
- data/lib/hobelar.rb +14 -3
- data/lib/hobelar/parsers.rb +25 -0
- data/lib/hobelar/parsers/getcheck.rb +3 -12
- data/lib/hobelar/parsers/getfilter.rb +35 -0
- metadata +4 -3
- data/lib/hobelar/core.rb +0 -0
data/.gitignore
ADDED
data/README.rdoc
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
= hobelar
|
2
2
|
|
3
3
|
Hobelar talks to {Reconnoiter's}[http://labs.omniti.com/labs/reconnoiter] REST interface.
|
4
|
+
The name comes from a variety of light cavalry, originally from Ireland, used for skirmishing and reconnaissance.
|
4
5
|
|
5
6
|
== Getting Started
|
6
7
|
|
@@ -30,7 +31,7 @@ If you don't have a valid CA, you'll need to disable peer validation when instan
|
|
30
31
|
|
31
32
|
(The MIT License)
|
32
33
|
|
33
|
-
Copyright (c)
|
34
|
+
Copyright (c) 2011 {Thom May}[http://github.com/thommay]
|
34
35
|
|
35
36
|
Permission is hereby granted, free of charge, to any person obtaining
|
36
37
|
a copy of this software and associated documentation files (the
|
data/hobelar.gemspec
CHANGED
data/lib/hobelar.rb
CHANGED
@@ -60,15 +60,26 @@ class Hobelar
|
|
60
60
|
end
|
61
61
|
|
62
62
|
def get_filter(set, path=nil)
|
63
|
-
|
63
|
+
p = path ? "/filters/show/#{path}/#{set}" : "/filters/show/#{set}"
|
64
|
+
request({:method=>"GET", :path=>p, :parser => Hobelar::Parsers::GetFilter.new})
|
64
65
|
end
|
65
66
|
|
66
67
|
def set_filter(set, rules, path=nil)
|
67
|
-
|
68
|
+
p = path ? "/filters/set/#{path}/#{set}" : "/filters/set/#{set}"
|
69
|
+
r = ""
|
70
|
+
rules.each do |rule|
|
71
|
+
r += "<rule type=\"#{rule[:type]}\" module=\"#{rule[:module]}\" metric=\"#{rule[:metric]}\" />"
|
72
|
+
end
|
73
|
+
|
74
|
+
body = "<?xml version=\"1.0\" encoding=\"utf8\"?><filterset>#{r}</filterset>"
|
75
|
+
request({:method=>"PUT", :path=>p, :body => body, :parser => Hobelar::Parsers::GetFilter.new})
|
68
76
|
end
|
69
77
|
|
78
|
+
# deleting filters doesn't actually appear to work; the API gives the correct response
|
79
|
+
# but nothing happens
|
70
80
|
def del_filter(set, path=nil)
|
71
|
-
|
81
|
+
p = path ? "/filters/delete/#{path}/#{set}" : "/filters/delete/#{set}"
|
82
|
+
request({:method=>"DELETE", :path=>p})
|
72
83
|
end
|
73
84
|
|
74
85
|
def request(params, &block)
|
data/lib/hobelar/parsers.rb
CHANGED
@@ -1,2 +1,27 @@
|
|
1
1
|
require 'nokogiri/xml/sax/document'
|
2
|
+
|
3
|
+
class Hobelar
|
4
|
+
class Parsers < Nokogiri::XML::SAX::Document
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@response = {}
|
8
|
+
end
|
9
|
+
|
10
|
+
def characters(string)
|
11
|
+
@value ||= ''
|
12
|
+
@value << string.strip
|
13
|
+
end
|
14
|
+
|
15
|
+
def attr_value(name, attrs)
|
16
|
+
(entry = attrs.detect {|a,v| a == name }) && entry.last
|
17
|
+
end
|
18
|
+
|
19
|
+
def start_element(name, attrs = [])
|
20
|
+
@value = nil
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
2
26
|
require 'hobelar/parsers/getcheck.rb'
|
27
|
+
require 'hobelar/parsers/getfilter.rb'
|
@@ -1,28 +1,19 @@
|
|
1
1
|
class Hobelar
|
2
2
|
class Parsers
|
3
|
-
class GetCheck <
|
3
|
+
class GetCheck < Hobelar::Parsers
|
4
4
|
|
5
5
|
attr_reader :response
|
6
6
|
|
7
7
|
def initialize
|
8
|
-
|
8
|
+
super
|
9
9
|
@response[:attributes] = {}
|
10
10
|
@response[:config] = {}
|
11
11
|
@response[:state] = {}
|
12
12
|
@response[:state][:metrics] = {}
|
13
13
|
end
|
14
14
|
|
15
|
-
def characters(string)
|
16
|
-
@value ||= ''
|
17
|
-
@value << string.strip
|
18
|
-
end
|
19
|
-
|
20
|
-
def attr_value(name, attrs)
|
21
|
-
(entry = attrs.detect {|a,v| a == name }) && entry.last
|
22
|
-
end
|
23
|
-
|
24
15
|
def start_element(name, attrs = [])
|
25
|
-
|
16
|
+
super
|
26
17
|
|
27
18
|
case name
|
28
19
|
when "attributes"
|
@@ -0,0 +1,35 @@
|
|
1
|
+
class Hobelar
|
2
|
+
class Parsers
|
3
|
+
class GetFilter < Hobelar::Parsers
|
4
|
+
|
5
|
+
attr_reader :response
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
super
|
9
|
+
@response[:rules] = []
|
10
|
+
end
|
11
|
+
|
12
|
+
def start_element(name, attrs = [])
|
13
|
+
super
|
14
|
+
|
15
|
+
case name
|
16
|
+
when "filterset"
|
17
|
+
@in_fset = true
|
18
|
+
when "rule"
|
19
|
+
@type = attr_value("type", attrs)
|
20
|
+
@module = attr_value("module", attrs)
|
21
|
+
@metric = attr_value("metric", attrs)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def end_element(name)
|
26
|
+
case name
|
27
|
+
when "filterset"
|
28
|
+
@in_fset = false
|
29
|
+
when "rule"
|
30
|
+
@response[:rules] << {:type => @type, :module => @module, :metric => @metric}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: hobelar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Thom May
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-03-
|
13
|
+
date: 2011-03-29 00:00:00 +01:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -77,14 +77,15 @@ extensions: []
|
|
77
77
|
extra_rdoc_files:
|
78
78
|
- README.rdoc
|
79
79
|
files:
|
80
|
+
- .gitignore
|
80
81
|
- Gemfile
|
81
82
|
- README.rdoc
|
82
83
|
- hobelar.gemspec
|
83
84
|
- lib/hobelar.rb
|
84
|
-
- lib/hobelar/core.rb
|
85
85
|
- lib/hobelar/exceptions.rb
|
86
86
|
- lib/hobelar/parsers.rb
|
87
87
|
- lib/hobelar/parsers/getcheck.rb
|
88
|
+
- lib/hobelar/parsers/getfilter.rb
|
88
89
|
has_rdoc: true
|
89
90
|
homepage: https://github.com/thommay/hobelar
|
90
91
|
licenses: []
|
data/lib/hobelar/core.rb
DELETED
File without changes
|