We often need to gather data either for day to day treatment, records, or for third party solution. In this article we will see how to collect Devices properties from XDM and output those CSV style.

Purpose : Make a script to extract devices’ properties to a CSV file.
You might want to take a look at our convention and our way to work is explained here : /blogs/2014/05/05/xenmobile-device-manager-webservices-for-noobs-introduction-p1

Peace of mind, peace of code

Since it gets us down to some codes I will not put all the code in here, just snapshots of important peace and our dear friend Mr. Geek will explain important stuff to you.

Before being down to explanation we need to have a flow right? We saw in the first articles that the method getAllDevices() returns an array of objects containing : IMEI, SerialNumber, StrongID. Well we need to :

  1. Get all devices
  2. Foreach devices Get devices’ properties
  3. Output that in CSV format

But well devices have different properties… so how are we going to deal with that ? well we could wrote something static where we decide which properties we want to display from my experience you’ll get more use with that, than a script simply extracting everything even non useful data..

How to leverage the resulting script

 
1) Download the script here : Script is here
To make our life easier we have a file called config-xdm.ini you will modify some entry in it as described below :

 
2) Invoke the script :

php –c php.ini-development –f DisplayDevicesPropertiesAsCSV.php

 

 
3) Put the result into a file :php –c php.ini-development –f DisplayDevicesPropertiesAsCSV.php › output.csv


 

Mr. Geek Explanation


 
1) Get properties of devices, GetDeviceInfo() makes the job and it needs a serialNumber, and IMEI as attributes. Perfect that’s what was returned by getAllDevices() in the first place.
see below the extract from the doc :

 

 
Mr. Geek Word : it will return an array with all properties ‘set’ meaning, all existing property for a device in the DB will be returned. As it is done when you double click on a device from the UI and go to properties section.