DRBD cluster facts
Some facts to help managing a DRBD cluster:
if FileTest.exists?("/proc/drbd")
result = {}
Thread::exclusive do
File.readlines("/proc/drbd").each do |l|
if l =~ /(\d+): cs:Unconfigured/
device = $1
result["drbdconnectionstate#{device}"] = "Unconfigured"
elsif l =~ /(\d+): cs:(\w+) st:(\w+)\/(\w+) ld:(\w+)/
device = $1
connectionstate = $2
localstate = $3
peerstate = $4
localdiskstate = $5
result["drbdconnectionstate#{device}"] = connectionstate
result["drbdlocalstate#{device}"] = localstate
result["drbdpeerstate#{device}"] = peerstate
result["drbdlocaldiskstate#{device}"] = localdiskstate
elsif l =~ /(\d+): cs:(\w+) st:(\w+)\/(\w+) ds:(\w+)\/(\w+)/
device = $1
connectionstate = $2
localstate = $3
peerstate = $4
localdiskstate = $5
peerdiskstate = $6
result["drbdconnectionstate#{device}"] = connectionstate
result["drbdlocalstate#{device}"] = localstate
result["drbdpeerstate#{device}"] = peerstate
result["drbdlocaldiskstate#{device}"] = localdiskstate
result["drbdpeerdiskstate#{device}"] = peerdiskstate
end
end
end
result.each { |name, fact|
Facter.add(name) do
setcode do
fact
end
end
}
end
It has been tested with DRBD version 0.7.24 and 8.0.4 (not sure the /proc/drbd format is the same for older versions of DRBD).
Here is a sample output from facter (indicates the state of /dev/drbd0 on the primary node while the secondary node is disconnected):
drbdconnectionstate0 => WFConnection drbdlocaldiskstate0 => UpToDate drbdlocalstate0 => Primary drbdpeerdiskstate0 => Outdated drbdpeerstate0 => Unknown