forked from lefred/facter-mysql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmysql.rb
70 lines (63 loc) · 1.82 KB
/
mysql.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# mysql.rb
# Facts related to MySQL status
#
# Author: Frederic -lefred- Descamps
# http://www.lefred.be/
# license: GPLv2
# this code is hosted on github : https://github.com/lefred/facter-mysql
# this file should be installed in your facter directory, for example on a fedora 14 it is
# in /usr/lib/ruby/site_ruby/1.8/facter
# mysql command line to execute queries
mysqlcmd = 'mysql -B -N -e'
#status = %x[#{mysqlcmd} "SHOW STATUS"].to_s.strip
status = %x[#{mysqlcmd} "SHOW STATUS"].split("\n")
replica = %x[#{mysqlcmd} "SHOW SLAVE STATUS\\G"].split("\n")
Facter.add(:mysql_version) do
setcode do
isinstalled = false
os = Facter.value('operatingsystem')
case os
when "RedHat", "CentOS", "SuSE", "Fedora"
[ 'mysql-server', 'MySQL-server-percona', 'Percona-Server-server' ].each { |dbtype|
if isinstalled then next
isinstalled = system "rpm -qa #{dbtype}\* >/dev/null 2>&1"
end
}
when "Debian", "Ubuntu"
['mysql-server', 'Percona-server'].each { |dbtype|
if isinstalled then next
isinstalled = system "dpkg -l #{dbtype} 2>&1 | egrep '(^ii|^hi)' >/dev/null"
end
}
else
end
if isinstalled then
%x[#{mysqlcmd} "SELECT VERSION()"].to_s.strip
end
end
end
mysqlversion = Facter.value('mysql_version')
if mysqlversion then
Facter.add(:mysql_version_server) do
setcode do
%x[#{mysqlcmd} "SELECT @@VERSION_COMMENT"].to_s.strip
end
end
status.each do|n|
el=n.split("\t")
Facter.add("mysql_#{el[0]}") do
setcode do
el[1]
end
end
end
replica.each do|n|
el=n.split(":")
Facter.add("mysql_replica_#{el[0].to_s.strip}") do
setcode do
el[1]
end
end
end
end