zabbix-rails 0.2.3 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e91a0b65f3d8c11a21c801e896756b8b33c2a3ac0cbcdb5aaadc51ff77347a3f
4
- data.tar.gz: 0cb4b629c690749a26f01ff2d6c3dad7ecb1aa78b17882e38b119333de361803
3
+ metadata.gz: d477e8482d7b336bc91a086a5b17d4623e4e6ecc3cc6e9ef86fc523fa57c97cb
4
+ data.tar.gz: 20ca6fb13b28defc342218df40a2a69d1b87b6a898bced5239935158659f527f
5
5
  SHA512:
6
- metadata.gz: dab95a7df10f9833babcbe70aea7077df0c3b57bdc4ac3479a643d4c7450e16ebb80e216390fcf35c3c8a0b7cbdc05706634e469c43b0871b714fda6b7483283
7
- data.tar.gz: 357db5c2018f7edf22d3066712fd47159eefc8a272474cddf4c5a6ef0fa4ea7cc596db6ce775f5c1b3b585c2aae5306eadd9c319e1da4746bf457805e5f4bb29
6
+ metadata.gz: e0b5ad8ce0ca98cbde47f8d3c745c400644853e8bbc4ce4f8151991da97cd3ce92f4aab0a370674dae50b78f7dd0dc003d1d1f386410d4e82620a0b16a2290b1
7
+ data.tar.gz: 85a9134058479f03dd307caab468070c55d793a97efae018a0b919cca5f7de119ec97e2b6eddd623b923027e2a92f175ed6dfd85426b73ab37879c317a5d275a
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
@@ -41,7 +41,7 @@ module Zabbix
41
41
  host = URI(base_url).host
42
42
  conn = Faraday::Connection.new(base_url)
43
43
  # 请求接口
44
- conn.get "#{url}" do |r|
44
+ conn.get(url) do |r|
45
45
  r.params.merge!(data)
46
46
  r.headers["Host"] = host
47
47
  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 +53,12 @@ module Zabbix
53
53
  def save_chart_graph(itemid, height = 400, width = 900, start_at = "now-6h", end_at = "now")
54
54
  filename = generate_name(itemid)
55
55
  save_file(filename, item_chart(itemid, height, width, start_at, end_at))
56
- "/assets/chart/#{File.basename(filename)}"
57
56
  end
58
57
 
59
58
  # 保存图片
60
59
  def save_file(filename, content)
61
60
  directory_base = "app/assets/images/chart/"
61
+
62
62
  # 生成绝对路径地址
63
63
  FileUtils.mkdir_p("#{Rails.root}/#{directory_base}") unless Dir.exist?("#{Rails.root}/#{directory_base}")
64
64
  filename.prepend(directory_base)
@@ -67,6 +67,8 @@ module Zabbix
67
67
  File.open(filename, "wb") do |chart|
68
68
  chart.write(content)
69
69
  end
70
+
71
+ "#{Rails.root}/#{filename}"
70
72
  end
71
73
 
72
74
  # 生成随机名称
@@ -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.4"
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.4
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-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails