icingatest.rb 859 Bytes
Newer Older
Markus Frosch's avatar
Markus Frosch committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# Example:
# icingatest_hostno => 1
# icingatest_instance => vagrant-snapshot
# icingatest_role => master
#
# icingatest_hostno => 1
# icingatest_instance => debian8-snapshot
# icingatest_role => satellite
#
hostname = Facter.value(:hostname)
domain = Facter.value(:domain)

if domain == 'vagrant.icinga.org'
  # improve / fake hostname for the Vagrant environment
  hostname = "icinga-test-vagrant-snapshot-#{hostname}"
end

if hostname =~ /^icinga-test-(.+)$/
Markus Frosch's avatar
Markus Frosch committed
19
  fragment = Regexp.last_match(1)
Markus Frosch's avatar
Markus Frosch committed
20
21
22
23

  if fragment =~ /^(\w+-\w+)-([a-z]+)(\d+)$/i
    Facter.add(:icingatest_instance) do
      setcode do
Markus Frosch's avatar
Markus Frosch committed
24
        Regexp.last_match(1)
Markus Frosch's avatar
Markus Frosch committed
25
26
27
28
      end
    end
    Facter.add(:icingatest_role) do
      setcode do
Markus Frosch's avatar
Markus Frosch committed
29
        Regexp.last_match(2)
Markus Frosch's avatar
Markus Frosch committed
30
31
32
33
      end
    end
    Facter.add(:icingatest_hostno) do
      setcode do
Markus Frosch's avatar
Markus Frosch committed
34
        Regexp.last_match(3)
Markus Frosch's avatar
Markus Frosch committed
35
36
37
38
      end
    end
  end
end