How can I do to include devices in my smart rules with Apama EPL?

Hello everyone,

I’m creating an Apama EPL code to add new devices to existing smart rules, because I have a lot of smart rules and the manual process is very time-consuming.

I can get managed objects from my smart rules and the only field that I checked and that references devices is ‘enabledSources’, however, when I include the device ID in this property, it shows in the ‘info’ tab that the device is active, but the smart rule doesn’t work for him.

How can I do to include devices in my smart rules with Apama EPL?

Thank you in advance

Note:
In general “manipulating” these internal, not documented structures like the MO for a SmartRule is not really a supported use case.

Having said that your approach seems to be correct. Two ideas:

  • Redploy the SmartRule after you changed the MO (this is also what the UI does).
  • If you have a device hierarchy make sure that you really use the ID of the device that also generates the data and not e.g. for the parent device

Hi Tobias,

Thank you so much for your help, apparently this can work, but how can I redeploy my smart rule via Apama?

The easiest way would be that instead of changing the MO via inventory API you change it via the API of the SmartRule microservice. Then you are doing technically the same as the UI does.
As already said these are not documented APIs but you could just open the developer tools in the browser and see how the call is being made from the UI.

Hi Tobias,

Thanks for your help, after some time testing how to implement a device in Smart Rule and reactivate it. Follow the example below the process.

action UpdateSmartRule(ManagedObject smartRule, string idFolder) {
		
		dictionary<string, string> header := {
			"Content-Type": "application/json;charset=UTF-8",	
			"Accept": "application/json, text/plain, */*"
		};				
		
		GenericRequest putRule := new GenericRequest;
		putRule.method := "PUT";
		putRule.path := "/service/smartrule/managedObjects/" + idFolder + "/smartrules/" + smartRule.id;
		putRule.headers := header;
		putRule.body := {"enabled": true};
		
		send putRule to GenericRequest.CHANNEL;	
	}

Note: The only way to send a PUT method that I found, without exception and minimum body, is with the ‘enabled’ property. Because, when I update my MO, the service route is updated as well (same PUT route)