Skip to content

Instantly share code, notes, and snippets.

@tasaif
Created May 16, 2019 22:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tasaif/0a3cbfcfcca4e25c7796300e7aeb7942 to your computer and use it in GitHub Desktop.
Save tasaif/0a3cbfcfcca4e25c7796300e7aeb7942 to your computer and use it in GitHub Desktop.
querying properties in many computers using session relevance
#!/usr/bin/env ruby
#
# Based on https://www.ibm.com/developerworks/community/blogs/e9d21113-aa93-467e-ac77-a0d20a21eaec/entry/Session_Relevance_Computer_Properties_query_Efficiency?lang=en
#
class App
def initialize
@properties = []
@template = File
.open("template.rel")
.readlines
.select {|line| !line.strip.start_with?('#')}
.join
end
def add_properties(properties)
@properties += properties
end
def set_bes_computers_criteria(crit)
@crit = crit
end
def generate_bes_properties_rel
(@properties.map do |prop|
"(bes property \"#{prop}\")"
end).join ','
end
def generate_pass_properties_rel
([*1..@properties.count].map {|n| "item #{n} of it"}).join ','
end
def generate_display_properties_rel
(@properties.each_with_index.map do |prop, index|
index += 1
"(concatenation \";\" of values of results (item 0 of it, item #{index} of it))"
end).join ",\n"
end
def generate_query
retval = @template
[
[/<bes computers>/, "set of (#{@crit})"],
[/<bes properties>/, generate_bes_properties_rel],
[/<pass properties>/, "#{generate_pass_properties_rel}"],
[/<display properties>/, "#{generate_display_properties_rel}"],
[/\n/, ""]
].each do |matching_regex, replacement|
retval.gsub!(matching_regex, replacement)
end
puts retval
end
end
app = App.new
app.add_properties([
"Computer Name",
"DOE Number",
"Computer Serial Number",
"IP Addresses",
"Mac Addresses",
"Last Report Time"
])
app.set_bes_computers_criteria('(unique values of applicable computers of bes fixlets whose ((cve id list of it) contains "CVE-2019-0708"))')
puts app.generate_query
((concatenation ";" of values of results (item 0 of it, item 1 of it)),(concatenation ";" of values of results (item 0 of it, item 2 of it)),(concatenation ";" of values of results (item 0 of it, item 3 of it)),(concatenation ";" of values of results (item 0 of it, item 4 of it)),(concatenation ";" of values of results (item 0 of it, item 5 of it)),(concatenation ";" of values of results (item 0 of it, item 6 of it))) of (elements of item 0 of it /*expand the computer set - gets you one line per computer*/, item 1 of it,item 2 of it,item 3 of it,item 4 of it,item 5 of it,item 6 of it) of (set of ((unique values of applicable computers of bes fixlets whose ((cve id list of it) contains "CVE-2019-0708"))), (bes property "Computer Name"),(bes property "DOE Number"),(bes property "Computer Serial Number"),(bes property "IP Addresses"),(bes property "Mac Addresses"),(bes property "Last Report Time"))
(
<display properties>
) of (
elements of item 0 of it /*expand the computer set - gets you one line per computer*/
, <pass properties>
) of (
<bes computers>
, <bes properties>
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment