Smart Group for proxy settings

Sobchak
Contributor

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.

1 ACCEPTED SOLUTION

mm2270
Legendary Contributor III

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)

View solution in original post

9 REPLIES 9

mm2270
Legendary Contributor III

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.

Sobchak
Contributor

So I created a script:

!/bin/bash

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?

Sobchak
Contributor

Ok, I see my mistake. I ran this as a policy and did not understand there was a section for creating Extension Attributes.

Sobchak
Contributor

So I created a new Extension attribute using these settings:
Data Type: String
Inventory Display: General
Input Type Script

Script

!/bin/bash

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?

mm2270
Legendary Contributor III

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)

May
Contributor III

@Sobchak

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

Sobchak
Contributor

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:

!/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
networksetup -setautoproxyurl "$connection" http://blahblahblah
fi
done

I know this does not work. What would I need to change?

Sobchak
Contributor

I found a script that I could modify for my needs. Thank you everyone for your help.

mm2270
Legendary Contributor III

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}')