Sha256: 2c554fb587e70ecf7a7940c5c61a7fb8f2e4adced14a28d9263c51e33a4dc56d

Contents?: true

Size: 938 Bytes

Versions: 1

Compression:

Stored size: 938 Bytes

Contents

require "json"
require "socket"

require "zabbix_sender_legacy/sender"

module ZabbixSenderLegacy
  MissingConfigFile = Class.new(StandardError)
  MissingServerActiveConfig = Class.new(StandardError)

  class << self
    def from_config(config_path = "/etc/zabbix/zabbix_agentd.conf")
      unless File.exist?(config_path)
        raise MissingConfigFile, "Missing config file with #{config_path}"
      end
      host, port = parse_config(config_path)
      Sender.new(host, port)
    end

    def new(zabbix_host="127.0.0.1", zabbix_port=10051)
      Sender.new(zabbix_host, zabbix_port)
    end

    private

    def parse_config(config_path)
      unless /^ServerActive\s*=\s*(?<server>[\w\-:,\.\[\]]+)\s*$/ =~ File.read(config_path)
        raise MissingServerActiveConfig, "Missing ServerActive config in #{config_path}"
      end 
      host, port = server.split(":")
      port ||= 10051
      [host, port.to_i]
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
zabbix_sender_legacy-0.1.7 lib/zabbix_sender_legacy.rb