zabbix_sender_api 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +30 -0
- data/LICENSE.txt +21 -0
- data/README.md +118 -0
- data/Rakefile +2 -0
- data/bin/console +12 -0
- data/bin/setup +8 -0
- data/exe/example.rb +22 -0
- data/images/.gitkeep +0 -0
- data/images/Spectacle.Z29721.png +0 -0
- data/images/Spectacle.l29721.png +0 -0
- data/lib/zabbix_sender_api.rb +8 -0
- data/lib/zabbix_sender_api/api.rb +273 -0
- data/lib/zabbix_sender_api/version.rb +3 -0
- data/zabbix-sender-help.md +73 -0
- data/zabbix_sender_api.gemspec +28 -0
- metadata +65 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 60cdb023473d8f310e562c2130af36a7200ef5edddf30f6783df1111a15cb2f3
|
4
|
+
data.tar.gz: d20950ef1e873d771bf1ccd7fab94f428e764cd33d5d35e5e7bf1a872ca2456e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ebd2c6648e9c4ab34dc1c982928b7c83f3bf998514c475d9f166c76b03a8f4cccd24471d16111c0abe72e6e86ff3d3baa0f7f71ec4843e11fb7a951aa566bd86
|
7
|
+
data.tar.gz: ff0383428a37b30a048b6e2c5fecab943368462a2922a6ea434635657c1f762ed976bb36e8cf5b894fdaa4931abc86bc5061295977c2100d4825b8f370ef974d
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
zabbix_sender_api (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
byebug (11.1.3)
|
10
|
+
coderay (1.1.3)
|
11
|
+
method_source (1.0.0)
|
12
|
+
pry (0.13.1)
|
13
|
+
coderay (~> 1.1)
|
14
|
+
method_source (~> 1.0)
|
15
|
+
pry-byebug (3.9.0)
|
16
|
+
byebug (~> 11.0)
|
17
|
+
pry (~> 0.13.0)
|
18
|
+
rake (12.3.3)
|
19
|
+
|
20
|
+
PLATFORMS
|
21
|
+
ruby
|
22
|
+
|
23
|
+
DEPENDENCIES
|
24
|
+
pry
|
25
|
+
pry-byebug
|
26
|
+
rake
|
27
|
+
zabbix_sender_api!
|
28
|
+
|
29
|
+
BUNDLED WITH
|
30
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Dave Parker
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
# zabbix_sender_api
|
2
|
+
|
3
|
+
This gem describes an api that takes some of the drudgery out of the task of putting together bulk data for the zabbix_sender utility.
|
4
|
+
|
5
|
+
zabbix_sender is a command line utility for sending monitoring data to Zabbix server or proxy. On the Zabbix server an item of type Zabbix trapper should be created with corresponding key.
|
6
|
+
|
7
|
+
* [Zabbix sender manpage](https://www.zabbix.com/documentation/4.0/manpages/zabbix_sender)
|
8
|
+
* [Zabbix sender CLI help](zabbix-sender-help.md)
|
9
|
+
|
10
|
+
|
11
|
+
zabbix_sender_api's function is to generate data to send to a zabbix_sender instance via stdin where zabbix_sender was invoked with these options:
|
12
|
+
|
13
|
+
```
|
14
|
+
-i --input-file input-file Load values from input file. Specify - for
|
15
|
+
standard input. Each line of file contains
|
16
|
+
whitespace delimited: <host> <key> <value>.
|
17
|
+
Specify - in <host> to use hostname from
|
18
|
+
configuration file or --host argument
|
19
|
+
|
20
|
+
-T --with-timestamps Each line of file contains whitespace delimited:
|
21
|
+
<host> <key> <timestamp> <value>. This can be used
|
22
|
+
with --input-file option. Timestamp should be
|
23
|
+
specified in Unix timestamp format
|
24
|
+
```
|
25
|
+
|
26
|
+
It is analogous to:
|
27
|
+
|
28
|
+
\<program that generates sender input\> | zabbix-sender -z \<zabbix-server-or-proxy-ip\> -T -i -
|
29
|
+
|
30
|
+
(You can use this api to just generate output that you then pipe to zabbix_sender yourself if you prefer)
|
31
|
+
|
32
|
+
|
33
|
+
## Installation
|
34
|
+
|
35
|
+
$ gem install zabbix_sender_api
|
36
|
+
|
37
|
+
## Usage
|
38
|
+
|
39
|
+
### Synopsis
|
40
|
+
```ruby
|
41
|
+
#!/usr/bin/env ruby
|
42
|
+
require 'zabbix_sender_api'
|
43
|
+
|
44
|
+
sender = Zabbix::Sender.new
|
45
|
+
|
46
|
+
rawdata = { :myFirstKey => 0, :mySecondKey => 100 }
|
47
|
+
|
48
|
+
data = Zabbix::Batch.new
|
49
|
+
|
50
|
+
rawdata.each_pair {|key,value|
|
51
|
+
data.addItemData(key: key,value: value)
|
52
|
+
}
|
53
|
+
|
54
|
+
sender.sendBatchAtomic(data)
|
55
|
+
```
|
56
|
+
|
57
|
+
The above will execute zabbix_sender for you and send data into it as described above.
|
58
|
+
|
59
|
+
Alternatively you can just
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
puts data.to_senderinput
|
63
|
+
```
|
64
|
+
... and do whatever you want w/ the stdout
|
65
|
+
|
66
|
+
|
67
|
+
To do low level discovery:
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
disco = Zabbix::Discovery.new(key: 'discoveryRuleKey')
|
71
|
+
|
72
|
+
disco.add_entity(:SOMEUSEFULVALUE => 'aValue', :ANOTHERONE => 'somethingElse')
|
73
|
+
|
74
|
+
data.addDiscovery(disco)
|
75
|
+
|
76
|
+
```
|
77
|
+
|
78
|
+
### Under the hood
|
79
|
+
|
80
|
+
The zabbix-sender cli utility provides a number of methods by which to insert data into zabbix.
|
81
|
+
|
82
|
+
* zabbix-sender ... -s zabbixHostName -k keyName -o value (one k-v pair at a time)
|
83
|
+
* zabbix-sender ... -i - (series of kv pairs from stdin using zabbix-sender start time as timestamp)
|
84
|
+
* zabbix-sender ... -T -i - (series of kv pairs with their own embedded timestamps from stdin)
|
85
|
+
|
86
|
+
In the latter two cases, the zabbix host name (the name of the host that zabbix is monitoring) is embedded
|
87
|
+
in the stdin data.
|
88
|
+
|
89
|
+
In all cases it is presumed that the zabbix server or proxy to which data should be sent is specified. This can
|
90
|
+
be done either by specifying it explicitly with the -z switch, or indirectly by pointing it to a zabbix sender configuration
|
91
|
+
file with the -c switch. If you let zabbix_sender_api handle executing zabbix_sender, the target will be specified on the
|
92
|
+
command line via the -z switch.
|
93
|
+
|
94
|
+
|
95
|
+
zabbix_sender_api utilizes the -T -i - form, so the generated data lines look like this:
|
96
|
+
|
97
|
+
```
|
98
|
+
"theHostBeingMonitored" myFirstKey 1551719379 0
|
99
|
+
"theHostBeingMonitored" mySecondKey 1551719379 100
|
100
|
+
```
|
101
|
+
|
102
|
+
The above lines will send data to two items associated with the host theHostBeingMonitored: myFirstKey gets the value 0, and mySecondKey gets the value 100. In both cases the
|
103
|
+
time stamp is identical but it need not be (see the exe/example.rb for specifics).
|
104
|
+
|
105
|
+
|
106
|
+
Low level discovery (LLD) is also possible with zabbix-sender; the format of the stdin data is not so pretty but zabbix_sender_api handles all that:
|
107
|
+
|
108
|
+
```
|
109
|
+
"theHostBeingMonitored" discoveryRuleKey 1551719797 {"data":[{"{#SOMEUSEFULVALUE}":"aValue","{#ANOTHERONE}":"somethingElse"}]}
|
110
|
+
```
|
111
|
+
The above line sends an LLD discovery structure (formatted as json) to the [discovery rule](https://www.zabbix.com/documentation/4.0/manual/discovery/low_level_discovery#discovery_rule) whose key is discoveryRuleKey. It describes one entity by passing the macro values
|
112
|
+
#SOMEUSEFULVALUE and #ANOTHERONE to the discovery rule. These '[lld macros](https://www.zabbix.com/documentation/4.0/manual/config/macros/lld_macros)' are available for use in item,trigger, and graph prototypes.
|
113
|
+
|
114
|
+
|
115
|
+
If you wished to use the above lld to actually do some discovery, you'd set things up in zabbix roughly like this:
|
116
|
+
|
117
|
+
![Discovery rule configuration](images/Spectacle.Z29721.png)
|
118
|
+
![Item prototype configuration](images/Spectacle.l29721.png )
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "zabbix_sender_api"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
require "pry"
|
11
|
+
Pry.start
|
12
|
+
|
data/bin/setup
ADDED
data/exe/example.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'zabbix_sender_api'
|
3
|
+
|
4
|
+
sender = Zabbix::Sender::Pipe.new
|
5
|
+
|
6
|
+
rawdata = { :myFirstKey => 0, :mySecondKey => 100 }
|
7
|
+
|
8
|
+
data = Zabbix::Sender::Batch.new
|
9
|
+
|
10
|
+
rawdata.each_pair {|key,value|
|
11
|
+
data.addItemData(key: key,value: value)
|
12
|
+
}
|
13
|
+
|
14
|
+
disco = Zabbix::Sender::Discovery.new(key: 'discoveryRuleKey')
|
15
|
+
|
16
|
+
disco.add_entity(:SOMEUSEFULVALUE => 'aValue', :ANOTHERONE => 'somethingElse')
|
17
|
+
|
18
|
+
data.addDiscovery(disco)
|
19
|
+
|
20
|
+
puts data.to_senderline
|
21
|
+
|
22
|
+
sender.sendBatchAtomic(data)
|
data/images/.gitkeep
ADDED
File without changes
|
Binary file
|
Binary file
|
@@ -0,0 +1,273 @@
|
|
1
|
+
module Zabbix
|
2
|
+
require 'socket'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
##
|
6
|
+
# AgentConfiguration holds data that's scraped from a zabbix_agentd config file. It's
|
7
|
+
# initialized when the gem is required. If it finds configuration you can
|
8
|
+
# access it with class methods. This is not meant to be instantiated.
|
9
|
+
|
10
|
+
class AgentConfiguration
|
11
|
+
def self.initialize
|
12
|
+
@agentConfPaths = [
|
13
|
+
'/etc/zabbix/zabbix_agentd.conf',
|
14
|
+
'/usr/local/etc/zabbix/zabbix_agentd.conf',
|
15
|
+
'/opt/zabbix/etc/zabbix_agentd.conf',
|
16
|
+
'/opt/zabbix/conf/zabbix_agentd.conf'
|
17
|
+
]
|
18
|
+
|
19
|
+
@proxy = nil
|
20
|
+
@hostname = nil
|
21
|
+
|
22
|
+
@agentConfPaths.each { |path|
|
23
|
+
if File.exist?(path)
|
24
|
+
File.new(path).each_line { |line|
|
25
|
+
if not @proxy
|
26
|
+
match = /^Server=?(.*)/.match(line)
|
27
|
+
if match
|
28
|
+
@proxy = match[1].strip.split(',').pop
|
29
|
+
end
|
30
|
+
end
|
31
|
+
if not @hostname
|
32
|
+
match = /^Hostname=?(.*)/.match(line)
|
33
|
+
if match
|
34
|
+
@hostname = match[1].strip
|
35
|
+
end
|
36
|
+
end
|
37
|
+
break if @proxy and @hostname
|
38
|
+
}
|
39
|
+
end
|
40
|
+
break if @proxy and @host
|
41
|
+
}
|
42
|
+
if not @host
|
43
|
+
@host = Socket.gethostname
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
##
|
48
|
+
# Returns the value of the Server= assignment in zabbix_agentd.conf (if any)
|
49
|
+
#
|
50
|
+
def self.zabbixProxy
|
51
|
+
@proxy
|
52
|
+
end
|
53
|
+
|
54
|
+
##
|
55
|
+
# Returns the value of the Hostname= asignment in zabbix_agentd.conf (if any)
|
56
|
+
#
|
57
|
+
def self.zabbixHostname
|
58
|
+
@hostname
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
module Sender
|
63
|
+
|
64
|
+
##
|
65
|
+
# Pipe instances encapsulate communication to a running instance of zabbix_sender
|
66
|
+
# via a pipe to STDIN. If you want your program to send data itself (as opposed
|
67
|
+
# to say printing stdin lines that you can then pipe to zabbix_sender yourself),
|
68
|
+
# you'll want to make an instance of this
|
69
|
+
#
|
70
|
+
class Pipe
|
71
|
+
##
|
72
|
+
# pipe file handle object
|
73
|
+
attr_reader :pipe
|
74
|
+
##
|
75
|
+
# target host (server or proxy) name or ip
|
76
|
+
attr_reader :targetHost
|
77
|
+
##
|
78
|
+
# path to the zabbix_sender executable
|
79
|
+
attr_reader :exePath
|
80
|
+
|
81
|
+
|
82
|
+
##
|
83
|
+
# Initialize a new Sender object. Both proxy: and path: are optional.
|
84
|
+
#
|
85
|
+
# An attempt is made to provide sane default values. If you have a zabbix_agentd.conf
|
86
|
+
# file in one of the usual places and zabbix_sender is on your path, it'll probably
|
87
|
+
# just work
|
88
|
+
#
|
89
|
+
def initialize(proxy: Zabbix::AgentConfiguration.zabbixProxy, path: 'zabbix_sender')
|
90
|
+
@targetHost = proxy
|
91
|
+
@exePath = path
|
92
|
+
@pipe = nil
|
93
|
+
end
|
94
|
+
|
95
|
+
##
|
96
|
+
# Opens a pipe to the zabbix_sender command with appropriate options specified.
|
97
|
+
# If the pipe is already opened when this command is called, it is first closed
|
98
|
+
# via a call to flush
|
99
|
+
def open
|
100
|
+
self.flush
|
101
|
+
@pipe = IO.popen(%Q(#{@exePath} -z #{@targetHost} -vv -T -i-),'w')
|
102
|
+
end
|
103
|
+
|
104
|
+
##
|
105
|
+
# Closes the zabbix_sender pipe if it's open
|
106
|
+
def flush
|
107
|
+
if @pipe and not @pipe.closed?
|
108
|
+
@pipe.close
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
##
|
113
|
+
# Send a Batch instance to zabbix (via zabbix_sender). This assumes that
|
114
|
+
# the pipe is already open.
|
115
|
+
def sendBatch(aBatch)
|
116
|
+
# Assumes that the pipe is open
|
117
|
+
@pipe.puts(aBatch.to_senderline)
|
118
|
+
end
|
119
|
+
|
120
|
+
##
|
121
|
+
# Send a Batch instance to zabbix (via zabbix_sender). This opens the pipe,
|
122
|
+
# writes the data to the pipe, and closes the pipe all in one go.
|
123
|
+
def sendBatchAtomic(aBatch)
|
124
|
+
self.open
|
125
|
+
self.sendBatch(aBatch)
|
126
|
+
self.flush
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
|
131
|
+
##
|
132
|
+
# ItemData instances hold the k-v pair of a value and its timestamp
|
133
|
+
# along with the hostname to which the data belongs. It handles
|
134
|
+
# formatting that data appropriately as input to zabbix_sender
|
135
|
+
class ItemData
|
136
|
+
##
|
137
|
+
# The item key that'll get the new value
|
138
|
+
attr_accessor:key
|
139
|
+
##
|
140
|
+
# The value that the item will get
|
141
|
+
attr_accessor :value
|
142
|
+
##
|
143
|
+
# The name of the zabbix host that owns the item key
|
144
|
+
attr_accessor :hostname
|
145
|
+
##
|
146
|
+
# The timestamp for this datapoint
|
147
|
+
attr_accessor :timestamp
|
148
|
+
|
149
|
+
##
|
150
|
+
# All values must be provided.
|
151
|
+
def initialize(key: nil,value: nil, timestamp: nil, hostname: nil)
|
152
|
+
@key = key
|
153
|
+
@value = value
|
154
|
+
@timestamp = timestamp
|
155
|
+
@hostname = hostname
|
156
|
+
end
|
157
|
+
|
158
|
+
##
|
159
|
+
# Render the ItemData instance as a line of text that can be piped into zabbix_sender
|
160
|
+
def to_senderline
|
161
|
+
if @timestamp.to_i == 0
|
162
|
+
puts %Q("#{@hostname}" #{@key} #{@timestamp.to_i} #{@value}\n)
|
163
|
+
abort("Attempt was made to render a timestamp of zero. You DO NOT want this - it can kill db performance. Fix it.")
|
164
|
+
end
|
165
|
+
return %Q("#{@hostname}" #{@key} #{@timestamp.to_i} #{@value}\n)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
##
|
170
|
+
# Discovery instances are a special type of ItemData that you will typically
|
171
|
+
# create and hang on to as you accumulate (discover) related entities. You
|
172
|
+
# then pass the discover instance into a Batch via addDiscovery(), which
|
173
|
+
# includes it in the batch of data just like an ordinary ItemData instance.
|
174
|
+
class Discovery < ItemData
|
175
|
+
##
|
176
|
+
# The only required parameter is key:, which is the discovery rule key.
|
177
|
+
#
|
178
|
+
def initialize(key: nil,value: nil, timestamp: nil, hostname: nil)
|
179
|
+
super
|
180
|
+
@entities = Array.new
|
181
|
+
end
|
182
|
+
##
|
183
|
+
# This is how you pass data to zabbix that you use to construct items from item templates. Pass in
|
184
|
+
# as many key-value pairs as you need. You'll reference these in the item prototype like {#MYKEY}
|
185
|
+
#
|
186
|
+
# Note that the keys (which you can pass as symbols if you want) are forced to uppercase. This is
|
187
|
+
# here because the author once spent way too much time trying to figure out why discovery wasn't
|
188
|
+
# working right one day. All caps seems to fix the issue.
|
189
|
+
#
|
190
|
+
def add_entity(aHash)
|
191
|
+
# just send in key value pairs - these will be the variables you can use in the discovery item prototypes
|
192
|
+
zabbified = Hash.new
|
193
|
+
aHash.each_pair { |key,value|
|
194
|
+
zabbified[%Q({##{key.to_s.upcase}})] = value
|
195
|
+
}
|
196
|
+
@entities.push(zabbified)
|
197
|
+
end
|
198
|
+
##
|
199
|
+
# Render this discovery instance as a zabbix_sender line.
|
200
|
+
#
|
201
|
+
def to_senderline
|
202
|
+
disco = { 'data'=>Array.new }
|
203
|
+
disco['data'] = @entities
|
204
|
+
@value = disco.to_json
|
205
|
+
super
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
##
|
210
|
+
# Batch instances hold all the data and discovery that you collect as your program
|
211
|
+
# does its thing with source data. Once you've done all your data collection, you can:
|
212
|
+
#
|
213
|
+
# * Send the batch instance to an instance of Pipe to have it transmitted to zabbix
|
214
|
+
# * puts mybatch.to_senderline to output the zabbix_sender input text
|
215
|
+
# * Use it to help feed data into zabbix by whatever other mechanism you might be
|
216
|
+
# using, e.g. a ruby implementation of the zabbix sender protocol
|
217
|
+
#
|
218
|
+
class Batch
|
219
|
+
##
|
220
|
+
# This is an array of all the ItemData and Discovery instances that have been added
|
221
|
+
# to this discovery since instantiation.
|
222
|
+
#
|
223
|
+
attr_reader :data
|
224
|
+
|
225
|
+
##
|
226
|
+
# Both parameters are optional - reasonable defaults are provided.
|
227
|
+
#
|
228
|
+
# Bear in mind that the hostname and timestamp values you provide here will be applied
|
229
|
+
# to all the ItemData and Discovery objects you add via the addItemData() and
|
230
|
+
# addDiscovery() methods by default (unless you override them when you add them)
|
231
|
+
def initialize(timestamp: Time.now, hostname: Zabbix::AgentConfiguration.zabbixHostname)
|
232
|
+
@time = timestamp
|
233
|
+
@hostname = hostname
|
234
|
+
@data = Array.new
|
235
|
+
end
|
236
|
+
##
|
237
|
+
# Create a new instance of ItemData and add that instance to the list of data that this
|
238
|
+
# batch contains. You must provide a key and a value. You *can* provide a timestamp and
|
239
|
+
# a hostname. If you do not provide a timestamp or hostname, they will be given the
|
240
|
+
# timestamp and hostname associated with the instance of Batch that you're working with
|
241
|
+
#
|
242
|
+
def addItemData(key: nil,value: nil,timestamp: @time, hostname: @hostname)
|
243
|
+
@data.push(ItemData.new(key: key,value: value,timestamp: timestamp,hostname: hostname))
|
244
|
+
end
|
245
|
+
|
246
|
+
##
|
247
|
+
# Add a discovery object to this batch of data. The object will be added to the
|
248
|
+
# top of the item list.
|
249
|
+
#
|
250
|
+
# If you did not specifically provide a hostname or a timestamp when you
|
251
|
+
# instantiated the Discovery, they'll given the ones provided when this instance
|
252
|
+
# of Batch was constructed.
|
253
|
+
#
|
254
|
+
def addDiscovery(aDiscovery)
|
255
|
+
# It doesn't matter right now really as zabbix has to digest the disco
|
256
|
+
# and won't do it before it tries to process the data, but it makes logical
|
257
|
+
# sense to put discos first.
|
258
|
+
aDiscovery.timestamp = @time if not aDiscovery.timestamp
|
259
|
+
aDiscovery.hostname = @hostname if not aDiscovery.hostname
|
260
|
+
@data.unshift(aDiscovery)
|
261
|
+
end
|
262
|
+
|
263
|
+
##
|
264
|
+
# Render this batch of data as a sequence of lines of text appropriate
|
265
|
+
# for sending into zabbix_sender
|
266
|
+
#
|
267
|
+
def to_senderline
|
268
|
+
@data.collect {|line| line.to_senderline}.join
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
272
|
+
end # module Sender
|
273
|
+
end # module Zabbix
|
@@ -0,0 +1,73 @@
|
|
1
|
+
```
|
2
|
+
root@zabbix-server:~# /opt/zabbix-server/bin/zabbix_sender -h
|
3
|
+
usage:
|
4
|
+
zabbix_sender [-v] -z server [-p port] [-I IP-address] -s host -k key
|
5
|
+
-o value
|
6
|
+
zabbix_sender [-v] -z server [-p port] [-I IP-address] [-s host] [-T] [-r]
|
7
|
+
-i input-file
|
8
|
+
zabbix_sender [-v] -c config-file [-z server] [-p port] [-I IP-address]
|
9
|
+
[-s host] -k key -o value
|
10
|
+
zabbix_sender [-v] -c config-file [-z server] [-p port] [-I IP-address]
|
11
|
+
[-s host] [-T] [-r] -i input-file
|
12
|
+
zabbix_sender -h
|
13
|
+
zabbix_sender -V
|
14
|
+
|
15
|
+
Utility for sending monitoring data to Zabbix server or proxy.
|
16
|
+
|
17
|
+
General options:
|
18
|
+
-c --config config-file Path to Zabbix agentd configuration file
|
19
|
+
|
20
|
+
-z --zabbix-server server Hostname or IP address of Zabbix server or proxy
|
21
|
+
to send data to. When used together with --config,
|
22
|
+
overrides the first entry of "ServerActive"
|
23
|
+
parameter specified in agentd configuration file
|
24
|
+
|
25
|
+
-p --port port Specify port number of trapper process of Zabbix
|
26
|
+
server or proxy. When used together with --config,
|
27
|
+
overrides the port of the first entry of
|
28
|
+
"ServerActive" parameter specified in agentd
|
29
|
+
configuration file (default: 10051)
|
30
|
+
|
31
|
+
-I --source-address IP-address Specify source IP address. When used
|
32
|
+
together with --config, overrides "SourceIP"
|
33
|
+
parameter specified in agentd configuration file
|
34
|
+
|
35
|
+
-s --host host Specify host name the item belongs to (as
|
36
|
+
registered in Zabbix frontend). Host IP address
|
37
|
+
and DNS name will not work. When used together
|
38
|
+
with --config, overrides "Hostname" parameter
|
39
|
+
specified in agentd configuration file
|
40
|
+
|
41
|
+
-k --key key Specify item key
|
42
|
+
-o --value value Specify item value
|
43
|
+
|
44
|
+
-i --input-file input-file Load values from input file. Specify - for
|
45
|
+
standard input. Each line of file contains
|
46
|
+
whitespace delimited: <host> <key> <value>.
|
47
|
+
Specify - in <host> to use hostname from
|
48
|
+
configuration file or --host argument
|
49
|
+
|
50
|
+
-T --with-timestamps Each line of file contains whitespace delimited:
|
51
|
+
<host> <key> <timestamp> <value>. This can be used
|
52
|
+
with --input-file option. Timestamp should be
|
53
|
+
specified in Unix timestamp format
|
54
|
+
|
55
|
+
-r --real-time Send metrics one by one as soon as they are
|
56
|
+
received. This can be used when reading from
|
57
|
+
standard input
|
58
|
+
|
59
|
+
-v --verbose Verbose mode, -vv for more details
|
60
|
+
|
61
|
+
-h --help Display this help message
|
62
|
+
-V --version Display version number
|
63
|
+
|
64
|
+
TLS connection options:
|
65
|
+
Not available. This Zabbix sender was compiled without TLS support
|
66
|
+
|
67
|
+
Example(s):
|
68
|
+
zabbix_sender -z 127.0.0.1 -s "Linux DB3" -k db.connections -o 43
|
69
|
+
|
70
|
+
Report bugs to: <https://support.zabbix.com>
|
71
|
+
Zabbix home page: <http://www.zabbix.com>
|
72
|
+
Documentation: <https://www.zabbix.com/documentation>
|
73
|
+
```
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative 'lib/zabbix_sender_api/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "zabbix_sender_api"
|
5
|
+
spec.version = ZabbixSenderApi::VERSION
|
6
|
+
spec.authors = ["Dave Parker"]
|
7
|
+
spec.email = ["daveparker01@gmail.com"]
|
8
|
+
|
9
|
+
spec.summary = %q{Ruby frontend to the zabbix_sender command line tool}
|
10
|
+
spec.description = %q{This gem describes an api to the zabbix sender facility. It saves tons of hassle when you're cranking out custom polling logic}
|
11
|
+
spec.homepage = "https://gitlab.com/svdasein/zabbix_sender_api"
|
12
|
+
spec.license = "MIT"
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
14
|
+
|
15
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
16
|
+
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
spec.metadata["source_code_uri"] = "https://gitlab.com/svdasein/zabbix_sender_api"
|
19
|
+
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
23
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
24
|
+
end
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: zabbix_sender_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dave Parker
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-08-02 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: This gem describes an api to the zabbix sender facility. It saves tons
|
14
|
+
of hassle when you're cranking out custom polling logic
|
15
|
+
email:
|
16
|
+
- daveparker01@gmail.com
|
17
|
+
executables:
|
18
|
+
- example.rb
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- ".gitignore"
|
23
|
+
- Gemfile
|
24
|
+
- Gemfile.lock
|
25
|
+
- LICENSE.txt
|
26
|
+
- README.md
|
27
|
+
- Rakefile
|
28
|
+
- bin/console
|
29
|
+
- bin/setup
|
30
|
+
- exe/example.rb
|
31
|
+
- images/.gitkeep
|
32
|
+
- images/Spectacle.Z29721.png
|
33
|
+
- images/Spectacle.l29721.png
|
34
|
+
- lib/zabbix_sender_api.rb
|
35
|
+
- lib/zabbix_sender_api/api.rb
|
36
|
+
- lib/zabbix_sender_api/version.rb
|
37
|
+
- zabbix-sender-help.md
|
38
|
+
- zabbix_sender_api.gemspec
|
39
|
+
homepage: https://gitlab.com/svdasein/zabbix_sender_api
|
40
|
+
licenses:
|
41
|
+
- MIT
|
42
|
+
metadata:
|
43
|
+
allowed_push_host: https://rubygems.org
|
44
|
+
homepage_uri: https://gitlab.com/svdasein/zabbix_sender_api
|
45
|
+
source_code_uri: https://gitlab.com/svdasein/zabbix_sender_api
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.3.0
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
requirements: []
|
61
|
+
rubygems_version: 3.1.2
|
62
|
+
signing_key:
|
63
|
+
specification_version: 4
|
64
|
+
summary: Ruby frontend to the zabbix_sender command line tool
|
65
|
+
test_files: []
|