class Zabbix::AgentConfiguration

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.

Public Class Methods

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' ]) click to toggle source

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.

# 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() click to toggle source

Returns the value of the Hostname= asignment in zabbix_agentd.conf (if any)

# File lib/zabbix_sender_api/api.rb, line 63
def self.zabbixHostname
  @hostname
end
zabbixProxy() click to toggle source

Returns the value of the Server= assignment in zabbix_agentd.conf (if any)

# File lib/zabbix_sender_api/api.rb, line 56
def self.zabbixProxy
  @proxy
end