forked from floored1585/pixel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
python-to-yaml.rb
66 lines (62 loc) · 2.22 KB
/
python-to-yaml.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#
# Pixel is an open source network monitoring system
# Copyright (C) 2016 all Pixel contributors!
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
require 'snmp/varbind'
require 'fileutils'
require 'yaml'
def eval_mib_data(mib_hash)
ruby_hash = mib_hash.
gsub(':', '=>'). # fix hash syntax
gsub('(', '[').gsub(')', ']'). # fix tuple syntax
sub('FILENAME =', 'filename ='). # get rid of constants
sub('MIB =', 'mib =')
mib = nil
eval(ruby_hash)
mib
end
def create_module(imp_file,exp_file)
mib = eval_mib_data(IO.read(imp_file))
if mib
module_name = mib["moduleName"]
raise "#{imp_file}: invalid file format; no module name" unless module_name
if mib["nodes"]
oid_hash = {}
mib["nodes"].each { |key, value| oid_hash[key] = value["oid"] }
if mib["notifications"]
mib["notifications"].each { |key, value| oid_hash[key] = value["oid"] }
end
File.open(exp_file, 'w') do |file|
YAML.dump(oid_hash, file)
file.puts
end
#module_name
else
warn "*** No nodes defined in: #{module_file} ***"
nil
end
else
warn "*** Import failed for: #{module_file} ***"
nil
end
end
#create_module('./SNMPv2-SMI.python','./SNMPv2-SMI.yaml')
#create_module('./CISCO-SMI.python','./CISCO-SMI.yaml')
#create_module('./CISCO-PRODUCTS-MIB.python','./CISCO-PRODUCTS-MIB.yaml')
#create_module('./JUNIPER-SMI.python','./JUNIPER-SMI.yaml')
#create_module('./JNX-CHAS-DEFINES-MIB.python','./JNX-CHAS-DEFINES-MIB.yaml')
create_module('./F10-SMI.python','./F10-SMI.yaml')
create_module('./F10-PRODUCTS-MIB.python','./F10-PRODUCTS-MIB.yaml')