Nine41 Consulting | Creating an XML File to Report Custom Inventory Information
apple, device management, dep, vpp, systems management, landesk, ivanti, lanrev, absolute, heat, mdm,
37
post-template-default,single,single-post,postid-37,single-format-standard,qode-quick-links-1.0,ajax_fade,page_not_loaded,,columns-3,qode-child-theme-ver-1.0.0,qode-theme-ver-11.0,qode-theme-bridge,wpb-js-composer js-comp-ver-5.1.1,vc_responsive
 

Creating an XML File to Report Custom Inventory Information

Creating an XML File to Report Custom Inventory Information

Have you ever needed to collect an additional piece of information, not collected by LANDESK by default, from one of your managed Macs?  The answer to that question will very likely be yes simply because every business environment is unique.

Often, the additional information that needs to be collected is simply a matter of enabling the LANDESK inventory scanner to pickup a new file type.   These types of changes are easy and can be added by leveraging the Manage Software List tool within the LANDESK console.  For more information on this method, see the LANDESK 9.6 Help file link.

However, if you want to collect the state of an object on the device, it may require a script to be written to query OS X itself.  The response from the OS will then need to be captured  in a format the LANDESK inventory scanner can then pick up and transmit back.

By default, the LANDESK inventory scanner can parse an XML or PLIST file placed in the “/Library/Application Support/LANDesk/CustomData” directory.  As such, we just need to write a script that places the response from the OS query into an XML or PLIST file and save it to the CustomData folder.  So doing will allow you to collect any type of information that may be relevant in your environment

The script below, written by Steve Goodrich for a LANDESK Interchange session, is an example script in which the OS is queried for the S.M.A.R.T. status after which the result is written to an output XML file.

This article will walk through each step of the script to explain what is going on, however, it will not be covering the details of XML and BASH.   I’ve posted some links below to research additional information on XML or BASH.

XML

Bash Scripting

  • http://www.tldp.org/LDP/Bash-Beginners-Guide/html/
  • http://www.tldp.org/LDP/abs/html/
  • http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html

OK, let’s create our script.  The first thing we need to do is open an editor.  On OS X, I prefer to use Xcode.  However there are a number of editors out there, like TextWrangler.  Just choose one that fits your preference.  The first line in the script needs to specify it’ll be using BASH.  As such, write:

[code language=”bash”]
#! bin/bash
[/code]

Now we need to specify the output file variable that’ll be called throughout the script along with it’s associated file path.  Because we want the LANDESK inventory scanner to pick up the information, we’ll write out output file to the CustomData folder and give it a name of SmartHardDriveStatus.xml.  You can name your file whatever makes sense for the information you’re collecting.

[code language=”bash”]
OUTPUT_FILE="/Library/Application Support/LANDesk/CustomData/SmartHardDriveStatus.xml"
[/code]

Next we’ll specify inside the output file, the XML structure we’ll be creating.  The echo command will place the text after the quotes into our XML file.  The carrot “>” before the “$OUTPUT_FILE” is telling the echo command where to write and the “$OUTPUT_FILE” is referring the variable created previously.

[code language=”bash”]echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" > "$OUTPUT_FILE" [/code]

With the output file created and the XML structure specified, we need to create the opening XML tag in which we’ll save the SMART status inside of.

[code language=”bash”]
echo "<SMART_info>" >> "$OUTPUT_FILE"
[/code]

OK, now we’re to the fun part.  We need to query OS X and obtain the status of the hard drive.  This can be accomplished using the diskutil command.  Most likely, the custom information you want to obtain will require a different command to query the OS.  Use the internet to search for the command you need and replace it with what is below.  Just make sure you echo your result and write it to an XML tag.  The example below has the results from the variables DRIVE and STATUS being written to an XML tag named from the DRIVE variable with the STATUS being written as the information inside the XML tag.

[code language=”bash”]
diskutil list  | egrep "^/" | while read drive

