How to trigger a script when a device is moved into a folder

Hello,

We would like to run an external script (could be a powershell script) when a device appears in a specific device group in MobiControl (potentially from provisioning a new device). The script needs to generate some files that will eventually be uploaded to the device using file sync rules. The script requires some details from device which we can use the REST API to obtain. Is there a way to coordinate this using Signal and Webhooks? If not, would there be another way for an external system to be notified of a device joining a device group or alternatively, a new device joining the system?

Thanks!

a year ago
SOTI MobiControl
ANSWERS
RC
Raymond Chan Diamond Contributor
a year ago

What are the version and build numbers of your MobiControl server?  Is it an on-premises or cloud implementation?

Is the script to be run on the same sever hosting your MobiControl server or on a different  host server instance?

AS
Andy Shutler
a year ago

Hi Raymond, 

The MobiControl server is 2024.1.0.1052 and it is an on-premise implementation. We want to run the script on the same server within powershell.

Thanks

You can use file sync rule (pre- or post- install script) or you can use a package (or task profile) containing those scripts assigned to only the relevant folders.

AS
Andy Shutler
a year ago

Hi Rafael,

Thanks for this, I will take a look and see if a pre- or post- script will work.

Ehm, if i understood your explanation correct, you don't need to generate files on the device but on server side?

Then my approach is not useable.

ZC
Zafer Cigdem
a year ago

Hi Andy,

is your request only available for some specifics devices moved to a folder or all devices that would be moved? can you please share overall use case for your needs? As what you can do also, you can tag related devices on the target group or destination group by using Custom data. And based on the custom data you can trigger some actions depending on the devices OS.

is it only Android devices or do you have any other OS for your need, I'll advice regarding your reply with my best. Thank you

Zafer

AS
Andy Shutler
a year ago

Hi Zafer,

This is for Android devices only.

The overall use case is as follows:

1) Android devices appear in a device group folder (either by manually placing or by add device policy)

2) A script needs to be run (could be a powershell script on the host Windows server) that will generate some configuration files that are required for the new device. We need to know the device IMEI so that we can generate the configuration files under a folder with that name (IMEI).

3) A file sync rule has been pre-created to upload the generated configuration files to all the devices in that device group, but specific to each device (within the IMEI named folders identifying which folders go to which devices).

Currently, we generate the configuration files by running a script that utilizes the REST API to get all devices in the specific device group, generated all the configuration files and place them in the associate IMEI named folders. This works, however, we would like it to be more dynamic in that each device has its configuration files generated when it appears in the system.

I hope this makes sense.

Cheers

Andy

ZC
Zafer Cigdem
a year ago

Hi Andy,

For the devices' IMEI information, you can either use get devices API call, below one should help

Or you can use Android JavaScript using as following to get the imei information and you can save this information to custom data that may provide flexibility on MobiControl Webconsole to assign some profile/policy/rule using the custom data as a filter for an automated process; such as using the custom data filter on your FileSync Policy/rule (source: Namespace: cellular | Android Agent JavaScript (soti.net)

mobicontrol.cellular.imei

example: 

mobicontrol.log.info('The device\'s IMEI is ' + mobicontrol.cellular.imei);

I hope this helps. 

Zafer

To add here, i would recommend to use mobicontrol.cellular.getImei(0) (IMEI1) or mobicontrol.cellular.getImei(1) (IMEI2) depending on which one should be used, otherwise you have a 50:50 if Simcard is inserted into the wrong slot when troubleshooting and so on.

And if the issue is as you describe here, i see only 2 possibilitys:

  1. Possibiliy: As Zafer mentioned, use API calls (you need to do this on regular base then) to get the relevant IMEI's, check if a relevant folder exists and if not, create the files.
  2. Possibility: Get all your IMEI1 before and create all of the folders and files before the devices are rolled out and then use the fileync rules. But to be honest I'm not sure if something like %IMEI% is working in the filesync rules (i don't think so but you can try).

I don't know what kind of files are being created here but can't you create those via javascript maybe instead? Then you could do that directly in a one-time script.

ZC
Zafer Cigdem
a year ago

I agree with Rafael,

it would be better to check use related sim-slots if you may have multi sim-card available devices. And checking the folder and creating it when required is a good approach as well.

You can do this either from File-Sync Rule/Policy side as a post/pre script or any part by using JS as well. Example would be as following:

var folderPath = '/sdcard/Download/Zafer2';

 

checkFolder();

function checkFolder() {

var foldercheck = new mobicontrol.io.File(folderPath);

if (foldercheck.exists) {

mobicontrol.log.info('Folder exists');

 

}

else {

mobicontrol.log.info('Folder does not exist.')

newFolder();

};

}

newFolder();

function newFolder() {

new mobicontrol.io.File(folderPath).createDirectory();

}

 

 

Zafer

A
AMMOD@SOTI
a year ago

Hi Andy Shutler

Thanks for posting on SOTI Pulse, Thanks Rafael,Zafer and Raymond for responding to the post, your expertise and willingness to help are greatly appreciated!

Have you had an opportunity to test the suggested solutions by Raymond ,Zafer and Rafael, and has it successfully addressed your query?
If yes please do mark it as a solution

If not, or If you have any additional questions or concerns, please don't hesitate to reach out. We're dedicated to providing assistance and support.