Sha256: 8d6e74c95c4ca9db74884b538f5a8bdedb1c02e346076fea200417c5d62240b8

Contents?: true

Size: 892 Bytes

Versions: 3

Compression:

Stored size: 892 Bytes

Contents

module Salus
  class ZabbixSenderRenderer < BaseRenderer
    def render(data)
      # Top level groups are considered hostnames
      result = {}
      data.each do |hostname, group|
        iterate(group) do |name, metric|
          unless metric.timestamp.nil?
            timestamp = metric.timestamp.to_i
            name  = name.gsub(/\.\[/, '[')
            name  = name.to_json if (name.match(/\s/))
            value = metric.value
            value = '""' if value.nil?
            value = value.to_json if (!value.nil? && metric.is_a?(Salus::Text))

            result[timestamp] = [] unless result.key?(timestamp)
            result[timestamp] << "#{hostname.dump} #{name} #{timestamp} #{value}"
          end
        end
      end
      # Zabbix requires timestamps to be sorted
      result.keys.sort.each { |k| STDOUT.puts result[k] }
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
salus-0.2.1 lib/salus/renderer/zabbixsender.rb
salus-0.2.0 lib/salus/renderer/zabbixsender.rb
salus-0.1.3 lib/salus/renderer/zabbixsender.rb