Skip to main content
Solved

Extension attribute with Network Segment help


AJPinto
Forum|alt.badge.img+26
  • Legendary Contributor
  • 2778 replies

I am trying to make an extension attribute to report which network segment a device is in for reporting to a "search inventory" report. Since you cannot really report on JAMFs network segments in settings in any meaningful way I am trying an extension attribute. Thankfully I only have 3 segments of interest for this specific situation.

We have a number of Mac Mini’s in our datacenter for contractors to remote access. I am trying to provide something easy for support to look at in an inventory report that tells them which computer belongs to which segment when they go to assign a device. I’m wanting it to tell them which vendors subnet the device is in (ie result1) as our support could not remember IP ranges if their live depended on it.

The following is what I was able to come up with however all devices come back with the "Does not fall in to 3 results" result regardless of their IP address. I have not tried to make an EA this complex before and have not really found anything useful so I am sure I missed something simple. Any help or suggestions would be much appreciated.

I have changed information to protect the identity of the individuals involved and to keep my legal team happy.

1#!/bin/sh
2
3
4IPAddress=$(ifconfig | grep "inet " | grep -Fv 127.0.0.1 | awk '{print $2}')
5
6if [[$IPAddress =~ 10.1.[147].*]]; then
7 echo "<result>Result1</result>"
8elif [[$IPAddress =~ 10.1.[246].*]]; then
9 echo "<result>result2</result>"
10elif [[$IPAddress =~ 10.1.[345].*]]; then
11 echo "<result>result3</result>"
12else
13 echo "<result>Does not fall in to 3 results<result>"
14fi

Best answer by sdagley

@AJPinto You need a space after the [[ and before the ]], but that should generate a syntax error, not return the if all else fails result. The other issue is that if you have a VPN connection active you're going to have 2 inet responses in addition to the 127.0.0.1 which your detection logic won't handle.

View original
Did this topic help you find an answer to your question?

2 replies

sdagley
Forum|alt.badge.img+25
  • Jamf Heroes
  • 3564 replies
  • Answer
  • January 13, 2021

@AJPinto You need a space after the [[ and before the ]], but that should generate a syntax error, not return the if all else fails result. The other issue is that if you have a VPN connection active you're going to have 2 inet responses in addition to the 127.0.0.1 which your detection logic won't handle.


AJPinto
Forum|alt.badge.img+26
  • Author
  • Legendary Contributor
  • 2778 replies
  • January 14, 2021

@sdagley I think that got it, thank you very much. I also had to remove the brackets from the 3rd octet in the IP address. I added a grep to exclude our VPN IP as you suggested though this will only be used for reporting on devices in our datacenter, though EA's cannot be limited like that :/.

Incase anyone else needs it here is this final product.

1#!/bin/sh
2
3IPAddress=$(ifconfig | grep "inet " | grep -Fv 127.0.0.1 | grep -Fv 10.127 | awk '{print $2}')
4
5if [[ $IPAddress =~ 111.112.123.* ]]; then
6 echo "<result>Result1</result>"
7elif [[ $IPAddress =~ 111.112.124.* ]]; then
8 echo "<result>Result2</result>"
9elif [[ $IPAddress =~ 111.112.125.* ]]; then
10 echo "<result>Result3</result>"
11else
12 echo "<result>Other catch all result</result>"
13fi

Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings