Module: SensuFacts
- Defined in:
- lib/facter/sensu_facts.rb
Class Method Summary collapse
- .add_agent_facts ⇒ Object
- .add_backend_facts ⇒ Object
- .add_facts ⇒ Object
- .add_sensuctl_facts ⇒ Object
- .get_version_info(cmd) ⇒ Object
- .which(cmd) ⇒ Object
Class Method Details
.add_agent_facts ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/facter/sensu_facts.rb', line 46 def self.add_agent_facts version, build, built = self.get_version_info('sensu-agent') agent = {} agent['version'] = version unless version.nil? agent['build'] = build unless build.nil? agent['built'] = built unless built.nil? if agent.empty? agent = nil end Facter.add(:sensu_agent) do setcode do agent end end end |
.add_backend_facts ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/facter/sensu_facts.rb', line 63 def self.add_backend_facts version, build, built = self.get_version_info('sensu-backend') backend = {} backend['version'] = version unless version.nil? backend['build'] = build unless build.nil? backend['built'] = built unless built.nil? if backend.empty? backend = nil end Facter.add(:sensu_backend) do setcode do backend end end end |
.add_facts ⇒ Object
40 41 42 43 44 |
# File 'lib/facter/sensu_facts.rb', line 40 def self.add_facts self.add_agent_facts self.add_backend_facts self.add_sensuctl_facts end |
.add_sensuctl_facts ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/facter/sensu_facts.rb', line 80 def self.add_sensuctl_facts version, build, built = self.get_version_info('sensuctl') sensuctl = {} sensuctl['version'] = version unless version.nil? sensuctl['build'] = build unless build.nil? sensuctl['built'] = built unless built.nil? if sensuctl.empty? sensuctl = nil end Facter.add(:sensuctl) do setcode do sensuctl end end end |
.get_version_info(cmd) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/facter/sensu_facts.rb', line 16 def self.get_version_info(cmd) path = self.which(cmd) return nil unless path if Facter.value(:kernel) == 'windows' output = Facter::Core::Execution.exec("\"#{path}\" version") else output = Facter::Core::Execution.exec("#{path} version 2>&1") end version = nil if output =~ /^#{cmd} version ([^,]+)/ version = $1.split('#')[0] end build = nil if output =~ /, build ([^,]+)/ build = $1 end built = nil # Match value that is optionally wrapped in single quotes if output =~ /built (?:')?([^']+)(?:')?$/ built = $1 end return version, build, built end |
.which(cmd) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/facter/sensu_facts.rb', line 4 def self.which(cmd) path = nil if File.exists?("C:\\Program Files\\sensu\\sensu-agent\\bin\\#{cmd}.exe") path = "C:\\Program Files\\sensu\\sensu-agent\\bin\\#{cmd}.exe" elsif File.exists?("C:\\Program Files\\Sensu\\#{cmd}.exe") path = "C:\\Program Files\\Sensu\\#{cmd}.exe" else path = Facter::Core::Execution.which(cmd) end path end |