zabbix_pusher 0.0.3 → 0.0.4

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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
data/bin/zabbix_pusher ADDED
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #
4
+ # Author:: Edmund Haselwanter (<office@iteh.at>)
5
+ # Copyright:: Copyright (c) 2011 Edmund Haselwanter
6
+ # License:: Apache License, Version 2.0
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+
20
+ require "rubygems"
21
+ require "ap"
22
+
23
+ $:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
24
+
25
+ require "zabbix_pusher"
26
+ require "zabbix_pusher/pusher_cli"
27
+ require "zabbix_pusher/jmx_cli"
28
+
29
+ cli = ZabbixPusher::PusherCLI.new
30
+ cli.parse_options(ARGV)
31
+ cli.config
32
+
33
+ values = ZabbixPusher::Pusher.new(cli.config[:templates],cli.config.merge(:jmx => {:base_uri => cli.config[:jmx__base_uri]}) ).send
34
+
35
+ ap values if cli.config[:show_send_values]
36
+
37
+
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #
4
+ # Author:: Edmund Haselwanter (<office@iteh.at>)
5
+ # Copyright:: Copyright (c) 2011 Edmund Haselwanter
6
+ # License:: Apache License, Version 2.0
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+
20
+ require "rubygems"
21
+ require "ap"
22
+
23
+ $:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
24
+
25
+ require "zabbix_pusher"
26
+ require "zabbix_pusher/jmx_cli"
27
+
28
+ cli = ZabbixPusher::JmxCLI.new
29
+ cli.parse_options(ARGV)
30
+ cli.config
31
+
32
+ jmx = ZabbixPusher::Jmx.new([],cli.config)
33
+
34
+ case cli.config[:command]
35
+ when :read
36
+ ap jmx.send(cli.config[:command],cli.config[:mbean],cli.config[:attribute],cli.config[:path],cli.config)
37
+ when :list
38
+ ap jmx.send(cli.config[:command],cli.config[:path],cli.config)
39
+ when :search
40
+ ap jmx.send(cli.config[:command],cli.config[:mbean],cli.config)
41
+
42
+ end
@@ -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,78 @@
1
+ #
2
+ # Author:: Edmund Haselwanter (<office@iteh.at>)
3
+ # Copyright:: Copyright (c) 2011 Edmund Haselwanter
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
18
+ require 'httparty'
19
+
20
+ module ZabbixPusher
21
+
22
+ class Jmx
23
+
24
+ include HTTParty
25
+ base_uri 'http://localhost:8080'
26
+ format :json
27
+
28
+ def initialize(items=[] ,options={})
29
+ self.class.base_uri options[:base_uri] if options[:base_uri]
30
+ @payload = Array.new
31
+ @items = items
32
+ @items.each do |item| mbean,attribute,path = item.split(';')
33
+ tokens = { "mbean" => mbean, "attribute" => attribute, "type" => "READ"}
34
+ tokens["path"] = path if path
35
+ @payload << tokens
36
+ end
37
+ end
38
+
39
+ # http://www.jolokia.org/reference/html/protocol.html#search
40
+
41
+ def search(mbean,config={})
42
+ self.class.post('/jolokia', :body => { "type" => "SEARCH", "mbean" => mbean, "config" => config}.to_json)
43
+ end
44
+
45
+ # http://www.jolokia.org/reference/html/protocol.html#list
46
+ # use options = { "maxDepth" => 2} to limit depth
47
+
48
+ def list(path,config={})
49
+ self.class.post('/jolokia', :body => { "type" => "LIST", "path" => path, "config" => config}.to_json)
50
+ end
51
+
52
+ def read(mbean,attribute,path=nil,config={})
53
+ payload = { "type" => "READ", "mbean" => mbean, "attribute" => attribute}
54
+ payload["path"] = path if path
55
+ payload["config"] = config if config.length > 0
56
+ ap payload.to_json
57
+ self.class.post('/jolokia', :body => payload.to_json)
58
+ end
59
+
60
+ def version
61
+ self.class.post('/jolokia', :body => { "type" => "VERSION"}.to_json)
62
+ end
63
+
64
+ def processed_items
65
+ data = self.class.post('/jolokia', :body => @payload.to_json)
66
+ result = Hash.new
67
+ data.each{|datum| result[result_key(datum)] = datum['value'] if datum['request']}
68
+ result
69
+ end
70
+
71
+ private
72
+
73
+ def result_key(datum)
74
+ "#{self.class.to_s.demodulize.underscore}[#{datum['request']['mbean']};#{datum['request']['attribute']};#{datum['request']['path']}]"
75
+ end
76
+ end
77
+
78
+ end
@@ -0,0 +1,71 @@
1
+ #
2
+ # Author:: Edmund Haselwanter (<office@iteh.at>)
3
+ # Copyright:: Copyright (c) 2011 Edmund Haselwanter
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
18
+ require 'mixlib/cli'
19
+
20
+ module ZabbixPusher
21
+ class PusherCLI
22
+ include Mixlib::CLI
23
+
24
+ option :jmx__base_uri,
25
+ :long => "--jmx_base_uri uri",
26
+ :description => "The jmx base uri"
27
+
28
+ end
29
+
30
+ class JmxCLI
31
+ include Mixlib::CLI
32
+
33
+ option :base_uri,
34
+ :short => "-b uri",
35
+ :default => "localhost:8080",
36
+ :long => "--base_uri uri",
37
+ :description => "The jmx base uri"
38
+
39
+ option :command,
40
+ :short => "-o command",
41
+ :default => "read",
42
+ :long => "--command action",
43
+ :description => "The command to perform",
44
+ :proc => Proc.new { |o| o.to_sym }
45
+
46
+ option :mbean,
47
+ :short => "-m mbean",
48
+ :long => "--mbean mbean",
49
+ :description => "The name of the mbean e.g. java.lang:type=Memory (needed for read command)"
50
+
51
+ option :attribute,
52
+ :short => "-a attribute",
53
+ :long => "--attribute attribute",
54
+ :description => "The name of the action e.g. HeapMemoryUsage (needed for read command)"
55
+
56
+ option :path,
57
+ :short => "-p path",
58
+ :long => "--path path",
59
+ :description => "The name of the path e.g. used (needed for read and list command)"
60
+
61
+ option :help,
62
+ :short => "-h",
63
+ :long => "--help",
64
+ :description => "Show this message",
65
+ :on => :tail,
66
+ :boolean => true,
67
+ :show_options => true,
68
+ :exit => 0
69
+
70
+ end
71
+ end
@@ -0,0 +1,76 @@
1
+ #
2
+ # Author:: Edmund Haselwanter (<office@iteh.at>)
3
+ # Copyright:: Copyright (c) 2011 Edmund Haselwanter
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
18
+ require 'mixlib/cli'
19
+
20
+ module ZabbixPusher
21
+ class PusherCLI
22
+ include Mixlib::CLI
23
+
24
+ option :config_file,
25
+ :short => "-c CONFIG",
26
+ :long => "--config CONFIG",
27
+ :default => 'config.rb',
28
+ :description => "The configuration file to use"
29
+
30
+ option :templates,
31
+ :short => "-t FILE",
32
+ :long => "--template FILE",
33
+ :description => "The template file(s) to use, can be a file a comma separated list of files or a directory",
34
+ #:required => true,
35
+ :proc => Proc.new { |t| (t =~ /,/) ? t.split(',') : t }
36
+
37
+ option :zabbix_server_name,
38
+ :short => "-z SERVER",
39
+ :long => "--zabbix-server SERVER",
40
+ :default => 'localhost',
41
+ :description => "Hostname or IP address of Zabbix Server"
42
+
43
+ option :zabbix_server_port,
44
+ :short => "-p SERVER PORT",
45
+ :long => "--port SERVER PORT",
46
+ :default => '10051',
47
+ :description => "Specify port number of server trapper running on the server. Default is 10051"
48
+
49
+ option :sender_hostname,
50
+ :short => "-s HOST",
51
+ :long => "--host HOSTNAME",
52
+ :description => "Specify host name. Host IP address and DNS name will not work."
53
+
54
+ option :log_level,
55
+ :short => "-l LEVEL",
56
+ :long => "--log_level LEVEL",
57
+ :description => "Set the log level (debug, info, warn, error, fatal)",
58
+ :proc => Proc.new { |l| l.to_sym }
59
+
60
+ option :show_send_values,
61
+ :short => "-v",
62
+ :long => "--show_send_values",
63
+ :description => "shows what values got send to zabbix",
64
+ :boolean => true
65
+
66
+ option :help,
67
+ :short => "-h",
68
+ :long => "--help",
69
+ :description => "Show this message",
70
+ :on => :tail,
71
+ :boolean => true,
72
+ :show_options => true,
73
+ :exit => 0
74
+
75
+ end
76
+ end
@@ -1,3 +1,20 @@
1
+ #
2
+ # Author:: Edmund Haselwanter (<office@iteh.at>)
3
+ # Copyright:: Copyright (c) 2011 Edmund Haselwanter
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
1
18
  module ZabbixPusher
