Class: Rubix::AutoSender
- Inherits:
-
Object
- Object
- Rubix::AutoSender
- Includes:
- Logs
- Defined in:
- lib/rubix/auto_sender.rb
Overview
A class used to send data to Zabbix.
This sender is used to implement the logic for the zabbix_pipe
utility. It is initialized with some metadata about a host, its host groups and templates, and applications into which items should be written, and it can then accept data and forward it to a Zabbix server using the zabbix_sender
utility that comes with Zabbix.
A sender can be given data in either TSV or JSON formats. With the JSON format, it is possible to embed data for hosts, host groups, &c. distinct from that with which this sender was initialized. This is a useful way to send many different kinds of data through the same process.
The sender will also auto-vivify any hosts, host gruops, templates, applications, and items it needs in order to be able to write data. This is expensive in terms of time so it can be turned off using the --fast
option.
Instance Attribute Summary collapse
-
#applications ⇒ Array<Rubix::Application>
The applications used to create items.
-
#host ⇒ Rubix::Host
The host the Sender will send data for.
-
#host_groups ⇒ Array<Rubix::HostGroup>
The hostgroups used to create this host.
-
#settings ⇒ Hash
Settings.
-
#templates ⇒ Array<Rubix::Template>
The templates used to create this host.
Instance Method Summary collapse
-
#auto_vivify? ⇒ true, false
Will this sender auto-vivify hosts, groups, items, &c.?.
-
#fast? ⇒ true, false
Is this sender running in ‘fast’ mode? If so, it will not auto-vivify any hosts, groups, items, &c.
-
#initialize(settings) ⇒ AutoSender
constructor
Create a new sender with the given
settings
. -
#process_line(line) ⇒ Object
Process a single line of text.
-
#run ⇒ Object
Run this sender.
Methods included from Logs
#debug, #error, #fatal, #info, #warn
Constructor Details
#initialize(settings) ⇒ AutoSender
Create a new sender with the given settings
.
61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/rubix/auto_sender.rb', line 61 def initialize settings @settings = settings confirm_settings if fast? info("Forwarding for #{settings['host']}...") if settings['verbose'] else initialize_host_groups initialize_templates initialize_host initialize_applications info("Forwarding for #{host.name}...") if settings['verbose'] end end |
Instance Attribute Details
#applications ⇒ Array<Rubix::Application>
Returns The applications used to create items.
41 42 43 |
# File 'lib/rubix/auto_sender.rb', line 41 def applications @applications end |
#host ⇒ Rubix::Host
Returns the host the Sender will send data for.
32 33 34 |
# File 'lib/rubix/auto_sender.rb', line 32 def host @host end |
#host_groups ⇒ Array<Rubix::HostGroup>
Returns the hostgroups used to create this host.
35 36 37 |
# File 'lib/rubix/auto_sender.rb', line 35 def host_groups @host_groups end |
#settings ⇒ Hash
Returns settings.
29 30 31 |
# File 'lib/rubix/auto_sender.rb', line 29 def settings @settings end |
#templates ⇒ Array<Rubix::Template>
Returns the templates used to create this host.
38 39 40 |
# File 'lib/rubix/auto_sender.rb', line 38 def templates @templates end |
Instance Method Details
#auto_vivify? ⇒ true, false
Will this sender auto-vivify hosts, groups, items, &c.?
86 87 88 |
# File 'lib/rubix/auto_sender.rb', line 86 def auto_vivify? !fast? end |
#fast? ⇒ true, false
Is this sender running in ‘fast’ mode? If so, it will not auto-vivify any hosts, groups, items, &c.
79 80 81 |
# File 'lib/rubix/auto_sender.rb', line 79 def fast? settings['fast'] end |
#process_line(line) ⇒ Object
Process a single line of text.
250 251 252 253 254 255 256 |
# File 'lib/rubix/auto_sender.rb', line 250 def process_line line if looks_like_json?(line) process_line_of_json_in_new_pipe(line) else process_line_of_tsv_in_this_pipe(line) end end |
#run ⇒ Object
Run this sender.
Will read from the correct source of data and exit the Ruby process once the source is consumed.
173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/rubix/auto_sender.rb', line 173 def run case when settings['pipe'] process_pipe when settings.rest.size > 0 settings.rest.each do |path| process_file(path) end else process_stdin end exit(0) end |