-
Notifications
You must be signed in to change notification settings - Fork 30
2023 demo F Fetching Objects
-
Let's get a report of all network segments with specified distribution points
-
Unfortunately, the summary-list data from
NetworkSegment.all
only includes their name, id, and start/end address
pp Jamf::NetworkSegment.all ;0
# [Array of Hashes]
# => 0
-
For any other info about a network segment, we must fetch the full object from the API and look at it
-
This is slower, but gives us far more info to work with than the summary-lists
Jamf::NetworkSegment.all_ids.each do |ns_id|
net_seg = Jamf::NetworkSegment.fetch id: ns_id
next unless net_seg.distribution_point
puts "Name: '#{net_seg.name}'\n Dist. Point: '#{net_seg.distribution_point}'"
end ;0
# [lines of output]
# => 0
-
Here we're using
each
to loop thru the ids of all network segments -
Each time thru, we use the id to fetch the full network segment
- We store it in the variable
net_seg
- We store it in the variable
-
net_seg
contains an object, an 'instance' of the classJamf::NetworkSegment
- Instances of classes have their own methods, separate from the methods of the class itself
-
NetworkSegment objects have a
distribution_point
method that returns the name of the distribution point, or nil if none is assigned -
So the
next
line skips those that have no distribution point set -
Then we print out two lines with the network segment name and the distribution point
- As with
echo -n
in bash, inside double-quotes,\n
means a newline character
- As with