zabbix_graph 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a948a295b74d3ef57097f5d32440d4f19a92cf79
4
- data.tar.gz: fc54a39e4e9c3eace4c5f12ec1acb16e9f95c99c
3
+ metadata.gz: 7b7abd8af739adb497359596530eaf4afba87f59
4
+ data.tar.gz: 1680e98fb258b00120c3bd99211e2430cc60584c
5
5
  SHA512:
6
- metadata.gz: 0d5099ab96cdfe4c30c4a807e9fab02f4c8954154ae890342c0a2b2b1d6d0a74e5b5f3dab726c4a622af35e42439a566bb62b74f11e417153268221739bdde28
7
- data.tar.gz: e51a130b9da10afe7574de82e77e1c526f1ab7c0f95224a6e83da7cc67e19a4b60a3717e308baa368c448705c1f0efe13f8776a158cc19c03b5d011344f30076
6
+ metadata.gz: 676fe4ac999bf6fefafa122efef76932c9d5918536d39f9e184b2b7467b40efe9b44521c32d29dfb35bb921a8f07498d484f426852e4daf0ebc389687f67d306
7
+ data.tar.gz: fa62deb91dc069fe53df259392cac8a1555cc8df6b7b43f29042e569da190f70f70b4eeed2ab62299ad3600f1c5efc9dabf42b5db1994f27813e92c4f9a63e42
data/README.md CHANGED
@@ -15,6 +15,17 @@ $ export ZABBIX_PASSWORD=...
15
15
  $ zabbix_graph
16
16
  ```
17
17
 
18
+ ### --item-graph and --host-graph
19
+
20
+ You can view graphs per item or host.
21
+
22
+ ```
23
+ $ zabbix_graph --item-graph
24
+ $ zabbix_graph --host-graph
25
+ $ zabbix_graph --item-graph --period=1d1h1m1s
26
+ $ zabbix_graph --host-graph --period=1d1h1m1s
27
+ ```
28
+
18
29
  ## Contributing
19
30
 
20
31
  1. Fork it ( https://github.com/[my-github-username]/zabbix_graph/fork )
data/lib/zabbix_graph.rb CHANGED
@@ -16,6 +16,7 @@ module ZabbixGraph
16
16
  parser = OptionParser.new
17
17
  parser.on('--host-graph') { options[:host_graph] = true }
18
18
  parser.on('--item-graph') { options[:item_graph] = true }
19
+ parser.on('--period=VAL') {|v| options[:period] = v }
19
20
  parser.parse!(argv)
20
21
 
21
22
  options
@@ -126,7 +127,7 @@ module ZabbixGraph
126
127
  end
127
128
 
128
129
  def query_string_from_items(items)
129
- query = [['action', 'batchgraph'], ['graphtype', '0']]
130
+ query = [['action', 'batchgraph'], ['graphtype', '0'], ['period', period.to_s]]
130
131
  items.each do |i|
131
132
  query << ['itemids[]', i['itemid']]
132
133
  end
@@ -134,6 +135,24 @@ module ZabbixGraph
134
135
  URI.encode_www_form(query)
135
136
  end
136
137
 
138
+ def period
139
+ return 3600 unless @options[:period]
140
+
141
+ @options[:period].scan(/(\d+)([smhd])/).map do |part|
142
+ scale = case part[1]
143
+ when "s"
144
+ 1
145
+ when "m"
146
+ 60
147
+ when "h"
148
+ 60 * 60
149
+ when "d"
150
+ 60 * 60 * 24
151
+ end
152
+ part[0].to_i * scale
153
+ end.inject(0) {|sum, i| sum + i }
154
+ end
155
+
137
156
  def zbx
138
157
  @zbx ||= ZabbixApi.connect(
139
158
  url: URI.join(zabbix_url, '/api_jsonrpc.php').to_s,
@@ -1,3 +1,3 @@
1
1
  module ZabbixGraph
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zabbix_graph
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryota Arai
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-12 00:00:00.000000000 Z
11
+ date: 2015-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: zabbixapi