I did manage to get this working in a manner similar to above. However, I wanted to add the value into an array so, instead of having it inline, I could call the variable when I needed it. I also wanted to be able to use it in other places throughout the application. I have other modifications that I am polishing up to fit my organizational needs.
$network_info[$part['_name']] = $part['Ethernet']['MAC Address'];
}
}
}
$network_info = (object) $network_info;
But then, I decided to take it a step further. I wanted the hardware addresses to be available in the client listing as well. While I could walk the array from the plist, that seemed expensive to execute it on ~4000 clients. So how do I go about getting it in the client table? Well, after overcoming my mild case of non-programmer's stupid, as well as several incidences of cranial flatulence, i managed to pass the values into the client table with postflight. I don't think it's necessarily pretty. but it works. Also, since it's a hardware value, I had no regrets including it in the table with the hardware records. Plus, now it can be called with $client. Another thing to keep in mind. This only works on the OS default values for network interface names. If you've changed yours for some reason, this will most likely not work.
Add this to scripts/postflight:
# Get Network Address fields
network=$(networksetup -listallnetworkservices|egrep "(Ethernet|AirPort|Wi-Fi)" |tr -cd [:alnum:][:space:]- |sed 's/^/"/g' |sed 's/$/"/g')
network_array=$(echo "$network"|sed 's/ //g')
for service in ${network_array[@]}; do
service=$(echo "$service" |tr -cd [:alnum:]- |sed 's/[0-9]/ &/g')
if [[ "$service" == "AirPort" || "$service" == "Wi-Fi" ]]; then
WIRELESS=$(networksetup -getmacaddress "$service" |awk '{print $3}')
elif [[ "$service" == "Ethernet" || "$service" == "Ethernet 1" ]]; then
ETHERNET=$(networksetup -getmacaddress "$service" |awk '{print $3}')
elif [[ "$service" == "Ethernet 2" ]]; then
ETHERNET2=$(networksetup -getmacaddress "$service" |awk '{print $3}')
fi
done
also in the report submission area, add these:
-d ethernet="$ETHERNET" \
-d ethernet2="$ETHERNET2" \
-d wireless="$WIRELESS" \
then in the __construct function in app/models/client:
$this->rs['ethernet'] = '';
$this->rs['ethernet2'] = '';
$this->rs['wireless'] = '';
Imagine my surprise that all this works. Not only does it work, but it seems (so far) to take into account myriad differences in hardware configurations. I've tested with everything I have available. iMacs and Mac minis are pretty straight forward. Mac Pros and Xserves report their two ethernet ports, MacBook Airs report AirPort (or Wi-Fi, OS dependent.)
I haven't gotten everything pushed to my github repo just yet. Since I'm new to version control, I'm cleaning up some other modifications before committing. Definitely need to work on my git workflow.
Please, have a look and let me know what you guys think.
- Brian
On Monday, July 2, 2012 1:45:26 AM UTC-4, nbalonso wrote:
it does work on MB air but hadn't had a chance to get one of the new retina MBP. Maybe someone else can confirm this.
As long as the device name contains Ethernet, AirPort or Wi-Fi I don't think it has any problem.
Noel