zabbix_manager 5.0.7 → 5.0.8

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: a06ad87ced47aa4288d704ff5343ebeda605d34f7d6944459cecf4f69711d38d
4
- data.tar.gz: 2e5e50ddf70f312b4c679d590d6a8aecbc6031764faf3f89e475c36958040772
3
+ metadata.gz: aa8b6fa1927ad9ff3012369cc92e302a7ef67c83e1dd8dcff2773257c10f9def
4
+ data.tar.gz: bcc2663a1d885d3e7632fc42eeb756de6aab34df75c289399f6464176fc6745b
5
5
  SHA512:
6
- metadata.gz: c6801af1c5372993075c7791ad45167c5b8a2f15a639861c7418e66d1ada84aee0e7c5bb7cb87369fcb662e93089d5bacee30623f7c110fee06f4bd95108ad48
7
- data.tar.gz: 55c96cd371fa3a682ce39a421683606e60f444a1d2e1db60c3525e86bce946614757fad310dacaa9e21631e85524346e9328eec5a82f65779386b5ea8dfc9a63
6
+ metadata.gz: 7fd2a1c9d746706fa2959a8734bd258b862b43db5c1c6e240a80b25e2ec16c0d09eb1b9ad60dbb8b4ddea4b9ae310d026ae9b8f2cd331abbc94b04244a63420d
7
+ data.tar.gz: 62f0b3557a65b5fdf1ff2e2ccd1c3406febc9190ad4ecca052b7f9dc4227d8ac98f371aacf36cb72f62e2af52506e3be9b74f40d15cf6665d88f712b073d4a7c
data/README.md CHANGED
@@ -1,11 +1,10 @@
1
1
  # Ruby Zabbix Api Module
2
2
 
