Listen for measurement create alarm on threshold reached

Product/components used and version/fix level:

Detailed explanation of the problem:

I have a use case where i am Listening for Manage Object and based on Received Json extract deviceId,fragement,alarmText ,Thresholds From
this and Then Listen for Measurement based on deviceId and get the Latest Received Value .
Use that Received value to check whether Value is above Thresholds or Below .If above then create alarm .
I am facing issues as Previous alarm also creating even if i update the alarm Text from Manage Object

Received ManageObject Json:

{
“alarm_text”: “Range_50_25500 Greater than 0.53 na and active less then 0.30”,
“alarm_type”: “Flow”,
“alarm_severity”: {
“name”: “Major”
},
“threshold_value”: “0.30”,
“rule_id”:“5432”
}

Send for Listen for Measurement

‘’’
result = thresoldValue > Recieved Measurement Value
if(result) {

					contextService.runWithinContext(microserviceCredentials, () -> {
						try {

                          
							AlarmRepresentation alarm = new AlarmRepresentation();
							var source = new ManagedObjectRepresentation();
							source.setId(GId.asGId(deviceId));
							alarm.setSource(source);
							alarm.setSeverity(alarmseverity);
							alarm.setType(alarmType+"_"+rule_id);
							alarm.setStatus("ACTIVE");
							alarm.setText(flowText);
							alarm.setDateTime(DateTime.now());
							alarm.setProperty("rule_id", rule_id);
							alarm.setProperty("alarm_type",alarmFlowType);
							alarmApi.create(alarm);
					
		'''			
					My  Problem  is when i am  updating  alarm Text Old  alarm Text  also appeared in  cumulocity alarm ,even  if  i  updated  the Alarm Text

Hi Vikash,

welcome! Alarm behavior can be confusing. From the code you shared it looks like you create a new alarm while an alarm already exists. This is a POST operation:
https://cumulocity.com/api/core/10.17.0/#operation/postAlarmCollectionResource

If an alarm of the same source and type already exists, only the “count” and “time” fields are updated in this case. If you want to change the text (or e.g. severity) of an alarm you have to fetch the existing alarm first and do an update on it using a PUT operation:
https://cumulocity.com/api/core/10.17.0/#operation/putAlarmResource

Best regards,
Harald

looks after handled separate create and update for alarms solve my issues

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.