Sha256: 8aca48d67ca5bb4271c70d3b9f2c16ade4357b774f98ffbef6b27888ff6046b0

Contents?: true

Size: 989 Bytes

Versions: 2

Compression:

Stored size: 989 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(zabbix_host: host, zabbix_port: port)
    end

    def new(zabbix_host="127.0.0.1", zabbix_port=10051)
      Sender.new(zabbix_host: zabbix_host, zabbix_port: 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

2 entries across 2 versions & 1 rubygems

Version Path
zabbix_sender_legacy-0.1.4.1 lib/zabbix_sender_legacy.rb
zabbix_sender_legacy-0.1.4 lib/zabbix_sender_legacy.rb