Class: Zabbix::AgentConfiguration
- Inherits:
-
Object
- Object
- Zabbix::AgentConfiguration
- Defined in:
- lib/zabbix_sender_api/api.rb
Overview
AgentConfiguration holds data that’s scraped from a zabbix_agentd config file. It’s initialized when the gem is required. You may optionally re-initialize the class with your own list of paths to search. If it finds configuration you can access it with class methods. This is not meant to be instantiated.
Class Method Summary collapse
-
.initialize(paths: [ '/etc/zabbix/zabbix_agentd.conf', '/usr/local/etc/zabbix/zabbix_agentd.conf', '/opt/zabbix/etc/zabbix_agentd.conf', '/opt/zabbix/conf/zabbix_agentd.conf' ]) ⇒ Object
You may optionally pass an array of full paths to agent conf files to look for during initialization.
-
.zabbixHostname ⇒ Object
Returns the value of the Hostname= asignment in zabbix_agentd.conf (if any).
-
.zabbixProxy ⇒ Object
Returns the value of the Server= assignment in zabbix_agentd.conf (if any).
Class Method Details
.initialize(paths: [ '/etc/zabbix/zabbix_agentd.conf', '/usr/local/etc/zabbix/zabbix_agentd.conf', '/opt/zabbix/etc/zabbix_agentd.conf', '/opt/zabbix/conf/zabbix_agentd.conf' ]) ⇒ Object
You may optionally pass an array of full paths to agent conf files to look for during initialization. By default some common places are checked, but you can specify your own. If you call this you’ll re-initialize the class, which will scan for values in any of the listed files it happens to find.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/zabbix_sender_api/api.rb', line 17 def self.initialize(paths: [ '/etc/zabbix/zabbix_agentd.conf', '/usr/local/etc/zabbix/zabbix_agentd.conf', '/opt/zabbix/etc/zabbix_agentd.conf', '/opt/zabbix/conf/zabbix_agentd.conf' ]) @agentConfPaths = paths @proxy = nil @hostname = nil @agentConfPaths.each { |path| if File.exist?(path) File.new(path).each_line { |line| if not @proxy match = /^Server=?(.*)/.match(line) if match @proxy = match[1].strip.split(',').pop end end if not @hostname match = /^Hostname=?(.*)/.match(line) if match @hostname = match[1].strip end end break if @proxy and @hostname } end break if @proxy and @host } if not @host @host = Socket.gethostname end end |
.zabbixHostname ⇒ Object
Returns the value of the Hostname= asignment in zabbix_agentd.conf (if any)
63 64 65 |
# File 'lib/zabbix_sender_api/api.rb', line 63 def self.zabbixHostname @hostname end |
.zabbixProxy ⇒ Object
Returns the value of the Server= assignment in zabbix_agentd.conf (if any)
56 57 58 |
# File 'lib/zabbix_sender_api/api.rb', line 56 def self.zabbixProxy @proxy end |