class MyCLI

Public Instance Methods

connect(host, port, timeout) click to toggle source
# File bin/riemann-cli, line 57
def connect(host, port, timeout)
    return Riemann::Client.new host: host, port: port, timeout: timeout
end
query() click to toggle source
# File bin/riemann-cli, line 45
def query()
    puts options if options[:verbose]
    c = connect(options[:server], options[:port], options[:timeout])
    c[options[:string]].each do |r|
        values_hash = r.to_hash()
        puts options[:format].gsub(/%{(.*?)}/) { |m|
            values_hash[$1.to_sym]
        }
    end
end
send() click to toggle source
# File bin/riemann-cli, line 22
def send()
    puts options if options[:verbose]
    c = connect(options[:server], options[:port], options[:timeout])
    event_fields = [:host, :service, :state, :time, :description, :tags, :metric, :ttl]
    event = {}
    event_fields.each do |f|
        unless options[f].nil?
            event[f] = options[f]
        end
    end
    if options[:tcp]
        puts "Sending using tcp" if options[:verbose]
        c.tcp << event
    else
        puts "Sending using udp" if options[:verbose]
        c.udp << event
    end
end