-
-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add icinga2_version fact for Windows
- Loading branch information
Lennart Betz
committed
Jul 5, 2022
1 parent
41db398
commit 0a708f5
Showing
1 changed file
with
14 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,21 @@ | ||
Facter.add('icinga2_version') do | ||
confine { Facter::Core::Execution.which('icinga2') } | ||
confine kernel: 'linux' | ||
setcode do | ||
icinga2_ver = Facter::Core::Execution.execute("icinga2 -V|grep 'version: r'") | ||
icinga2_ver.match(%r{\d+\.\d+\.\d+})[0] if icinga2_ver | ||
end | ||
end | ||
|
||
Facter.add('icinga2_version') do | ||
confine kernel: 'windows' | ||
setcode do | ||
file = if tmp = Facter::Core::Execution.which('icinga2.exe') | ||
tmp | ||
else | ||
'C:/Program Files/ICINGA2/sbin/icinga2.exe' | ||
end | ||
cmd = "#{file.split(':').first}:\"#{file.split(':').last.tr('/', '\\')}\" -V 2>&1" | ||
Facter::Core::Execution.execute("cmd /C #{cmd}").lines.grep(%r{version: (r|v)?\d+\.\d+\d+}).first.split(':').last.delete('vr)').strip if File.executable?(file) | ||
end | ||
end |