Module: ZabbixRubyClient::PluginBase

Instance Method Summary collapse

Instance Method Details

#getline(file, pattern = false) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/zabbix-ruby-client/plugin_base.rb', line 36

def getline(file, pattern=false)
  if File.readable? file
    File.open(file,'r') do |f|
      f.each do |l|
        line = l.strip
        if pattern
          if Regexp.new(pattern).match line
            Log.debug "File #{file}: #{line}"
            return line
          end
        else
          return line
        end
      end
    end
    Log.warn "File #{file}: pattern \"#{pattern}\" not found."
    false
  else
    if File.file? file
      Log.error "File not readable: #{file}"
    else
      Log.error "File not found: #{file}"
    end
    false
  end
end

#getlines(file, pattern = false) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/zabbix-ruby-client/plugin_base.rb', line 63

def getlines(file, pattern=false)
  lines = []
  if File.readable? file
    File.open(file,'r') do |f|
      f.each do |l|
        line = l.strip
        if pattern
          if Regexp.new(pattern).match line
            Log.debug "File #{file}: #{line}"
            lines << line
          end
        else
           lines << line
        end
      end
    end
    Log.warn "File #{file}: pattern \"#{pattern}\" not found." unless lines.count > 0
    lines
  else
    if File.file? file
      Log.error "File not readable: #{file}"
    else
      Log.error "File not found: #{file}"
    end
    false
  end
end

#httprequest(url) ⇒ Object



8
9
# File 'lib/zabbix-ruby-client/plugin_base.rb', line 8

def httprequest(url)
end

#osObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/zabbix-ruby-client/plugin_base.rb', line 18

def os
  @_os ||= (
    host_os = RbConfig::CONFIG['host_os']
    case host_os
    when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
      :windows
    when /darwin|mac os/
      :macosx
    when /linux/
      :linux
    when /solaris|bsd/
      :unix
    else
      raise Error::WebDriverError, "unknown os: #{host_os.inspect}"
    end
  )
end

#perform(command) ⇒ Object



11
12
# File 'lib/zabbix-ruby-client/plugin_base.rb', line 11

def perform(command)
end

#timeObject



14
15
16
# File 'lib/zabbix-ruby-client/plugin_base.rb', line 14

def time
  @_now ||= Time.now.to_i
end