do
     
     DRIVE=`basename $drive`
     
     STATUS=`diskutil info $drive | grep SMART | awk ‘{ $1=$2="" ;print $0 }’`
     
     echo "<$DRIVE> $STATUS " >> "$OUTPUT_FILE"
done
[/code]

The final step to the script requires us to close out the first SMART_info tag we created.  It’s a pretty simple command.

[code language=”bash”]
echo "</SMART_info>" >> “$OUTPUT_FILE"
[/code]

That’s it. You can save your script as a .sh file.  Completed, it’ll look similar to what I have below:

[code language=”bash”]
#!/bin/bash

# Create the Output file with the appropriate XML structure so the inventory scanner can read the data

# The output file path

OUTPUT_FILE="/Library/Application Support/LANDesk/CustomData/SmartHardDriveStatus.xml"

# specifying the XML structure and telling to return the string to the output file

echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" > "$OUTPUT_FILE"

# creating the XML tag for the SMART info. Change this to match your custom inventory

echo "<SMART_info>" >> "$OUTPUT_FILE"

# command to list all of the drives, capture the status and insert the status as XML output in the output file

diskutil list | egrep "^/" | while read drive

do
     
     DRIVE=`basename $drive`
     
     STATUS=`diskutil info $drive | grep SMART | awk ‘{ $1=$2="" ;print $0 }’`
           echo "<$DRIVE> $STATUS </$DRIVE>" >> "$OUTPUT_FILE"

done

# close the XML tag for SMART Info

echo "</SMART_info>" >> "$OUTPUT_FILE"
[/code]

Screen Shot 2015-06-29 at 9.45.55 AM

To test it out, modify the properties of the file to make it executable.  To do this, you’ll need to open up Terminal and browse to the path of where the script has been saved.  You’ll then need to run the command:

chmod a+x scriptfilename.sh

Once the executable properties have been given to the file, you can manually run it on your test machine by calling it in terminal.

sudo ./scriptfilename.sh

In my next post I’ll walk through how we can use the pkgbuild command to create a package out of our script, deploying it the Apple-esque way as opposed to the UNIX method of deploying a .sh file.

2 Comments

Post A Comment

ARE YOU READY TO GET STARTED?
Please fill out your information, and a specialist will reach out to discuss our services in more details.
Your Information will never be shared with any third party.
        
Free Training Videos
Register to gain access to all of our free content.
YOUR PHONE
YOUR NAME
YOUR EMAIL
        
Get Started
Provide us your contact information and we will reach out as quickly as possible.
YOUR PHONE
YOUR NAME
YOUR EMAIL
        
Additional Questions?
Provide us your contact information and we will reach out as quickly as possible.
YOUR PHONE
YOUR NAME
YOUR EMAIL
        
Pay by PO?
Provide us your contact information and we will reach out to help you sign up by PO.
YOUR PHONE
YOUR NAME
YOUR EMAIL
Subscribe Now
Subscribing to our site gives you access to our Apple Admin 101 training videos as well as allowing us to notify you of each new blog post we release.
YOUR PHONE
YOUR NAME
YOUR EMAIL
Pay by PO
Send us your contact information and we will reach out to help you sign up by PO.
YOUR PHONE
YOUR NAME
YOUR EMAIL
Additional Questions?
Send us your contact information and your questions and we will reach out as quickly as possible.
YOUR PHONE
YOUR NAME
YOUR EMAIL
YOUR QUESTIONS
Get Started
Provide us your contact information and we will reach out as quickly as possible.
YOUR PHONE
YOUR NAME
YOUR EMAIL
Free Training Videos
Subscribing to our site gives you access to our Apple Admin 101 training videos as well as allowing us to notify you of each new blog post we release.
FIRST NAME
LAST NAME
PHONE
EMAIL
Subscribe Now
Subscribing to our site gives you access to our Apple Admin 101 training videos as well as allowing us to notify you of each new blog post we release.
FIRST NAME
LAST NAME
PHONE
EMAIL