Some checks failed
/ Test (basic) on ubuntu-latest with golang 1.23 (push) Has been cancelled
/ Test (race) on ubuntu-latest with golang 1.23 (push) Has been cancelled
/ Test (shell) on ubuntu-latest with golang 1.23 (push) Has been cancelled
This lets us look at the available resource data for collection, and to filter it so we can decide what we want to collect on our machine. Other types of collect functions could be added in the future.
53 lines
1016 B
Plaintext
53 lines
1016 B
Plaintext
import "fmt"
|
|
import "golang/strings" as golang_strings
|
|
import "iter"
|
|
import "world/collect"
|
|
|
|
file "/tmp/foo" {
|
|
state => $const.res.file.state.exists,
|
|
content => "i am foo\n",
|
|
|
|
Meta:export => ["*",],
|
|
#Meta:export => ["${hostname}",], # alternatively
|
|
}
|
|
file "/tmp/fah" {
|
|
state => $const.res.file.state.exists,
|
|
content => "i am fah\n",
|
|
|
|
#Meta:export => ["*",],
|
|
Meta:export => ["${hostname}",],
|
|
}
|
|
|
|
$all = collect.res("file") # []struct{name str; host str;}
|
|
|
|
# any kind of filter code that you want!
|
|
$fn = func($st) {
|
|
golang_strings.has_prefix($st->name, "/tmp/fo")
|
|
}
|
|
|
|
$filtered = iter.filter($all, $fn)
|
|
|
|
print "all" {
|
|
msg => fmt.printf("%v", $all),
|
|
|
|
Meta:autogroup => false,
|
|
}
|
|
print "filtered" {
|
|
msg => fmt.printf("%v", $filtered),
|
|
|
|
Meta:autogroup => false,
|
|
}
|
|
|
|
collect file $filtered {
|
|
Meta:hidden => true, # let's not apply these for now
|
|
}
|
|
|
|
# you can do it manually like this
|
|
#$collected = [
|
|
# struct{name => "/tmp/foo", host => "${hostname}",},
|
|
#]
|
|
#
|
|
#collect file $collected {
|
|
# Meta:hidden => false,
|
|
#}
|