File tree Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ Facter . add ( :zbx_admin_passwd_default ) do
4+ confine kernel : 'Linux'
5+ setcode do
6+ require 'zabbixapi'
7+ rescue LoadError
8+ nil
9+ else
10+ def ini_parse ( file )
11+ current_section = { }
12+ map = { }
13+ file . rewind
14+ file . each_line do |line |
15+ line = line . split ( %r{^|\s ;} ) . first # remove comments
16+ section = line . match ( %r{^\s *\[ ([^\[ \] ]+)\] \s *$} ) unless line . nil?
17+ if section
18+ current_section = section [ 1 ]
19+ elsif current_section
20+ item = line . match ( %r{^\s *(.+?)\s *=\s *(.+?)\s *$} ) unless line . nil?
21+ if item
22+ map [ current_section ] = map [ current_section ] || { }
23+ map [ current_section ] [ item [ 1 ] ] = item [ 2 ]
24+ end
25+ end
26+ end
27+ map
28+ end
29+
30+ def api_config
31+ @api_config ||= ini_parse ( File . new ( '/etc/zabbix/api.conf' ) )
32+ end
33+
34+ begin
35+ protocol = api_config [ 'default' ] [ 'apache_use_ssl' ] == 'true' ? 'https' : 'http'
36+ zbx_check = ZabbixApi . connect (
37+ url : "#{ protocol } ://#{ api_config [ 'default' ] [ 'zabbix_url' ] } /api_jsonrpc.php" ,
38+ user : api_config [ 'default' ] [ 'zabbix_user' ] ,
39+ password : 'zabbix' ,
40+ http_user : api_config [ 'default' ] [ 'zabbix_user' ] ,
41+ http_password : 'zabbix' ,
42+ ignore_version : true
43+ )
44+ rescue ZabbixApi ::ApiError
45+ ret = false
46+ else
47+ ret = true
48+ zbx_check . query ( method : 'user.logout' , params : { } )
49+ end
50+ ret
51+ end
52+ end
You can’t perform that action at this time.
0 commit comments