Posted on 05-24-2017 06:06 AM
Is there a way to make a smart group based on whether or not a Mac has specific proxy settings?
We are pushing a script: networksetup -setautoproxyurl Ethernet http://blahblahblah and I want to create a smart group to make sure all our Macs always have this set correctly.
Solved! Go to Solution.
Posted on 05-24-2017 01:21 PM
Yes, the problem is that Extension Attribute scripts need to echo back the result within result tags, like so
#!/bin/bash
echo "<result>$(networksetup -getautoproxyurl Ethernet | awk '/URL/{print $NF}')</result>"
From there, create a Smart Group that uses the new EA as its criteria (along with anything else you need) The EA value you want for machines without the proxy set would be (null)
Posted on 05-24-2017 08:53 AM
You'd need to create an Extension Attribute script that captures the proxy settings for the port you're looking to set it on, like Ethernet, and then use the results from the EA to gather Macs that do not have it set as you want.
For ex, you can use networksetup -getautoproxyurl Ethernet
to read the settings back. You can throw on a | awk '/URL/{print $NF}'
at the end to get just the URL assigned, or it comes back with (null)
if its not set.
Posted on 05-24-2017 10:36 AM
So I created a script:
networksetup -getautoproxyurl Ethernet | awk '/URL/{print $NF}'
Added it to a policy and ran it on a test machine. The script result shows the proxy that I added to the machine earlier.
Now how do I make a smart group that shows all the Macs that do not have this proxy?
Posted on 05-24-2017 10:59 AM
Ok, I see my mistake. I ran this as a policy and did not understand there was a section for creating Extension Attributes.
Posted on 05-24-2017 11:31 AM
So I created a new Extension attribute using these settings:
Data Type: String
Inventory Display: General
Input Type Script
Script
networksetup -getautoproxyurl Ethernet | awk '/URL/{print $NF}'
I forced my test Mac to update inventory, but the new field is still empty. Do you see what I did wrong?
Posted on 05-24-2017 01:21 PM
Yes, the problem is that Extension Attribute scripts need to echo back the result within result tags, like so
#!/bin/bash
echo "<result>$(networksetup -getautoproxyurl Ethernet | awk '/URL/{print $NF}')</result>"
From there, create a Smart Group that uses the new EA as its criteria (along with anything else you need) The EA value you want for machines without the proxy set would be (null)
Posted on 05-25-2017 06:52 AM
If you want to check that the proxy is enabled on all network interfaces (not just ethernet) you can use the following EA script, kindly provided by @mm2270
#!/bin/bash
# From https://jamfnation.jamfsoftware.com/discussion.html?id=13779 mm2270
# Checks each interface for proxy, answers Yes if all on, answers No if any are off (skips over missing interfaces)
validConnections=("Ethernet" "Wi-Fi" "USB Ethernet"
"Broadcom NetXtreme Gigabit Ethernet Controller"
"Display Ethernet"
"Thunderbolt Bridge"
"Thunderbolt Ethernet")
while read connection; do
if [[ $(echo "${validConnections[@]}" | grep "$connection") ]]; then
setting=$(networksetup -getautoproxyurl "$connection" | awk '/Enabled/{print $NF}')
if [[ "$setting" == "No" ]]; then
Disabled+=("$connection")
elif [[ "$setting" == "Yes" ]]; then
Enabled+=("$connection")
fi
fi
done < <(networksetup -listallhardwareports | awk -F': ' '/Hardware Port:/{print $NF}')
if [[ -z "${Disabled[@]}" ]]; then
echo "<result>Yes</result>"
else
echo "<result>No</result>"
fi
Posted on 05-25-2017 10:33 AM
I see what this is doing and I have it working, but now I am wondering how to set the proxy on all available connections. Would it be something like:
validConnections=("Ethernet" "Wi-Fi" "USB Ethernet" "Broadcom NetXtreme Gigabit Ethernet Controller" "Display Ethernet" "Thunderbolt Bridge" "Thunderbolt Ethernet")
while read connection; do
if [[ $(echo "${validConnections[@]}" | grep "$connection") ]]; then
networksetup -setautoproxyurl "$connection" http://blahblahblah
fi
done
I know this does not work. What would I need to change?
Posted on 05-25-2017 12:32 PM
I found a script that I could modify for my needs. Thank you everyone for your help.
Posted on 05-25-2017 12:36 PM
Try this.
#!/bin/bash
validConnections=("Ethernet" "Wi-Fi" "USB Ethernet"
"Broadcom NetXtreme Gigabit Ethernet Controller"
"Display Ethernet"
"Thunderbolt Bridge"
"Thunderbolt Ethernet")
while read connection; do
if [[ $(echo "${validConnections[@]}" | grep "$connection") ]]; then
setting=$(networksetup -getautoproxyurl "$connection" | awk '/Enabled/{print $NF}')
if [[ "$setting" == "No" ]]; then
echo "Setting proxy for $connection to http://blahblahblah"
networksetup -setautoproxyurl "$connection" http://blahblahblah
else
echo "Proxy for $connection is set to http://blahblahblah"
fi
fi
done < <(networksetup -listallhardwareports | awk -F': ' '/Hardware Port:/{print $NF}')