Class: Zabbirc::Zabbix::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/zabbirc/zabbix/connection.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConnection

Returns a new instance of Connection.



38
39
40
41
# File 'lib/zabbirc/zabbix/connection.rb', line 38

def initialize
  @client = ::Zabbix::Client.new(Zabbirc.config.zabbix_api_url, debug: false)
  @client.user.(user: Zabbirc.config., password: Zabbirc.config.zabbix_password)
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



6
7
8
# File 'lib/zabbirc/zabbix/connection.rb', line 6

def client
  @client
end

Class Method Details

.down!Object



12
13
14
# File 'lib/zabbirc/zabbix/connection.rb', line 12

def self.down!
  @@down = true
end

.down?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/zabbirc/zabbix/connection.rb', line 16

def self.down?
  @@down == true
end

.get_connectionObject



8
9
10
# File 'lib/zabbirc/zabbix/connection.rb', line 8

def self.get_connection
  Thread.current[:zabbix_connection] ||= self.new
end

.test_connectionObject



28
29
30
31
32
33
34
35
36
# File 'lib/zabbirc/zabbix/connection.rb', line 28

def self.test_connection
  self.new
  self.up!
  true
rescue => e
  Zabbirc.logger.fatal "Could not connect to zabbix: #{e}"
  self.down!
  false
end

.up!Object



20
21
22
# File 'lib/zabbirc/zabbix/connection.rb', line 20

def self.up!
  @@down = false
end

.up?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/zabbirc/zabbix/connection.rb', line 24

def self.up?
  @@down == false
end