-
-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fact to check if zabbix admin is using default password
- Loading branch information
DEFERME Bert
committed
Jul 28, 2022
1 parent
4a7ea47
commit d6a1429
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# frozen_string_literal: true | ||
|
||
Facter.add(:zbx_admin_passwd_default) do | ||
confine kernel: 'Linux' | ||
setcode do | ||
require 'zabbixapi' | ||
rescue LoadError | ||
nil | ||
else | ||
def ini_parse(file) | ||
current_section = {} | ||
map = {} | ||
file.rewind | ||
file.each_line do |line| | ||
line = line.split(%r{^|\s;}).first # remove comments | ||
section = line.match(%r{^\s*\[([^\[\]]+)\]\s*$}) unless line.nil? | ||
if section | ||
current_section = section[1] | ||
elsif current_section | ||
item = line.match(%r{^\s*(.+?)\s*=\s*(.+?)\s*$}) unless line.nil? | ||
if item | ||
map[current_section] = map[current_section] || {} | ||
map[current_section][item[1]] = item[2] | ||
end | ||
end | ||
end | ||
map | ||
end | ||
|
||
def api_config | ||
@api_config ||= ini_parse(File.new('/etc/zabbix/api.conf')) | ||
end | ||
|
||
begin | ||
protocol = api_config['default']['apache_use_ssl'] == 'true' ? 'https' : 'http' | ||
zbx_check = ZabbixApi.connect( | ||
url: "#{protocol}://#{api_config['default']['zabbix_url']}/api_jsonrpc.php", | ||
user: api_config['default']['zabbix_user'], | ||
password: 'zabbix', | ||
http_user: api_config['default']['zabbix_user'], | ||
http_password: 'zabbix', | ||
ignore_version: true | ||
) | ||
rescue ZabbixApi::ApiError | ||
ret = false | ||
else | ||
ret = true | ||
zbx_check.query(method: 'user.logout', params: {}) | ||
end | ||
ret | ||
end | ||
end |