I would like to provide the mac address of a computer and using the CLI get both the computer name and its current IP address. The purpose for this is to remotely re-image a computer but have a script contact the BigFix database and automatically name and IP the system post imaging. Is this possible using the command line interface and if so how would I write this?
So you want to query the BigFix database for the most recent computer entry with the same MAC address of the current computer in order to find what its name and static IP should be?
This is possible with the RESTAPI to use session relevance to do this. Start with the presentation debugger or session relevance tester or Webreports QnA to actually write the session relevance to return the correct results. Once you have this, you can do it on the command line either using the RESTAPI or there is a command line tool from IBM as well.
unique values of (item 0 of it & ", " & item 1 of it) of ((name of it) of computer of it, values of it) of results of bes properties whose(name of it as lowercase starts with "mac addresses")
This could be filtered to look for a specific MAC address only so that it would not return a ton of results.
One issue I see is that you may have multiple IPs and multiple MAC Addresses on the same computer.
You will also have issues if the computer names are not globally unique and there are multiple entries for the same computer name. In those cases you might take the most recent entry for that computer name, but that won’t work if they are not unique.
I definitely like this concept of pulling historical data out of BigFix using Session Relevance to automatically configure the computer being imaged.
These systems are all desktops so in theory they should only have one MAC address. I suppose I could also use the serial number of the computer to determine its match in the database. All computers will be uniquely named so that shouldn’t be an issue.
We used to use Altiris so querying the database was a bit easier just using a simple SQL query. I will look into using the Web reports QnA to debug the syntax. I also noticed that when using the command line tool it does not like quotations marks and that you need to escape them. Is there any documentation about the syntax that is supposed to be used? All I could find were simple examples when I googled CLI and BigFix, should I instead be looking at the RestAPI?
escaping quotes is a pain and you have to do it differently depending on what you are using. %22 should work in most cases, unless you need quotes inside quotes inside quotes… the more layers you go down the rabbit hole, the more confusing it gets.
Also, as far as the single MAC address goes… that will generally be the case, but if you have a 13in MacBook Pro with a thunderbolt to ethernet adapter sometimes, and a thunderbolt display others, and perhaps a USB to ethernet adapter in the mix… that is 4 NICs, 4 MAC addresses.
I realize this isn’t typical, but having many NICs in the mix is more common for Apple Laptops. ( Which may or may not run Windows )
If you have an iMac with a Thunderbolt display, that is 2 NICs.
How would you filter based on a specific mac address and how do I return the computer name and ip address? This returns the computer name and mac address. It worked great by the way but did return ALL of them.
I’m not certain how to get the IP Addresses offhand, but it is possible. I’d have to look into where to get that from.
This isn’t the best option, but this would filter based upon MAC address:
unique values of (item 0 of it & ", " & item 1 of it) of ((name of it) of computer of it, values of it) whose(item 1 of it = "MAC-ADDRESS") of results of bes properties whose(name of it as lowercase starts with "mac addresses")
It seems like you want to find a specific computer object based upon MAC Address and then get the name and IP address of that object. This is a different type of query. It needs written a different way for that to work well.
I can’t write it at the moment, but this is the pseudo code:
(name of it, IP_ADDRESS of it) of bes computers whose("SPECIFIC-MAC-ADDRESS" = MAC_ADDRESS of it)
This will need to use the property inspectors, but I need to figure out the formatting.
unique values of (values of results from (bes properties whose( exists (it as lowercase as trimmed string) whose(it starts with "mac addresses" OR it contains "ip address" OR it contains "computer name") of names of it )) of it) of bes computers whose(exists values whose("_MAC_ADDRESS_" as lowercase = it as lowercase) of results from (bes properties whose(name of it as lowercase starts with "mac addresses")) of it)
This doesn’t look like anything wrong with the query itself. It looks like there are some unicode characters in there that don’t belong. Try copy it, pasting it into notepad or the fixlet debugger or similar. Then replace the quotes, copy it, then run it.
The unicode characters were indeed the culprit. Once I tried it again after pasting into notepad and replacing the quotes with %22 it worked. One more question. The results spit out correctly (obfuscated below) except I am not sure why there is a 0 for the first answer string.
I tried it with a different PC and it did not return the 0. I then tried using serial number instead using the following query on another PC:
iem get query --relevance “unique values of (values of results from (bes properties whose (exists (it as lowercase as trimmed string) whose (it contains %22ip address%22 OR it contains %22computer name%22) of names of it )) of it) of bes computers whose(exists values whose (%2275GVK02%22 as lowercase = it as lowercase) of results from (bes properties whose(name of it as lowercase = %22serial number%22)) of it)”
The results have a 2 in the middle. I even changed the parameters a bit and used = instead of starts with for the serial number name but still it returned the same result.
I am setting up a vbscript to read the results of the output.xml file from the query above. I might be able to just include what results I am looking for using instr but it is a mystery so far as to why seemingly random data is getting returned in this query.
Here is a way to filter them out, though ideally they wouldn’t show up in the first place:
unique values whose(not exists (it as integer)) of (values of results from (bes properties whose( exists (it as lowercase as trimmed string) whose(it starts with "mac addresses" OR it contains "ip address" OR it contains "computer name") of names of it )) of it) of bes computers whose(exists values whose("98-90-96-d8-0a-dc" as lowercase = it as lowercase) of results from (bes properties whose(name of it as lowercase starts with "mac addresses")) of it)
I changed it from it contains to it = for the ip address and computer name parts and it works correctly now. I am guessing some computers had a second property that contained the words “ip address”. Since I only need the “real” IP address I can ignore the other result.
iem get query --relevance “unique values of (values of results from (bes properties whose (exists (it as lowercase as trimmed string) whose (it = %22ip address%22 OR it = %22computer name%22) of names of it )) of it) of bes computers whose(exists values whose (%22DVS9Q22%22 as lowercase = it as lowercase) of results from (bes properties whose(name of it as lowercase = %22serial number%22)) of it)”
originally I was being more broad with the properties in case they had many OS specific properties, but this doesn’t seem to be needed for IP address, and it may not be needed for others either.