zabbix_pusher 0.0.3

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 ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .idea/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in zabbix_pusher.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+
4
+ require 'bundler'
5
+ require 'rspec/core/rake_task'
6
+
7
+ Bundler::GemHelper.install_tasks
8
+ RSpec::Core::RakeTask.new :spec
@@ -0,0 +1,3 @@
1
+ module ZabbixPusher
2
+ VERSION = "0.0.3"
3
+ end
@@ -0,0 +1,80 @@
1
+ require "zabbix_pusher/version"
2
+ require "active_support/core_ext/string/inflections.rb"
3
+ require 'nokogiri'
4
+ require 'yajl/json_gem'
5
+
6
+ module ZabbixPusher
7
+ class Pusher
8
+ def initialize(templates, options = {} )
9
+ options[:zabbix_server_name] = 'localhost' unless options[:zabbix_server_name]
10
+ options[:zabbix_server_port] = '10051' unless options[:zabbix_server_port]
11
+
12
+ @options = options
13
+
14
+ @templates = []
15
+ @templates = Dir.glob(File.join(templates),'*.xml') if File.directory?(templates)
16
+ @templates = templates.map{ |template| template if File.exist?(template) }.compact if templates.is_a?(Array)
17
+ @templates = [templates] if File.exist?(templates)
18
+
19
+ @items = Hash.new
20
+
21
+ @templates.each do |template|
22
+ template_items = Nokogiri::XML(File.open(template))
23
+ items = template_items.xpath('//item').map {|item| item.attributes['key'].text}.compact
24
+ items.each do |item|
25
+ parts = item.match(/([^\[]+)\[([^\]]+)/)
26
+ key = parts[1]
27
+ attributes = parts[2]
28
+ (@items[key.to_sym]) ? @items[key.to_sym] << attributes : @items[key.to_sym] = [attributes]
29
+ end
30
+ end
31
+ end
32
+
33
+ def send(items = :all)
34
+
35
+ return if @items.nil?
36
+
37
+ pushers = ( items == :all) ? (@items.keys.map{ |key| "ZabbixPusher::#{key.to_s.camelize}".constantize}) : ["ZabbixPusher::#{items.camelize}".constantize]
38
+
39
+ processed_items = Hash.new
40
+
41
+ pushers.map do |pusher|
42
+ pusher_key = pusher.to_s.demodulize.underscore.to_sym
43
+ processed_items.update pusher.new(@items[pusher_key],@options[pusher_key]).send(:processed_items)
44
+ end
45
+ processed_items
46
+ end
47
+ end
48
+
49
+ require 'httparty'
50
+
51
+ class Jmx
52
+
53
+ include HTTParty
54
+ base_uri 'http://localhost:8080'
55
+ format :json
56
+
57
+ def initialize(items,options)
58
+ self.class.base_uri options[:base_uri] if options[:base_uri]
59
+ @payload = Array.new
60
+ @items = items
61
+ @items.each do |item| mbean,attribute,path = item.split(';')
62
+ tokens = { "mbean" => mbean, "attribute" => attribute, "type" => "READ"}
63
+ tokens["path"] = path if path
64
+ @payload << tokens
65
+ end
66
+ end
67
+
68
+ def processed_items
69
+ data = self.class.post('/jolokia', :body => @payload.to_json)
70
+ result = Hash.new
71
+ data.each{|datum| result[result_key(datum)] = datum['value'] if datum['request']}
72
+ result
73
+ end
74
+
75
+ def result_key(datum)
76
+ "#{datum['request']['mbean']};#{datum['request']['attribute']};#{datum['request']['path']}"
77
+ end
78
+ end
79
+
80
+ end
@@ -0,0 +1,7 @@
1
+ HTTP/1.1 200 OK
2
+ Server: Apache-Coyote/1.1
3
+ Content-Type: text/plain;charset=utf-8
4
+ Content-Length: 512
5
+ Date: Wed, 15 Jun 2011 15:17:12 GMT
6
+
7
+ [{"timestamp":1308151032,"status":200,"request":{"mbean":"java.lang:name=CMS Perm Gen,type=MemoryPool","path":"committed","attribute":"Usage","type":"read"},"value":31518720},{"timestamp":1308151032,"status":200,"request":{"mbean":"java.lang:name=CMS Perm Gen,type=MemoryPool","path":"max","attribute":"Usage","type":"read"},"value":67108864},{"timestamp":1308151032,"status":200,"request":{"mbean":"java.lang:name=CMS Perm Gen,type=MemoryPool","path":"used","attribute":"Usage","type":"read"},"value":18890360}]
@@ -0,0 +1,96 @@
1
+ <?xml version="1.0"?>
2
+ <zabbix_export version="1.0" date="22.12.07" time="03.42">
3
+ <hosts>
4
+ <host name="Template_Tomcat">
5
+ <proxy_hostid>0</proxy_hostid>
6
+ <useip>0</useip>
7
+ <dns/>
8
+ <ip>0.0.0.0</ip>
9
+ <port>0</port>
10
+ <status>3</status>
11
+ <groups>
12
+ <group>Templates</group>
13
+ <group>Web Server</group>
14
+ </groups>
15
+ <triggers/>
16
+ <groups>
17
+ <group>Templates</group>
18
+ </groups>
19
+ <items>
20
+ <item type="7" key="jmx[java.lang:name=CMS Perm Gen,type=MemoryPool;Usage;committed]" value_type="3">
21
+ <description>memorypool cms perm gen committed</description>
22
+ <delay>30</delay>
23
+ <history>90</history>
24
+ <trends>365</trends>
25
+ <units>B</units>
26
+ <formula>1</formula>
27
+ <snmp_community>public</snmp_community>
28
+ <snmp_oid>interfaces.ifTable.ifEntry.ifInOctets.1</snmp_oid>
29
+ <snmp_port>161</snmp_port>
30
+ </item>
31
+ <item type="7" key="jmx[java.lang:name=CMS Perm Gen,type=MemoryPool;Usage;max]" value_type="3">
32
+ <description>memorypool cms perm gen max</description>
33
+ <delay>3600</delay>
34
+ <history>90</history>
35
+ <trends>365</trends>
36
+ <units>B</units>
37
+ <formula>1</formula>
38
+ <snmp_community>public</snmp_community>
39
+ <snmp_oid>interfaces.ifTable.ifEntry.ifInOctets.1</snmp_oid>
40
+ <snmp_port>161</snmp_port>
41
+ </item>
42
+ <item type="7" key="jmx[java.lang:name=CMS Perm Gen,type=MemoryPool;Usage;used]" value_type="3">
43
+ <description>memorypool cms perm gen used</description>
44
+ <delay>30</delay>
45
+ <history>90</history>
46
+ <trends>365</trends>
47
+ <units>B</units>
48
+ <formula>1</formula>
49
+ <snmp_community>public</snmp_community>
50
+ <snmp_oid>interfaces.ifTable.ifEntry.ifInOctets.1</snmp_oid>
51
+ <snmp_port>161</snmp_port>
52
+ </item>
53
+ </items>
54
+ <triggers/>
55
+ <graphs>
56
+ <graph name="memorypool cms perm gen" width="900" height="200">
57
+ <show_work_period>1</show_work_period>
58
+ <show_triggers>1</show_triggers>
59
+ <ymin_type>0</ymin_type>
60
+ <ymax_type>0</ymax_type>
61
+ <ymin_item_key></ymin_item_key>
62
+ <ymax_item_key></ymax_item_key>
63
+ <show_work_period>0</show_work_period>
64
+ <show_triggers>0</show_triggers>
65
+ <graphtype>1</graphtype>
66
+ <yaxismin>0.0000</yaxismin>
67
+ <yaxismax>100.0000</yaxismax>
68
+ <show_legend>0</show_legend>
69
+ <show_3d>0</show_3d>
70
+ <percent_left>0.0000</percent_left>
71
+ <percent_right>0.0000</percent_right>
72
+ <graph_elements>
73
+ <graph_element item="{HOSTNAME}:jmx[java.lang:name=CMS Perm Gen,type=MemoryPool;Usage;committed]">
74
+ <color>000099</color>
75
+ <yaxisside>1</yaxisside>
76
+ <calc_fnc>2</calc_fnc>
77
+ <periods_cnt>5</periods_cnt>
78
+ </graph_element>
79
+ <graph_element item="{HOSTNAME}:jmx[java.lang:name=CMS Perm Gen,type=MemoryPool;Usage;max]">
80
+ <color>990000</color>
81
+ <yaxisside>1</yaxisside>
82
+ <calc_fnc>2</calc_fnc>
83
+ <periods_cnt>5</periods_cnt>
84
+ </graph_element>
85
+ <graph_element item="{HOSTNAME}:jmx[java.lang:name=CMS Perm Gen,type=MemoryPool;Usage;used]">
86
+ <color>009900</color>
87
+ <yaxisside>1</yaxisside>
88
+ <calc_fnc>2</calc_fnc>
89
+ <periods_cnt>5</periods_cnt>
90
+ </graph_element>
91
+ </graph_elements>
92
+ </graph>
93
+ </graphs>
94
+ </host>
95
+ </hosts>
96
+ </zabbix_export>
@@ -0,0 +1,13 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ $: << File.join(File.dirname(__FILE__), "/../lib")
4
+ require 'zabbix_pusher'
5
+ require 'fakeweb'
6
+
7
+ FakeWeb.allow_net_connect = false
8
+
9
+ def fixture_file(filename)
10
+ return '' if filename == ''
11
+ file_path = File.expand_path(File.dirname(__FILE__) + '/fixtures/' + filename)
12
+ File.read(file_path)
13
+ end
@@ -0,0 +1,35 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require File.join(File.dirname(__FILE__), "/spec_helper")
4
+ require 'ap'
5
+
6
+ describe ZabbixPusher::Pusher do
7
+
8
+ context 'Initialization' do
9
+
10
+ FakeWeb.register_uri(:post, "http://localhost:4568/jolokia", :response => fixture_file("cms_perm_response.txt"))
11
+
12
+ it 'should accept a template file' do
13
+ @m = ZabbixPusher::Pusher.new(File.join(File.dirname(__FILE__), 'fixtures/tomcat_template.xml'),:jmx => {:base_uri => "http://localhost:4568"})
14
+ @m.send.should == {
15
+ "java.lang:name=CMS Perm Gen,type=MemoryPool;Usage;max" => 67108864,
16
+ "java.lang:name=CMS Perm Gen,type=MemoryPool;Usage;committed" => 31518720,
17
+ "java.lang:name=CMS Perm Gen,type=MemoryPool;Usage;used" => 18890360
18
+ }
19
+ end
20
+
21
+ end
22
+
23
+ context 'process items' do
24
+
25
+
26
+ before(:each) do
27
+ end
28
+
29
+ it "should get the title" do
30
+ end
31
+
32
+
33
+ end
34
+
35
+ end
@@ -0,0 +1,32 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "zabbix_pusher/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "zabbix_pusher"
7
+ s.version = ZabbixPusher::VERSION
8
+ s.authors = ["Edmund Haselwanter"]
9
+ s.email = ["edmund@haselwanter.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Push data to Zabbix}
12
+ s.description = %q{zabbix_pusher is a gem to parse zabbix templates and push the data to the corresponding zabbix server}
13
+
14
+ s.rubyforge_project = "zabbix_pusher"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_dependency 'nokogiri', '~> 1.4.4'
22
+ s.add_dependency 'zabbix', '~> 0.3.0'
23
+ s.add_dependency 'httparty', '~> 0.7.8'
24
+ s.add_dependency 'activesupport', '~> 3.0.8'
25
+ s.add_dependency "i18n", "~> 0.6.0"
26
+ s.add_dependency 'yajl-ruby', '~> 0.8.2'
27
+
28
+ s.add_development_dependency 'rspec', '~> 2.6.0'
29
+ s.add_development_dependency 'fakeweb', '~> 1.3.0'
30
+ s.add_development_dependency "awesome_print", "~> 0.4.0"
31
+
32
+ end
metadata ADDED
@@ -0,0 +1,223 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: zabbix_pusher
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 3
10
+ version: 0.0.3
11
+ platform: ruby
12
+ authors:
13
+ - Edmund Haselwanter
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-06-15 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: nokogiri
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 15
30
+ segments:
31
+ - 1
32
+ - 4
33
+ - 4
34
+ version: 1.4.4
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: zabbix
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ hash: 19
46
+ segments:
47
+ - 0
48
+ - 3
49
+ - 0
50
+ version: 0.3.0
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: httparty
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ hash: 19
62
+ segments:
63
+ - 0
64
+ - 7
65
+ - 8
66
+ version: 0.7.8
67
+ type: :runtime
68
+ version_requirements: *id003
69
+ - !ruby/object:Gem::Dependency
70
+ name: activesupport
71
+ prerelease: false
72
+ requirement: &id004 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ hash: 23
78
+ segments:
79
+ - 3
80
+ - 0
81
+ - 8
82
+ version: 3.0.8
83
+ type: :runtime
84
+ version_requirements: *id004
85
+ - !ruby/object:Gem::Dependency
86
+ name: i18n
87
+ prerelease: false
88
+ requirement: &id005 !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ hash: 7
94
+ segments:
95
+ - 0
96
+ - 6
97
+ - 0
98
+ version: 0.6.0
99
+ type: :runtime
100
+ version_requirements: *id005
101
+ - !ruby/object:Gem::Dependency
102
+ name: yajl-ruby
103
+ prerelease: false
104
+ requirement: &id006 !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ hash: 59
110
+ segments:
111
+ - 0
112
+ - 8
113
+ - 2
114
+ version: 0.8.2
115
+ type: :runtime
116
+ version_requirements: *id006
117
+ - !ruby/object:Gem::Dependency
118
+ name: rspec
119
+ prerelease: false
120
+ requirement: &id007 !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ~>
124
+ - !ruby/object:Gem::Version
125
+ hash: 23
126
+ segments:
127
+ - 2
128
+ - 6
129
+ - 0
130
+ version: 2.6.0
131
+ type: :development
132
+ version_requirements: *id007
133
+ - !ruby/object:Gem::Dependency
134
+ name: fakeweb
135
+ prerelease: false
136
+ requirement: &id008 !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ~>
140
+ - !ruby/object:Gem::Version
141
+ hash: 27
142
+ segments:
143
+ - 1
144
+ - 3
145
+ - 0
146
+ version: 1.3.0
147
+ type: :development
148
+ version_requirements: *id008
149
+ - !ruby/object:Gem::Dependency
150
+ name: awesome_print
151
+ prerelease: false
152
+ requirement: &id009 !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ~>
156
+ - !ruby/object:Gem::Version
157
+ hash: 15
158
+ segments:
159
+ - 0
160
+ - 4
161
+ - 0
162
+ version: 0.4.0
163
+ type: :development
164
+ version_requirements: *id009
165
+ description: zabbix_pusher is a gem to parse zabbix templates and push the data to the corresponding zabbix server
166
+ email:
167
+ - edmund@haselwanter.com
168
+ executables: []
169
+
170
+ extensions: []
171
+
172
+ extra_rdoc_files: []
173
+
174
+ files:
175
+ - .gitignore
176
+ - Gemfile
177
+ - Rakefile
178
+ - lib/zabbix_pusher.rb
179
+ - lib/zabbix_pusher/version.rb
180
+ - spec/fixtures/cms_perm_response.txt
181
+ - spec/fixtures/tomcat_template.xml
182
+ - spec/spec_helper.rb
183
+ - spec/zabbix_pusher_spec.rb
184
+ - zabbix_pusher.gemspec
185
+ has_rdoc: true
186
+ homepage: ""
187
+ licenses: []
188
+
189
+ post_install_message:
190
+ rdoc_options: []
191
+
192
+ require_paths:
193
+ - lib
194
+ required_ruby_version: !ruby/object:Gem::Requirement
195
+ none: false
196
+ requirements:
197
+ - - ">="
198
+ - !ruby/object:Gem::Version
199
+ hash: 3
200
+ segments:
201
+ - 0
202
+ version: "0"
203
+ required_rubygems_version: !ruby/object:Gem::Requirement
204
+ none: false
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ hash: 3
209
+ segments:
210
+ - 0
211
+ version: "0"
212
+ requirements: []
213
+
214
+ rubyforge_project: zabbix_pusher
215
+ rubygems_version: 1.3.7
216
+ signing_key:
217
+ specification_version: 3
218
+ summary: Push data to Zabbix
219
+ test_files:
220
+ - spec/fixtures/cms_perm_response.txt
221
+ - spec/fixtures/tomcat_template.xml
222
+ - spec/spec_helper.rb
223
+ - spec/zabbix_pusher_spec.rb