-
-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #117 from alexjfisher/runtime_fact
Add `proxysql_runtime` fact
- Loading branch information
Showing
2 changed files
with
63 additions
and
1 deletion.
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
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,41 @@ | ||
Facter.add(:proxysql_runtime) do | ||
client = nil | ||
|
||
confine :proxysql_version do |version| | ||
version =~ %r{^2} | ||
end | ||
|
||
confine do | ||
begin | ||
require 'mysql2' | ||
rescue LoadError | ||
next | ||
end | ||
|
||
begin | ||
client = Mysql2::Client.new(default_file: '/root/.my.cnf') | ||
rescue Mysql2::Error::ConnectionError => e | ||
Facter.debug(e.inspect) | ||
end | ||
client | ||
end | ||
|
||
setcode do | ||
fact = {} | ||
[ | ||
# tables that might include unencrypted credentials have not been included here. | ||
'runtime_mysql_servers', | ||
'runtime_mysql_aws_aurora_hostgroups', | ||
'runtime_mysql_galera_hostgroups', | ||
'runtime_mysql_group_replication_hostgroups', | ||
'runtime_mysql_query_rules', | ||
'runtime_mysql_query_rules_fast_routing', | ||
'runtime_mysql_replication_hostgroups', | ||
'runtime_proxysql_servers' | ||
].each do |table| | ||
results = client.query("SELECT * FROM #{table}") | ||
fact[table] = results.map { |row| row } | ||
end | ||
fact | ||
end | ||
end |