2
- VERSION = "0.0.3"
19
+ VERSION = "0.0.4"
3
20
  end
data/lib/zabbix_pusher.rb CHANGED
@@ -1,33 +1,67 @@
1
+ #
2
+ # Author:: Edmund Haselwanter (<office@iteh.at>)
3
+ # Copyright:: Copyright (c) 2011 Edmund Haselwanter
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
1
18
  require "zabbix_pusher/version"
2
19
  require "active_support/core_ext/string/inflections.rb"
3
20
  require 'nokogiri'
4
21
  require 'yajl/json_gem'
22
+ require 'zabbix'
23
+ require "socket"
24
+ require "zabbix_pusher/jmx"
5
25
 
6
26
  module ZabbixPusher
27
+
28
+ def self.root
29
+ @root ="#{File.expand_path('../..',__FILE__)}"
30
+ end
31
+
7
32
  class Pusher
8
33
  def initialize(templates, options = {} )
9
34
  options[:zabbix_server_name] = 'localhost' unless options[:zabbix_server_name]
10
35
  options[:zabbix_server_port] = '10051' unless options[:zabbix_server_port]
36
+ options[:sender_hostname] = Socket.gethostname unless options[:sender_hostname]
11
37
 
12
38
  @options = options
39
+ @templates = template_files(templates)
40
+ @items = template_items(@templates)
41
+ end
13
42
 
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)
43
+ def template_files(templates)
44
+ template_files = []
45
+ template_files = Dir.glob(File.join(templates,'*.xml')) if !templates.is_a?(Array) && File.directory?(templates)
46
+ template_files = templates.map{ |template| template if File.exist?(template) }.compact if templates.is_a?(Array)
47
+ template_files = [templates] if !templates.is_a?(Array) && File.exist?(templates) && !File.directory?(templates)
48
+ template_files
49
+ end
18
50
 
