zabbix-rails 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/zabbix/connector.rb +1 -1
- data/lib/zabbix/host_monitor.rb +32 -28
- data/lib/zabbix/version.rb +1 -1
- data/lib/zabbix-rails.rb +1 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc900e22c2b768dc73bde34170d11ba6a48c77991327b73f7fbd41412436b486
|
4
|
+
data.tar.gz: 176ce89b2a08a21c5b9080fc7ac232cee0c86b1c712789cd304cf7f5c25dede5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c0555d90621bba8a554f3fb5dd2dc3365ee59074ca7aea388d95cb31178919d9498426af86337e601e3e24fd15fd6491769c4766c30e458e4711070a09d3844
|
7
|
+
data.tar.gz: 59207e8a1d46499bbfd9e6bd9f882eb43b27efaf23ef82aed495c942dcc4cbe875caf03d82c616b445a2131e4105a9c6fc6760517ce0b3b27b1cedafc6c7ca26
|
data/lib/zabbix/connector.rb
CHANGED
data/lib/zabbix/host_monitor.rb
CHANGED
@@ -5,41 +5,45 @@ module Zabbix
|
|
5
5
|
extend ActiveSupport::Concern
|
6
6
|
include ZabbixConnectConcern
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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("
|
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("
|
31
|
-
|
39
|
+
Rails.logger.warn("未获取 ZABBIX_MGMT 对象,无法执行创建或更新监控主机: #{item.name} #{item.sn}")
|
40
|
+
nil
|
32
41
|
end
|
33
|
-
|
34
|
-
#
|
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
|
-
|
42
|
-
Rails.logger.warn("无法执行创建或更新监控主机: #{item.name} #{item.sn} #{e}")
|
45
|
+
|
43
46
|
end
|
47
|
+
|
44
48
|
end
|
45
49
|
end
|
data/lib/zabbix/version.rb
CHANGED
data/lib/zabbix-rails.rb
CHANGED