Class: Zabbirc::Zabbix::Connection
- Inherits:
-
Object
- Object
- Zabbirc::Zabbix::Connection
- Defined in:
- lib/zabbirc/zabbix/connection.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Class Method Summary collapse
- .down! ⇒ Object
- .down? ⇒ Boolean
- .get_connection ⇒ Object
- .test_connection ⇒ Object
- .up! ⇒ Object
- .up? ⇒ Boolean
Instance Method Summary collapse
-
#initialize ⇒ Connection
constructor
A new instance of Connection.
Constructor Details
#initialize ⇒ Connection
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.login(user: Zabbirc.config.zabbix_login, password: Zabbirc.config.zabbix_password) end |
Instance Attribute Details
#client ⇒ Object (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
16 17 18 |
# File 'lib/zabbirc/zabbix/connection.rb', line 16 def self.down? @@down == true end |
.get_connection ⇒ Object
8 9 10 |
# File 'lib/zabbirc/zabbix/connection.rb', line 8 def self.get_connection Thread.current[:zabbix_connection] ||= self.new end |
.test_connection ⇒ Object
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
24 25 26 |
# File 'lib/zabbirc/zabbix/connection.rb', line 24 def self.up? @@down == false end |