19
- @items = Hash.new
51
+ def template_items(templates)
52
+ parsed_items = Hash.new
20
53
 
21
- @templates.each do |template|
54
+ templates.each do |template|
22
55
  template_items = Nokogiri::XML(File.open(template))
23
56
  items = template_items.xpath('//item').map {|item| item.attributes['key'].text}.compact
24
57
  items.each do |item|
25
58
  parts = item.match(/([^\[]+)\[([^\]]+)/)
26
59
  key = parts[1]
27
60
  attributes = parts[2]
28
- (@items[key.to_sym]) ? @items[key.to_sym] << attributes : @items[key.to_sym] = [attributes]
61
+ (parsed_items[key.to_sym]) ? parsed_items[key.to_sym] << attributes : parsed_items[key.to_sym] = [attributes]
29
62
  end
30
63
  end
64
+ parsed_items
31
65
  end
32
66
 
33
67
  def send(items = :all)
@@ -42,38 +76,15 @@ module ZabbixPusher
42
76
  pusher_key = pusher.to_s.demodulize.underscore.to_sym
43
77
  processed_items.update pusher.new(@items[pusher_key],@options[pusher_key]).send(:processed_items)
44
78
  end
45
- processed_items
46
- end
47
- end
48
-
49
- require 'httparty'
50
79
 
51
- class Jmx
80
+ zbx = Zabbix::Sender::Buffer.new :host => @options[:zabbix_server_name], :port => @options[:zabbix_server_port]
52
81
 
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
82
+ processed_items.each do |key,value|
83
+ zbx.append key, value, :host => @options[:sender_hostname]
65
84
  end
66
- end
85
+ zbx.flush
67
86
 
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']}"
87
+ processed_items
77
88
  end
78
89
  end
79
90
 
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,22 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
+ #
4
+ # Author:: Edmund Haselwanter (<office@iteh.at>)
5
+ # Copyright:: Copyright (c) 2011 Edmund Haselwanter
6
+ # License:: Apache License, Version 2.0
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+
3
20
  $: << File.join(File.dirname(__FILE__), "/../lib")
4
21
  require 'zabbix_pusher'
5
22
  require 'fakeweb'
@@ -1,5 +1,22 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
+ #
4
+ # Author:: Edmund Haselwanter (<office@iteh.at>)
5
+ # Copyright:: Copyright (c) 2011 Edmund Haselwanter
6
+ # License:: Apache License, Version 2.0
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+
3
20
  require File.join(File.dirname(__FILE__), "/spec_helper")
4
21
  require 'ap'
5
22
 
@@ -11,11 +28,8 @@ describe ZabbixPusher::Pusher do
11
28
 
12
29
  it 'should accept a template file' do
13
30
  @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
- }
31
+ @m.send.should == {"jmx[java.lang:name=CMS Perm Gen,type=MemoryPool;Usage;max]"=>67108864, "jmx[java.lang:name=CMS Perm Gen,type=MemoryPool;Usage;used]"=>18890360, "jmx[java.lang:name=CMS Perm Gen,type=MemoryPool;Usage;committed]"=>31518720}
32
+
19
33
  end
