iosparse 0.0.7 → 0.0.8
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/README.md +8 -2
- data/iosparse.gemspec +1 -1
- data/lib/iosparse.rb +25 -47
- metadata +1 -1
data/README.md
CHANGED
@@ -5,7 +5,7 @@ Good question. First install it using `gem install iosparse`. Then use it. Cr
|
|
5
5
|
|
6
6
|
````
|
7
7
|
config = IOSParse.new('path/to/ios.conf')
|
8
|
-
puts config.
|
8
|
+
puts config.find_all('interface')
|
9
9
|
````
|
10
10
|
````
|
11
11
|
Output:
|
@@ -19,4 +19,10 @@ Output:
|
|
19
19
|
|
20
20
|
All objects returned are arrays that can be further manipulated and parsed. "Human readable" format coming soon, maybe even a CLI. Please note the mock Cisco ASA config file in the spec test is completely fabricated and is not intended to be a correct configuration, it is only to be used for it's syntax.
|
21
21
|
|
22
|
-
All '\n' are
|
22
|
+
All '\n' are injected as delimiters to show where children lines separate from the parent and inteded to be used for easy String#gsub to parse and print in other formats. Feel free to look at the documentation link on the <a href="http://rubygems.org/gems/iosparse">rubygems</a> site.
|
23
|
+
|
24
|
+
Current methods:
|
25
|
+
|
26
|
+
`find_all` used to find all specific rules, interface, object-group, route, name, etc.
|
27
|
+
`has` used to find any rule that includes a specific string.
|
28
|
+
`group_has_ip` returns group(s) that include a specific IP.
|
data/iosparse.gemspec
CHANGED
data/lib/iosparse.rb
CHANGED
@@ -9,7 +9,7 @@ class IOSParse
|
|
9
9
|
end
|
10
10
|
|
11
11
|
# Custom filter
|
12
|
-
def
|
12
|
+
def find_all(custom_filter)
|
13
13
|
options = {
|
14
14
|
filter: /^#{custom_filter}.+/,
|
15
15
|
parent: "#{custom_filter}"
|
@@ -17,58 +17,22 @@ class IOSParse
|
|
17
17
|
find_blocks(options)
|
18
18
|
end
|
19
19
|
|
20
|
-
#
|
21
|
-
def
|
20
|
+
# Custom seek
|
21
|
+
def has(custom_seek)
|
22
22
|
options = {
|
23
|
-
filter:
|
24
|
-
parent: "
|
23
|
+
filter: /.+#{custom_seek}.+/,
|
24
|
+
parent: "#{custom_seek}"
|
25
25
|
}
|
26
26
|
find_blocks(options)
|
27
27
|
end
|
28
28
|
|
29
|
-
#
|
30
|
-
def
|
29
|
+
# What group is an IP in?
|
30
|
+
def group_has_ip(ip)
|
31
31
|
options = {
|
32
|
-
filter: /^
|
33
|
-
parent: "
|
32
|
+
filter: /^object-group.+#{ip}.+/,
|
33
|
+
parent: "#{ip}"
|
34
34
|
}
|
35
|
-
|
36
|
-
end
|
37
|
-
|
38
|
-
# Find all access-lists
|
39
|
-
def access_lists
|
40
|
-
options = {
|
41
|
-
filter: /^access-list.+/,
|
42
|
-
parent: "access-list"
|
43
|
-
}
|
44
|
-
find_blocks(options)
|
45
|
-
end
|
46
|
-
|
47
|
-
# Find all names
|
48
|
-
def names
|
49
|
-
options = {
|
50
|
-
filter: /^name.+/,
|
51
|
-
parent: "name"
|
52
|
-
}
|
53
|
-
find_blocks(options)
|
54
|
-
end
|
55
|
-
|
56
|
-
# Find all routes
|
57
|
-
def routes
|
58
|
-
options = {
|
59
|
-
filter: /^route[^r].+/,
|
60
|
-
parent: "route"
|
61
|
-
}
|
62
|
-
find_blocks(options)
|
63
|
-
end
|
64
|
-
|
65
|
-
# Find all object-groups
|
66
|
-
def object_groups
|
67
|
-
options = {
|
68
|
-
filter: /^object-group.+/,
|
69
|
-
parent: "object-group"
|
70
|
-
}
|
71
|
-
find_blocks(options)
|
35
|
+
find_object_group(options)
|
72
36
|
end
|
73
37
|
|
74
38
|
private
|
@@ -81,6 +45,16 @@ class IOSParse
|
|
81
45
|
normalize(output)
|
82
46
|
end
|
83
47
|
|
48
|
+
def find_object_group(options)
|
49
|
+
input = Array.new
|
50
|
+
output = Array.new
|
51
|
+
@yaml.each do |line|
|
52
|
+
input << line.match(options[:filter]) if line.match(options[:filter])
|
53
|
+
end
|
54
|
+
input.each { |rule| output << rule.to_s.split("\s-\s")[0] }
|
55
|
+
normalize(output)
|
56
|
+
end
|
57
|
+
|
84
58
|
# Load Cisco 'show all' dump
|
85
59
|
def load_config(filename)
|
86
60
|
@config = File.open(filename, 'r')
|
@@ -126,4 +100,8 @@ class IOSParse
|
|
126
100
|
end
|
127
101
|
end
|
128
102
|
end
|
129
|
-
end
|
103
|
+
end
|
104
|
+
|
105
|
+
config = IOSParse.new('../spec/etc/cisco_asa.config')
|
106
|
+
|
107
|
+
puts config.group_has_ip('10.10.15.100').class
|