zabbix-rails 0.1.2 → 0.1.5
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 +3 -2
- data/lib/zabbix/dns_monitor.rb +3 -1
- data/lib/zabbix/engine.rb +1 -1
- data/lib/zabbix/host_monitor.rb +31 -33
- data/lib/zabbix/item_trigger.rb +3 -1
- data/lib/zabbix/version.rb +1 -1
- data/lib/zabbix-rails.rb +1 -2
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c17c05a667ebfd11b5d4570c766da4a306ec26f4118893b4efdf5c449af2c509
|
4
|
+
data.tar.gz: 0d5bca9ba31c6a87cbbc3e5315ba6e0b7f353e0fbeb85bbdd17fccec76b7319b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4cbfb30bb0860f289adc7f03105bdf10568f188712cb6f8ad6c84d4ee0620374cab4d4c915999797587051f8aadbb931592461d41b676ba21aba97812f23926
|
7
|
+
data.tar.gz: 53b13efb8a0923e2f4e89641bdf903e58ab5ec8183c2bb7927120ae09120082eaffb1a0e0a05f1eb6c6a3ea7b2bc87a526f69de13f24ad7f9ad914bf3a11e5c2
|
data/lib/zabbix/connector.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
+
|
1
2
|
module Zabbix
|
2
|
-
|
3
|
-
extend ActiveSupport::Concern
|
3
|
+
extend ::ActiveSupport::Concern
|
4
4
|
|
5
|
+
module Connector
|
5
6
|
# 开发测试环境需要单独开启缓存功能:bin/rails dev:cache
|
6
7
|
# 将鉴权后的 zabbix-rails 对象缓存到 Rails,减少不必要的认证动作加速执行
|
7
8
|
# https://guides.rubyonrails.org/caching_with_rails.html
|
data/lib/zabbix/dns_monitor.rb
CHANGED
data/lib/zabbix/engine.rb
CHANGED
data/lib/zabbix/host_monitor.rb
CHANGED
@@ -1,48 +1,46 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Zabbix
|
4
|
+
extend ::ActiveSupport::Concern
|
5
|
+
|
4
6
|
module HostMonitor
|
5
|
-
|
6
|
-
include ZabbixConnectConcern
|
7
|
+
include Zabbix::Connector
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
hostid = item[:hostid]
|
9
|
+
# 创建或更新 HostMonitor主机监控对象
|
10
|
+
def refresh_zabbix_host(item)
|
11
|
+
if zabbix_connector.present? && (zabbix_connector.is_a? ZabbixManager)
|
12
|
+
# 查询已关联的 hostid
|
13
|
+
hostid = item[:hostid]
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
else
|
27
|
-
Rails.logger.warn("正在更新监控对象: #{item.sn} - #{item.name}")
|
28
|
-
zabbix_connector.hosts.create_or_update(item.host_params)
|
29
|
-
end
|
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
|
30
26
|
else
|
31
|
-
Rails.logger.warn("
|
27
|
+
Rails.logger.warn("正在更新监控对象: #{item.sn} - #{item.name}")
|
32
28
|
zabbix_connector.hosts.create_or_update(item.host_params)
|
33
29
|
end
|
34
|
-
|
35
|
-
# 返回监控对象的 host_id
|
36
|
-
Rails.logger.warn("成功执行创建或更新监控主机: #{item.name} #{item.sn}")
|
37
|
-
zabbix_connector.hosts.get_id(host: item.sn).presence || nil
|
38
30
|
else
|
39
|
-
Rails.logger.warn("
|
40
|
-
|
31
|
+
Rails.logger.warn("正在新增监控对象: #{item.sn} - #{item.name}")
|
32
|
+
zabbix_connector.hosts.create_or_update(item.host_params)
|
41
33
|
end
|
42
|
-
rescue => e
|
43
|
-
Rails.logger.warn("无法执行创建或更新监控主机: #{item.name} #{item.sn} #{e}")
|
44
|
-
end
|
45
34
|
|
35
|
+
# 返回监控对象的 host_id
|
36
|
+
Rails.logger.warn("成功执行创建或更新监控主机: #{item.name} #{item.sn}")
|
37
|
+
zabbix_connector.hosts.get_id(host: item.sn).presence || nil
|
38
|
+
else
|
39
|
+
Rails.logger.warn("未获取 ZABBIX_MGMT 对象,无法执行创建或更新监控主机: #{item.name} #{item.sn}")
|
40
|
+
nil
|
41
|
+
end
|
42
|
+
rescue => e
|
43
|
+
Rails.logger.warn("无法执行创建或更新监控主机: #{item.name} #{item.sn} #{e}")
|
46
44
|
end
|
47
45
|
|
48
46
|
end
|
data/lib/zabbix/item_trigger.rb
CHANGED
data/lib/zabbix/version.rb
CHANGED
data/lib/zabbix-rails.rb
CHANGED
@@ -4,13 +4,12 @@ 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"
|
8
7
|
|
9
8
|
# 加载外部依赖
|
10
9
|
require "zabbix_manager"
|
11
10
|
|
12
11
|
module Zabbix
|
13
|
-
|
12
|
+
extend ::ActiveSupport::Concern
|
14
13
|
|
15
14
|
class << self
|
16
15
|
attr_accessor :url, :user, :password, :debug
|
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.1.
|
4
|
+
version: 0.1.5
|
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-03-
|
11
|
+
date: 2022-03-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: '0'
|
27
27
|
description: Description of Zabbix-rails.
|
28
28
|
email:
|
29
29
|
- careline@foxmail.com
|