zabbix-rails 0.1.1 → 0.1.2

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: c08d62e412a270dbcc25ff8c0fbed71b448217dfd461c0c14290d53b75aa155d
4
- data.tar.gz: 9012f1824fee422931f7f464ccfd1bb567bc6c8f501cd7343ea406002073b4ff
3
+ metadata.gz: bc900e22c2b768dc73bde34170d11ba6a48c77991327b73f7fbd41412436b486
4
+ data.tar.gz: 176ce89b2a08a21c5b9080fc7ac232cee0c86b1c712789cd304cf7f5c25dede5
5
5
  SHA512:
6
- metadata.gz: 9c1f62a5f09290006d51d2211061d89201303719f87836542d4d6e1af9e4e346cdece9d88cd91dc9f99c1c9ecc42408fb5c2ce868a7ecb585a19f83f8137ba24
7
- data.tar.gz: ec142fb5c24d488157982a6a71c22475a67928a32ee1ebdc01a64682d5a9b5992c025a9b9f3945f16a3773307a146130b8735861600f2fb90bc24ec3d25b99ea
6
+ metadata.gz: 6c0555d90621bba8a554f3fb5dd2dc3365ee59074ca7aea388d95cb31178919d9498426af86337e601e3e24fd15fd6491769c4766c30e458e4711070a09d3844
7
+ data.tar.gz: 59207e8a1d46499bbfd9e6bd9f882eb43b27efaf23ef82aed495c942dcc4cbe875caf03d82c616b445a2131e4105a9c6fc6760517ce0b3b27b1cedafc6c7ca26
@@ -1,6 +1,6 @@
1
1
  module Zabbix
2
2
  module Connector
3
- include ActiveSupport::Concern
3
+ extend ActiveSupport::Concern
4
4
 
5
5
  # 开发测试环境需要单独开启缓存功能:bin/rails dev:cache
6
6
  # 将鉴权后的 zabbix-rails 对象缓存到 Rails,减少不必要的认证动作加速执行
@@ -5,41 +5,45 @@ module Zabbix
5
5
  extend ActiveSupport::Concern
6
6
  include ZabbixConnectConcern
7
7
 
8
- # 创建或更新 zabbix-rails 主机监控对象
9
- def refresh_zabbix_host(item)
10
- if zabbix_connector.present? && (zabbix_connector.is_a? ZabbixManager)
11
- # 查询已关联的 hostid
12
- hostid = item[:hostid]
8
+ class << self
9
+ # 创建或更新 zabbix-rails 主机监控对象
10
+ def refresh_zabbix_host(item)
11
+ if zabbix_connector.present? && (zabbix_connector.is_a? ZabbixManager)
12
+ # 查询已关联的 hostid
13
+ hostid = item[:hostid]
13
14
 
14
- # 封装数据之前确保设备属组已经存在
15
- search_id = zabbix_connector.hosts.get_id(host: item.sn)
16
- # 构建 zabbix-rails 监控对象数据结构,创建或者更新数据
17
- if hostid.present?
18
- if search_id.blank?
19
- Rails.logger.warn("监控主机信息发生变化,正在创建监控对象: #{item}.inspect")
20
- Zabbix::DeleteMonitor.perform_now(item.sn)
21
- zabbix_connector.hosts.create_or_update(item.host_params)
22
- elsif hostid != search_id
23
- Rails.logger.warn("ZABBIX已有监控项,正在刷新数据 #{hostid} - #{search_id}")
24
- search_id
15
+ # 封装数据之前确保设备属组已经存在
16
+ search_id = zabbix_connector.hosts.get_id(host: item.sn)
17
+ # 构建 zabbix-rails 监控对象数据结构,创建或者更新数据
18
+ if hostid.present?
19
+ if search_id.blank?
20
+ Rails.logger.warn("监控主机信息发生变化,正在创建监控对象: #{item}.inspect")
21
+ Zabbix::DeleteMonitor.perform_now(item.sn)
22
+ zabbix_connector.hosts.create_or_update(item.host_params)
23
+ elsif hostid != search_id
24
+ Rails.logger.warn("ZABBIX已有监控项,正在刷新数据 #{hostid} - #{search_id}")
25
+ search_id
26
+ else
27
+ Rails.logger.warn("正在更新监控对象: #{item.sn} - #{item.name}")
28
+ zabbix_connector.hosts.create_or_update(item.host_params)
29
+ end
25
30
  else
26
- Rails.logger.warn("正在更新监控对象: #{item.sn} - #{item.name}")
31
+ Rails.logger.warn("正在新增监控对象: #{item.sn} - #{item.name}")
27
32
  zabbix_connector.hosts.create_or_update(item.host_params)
28
33
  end
34
+
35
+ # 返回监控对象的 host_id
36
+ Rails.logger.warn("成功执行创建或更新监控主机: #{item.name} #{item.sn}")
37
+ zabbix_connector.hosts.get_id(host: item.sn).presence || nil
29
38
  else
30
- Rails.logger.warn("正在新增监控对象: #{item.sn} - #{item.name}")
31
- zabbix_connector.hosts.create_or_update(item.host_params)
39
+ Rails.logger.warn("未获取 ZABBIX_MGMT 对象,无法执行创建或更新监控主机: #{item.name} #{item.sn}")
40
+ nil
32
41
  end
33
-
34
- # 返回监控对象的 host_id
35
- Rails.logger.warn("成功执行创建或更新监控主机: #{item.name} #{item.sn}")
36
- zabbix_connector.hosts.get_id(host: item.sn).presence || nil
37
- else
38
- Rails.logger.warn("未获取 ZABBIX_MGMT 对象,无法执行创建或更新监控主机: #{item.name} #{item.sn}")
39
- nil
42
+ rescue => e
43
+ Rails.logger.warn("无法执行创建或更新监控主机: #{item.name} #{item.sn} #{e}")
40
44
  end
41
- rescue => e
42
- Rails.logger.warn("无法执行创建或更新监控主机: #{item.name} #{item.sn} #{e}")
45
+
43
46
  end
47
+
44
48
  end
45
49
  end
@@ -1,3 +1,3 @@
1
1
  module Zabbix
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
data/lib/zabbix-rails.rb CHANGED
@@ -4,6 +4,7 @@ require "zabbix/host_monitor"
4
4
  require "zabbix/item_trigger"
5
5
  require "zabbix/dns_monitor"
6
6
  require "zabbix/railtie"
7
+ require "active_support/concern"
7
8
 
8
9
  # 加载外部依赖
9
10
  require "zabbix_manager"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zabbix-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - WENWU.YAN