20
34
 
21
35
  end
@@ -7,7 +7,9 @@ Gem::Specification.new do |s|
7
7
  s.version = ZabbixPusher::VERSION
8
8
  s.authors = ["Edmund Haselwanter"]
9
9
  s.email = ["edmund@haselwanter.com"]
10
- s.homepage = ""
10
+ s.homepage = "http://iteh.at"
11
+ s.license = 'Apache'
12
+
11
13
  s.summary = %q{Push data to Zabbix}
12
14
  s.description = %q{zabbix_pusher is a gem to parse zabbix templates and push the data to the corresponding zabbix server}
13
15
 
@@ -24,9 +26,10 @@ Gem::Specification.new do |s|
24
26
  s.add_dependency 'activesupport', '~> 3.0.8'
25
27
  s.add_dependency "i18n", "~> 0.6.0"
26
28
  s.add_dependency 'yajl-ruby', '~> 0.8.2'
29
+ s.add_dependency "awesome_print", "~> 0.4.0"
30
+ s.add_dependency "mixlib-cli", "~> 1.2.0"
27
31
 
28
32
  s.add_development_dependency 'rspec', '~> 2.6.0'
29
33
  s.add_development_dependency 'fakeweb', '~> 1.3.0'
30
- s.add_development_dependency "awesome_print", "~> 0.4.0"
31
34
 
32
35
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zabbix_pusher
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Edmund Haselwanter
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-06-15 00:00:00 +02:00
18
+ date: 2011-06-16 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -115,58 +115,75 @@ dependencies:
115
115
  type: :runtime
116
116
  version_requirements: *id006
117
117
  - !ruby/object:Gem::Dependency
118
- name: rspec
118
+ name: awesome_print
119
119
  prerelease: false
120
120
  requirement: &id007 !ruby/object:Gem::Requirement
121
121
  none: false
122
122
  requirements:
123
123
  - - ~>
124
124
  - !ruby/object:Gem::Version
125
- hash: 23
125
+ hash: 15
126
126
  segments:
127
- - 2
128
- - 6
129
127
  - 0
130
- version: 2.6.0
131
- type: :development
128
+ - 4
129
+ - 0
130
+ version: 0.4.0
131
+ type: :runtime
132
132
  version_requirements: *id007
133
133
  - !ruby/object:Gem::Dependency
134
- name: fakeweb
134
+ name: mixlib-cli
135
135
  prerelease: false
136
136
  requirement: &id008 !ruby/object:Gem::Requirement
137
137
  none: false
138
138
  requirements:
139
139
  - - ~>
140
140
  - !ruby/object:Gem::Version
141
- hash: 27
141
+ hash: 31
142
142
  segments:
143
143
  - 1
144
- - 3
144
+ - 2
145
145
  - 0
146
- version: 1.3.0
147
- type: :development
146
+ version: 1.2.0
147
+ type: :runtime
148
148
  version_requirements: *id008
149
149
  - !ruby/object:Gem::Dependency
150
- name: awesome_print
150
+ name: rspec
151
151
  prerelease: false
152
152
  requirement: &id009 !ruby/object:Gem::Requirement
153
153
  none: false
154
154
  requirements:
155
155
  - - ~>
156
156
  - !ruby/object:Gem::Version
157
- hash: 15
157
+ hash: 23
158
158
  segments:
159
+ - 2
160
+ - 6
159
161
  - 0
160
- - 4
161
- - 0
162
- version: 0.4.0
162
+ version: 2.6.0
163
163
  type: :development
164
164
  version_requirements: *id009
165
+ - !ruby/object:Gem::Dependency
166
+ name: fakeweb
167
+ prerelease: false
168
+ requirement: &id010 !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ~>
172
+ - !ruby/object:Gem::Version
173
+ hash: 27
174
+ segments:
175
+ - 1
176
+ - 3
177
+ - 0
178
+ version: 1.3.0
179
+ type: :development
180
+ version_requirements: *id010
165
181
  description: zabbix_pusher is a gem to parse zabbix templates and push the data to the corresponding zabbix server
166
182
  email:
167
183
  - edmund@haselwanter.com
168
- executables: []
169
-
184
+ executables:
185
+ - zabbix_pusher
186
+ - zabbix_pusher_jmx
170
187
  extensions: []
171
188
 
172
189
  extra_rdoc_files: []
@@ -174,8 +191,15 @@ extra_rdoc_files: []
174
191
  files:
175
192
  - .gitignore
176
193
  - Gemfile
194
+ - LICENSE
177
195
  - Rakefile
196
+ - bin/zabbix_pusher
197
+ - bin/zabbix_pusher_jmx
198
+ - examples/tomcat_template.xml
178
199
  - lib/zabbix_pusher.rb
200
+ - lib/zabbix_pusher/jmx.rb
201
+ - lib/zabbix_pusher/jmx_cli.rb
202
+ - lib/zabbix_pusher/pusher_cli.rb
179
203
  - lib/zabbix_pusher/version.rb
180
204
  - spec/fixtures/cms_perm_response.txt
181
205
  - spec/fixtures/tomcat_template.xml
@@ -183,9 +207,9 @@ files:
183
207
  - spec/zabbix_pusher_spec.rb
184
208
  - zabbix_pusher.gemspec
185
209
  has_rdoc: true
186
- homepage: ""
187
- licenses: []
188
-
210
+ homepage: http://iteh.at
211
+ licenses:
212
+ - Apache
189
213
  post_install_message:
190
214
  rdoc_options: []
191
215