zabbix-rails 0.2.3 → 0.2.6

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
  SHA256:
3
- metadata.gz: e91a0b65f3d8c11a21c801e896756b8b33c2a3ac0cbcdb5aaadc51ff77347a3f
4
- data.tar.gz: 0cb4b629c690749a26f01ff2d6c3dad7ecb1aa78b17882e38b119333de361803
3
+ metadata.gz: '04028ecb3b9665bf45fe93d6bc65797804e34f0f32eb3d1858afec834b550c84'
4
+ data.tar.gz: 7370e0c11ee2220e323e32cac92e1a22647a6b19f759fbcc5d628bf487e09936
5
5
  SHA512:
6
- metadata.gz: dab95a7df10f9833babcbe70aea7077df0c3b57bdc4ac3479a643d4c7450e16ebb80e216390fcf35c3c8a0b7cbdc05706634e469c43b0871b714fda6b7483283
7
- data.tar.gz: 357db5c2018f7edf22d3066712fd47159eefc8a272474cddf4c5a6ef0fa4ea7cc596db6ce775f5c1b3b585c2aae5306eadd9c319e1da4746bf457805e5f4bb29
6
+ metadata.gz: 92759a5c33530cc15566d5758a25a1ecdb0667184a127f626eae9fd429c8a1e2919b06a515298c233a02e4a6456fe23659ed7fd9be5ea67474316607e8af8a54
7
+ data.tar.gz: 86a63bfbe19b364b51ff00c6cf37280f5a08e311d5c561720e4278da9016cf593cbab95109e61b8d933ec58bd09ef138c7e798da684ce41addd5410ad00b209d
data/README.md CHANGED
@@ -1,13 +1,16 @@
1
1
  # Zabbix-Rails
2
+
2
3
  主要实现 zabbix_connector 对象缓存,加速 API 交互效率。 依赖 zabbix_manager 作为后端请求模块
3
4
 
4
5
  ## Usage
6
+
5
7
  ```
6
8
  1、include Zabbix::Connector 到模块或者类对象;
7
9
  2、调用 zabbix_connector 方法自动实现后端鉴权,当前前提是配置好 'zabbix_rails.rb in config/initializers'
8
- 3、调用 Zabbix::HostMonitor 实现自动维护监控对象
9
- 4、调用 Zabbix::ItemTrigger 实现自动维护触发器对象
10
+ 3、调用 Zabbix::HostMonitor 实现自动维护监控对象,需要自行实现 [Zabbix::DeleteMonitor] 的JOB 消息队列函数;
11
+ 4、调用 Zabbix::ItemTrigger 实现自动维护触发器对象,需要自行实现 [Zabbix::DeleteTrigger] 的JOB 消息队列函数;
10
12
  5、调用 Zabbix::Dns 实现自动维护 DNS 监控
13
+ 6、调用 Zabbix::Chart 实现自动登录 zabbix 下载 item 的监控快照图片,同时兼容 V5 和 V6 版本,下载路径在 app/assets/images/chart;
11
14
  ```
12
15
 
13
16
  ## Installation
@@ -32,13 +35,19 @@ $ gem install zabbix-rails
32
35
 
33
36
  add zabbix_rails.rb in config/initializers
34
37
 
38
+ ```ruby
39
+ Zabbix.configure do |config|
40
+ config.url = Rails.application.credentials.zabbix.url
41
+ config.user = Rails.application.credentials.zabbix.username
42
+ config.password = Rails.application.credentials.zabbix.password
43
+ config.debug = false
44
+ end
35
45
  ```
36
- # Zabbix.configure do |config|
37
- # c.url = Rails.application.credentials.zabbix.url
38
- # c.user = Rails.application.credentials.zabbix.username
39
- # c.password = Rails.application.credentials.zabbix.password
40
- # c.debug = false
41
- # end
46
+
47
+ 下载 zabbix item 图片范例:
48
+ ```ruby
49
+ include Zabbix::Chart
50
+ save_chart_graph 37932
42
51
  ```
43
52
 
44
53
  ## Contributing
data/lib/zabbix/chart.rb CHANGED
@@ -21,6 +21,27 @@ module Zabbix
21
21
  _item_chart("/chart2.php", data)
22
22
  end
23
23
 
24
+ # 接口图片
25
+ def iface_chart(*itemids)
26
+ # 构造数据结构
27
+ data = {
28
+ from: "now-6h",
29
+ to: "now",
30
+ itemids: [itemids].flatten,
31
+ height: 400,
32
+ width: 900
33
+ }
34
+
35
+ # 请求后端返回图片对象
36
+ _item_chart(data)
37
+ end
38
+
39
+ # 保存接口流量图片
40
+ def save_iface_graph(*itemids)
41
+ filename = generate_name([itemids].flatten[0])
42
+ save_file(filename, iface_chart(itemids))
43
+ end
44
+
24
45
  # 请求生成 item_chart 对象
25
46
  def item_chart(itemid, height = 400, width = 900, start_at = "now-6h", end_at = "now")
26
47
  # 构造数据结构
@@ -41,7 +62,7 @@ module Zabbix
41
62
  host = URI(base_url).host
42
63
  conn = Faraday::Connection.new(base_url)
43
64
  # 请求接口
44
- conn.get "#{url}" do |r|
65
+ conn.get(url) do |r|
45
66
  r.params.merge!(data)
46
67
  r.headers["Host"] = host
47
68
  r.headers["Accept"] = "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"
@@ -53,12 +74,12 @@ module Zabbix
53
74
  def save_chart_graph(itemid, height = 400, width = 900, start_at = "now-6h", end_at = "now")
54
75
  filename = generate_name(itemid)
55
76
  save_file(filename, item_chart(itemid, height, width, start_at, end_at))
56
- "/assets/chart/#{File.basename(filename)}"
57
77
  end
58
78
 
59
79
  # 保存图片
60
80
  def save_file(filename, content)
61
81
  directory_base = "app/assets/images/chart/"
82
+
62
83
  # 生成绝对路径地址
63
84
  FileUtils.mkdir_p("#{Rails.root}/#{directory_base}") unless Dir.exist?("#{Rails.root}/#{directory_base}")
64
85
  filename.prepend(directory_base)
@@ -67,6 +88,8 @@ module Zabbix
67
88
  File.open(filename, "wb") do |chart|
68
89
  chart.write(content)
69
90
  end
91
+
92
+ "#{Rails.root}/#{filename}"
70
93
  end
71
94
 
72
95
  # 生成随机名称
@@ -75,3 +98,4 @@ module Zabbix
75
98
  end
76
99
  end
77
100
  end
101
+
@@ -68,12 +68,13 @@ module Zabbix
68
68
  }
69
69
 
70
70
  # 请求认证
71
- ret = conn.post "/index.php" do |r|
71
+ ret = conn.post("/index.php") do |r|
72
72
  r.headers["Host"] = host
73
73
  r.body = data
74
74
  end
75
75
 
76
- ret.headers["set-cookie"].presence || nil
76
+ # 此处需要特殊处理,否则 V5 版本无法正常加载缓存
77
+ ret.headers["set-cookie"]&.gsub(/ HttpOnly,?/, "").presence || nil
77
78
  end
78
79
  end
79
80
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Zabbix
4
- VERSION = "0.2.3"
4
+ VERSION = "0.2.6"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zabbix-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - WENWU.YAN
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-03 00:00:00.000000000 Z
11
+ date: 2022-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails