gri 10.0.0
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.
- checksums.yaml +7 -0
- data/.gitignore +7 -0
- data/MIT-LICENSE.txt +20 -0
- data/README.md +132 -0
- data/Rakefile +5 -0
- data/bin/grapher +17 -0
- data/bin/gri +5 -0
- data/bin/gricast +17 -0
- data/bin/grispark +5 -0
- data/bin/griwalk +9 -0
- data/bin/trad +19 -0
- data/bin/trad-http +17 -0
- data/gri.gemspec +21 -0
- data/lib/fluent/plugin/out_gri.rb +56 -0
- data/lib/gri/api.rb +28 -0
- data/lib/gri/app_collector.rb +154 -0
- data/lib/gri/app_walker.rb +23 -0
- data/lib/gri/blank.rb +49 -0
- data/lib/gri/builtindefs.rb +211 -0
- data/lib/gri/cast.rb +84 -0
- data/lib/gri/cgraph.rb +37 -0
- data/lib/gri/clist.rb +163 -0
- data/lib/gri/collector.rb +284 -0
- data/lib/gri/config.rb +134 -0
- data/lib/gri/ds_list.rb +166 -0
- data/lib/gri/format_helper.rb +112 -0
- data/lib/gri/gparams.rb +43 -0
- data/lib/gri/graph.rb +239 -0
- data/lib/gri/grapher.rb +70 -0
- data/lib/gri/ldb.rb +160 -0
- data/lib/gri/list.rb +242 -0
- data/lib/gri/log.rb +140 -0
- data/lib/gri/loop.rb +109 -0
- data/lib/gri/ltsv.rb +58 -0
- data/lib/gri/main.rb +107 -0
- data/lib/gri/mlog.rb +22 -0
- data/lib/gri/mmsgpack.rb +57 -0
- data/lib/gri/msnmp.rb +601 -0
- data/lib/gri/page.rb +235 -0
- data/lib/gri/pcollector.rb +209 -0
- data/lib/gri/plugin.rb +75 -0
- data/lib/gri/plugin/bootstrap.rb +65 -0
- data/lib/gri/plugin/cisco.rb +98 -0
- data/lib/gri/plugin/exec_collector.rb +89 -0
- data/lib/gri/plugin/juniper.rb +5 -0
- data/lib/gri/plugin/netsnmp.rb +8 -0
- data/lib/gri/plugin/ucdavis.rb +176 -0
- data/lib/gri/plugin/writer_fluentd.rb +26 -0
- data/lib/gri/polling_unit.rb +88 -0
- data/lib/gri/q.rb +5 -0
- data/lib/gri/request.rb +29 -0
- data/lib/gri/rrd.rb +438 -0
- data/lib/gri/scheduler.rb +68 -0
- data/lib/gri/sgraph.rb +147 -0
- data/lib/gri/spark.rb +94 -0
- data/lib/gri/tra_collector.rb +80 -0
- data/lib/gri/trad.rb +170 -0
- data/lib/gri/updater.rb +201 -0
- data/lib/gri/util_daemon.rb +19 -0
- data/lib/gri/util_marshal.rb +13 -0
- data/lib/gri/utils.rb +63 -0
- data/lib/gri/vendor.rb +76 -0
- data/lib/gri/version.rb +3 -0
- data/lib/gri/wmain.rb +67 -0
- data/lib/gri/writer.rb +184 -0
- data/mcollector +47 -0
- data/test/mock.rb +60 -0
- data/test/root/gra/.sysdb/sysdb.txt +3 -0
- data/test/root/gra/testhost/.records.txt +2 -0
- data/test/root/if.def +2 -0
- data/test/root/test.conf +4 -0
- data/test/root/testtab +9 -0
- data/test/root/testtab2 +2 -0
- data/test/root/tra/testhost/_/20130614 +20 -0
- data/test/test_app.rb +58 -0
- data/test/test_builtindefs.rb +24 -0
- data/test/test_collector.rb +58 -0
- data/test/test_config.rb +62 -0
- data/test/test_ds_list.rb +48 -0
- data/test/test_exec_collector.rb +33 -0
- data/test/test_format_helper.rb +68 -0
- data/test/test_graph.rb +69 -0
- data/test/test_ldb.rb +29 -0
- data/test/test_list.rb +65 -0
- data/test/test_log.rb +16 -0
- data/test/test_loop.rb +35 -0
- data/test/test_ltsv.rb +38 -0
- data/test/test_main.rb +19 -0
- data/test/test_mmsgpack.rb +27 -0
- data/test/test_msnmp.rb +147 -0
- data/test/test_page.rb +51 -0
- data/test/test_pcollector.rb +71 -0
- data/test/test_plugin.rb +62 -0
- data/test/test_plugin_cisco.rb +23 -0
- data/test/test_polling_unit.rb +58 -0
- data/test/test_request.rb +26 -0
- data/test/test_rrd.rb +53 -0
- data/test/test_rrd_updater.rb +139 -0
- data/test/test_scheduler.rb +31 -0
- data/test/test_tra_collector.rb +40 -0
- data/test/test_trad.rb +33 -0
- data/test/test_util_marshal.rb +17 -0
- data/test/test_utils.rb +15 -0
- data/test/test_vendor.rb +40 -0
- data/test/test_writer.rb +33 -0
- data/test/unittest_helper.rb +27 -0
- metadata +208 -0
data/lib/gri/writer.rb
ADDED
@@ -0,0 +1,184 @@
|
|
1
|
+
require 'gri/ltsv'
|
2
|
+
|
3
|
+
module GRI
|
4
|
+
class Writer
|
5
|
+
TYPES = {}
|
6
|
+
|
7
|
+
def self.create wtype, options
|
8
|
+
if (klass = TYPES[wtype])
|
9
|
+
options.select {|k, v| String === k}.each {|k, v|
|
10
|
+
options[k.gsub('-', '_').intern] = v}
|
11
|
+
klass.new options
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
attr_accessor :loop
|
16
|
+
|
17
|
+
def initialize options={}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class STDOUTWriter < Writer
|
22
|
+
TYPES['stdout'] = self
|
23
|
+
|
24
|
+
def initialize options={}
|
25
|
+
@options = options
|
26
|
+
end
|
27
|
+
def write records
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class RRDWriter < Writer
|
32
|
+
TYPES['rrd'] = self
|
33
|
+
|
34
|
+
def initialize options={}
|
35
|
+
@options = options
|
36
|
+
@gra_dir = options[:gra_dir]
|
37
|
+
@sysinfos = {}
|
38
|
+
end
|
39
|
+
|
40
|
+
def write records
|
41
|
+
now = Time.now.to_i
|
42
|
+
hrecords = {}
|
43
|
+
updaters = {}
|
44
|
+
for record in records
|
45
|
+
if (host = record['_host']) and (key = record['_key'])
|
46
|
+
if key == 'SYS'
|
47
|
+
@sysinfos[host] = record
|
48
|
+
else
|
49
|
+
data_name, index = key.scan(/\A([^_\d]*)(_?.*)/).first
|
50
|
+
basename = "#{host}_#{key}"
|
51
|
+
unless (updater = updaters[basename])
|
52
|
+
hdir = "#{@gra_dir}/#{host}"
|
53
|
+
FileUtils.mkdir_p hdir unless File.directory? hdir
|
54
|
+
opts = {:data_name=>data_name, :gra_dir=>@gra_dir,
|
55
|
+
:host=>host, :key=>key,
|
56
|
+
:interval=>(record['_interval'] || @options[:interval])}
|
57
|
+
if @options[:rrdcached_address]
|
58
|
+
opts[:rrdcached_address] = @options[:rrdcached_address]
|
59
|
+
end
|
60
|
+
if @options[:base_dir]
|
61
|
+
opts[:base_dir] = @options[:base_dir]
|
62
|
+
end
|
63
|
+
updater = updaters[basename] = RRDUpdater.new(opts)
|
64
|
+
end
|
65
|
+
time = (record['_time'] || now).to_i
|
66
|
+
updater.update time, record
|
67
|
+
key = updater.key
|
68
|
+
end
|
69
|
+
(r = record.dup)['_key'] = key
|
70
|
+
r['_mtime'] = now
|
71
|
+
(hrecords[host] ||= {})[key] = r
|
72
|
+
end
|
73
|
+
end
|
74
|
+
hrecords.each {|host, h|
|
75
|
+
path = "#{@gra_dir}/#{host}/.records.txt"
|
76
|
+
FileUtils.mkdir_p File.dirname(path) unless File.exist? path
|
77
|
+
Utils.update_ltsv_file path, '_key', h
|
78
|
+
}
|
79
|
+
updaters.each {|k, u| u.close}
|
80
|
+
end
|
81
|
+
|
82
|
+
def finalize
|
83
|
+
unless @sysinfos.empty?
|
84
|
+
if @options[:merge_p]
|
85
|
+
path = "#{@gra_dir}/.sysdb/sysdb.tmp.#{$$}"
|
86
|
+
open(path, 'w') {|f| LTSV.dump_to_io @sysinfos, f}
|
87
|
+
else
|
88
|
+
path = "#{@gra_dir}/.sysdb/sysdb.txt"
|
89
|
+
FileUtils.mkdir_p File.dirname(path) unless File.exist? path
|
90
|
+
Utils.update_ltsv_file path, '_host', @sysinfos
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def merge
|
96
|
+
sysdb_dir = "#{@gra_dir}/.sysdb"
|
97
|
+
path0 = sysdb_dir + '/sysdb.txt'
|
98
|
+
values = LTSV.load_from_file(path0) rescue {}
|
99
|
+
nvalues = values.inject({}) {|h, v| h[v['_host']] = v; h}
|
100
|
+
for path in Dir.glob(sysdb_dir + '/sysdb.tmp.*')
|
101
|
+
(other = LTSV.load_from_file(path); File.unlink path) rescue next
|
102
|
+
other = other.inject({}) {|h, v| h[v['_host']] = v; h}
|
103
|
+
nvalues.merge! other
|
104
|
+
end
|
105
|
+
LTSV.dump_to_file nvalues, path0
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
class TextWriter < Writer
|
110
|
+
TYPES['text'] = self
|
111
|
+
TYPES['ldb'] = self
|
112
|
+
|
113
|
+
def initialize options={}
|
114
|
+
@options = options
|
115
|
+
@dir = @options[:tra_dir]
|
116
|
+
Dir.mkdir @dir unless File.exist? @dir
|
117
|
+
end
|
118
|
+
|
119
|
+
def write records
|
120
|
+
now = Time.now
|
121
|
+
date = "%04d%02d%02d" % [now.year, now.mon, now.day]
|
122
|
+
time = now.to_i
|
123
|
+
@ios = {}
|
124
|
+
for record in records
|
125
|
+
#record['_time'] = time
|
126
|
+
if (host = record['_host']) and (key = record['_key'])
|
127
|
+
hdir = "#{@dir}/#{host}"
|
128
|
+
Dir.mkdir hdir unless File.exist? hdir
|
129
|
+
data_name, index = key.scan(/\A([^_\d]*)(_?.*)/).first
|
130
|
+
interval = record['_interval']
|
131
|
+
kdir = "#{hdir}/#{data_name}_#{interval}"
|
132
|
+
Dir.mkdir kdir unless File.exist? kdir
|
133
|
+
path = kdir + '/' + date
|
134
|
+
unless io = @ios[path]
|
135
|
+
io = @ios[path] = File.open(path, 'a')
|
136
|
+
end
|
137
|
+
io.puts LTSV.serialize(record)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
@ios.each {|k, io| io.close}
|
141
|
+
end
|
142
|
+
|
143
|
+
def finalize
|
144
|
+
end
|
145
|
+
|
146
|
+
def purge_logs
|
147
|
+
if (day = @options[:tra_expire_day].to_i) > 0
|
148
|
+
self.class.expire @dir, day
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
def self.expire dir, day
|
153
|
+
run_expire_path = dir + '/.run_expire'
|
154
|
+
now = Time.now
|
155
|
+
if File.exist? run_expire_path
|
156
|
+
last_run = nil
|
157
|
+
open(run_expire_path) {|f| last_run = f.read}
|
158
|
+
last_run = Time.at(last_run.to_i)
|
159
|
+
return if (now - last_run < 24*3600) and !$debug
|
160
|
+
end
|
161
|
+
if (day = day.to_i) > 0
|
162
|
+
t = (now - day * 24 * 3600)
|
163
|
+
expire_date = "%04d%02d%02d" % [t.year, t.mon, t.day]
|
164
|
+
begin
|
165
|
+
Dir.glob(dir + '/*') {|hdir|
|
166
|
+
next if File.symlink? hdir
|
167
|
+
Dir.glob(hdir + '/*') {|path|
|
168
|
+
if File.directory? path
|
169
|
+
Dir.glob(path + '/*') {|path2|
|
170
|
+
if (basename = File.basename path2) < expire_date
|
171
|
+
File.unlink path2
|
172
|
+
end
|
173
|
+
}
|
174
|
+
end
|
175
|
+
}
|
176
|
+
}
|
177
|
+
open(run_expire_path, 'w') {|f| f.print now.to_i.to_s}
|
178
|
+
rescue SystemCallError
|
179
|
+
Log.error "ERROR: #{$!}"
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
data/mcollector
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# coding: us-ascii
|
2
|
+
|
3
|
+
if Object.const_defined? :RUBY_VERSION
|
4
|
+
lib_dir = File.dirname(__FILE__) + '/lib'
|
5
|
+
$LOAD_PATH.push lib_dir
|
6
|
+
require 'rubygems'
|
7
|
+
require 'socket'
|
8
|
+
else
|
9
|
+
# mruby
|
10
|
+
GC.disable #XXX
|
11
|
+
lib_dir = File.dirname(__FILE__) + '/lib'
|
12
|
+
$LOAD_PATH.push lib_dir
|
13
|
+
end
|
14
|
+
|
15
|
+
require 'gri/mlog'
|
16
|
+
require 'gri/app_collector'
|
17
|
+
require 'gri/writer'
|
18
|
+
require 'gri/config'
|
19
|
+
require 'gri/builtindefs'
|
20
|
+
require 'gri/plugin'
|
21
|
+
|
22
|
+
config_path = '/usr/local/gri/gri.conf'
|
23
|
+
gritab_path = nil
|
24
|
+
wtype = nil
|
25
|
+
while arg = ARGV.shift
|
26
|
+
case arg
|
27
|
+
when /\A--debug/
|
28
|
+
$debug = true
|
29
|
+
when /\A--config-path(?:=(\w+))?/
|
30
|
+
config_path = ($1 || ARGV.shift)
|
31
|
+
when /\A--gritab-path(?:=(\w+))?/
|
32
|
+
gritab_path = ($1 || ARGV.shift)
|
33
|
+
when /\A--writer(?:=(\w+))?/
|
34
|
+
wtype = ($1 || ARGV.shift)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
config = GRI::Config.init config_path
|
39
|
+
config['gritab-path'] = gritab_path if gritab_path
|
40
|
+
GRI::Plugin.load_plugins [], config
|
41
|
+
config['root-dir'] ||= GRI::Config::ROOT_PATH
|
42
|
+
config['tra-dir'] ||= '/usr/local/gri/tra'
|
43
|
+
wtype ||= 'fluent'
|
44
|
+
writer = GRI::Writer.create wtype, config.to_h
|
45
|
+
app = GRI::AppCollector.new(config)
|
46
|
+
app.writers.push writer
|
47
|
+
app.run
|
data/test/mock.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
class MockLoop
|
2
|
+
def initialize
|
3
|
+
@handlers = {}
|
4
|
+
@rs = []
|
5
|
+
end
|
6
|
+
|
7
|
+
def attach collector
|
8
|
+
collector.attach self
|
9
|
+
end
|
10
|
+
|
11
|
+
def detach collector
|
12
|
+
collector.on_detach
|
13
|
+
end
|
14
|
+
|
15
|
+
def on_detach &on_detach
|
16
|
+
@on_detach = on_detach
|
17
|
+
end
|
18
|
+
|
19
|
+
def watch io, flag, to, handler
|
20
|
+
@handlers[io] = handler
|
21
|
+
@rs.push io
|
22
|
+
end
|
23
|
+
|
24
|
+
def run
|
25
|
+
end
|
26
|
+
|
27
|
+
def run_handler ind
|
28
|
+
io = @rs[ind]
|
29
|
+
@handlers[io].on_readable io
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class MockIO
|
34
|
+
def close; end
|
35
|
+
end
|
36
|
+
|
37
|
+
module MockFork
|
38
|
+
def fork &cb
|
39
|
+
1
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class MockUDPSocket
|
44
|
+
attr_accessor :data
|
45
|
+
|
46
|
+
def connect host, port
|
47
|
+
@host = host
|
48
|
+
@port = port
|
49
|
+
end
|
50
|
+
|
51
|
+
def send msg, flags
|
52
|
+
@msg = msg
|
53
|
+
end
|
54
|
+
|
55
|
+
def recv maxlen, flags
|
56
|
+
@data
|
57
|
+
end
|
58
|
+
|
59
|
+
def close; end
|
60
|
+
end
|
@@ -0,0 +1,3 @@
|
|
1
|
+
_host:192.168.0.1 sysUpTime:2555041303 sysDescr:Linux host.example.com 2.6.18-164.6.1.el5 #1 SMP Tue Nov 3 16:18:27 EST 2009 i686
|
2
|
+
_host:testhost sysUpTime:999999 sysDescr:Linux host.example.com 2.6.18-164.6.1.el5 #1 SMP Tue Nov 3 16:18:27 EST 2009 i686
|
3
|
+
_host:r00.example.com sysDescr:IOS XR Software (Cisco CRS-8/S), Version 9.9.9[00]
|
data/test/root/if.def
ADDED
data/test/root/test.conf
ADDED
data/test/root/testtab
ADDED
data/test/root/testtab2
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
ifOutDiscards:0 ifInNUcastPkts:136951 _key:_eth0 ifInUcastPkts:116663644 ifHighSpeed:1000 ifInErrors:0 ifAdminStatus:1 ifSpeed:1000000000 ifHCInOctets:27494649894 _time:1371175021 ifOutNUcastPkts:0 ifInDiscards:0 ifOperStatus:1 ifHCOutOctets:12602582932 _mtime:1371175021 ifOutOctets:12602582932 ifInOctets:27494649894 ifOutErrors:0 ifAlias: _host:testhost ipaddr:198.51.100.208/255.255.255.0 ifOutUcastPkts:83951137 ifDescr:eth0
|
2
|
+
ifOutOctets:12602738085 ifOutUcastPkts:83952397 ifInNUcastPkts:136956 _host:testhost ifInDiscards:0 ifDescr:eth0 ifOutDiscards:0 ifHCInOctets:27494875934 ipaddr:198.51.100.208/255.255.255.0 ifAlias: ifInUcastPkts:116665729 ifInErrors:0 _mtime:1371175321 ifOutNUcastPkts:0 ifOutErrors:0 ifOperStatus:1 ifAdminStatus:1 ifHCOutOctets:12602738085 _time:1371175322 _key:_eth0 ifInOctets:27494875934 ifSpeed:1000000000 ifHighSpeed:1000
|
3
|
+
ifInNUcastPkts:136961 ifDescr:eth0 ipaddr:198.51.100.208/255.255.255.0 ifOutUcastPkts:83953757 ifInOctets:27495118285 ifOperStatus:1 ifHCInOctets:27495118285 _host:testhost ifOutOctets:12602899810 ifHighSpeed:1000 ifAlias: ifOutNUcastPkts:0 _key:_eth0 ifInUcastPkts:116667880 ifInErrors:0 ifInDiscards:0 _mtime:1371175621 ifOutDiscards:0 ifHCOutOctets:12602899810 _time:1371175621 ifOutErrors:0 ifAdminStatus:1 ifSpeed:1000000000
|
4
|
+
ifOutDiscards:0 ifInOctets:27495328828 ifInUcastPkts:116669910 ifInDiscards:0 ifAdminStatus:1 ifHCInOctets:27495328828 _time:1371175921 ifDescr:eth0 _mtime:1371175921 ifOutOctets:12603046499 ifOutUcastPkts:83954969 ifOperStatus:1 ifSpeed:1000000000 ifOutNUcastPkts:0 ifInNUcastPkts:136966 ifAlias: ifHighSpeed:1000 _key:_eth0 _host:testhost ifOutErrors:0 ipaddr:198.51.100.208/255.255.255.0 ifInErrors:0 ifHCOutOctets:12603046499
|
5
|
+
ifOutNUcastPkts:0 ifSpeed:1000000000 ifOutUcastPkts:83956472 ifInUcastPkts:116672186 ifOutErrors:0 _mtime:1371176222 _host:testhost ifOperStatus:1 ifDescr:eth0 ifAlias: ifInErrors:0 ifOutOctets:12603224788 _key:_eth0 ifInDiscards:0 ipaddr:198.51.100.208/255.255.255.0 ifHighSpeed:1000 ifHCInOctets:27495585909 ifInNUcastPkts:136971 ifOutDiscards:0 ifInOctets:27495585909 ifHCOutOctets:12603224788 _time:1371176222 ifAdminStatus:1
|
6
|
+
_mtime:1371176521 _host:testhost ifOutNUcastPkts:0 ifInUcastPkts:116674397 ifInErrors:0 ipaddr:198.51.100.208/255.255.255.0 ifOutOctets:12603382781 ifHCOutOctets:12603382781 ifAdminStatus:1 ifSpeed:1000000000 ifOutDiscards:0 ifInDiscards:0 _key:_eth0 _time:1371176521 ifInNUcastPkts:136976 ifOperStatus:1 ifDescr:eth0 ifOutErrors:0 ifInOctets:27495830850 ifOutUcastPkts:83957856 ifAlias: ifHighSpeed:1000 ifHCInOctets:27495830850
|
7
|
+
_key:_eth0 _host:testhost ifHCInOctets:27496048401 ifOutDiscards:0 _mtime:1371176821 ipaddr:198.51.100.208/255.255.255.0 ifInErrors:0 ifOutOctets:12603528168 ifOutNUcastPkts:0 ifAlias: ifInNUcastPkts:136981 ifOutUcastPkts:83959049 ifOperStatus:1 ifHighSpeed:1000 ifAdminStatus:1 ifDescr:eth0 _time:1371176821 ifInUcastPkts:116676373 ifInDiscards:0 ifSpeed:1000000000 ifHCOutOctets:12603528168 ifInOctets:27496048401 ifOutErrors:0
|
8
|
+
ifOutErrors:0 _key:_eth0 ifOutUcastPkts:83960396 ifOperStatus:1 ifHighSpeed:1000 ifInUcastPkts:116678564 ifOutOctets:12603694511 ifAdminStatus:1 ifAlias: ifInNUcastPkts:136985 ifInErrors:0 ifSpeed:1000000000 ifDescr:eth0 ipaddr:198.51.100.208/255.255.255.0 ifHCOutOctets:12603694511 _mtime:1371177121 ifOutNUcastPkts:0 ifHCInOctets:27496309820 _time:1371177121 _host:testhost ifOutDiscards:0 ifInDiscards:0 ifInOctets:27496309820
|
9
|
+
ifHighSpeed:1000 ifOutOctets:12603839868 _mtime:1371177421 ifHCInOctets:27496535042 ifHCOutOctets:12603839868 ifInErrors:0 ifInUcastPkts:116680537 ifOperStatus:1 ifSpeed:1000000000 _key:_eth0 ifInNUcastPkts:136990 ifInDiscards:0 ifDescr:eth0 _time:1371177421 ipaddr:198.51.100.208/255.255.255.0 ifOutDiscards:0 ifAlias: ifOutErrors:0 ifInOctets:27496535042 ifOutUcastPkts:83961590 ifAdminStatus:1 ifOutNUcastPkts:0 _host:testhost
|
10
|
+
ifHighSpeed:1000 ifHCInOctets:27496761294 ifOutNUcastPkts:0 ifOutUcastPkts:83962783 ifOutDiscards:0 _host:testhost ifInDiscards:0 ifAdminStatus:1 ipaddr:198.51.100.208/255.255.255.0 ifInNUcastPkts:136996 ifInUcastPkts:116682517 ifAlias: ifHCOutOctets:12603985303 ifOutErrors:0 _time:1371177721 _key:_eth0 ifInErrors:0 ifOperStatus:1 ifSpeed:1000000000 _mtime:1371177721 ifOutOctets:12603985303 ifInOctets:27496761294 ifDescr:eth0
|
11
|
+
ifAdminStatus:1 _mtime:1371178022 ifInNUcastPkts:137000 ifInUcastPkts:116684520 _key:_eth0 ifOutNUcastPkts:0 ifInDiscards:0 _time:1371178022 ifAlias: ifOutDiscards:0 ifSpeed:1000000000 ifHighSpeed:1000 ifHCInOctets:27496981613 ifOperStatus:1 ifDescr:eth0 ifHCOutOctets:12604130342 _host:testhost ifOutUcastPkts:83963970 ifOutOctets:12604130342 ipaddr:198.51.100.208/255.255.255.0 ifInOctets:27496981613 ifOutErrors:0 ifInErrors:0
|
12
|
+
ifOutErrors:0 ifOutOctets:12604275519 _time:1371178322 ifInOctets:27497194428 _key:_eth0 ifInUcastPkts:116686502 ifInDiscards:0 _mtime:1371178322 ifInNUcastPkts:137005 ifAdminStatus:1 ifAlias: ifHighSpeed:1000 _host:testhost ifOutUcastPkts:83965158 ifOutDiscards:0 ifHCOutOctets:12604275519 ifOutNUcastPkts:0 ifOperStatus:1 ifDescr:eth0 ifHCInOctets:27497194428 ipaddr:198.51.100.208/255.255.255.0 ifInErrors:0 ifSpeed:1000000000
|
13
|
+
ifInOctets:27497416028 ifOutUcastPkts:83966348 ifOutDiscards:0 _host:testhost ifInDiscards:0 ifAdminStatus:1 ifInErrors:0 ifOutOctets:12604420636 ifOperStatus:1 _mtime:1371178621 ifHCInOctets:27497416028 ifInUcastPkts:116688523 ifDescr:eth0 ifOutNUcastPkts:0 ifSpeed:1000000000 ipaddr:198.51.100.208/255.255.255.0 ifAlias: _time:1371178621 _key:_eth0 ifOutErrors:0 ifHCOutOctets:12604420636 ifInNUcastPkts:137010 ifHighSpeed:1000
|
14
|
+
ifOutErrors:0 ifInNUcastPkts:137016 ifOutUcastPkts:83967540 ifInErrors:0 ifSpeed:1000000000 ifHighSpeed:1000 _time:1371178922 _key:_eth0 ifDescr:eth0 ifOperStatus:1 ifInUcastPkts:116690529 ifAdminStatus:1 ifAlias: _mtime:1371178922 _host:testhost ifOutDiscards:0 ifOutOctets:12604565981 ifHCOutOctets:12604565981 ifHCInOctets:27497623151 ifInDiscards:0 ipaddr:198.51.100.208/255.255.255.0 ifOutNUcastPkts:0 ifInOctets:27497623151
|
15
|
+
ipaddr:198.51.100.208/255.255.255.0 ifDescr:eth0 ifOutDiscards:0 ifInDiscards:0 ifInOctets:27497835613 ifHCInOctets:27497835613 _key:_eth0 _host:testhost ifOutNUcastPkts:0 ifAdminStatus:1 ifOutErrors:0 ifHighSpeed:1000 ifInUcastPkts:116692506 ifInErrors:0 ifSpeed:1000000000 ifAlias: ifHCOutOctets:12604711242 ifOperStatus:1 _time:1371179221 _mtime:1371179221 ifOutUcastPkts:83968730 ifOutOctets:12604711242 ifInNUcastPkts:137019
|
16
|
+
_host:testhost ifDescr:eth0 ifOutOctets:12604856191 ifAlias: ipaddr:198.51.100.208/255.255.255.0 ifOutNUcastPkts:0 ifOperStatus:1 ifHCInOctets:27498054760 ifInErrors:0 ifAdminStatus:1 _time:1371179522 ifInUcastPkts:116694492 ifInOctets:27498054760 ifHCOutOctets:12604856191 _mtime:1371179522 ifInNUcastPkts:137025 ifInDiscards:0 ifSpeed:1000000000 ifOutDiscards:0 _key:_eth0 ifOutUcastPkts:83969916 ifOutErrors:0 ifHighSpeed:1000
|
17
|
+
_mtime:1371179822 ifAdminStatus:1 ifHCOutOctets:12605008314 ifOutNUcastPkts:0 ifOutOctets:12605008314 _host:testhost ifInDiscards:0 ifOperStatus:1 ifInUcastPkts:116696540 ifAlias: _time:1371179822 ipaddr:198.51.100.208/255.255.255.0 ifHCInOctets:27498292406 ifInErrors:0 ifOutUcastPkts:83971184 ifOutErrors:0 ifInOctets:27498292406 ifSpeed:1000000000 ifDescr:eth0 ifHighSpeed:1000 _key:_eth0 ifInNUcastPkts:137030 ifOutDiscards:0
|
18
|
+
_host:testhost ifAlias: ifInErrors:0 ifAdminStatus:1 ifHCOutOctets:12605153527 _mtime:1371180121 ifOutDiscards:0 ifSpeed:1000000000 ifHighSpeed:1000 ifOutNUcastPkts:0 ifOutUcastPkts:83972374 ifInOctets:27498512600 ifOperStatus:1 ifDescr:eth0 ipaddr:198.51.100.208/255.255.255.0 ifInNUcastPkts:137036 ifOutOctets:12605153527 _time:1371180121 ifHCInOctets:27498512600 ifInDiscards:0 ifOutErrors:0 _key:_eth0 ifInUcastPkts:116698540
|
19
|
+
ifOutDiscards:0 _host:testhost ipaddr:198.51.100.208/255.255.255.0 ifHCInOctets:27498717329 ifInNUcastPkts:137041 ifInOctets:27498717329 ifOutOctets:12605298644 _mtime:1371180421 ifHighSpeed:1000 ifInErrors:0 ifInDiscards:0 ifDescr:eth0 _time:1371180421 ifOutNUcastPkts:0 ifOutUcastPkts:83973564 ifOutErrors:0 ifAdminStatus:1 ifAlias: ifHCOutOctets:12605298644 ifInUcastPkts:116700513 ifOperStatus:1 ifSpeed:1000000000 _key:_eth0
|
20
|
+
ifHCOutOctets:12605443941 ifHCInOctets:27498895868 _host:testhost ifInUcastPkts:116702539 ifOperStatus:1 ifDescr:eth0 ifOutNUcastPkts:0 ifInDiscards:0 ifAdminStatus:1 ifAlias: _key:_eth0 ipaddr:198.51.100.208/255.255.255.0 ifOutErrors:0 _time:1371180722 _mtime:1371180722 ifInNUcastPkts:137045 ifInOctets:27498895868 ifSpeed:1000000000 ifInErrors:0 ifOutDiscards:0 ifOutOctets:12605443941 ifHighSpeed:1000 ifOutUcastPkts:83974756
|
data/test/test_app.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/unittest_helper')
|
2
|
+
|
3
|
+
require 'gri/app_collector'
|
4
|
+
|
5
|
+
module GRI
|
6
|
+
|
7
|
+
class MockWriter
|
8
|
+
attr_reader :record_count
|
9
|
+
def initialize
|
10
|
+
@record_count = 0
|
11
|
+
end
|
12
|
+
|
13
|
+
def write records
|
14
|
+
@record_count += records.size
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class TestApp < Test::Unit::TestCase
|
19
|
+
def setup
|
20
|
+
@root_dir = File.dirname(__FILE__) + '/root'
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_app_load_target_lines
|
24
|
+
config = Config.new
|
25
|
+
path = File.expand_path(@root_dir + '/testtab')
|
26
|
+
config['gritab-path'] = path
|
27
|
+
app = AppCollector.new config
|
28
|
+
lines = app.load_target_lines config
|
29
|
+
assert(lines.size >= 9)
|
30
|
+
|
31
|
+
targets = app.get_targets_from_lines lines, config
|
32
|
+
host, options = targets.first
|
33
|
+
ae 'localhost', host
|
34
|
+
ae '2c', options['ver']
|
35
|
+
ae 'public', options['community']
|
36
|
+
assert !options['interfaces']
|
37
|
+
|
38
|
+
config['host-pat'] = '00'
|
39
|
+
targets = app.get_targets_from_lines lines, config
|
40
|
+
ae 1, targets.size
|
41
|
+
ae 'host00', targets.first.first
|
42
|
+
|
43
|
+
config['host-pat'] = '02'
|
44
|
+
targets = app.get_targets_from_lines lines, config
|
45
|
+
ae 2, targets.size
|
46
|
+
ae 'host02', targets.last.first
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_load_fake_descr_files
|
50
|
+
config = Config.new
|
51
|
+
app = AppCollector.new config
|
52
|
+
files = [@root_dir + '/if.def']
|
53
|
+
h = app.load_fake_descr_files files
|
54
|
+
ae 'Test eth0 Description', h['testhost']['_eth0']
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/unittest_helper')
|
2
|
+
|
3
|
+
require 'gri/builtindefs'
|
4
|
+
require 'gri/msnmp'
|
5
|
+
require 'gri/vendor'
|
6
|
+
require 'gri/plugin/ucdavis'
|
7
|
+
|
8
|
+
module GRI
|
9
|
+
|
10
|
+
class TestBuiltinDEFS < Test::Unit::TestCase
|
11
|
+
def setup
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_get_spec
|
15
|
+
specs = DEFS.get_specs 'num'
|
16
|
+
ae '_index', specs[:prop][:name]
|
17
|
+
ae 4, specs[:rra].size
|
18
|
+
specs = DEFS.get_specs ''
|
19
|
+
ae 'ifInOctets,inoctet,DERIVE,MAX,AREA,#90f090,in,8', specs[:ds].first
|
20
|
+
specs = DEFS.get_specs :l
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# coding: us-ascii
|
2
|
+
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + '/unittest_helper')
|
4
|
+
|
5
|
+
require 'socket'
|
6
|
+
require 'mock'
|
7
|
+
require 'gri/log'
|
8
|
+
require 'gri/collector'
|
9
|
+
|
10
|
+
module GRI
|
11
|
+
|
12
|
+
class MockSNMP < SNMP
|
13
|
+
def connect
|
14
|
+
@sock = MockUDPSocket.new
|
15
|
+
@sock.connect @host, @port
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class TestCollector < Test::Unit::TestCase
|
20
|
+
TEST_SYS = "0\x81\xF2\x02\x01\x01\x04\bpublic00\xA2\x81\xE2\x02" +
|
21
|
+
"\x02\x03\xE9\x02\x01\x00\x02\x01\x000\x81\xD50d\x06\b+\x06\x01" +
|
22
|
+
"\x02\x01\x01\x01\x00\x04XLinux xxxxx.yyyyy.zzz.com " +
|
23
|
+
"X.X.XX-XXX.XX.X.XXX #1 SMP Thu Oct 31 12:00:00 EDT 2013 x86_64" +
|
24
|
+
"0\x1F\x06\b+\x06\x01\x02\x01\x01\x05\x00\x04\x13xxxxx.yyyyy.zzz.com" +
|
25
|
+
"0\x16\x06\b+\x06\x01\x02\x01\x01\x02\x00\x06\n+\x06\x01\x04\x01" +
|
26
|
+
"\xBF\b\x03\x02\n0\x10\x06\b+\x06\x01\x02\x01\x01\x03\x00C\x04" +
|
27
|
+
"\x7F\xC9i\xA10\"\x06\b+\x06\x01\x02\x01\x01\x06\x00" +
|
28
|
+
"\x04\x16xxxxx xxxx, xxxxx xxx."
|
29
|
+
|
30
|
+
def test_snmp_collecotr
|
31
|
+
c = Collector.create('snmp', 'testhost', {}) {|records|}
|
32
|
+
snmp = MockSNMP.new 'testhost'
|
33
|
+
c.instance_eval {
|
34
|
+
@loop = MockLoop.new
|
35
|
+
@snmp = snmp
|
36
|
+
}
|
37
|
+
|
38
|
+
rs = {}
|
39
|
+
c.get(SNMPCollector::SYSOIDS) {|results|
|
40
|
+
results.each {|enoid, tag, val| rs[SNMP::ROIDS[enoid]] = val}
|
41
|
+
}
|
42
|
+
ae :GET_REQ, snmp.state
|
43
|
+
|
44
|
+
ae 0, c.instance_eval('@retry_count')
|
45
|
+
c.retry
|
46
|
+
ae 1, c.instance_eval('@retry_count')
|
47
|
+
|
48
|
+
snmp.sock.data = TEST_SYS
|
49
|
+
c.on_readable
|
50
|
+
ae rs['sysName.0'], 'xxxxx.yyyyy.zzz.com'
|
51
|
+
|
52
|
+
enoid = BER.enc_v_oid SNMP::OIDS['ipAdEntIfIndex']
|
53
|
+
c.walk(enoid) {|enoid, tag, val|}
|
54
|
+
ae :GETNEXT_REQ, snmp.state
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|