3
3
  [![Gem Version](http://img.shields.io/gem/v/zabbix_manager.svg)][gem]
4
- [![Build Status](https://github.com/anapsix/zabbix_manager/workflows/CI/badge.svg)][github-ci]
5
4
 
6
5
  [gem]: https://rubygems.org/gems/zabbix_manager
7
- [github-ci]: https://github.com/express42/zabbix_manager/actions?query=workflow%3ACI
8
6
 
7
+ Most codes borrowed from zabbixapi, but fit for my everyday works well!
9
8
  Simple and lightweight ruby module for working with [Zabbix][Zabbix] via the [Zabbix API][Zabbix API]
10
9
 
11
10
  ## Installation
@@ -23,26 +22,7 @@ gem install zabbix_manager -v 4.2.0
23
22
  [documentation]: http://rdoc.info/gems/zabbix_manager
24
23
 
25
24
  ## Examples
26
- [https://github.com/express42/zabbix_manager/tree/master/examples][examples]
27
25
 
28
- [examples]: https://github.com/express42/zabbix_manager/tree/master/examples
29
-
30
- ## Version Policy
31
-
32
- **NOTE:** `master` branch is used for ongoing development on Zabbix API 5.x (5.0 and 5.2).
33
-
34
- We support only two last versions of zabbix (5.0 and 5.2), so you should consider all previous versions deprecated.
35
-
36
- * Zabbix 1.8.2 (api version 1.2) | zabbix_manager 0.6.x | [branch zabbix1.8](https://github.com/express42/zabbix_manager/tree/zabbix1.8)
37
- * Zabbix 1.8.9 (api version 1.3) | zabbix_manager 0.6.x | [branch zabbix1.8](https://github.com/express42/zabbix_manager/tree/zabbix1.8)
38
- * Zabbix 2.0.x (api version 1.4 -> 2.0.10) | zabbix_manager 2.0.x | [branch zabbix2.0](https://github.com/express42/zabbix_manager/tree/zabbix2.0)
39
- * Zabbix 2.2.x (api version 2.2.x) | zabbix_manager 2.2.x | [branch zabbix2.2](https://github.com/express42/zabbix_manager/tree/zabbix2.2)
40
- * Zabbix 2.4.x (api version 2.2.x) | zabbix_manager 2.4.x | [branch zabbix2.4](https://github.com/express42/zabbix_manager/tree/zabbix2.4)
41
- * Zabbix 3.0.x (api version 3.0.x) | zabbix_manager 3.0.x | [branch zabbix3.0](https://github.com/express42/zabbix_manager/tree/zabbix3.0)
42
- * Zabbix 3.2.x (api version 3.2.x) | zabbix_manager 3.2.x | [branch zabbix3.2](https://github.com/express42/zabbix_manager/tree/zabbix3.2)
43
- * Zabbix 4.0.x (api version 4.0.x) | zabbix_manager 4.1.x | [branch zabbix4.0](https://github.com/express42/zabbix_manager/tree/zabbix4.0)
44
- * Zabbix 4.2.x (api version 4.2.x) | zabbix_manager 4.1.x | [branch zabbix4.0](https://github.com/express42/zabbix_manager/tree/zabbix4.0)
45
- * Zabbix 4.4.x (api version 4.4.x) | zabbix_manager 4.2.x | [branch zabbix4.2](https://github.com/express42/zabbix_manager/tree/zabbix4.2)
46
26
 
47
27
  ## Supported Ruby Versions
48
28
  This library aims to support and is [tested against][github-ci] the following Ruby
@@ -86,13 +66,3 @@ dropped.
86
66
 
87
67
  [Zabbix]: https://www.zabbix.com
88
68
  [Zabbix API]: https://www.zabbix.com/documentation/5.2/manual/api
89
-
90
- ## Copyright
91
-
92
- - Copyright (c) 2021 [contributors]
93
- - Copyright (c) 2015-2018 Express 42 and [contributors]
94
-
95
- See [LICENSE] for details.
96
-
97
- [LICENSE]: LICENSE.md
98
- [contributors]: https://github.com/express42/zabbix_manager/graphs/contributors
@@ -21,38 +21,38 @@ class ZabbixManager
21
21
  # @return [Hash]
22
22
  def default_options
23
23
  {
24
- name: nil,
25
- key_: nil,
26
- hostid: nil,
27
- delay: 60,
28
- history: 3600,
29
- status: 0,
30
- type: 7,
31
- snmp_community: "",
32
- snmp_oid: "",
33
- value_type: 3,
34
- data_type: 0,
35
- trapper_hosts: "localhost",
36
- snmp_port: 161,
37
- units: "",
38
- multiplier: 0,
39
- delta: 0,
40
- snmpv3_securityname: "",
41
- snmpv3_securitylevel: 0,
24
+ name: nil,
25
+ key_: nil,
26
+ hostid: nil,
27
+ delay: 60,
28
+ history: 3600,
29
+ status: 0,
30
+ type: 7,
31
+ snmp_community: "",
32
+ snmp_oid: "",
33
+ value_type: 3,
34
+ data_type: 0,
35
+ trapper_hosts: "localhost",
36
+ snmp_port: 161,
37
+ units: "",
38
+ multiplier: 0,
39
+ delta: 0,
40
+ snmpv3_securityname: "",
41
+ snmpv3_securitylevel: 0,
42
42
  snmpv3_authpassphrase: "",
43
43
  snmpv3_privpassphrase: "",
44
- formula: 0,
45
- trends: 86_400,
46
- logtimefmt: "",
47
- valuemapid: 0,
48
- delay_flex: "",
49
- authtype: 0,
50
- username: "",
51
- password: "",
52
- publickey: "",
53
- privatekey: "",
54
- params: "",
55
- ipmi_sensor: ""
44
+ formula: 0,
45
+ trends: 86_400,
46
+ logtimefmt: "",
47
+ valuemapid: 0,
48
+ delay_flex: "",
49
+ authtype: 0,
50
+ username: "",
51
+ password: "",
52
+ publickey: "",
53
+ privatekey: "",
54
+ params: "",
55
+ ipmi_sensor: ""
56
56
  }
57
57
  end
58
58
 
@@ -93,13 +93,17 @@ class ZabbixManager
93
93
  method: "item.get",
94
94
  params: {
95
95
  # output: ["itemid", "name", "snmp_oid", "key_", "triggerids"],
96
- output: "extend",
96
+ output: "extend",
97
97
  hostids: hostid,
98
- search: {
98
+ search: {
99
99
  name: iface
100
100
  }
101
101
  }
102
- ).select { |item| item["snmp_oid"].match?(/1.3.6.1.2.1.31.1.1.1.(6|10|15)./) }
102
+ ).select {
103
+ |item| item["snmp_oid"].match?(/(1.3.6.1.2.1.31.1.1.1.(6|10|15)|1.3.6.1.2.1.2.2.1.8)./)
104
+ }.sort_by {
105
+ |item| item["key_"]
106
+ }
103
107
 
104
108
  # 检查是是否存在
105
109
  result.empty? ? nil : result
@@ -116,17 +120,17 @@ class ZabbixManager
116
120
  method: "item.create",
117
121
  params: {
118
122
  hostid: hostid,
119
- name: item_name,
120
- key_: item_key_,
123
+ name: item_name,
124
+ key_: item_key_,
121
125
  # 代表 zabbix_agent
122
126
  type: 0,
123
127
  # 代表字符串
124
128
  value_type: 1,
125
129
  # 固定参数
126
- delay: "1m",
127
- history: "90d",
130
+ delay: "1m",
131
+ history: "90d",
128
132
  lifetime: "30d",
129
- timeout: "3s"
133
+ timeout: "3s"
130
134
  }
131
135
  )
132
136
  p "成功创建 dns监控 #{dns_name}"
@@ -139,7 +143,7 @@ class ZabbixManager
139
143
  result = @client.api_request(
140
144
  method: "item.get",
141
145
  params: {
142
- output: "extend",
146
+ output: "extend",
143
147
  hostids: "16914"
144
148
  }
145
149
  )
@@ -28,11 +28,11 @@ class ZabbixManager
28
28
  @client.api_request(
29
29
  method: "trigger.get",
30
30
  params: {
31
- filter: {
31
+ filter: {
32
32
  keys.to_sym => data[keys.to_sym]
33
33
  },
34
- output: "extend",
35
- select_items: "extend",
34
+ output: "extend",
35
+ select_items: "extend",
36
36
  select_functions: "extend"
37
37
  }
38
38
  )
@@ -72,8 +72,8 @@ class ZabbixManager
72
72
  # disable old trigger
73
73
  log "[DEBUG] disable :" + @client.api_request(method: "#{method_name}.update",
74
74
  params: [{
75
- triggerid: data[:triggerid], status: "1"
76
- }]).inspect
75
+ triggerid: data[:triggerid], status: "1"
76
+ }]).inspect
77
77
  # create new trigger
78
78
  data.delete(:triggerid)
79
79
  create(data)
@@ -110,11 +110,11 @@ class ZabbixManager
110
110
  # 测试数据
111
111
  def mojo_data
112
112
  data = {
113
- comments: "MOJO1",
114
- opdata: "MOJO_OPDATA",
115
- priority: 1,
116
- description: "MOJO1",
117
- expression: "{SZX1-ISP-SW7:net.if.in[ifHCInOctets.1].avg(15m)}>=450000000 or {SZX1-ISP-SW7:net.if.out[ifHCOutOctets.1].avg(15m)}>=450000000",
113
+ comments: "MOJO1",
114
+ opdata: "MOJO_OPDATA",
115
+ priority: 1,
116
+ description: "MOJO1",
117
+ expression: "{SZX1-ISP-SW7:net.if.in[ifHCInOctets.1].avg(15m)}>=450000000 or {SZX1-ISP-SW7:net.if.out[ifHCOutOctets.1].avg(15m)}>=450000000",
118
118
  recovery_expression: "{SZX1-ISP-SW7:net.if.in[ifHCInOctets.1].avg(15m)}<=350000000 or {SZX1-ISP-SW7:net.if.out[ifHCOutOctets.1].avg(15m)}<=350000000"
119
119
  }
120
120
 
@@ -128,15 +128,15 @@ class ZabbixManager
128
128
  result = @client.api_request(
129
129
  method: "trigger.create",
130
130
  params: {
131
- comments: data["comments"],
132
- priority: data["priority"],
133
- description: data["description"],
134
- expression: data["expression"],
131
+ comments: data["comments"],
132
+ priority: data["priority"],
133
+ description: data["description"],
134
+ expression: data["expression"],
135
135
  recovery_expression: data["recovery_expression"],
136
- opdata: data["opdata"],
137
- recovery_mode: 1,
138
- type: 0,
139
- manual_close: 1
136
+ opdata: data["opdata"],
137
+ recovery_mode: 1,
138
+ type: 0,
139
+ manual_close: 1
140
140
  }
141
141
  )
142
142
  # 检查是是否存在
@@ -150,21 +150,35 @@ class ZabbixManager
150
150
  result = @client.api_request(
151
151
  method: "trigger.update",
152
152
  params: {
153
- triggerid: triggerid,
154
- comments: data["comments"],
155
- priority: data["priority"],
156
- description: data["description"],
157
- expression: data["expression"],
153
+ triggerid: triggerid,
154
+ comments: data["comments"],
155
+ priority: data["priority"],
156
+ description: data["description"],
157
+ expression: data["expression"],
158
158
  recovery_expression: data["recovery_expression"],
159
- opdata: data["opdata"],
160
- recovery_mode: 1,
161
- type: 1,
162
- manual_close: 1
159
+ opdata: data["opdata"],
160
+ recovery_mode: 1,
161
+ type: 1,
162
+ manual_close: 1
163
163
  }
164
164
  )
165
165
  # ap result
166
166
  # 检查是是否存在
167
167
  result.empty? ? nil : result["triggerids"]
168
168
  end
169
+
170
+ # 添加触发器依赖项
171
+ def add_trigger_dependency(triggerid, depend_on_trigger_id)
172
+ log "[DEBUG] Call add_trigger_dependency with parameters: #{triggerid} #{depend_on_trigger_id}"
173
+ # 请求生成触发器
174
+ result = @client.api_request(
175
+ method: "trigger.adddependencies",
176
+ params: {
177
+ triggerid: triggerid,
178
+ dependsOnTriggerid: depend_on_trigger_id
179
+ }
180
+ )
181
+ result.empty? ? nil : result["triggerids"]
182
+ end
169
183
  end
170
184
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ZabbixManager
4
- VERSION = "5.0.7"
4
+ VERSION = "5.0.8"
5
5
  end
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
27
27
  spec.email = ["careline@foxmail.com"]
28
28
 
29
29
  spec.summary = "Simple and lightweight ruby module for working with the Zabbix API, support 4.0 5.0 6.0"
30
- spec.description = "Most codes borrowed from zabbix_manager, But changed some logic for everyday jobs."
30
+ spec.description = "Most codes borrowed from ZabbixApi, But changed some logic for everyday jobs."
31
31
  spec.homepage = "https://github.com/snmpd/zabbix_manager"
32
32
  spec.licenses = "MIT"
33
33
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zabbix_manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.7
4
+ version: 5.0.8
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-17 00:00:00.000000000 Z
11
+ date: 2022-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http
@@ -182,7 +182,7 @@ dependencies:
182
182
  - - "~>"
183
183
  - !ruby/object:Gem::Version
184
184
  version: 0.5.1
185
- description: Most codes borrowed from zabbix_manager, But changed some logic for everyday
185
+ description: Most codes borrowed from ZabbixApi, But changed some logic for everyday
186
186
  jobs.
187
187
  email:
188
188
  - careline@foxmail.com