# Executing Actions

### Executing actions

#### openAlarm(subEntityIdentifier, alarmName, ruleName, severity, priority, alarmDescription, extraInfo)

> **Deprecated:** Use `alarm` object functions instead.

Opens an alarm for the selected entity.

**Kind**: global function  
**Returns**: void

| Param            | Type    | Description               |
| ---------------- |---------| --------------------------|
| subEntityIdentifier | String  | You can open an alarm on device, subscription or subscriber identifier. With _subEntityIdentifier_ you define selected identifier. If is undefined it will open on _provision.administration.identifier_ identifier. |
| alarmName        | String  | Name that you want to see in opened alarm |
| ruleName         | String  | Name of rule that produce opening of alarm. |
| severity         | String  | Alarm severity. Values can be INFORMATIVE, URGENT or CRITICAL. |
| priority         | String  | Alarm priority. Values can be LOW, MEDIUM or HIGH. |
| alarmDescription | String  | Alarm description. |
| extraInfo        | String  | Extra information. |

Examples of use
This example open alarm _apnMismatch_ to subscription.

```javascript
openAlarm('subscription_battery_id', 'apnMismatch' , 'apnMismatchRule', 'URGENT', 'MEDIUM', 'APN mismatch with provisioned value')
```

And this example open alarm _highTemperature_ to device.

```javascript
openAlarm(undefined, 'highTemperature' , 'highTemperatureRule', 'URGENT', 'MEDIUM', 'Device temperature is high')
```

#### closeAlarmByRuleName(entityIdDatastream, ruleName)

> **Deprecated:** Use `alarm` object functions instead.
 
Closes an alarm for the selected entity using rule name.

**Kind**: global function  
**Returns**: void

| Param            | Type    | Description               |
| ---------------- |---------| --------------------------|
| entityIdDatastream | String  | You can close an alarm on device, subscription or subscriber identifier. With _entityIdDatastream_ you define selected identifier. If is undefined it will close on _provision.administration.identifier_ identifier. |
| ruleName         | String  | Name of rule that open alarm. |

Example of use:

```javascript
closeAlarmByRuleName(undefined, 'highTemperatureRule')
```

#### closeAlarmByAlarmName(entityIdDatastream, alarmName)

> **Deprecated:** Use `alarm` object functions instead.

Closes an alarm for the selected entity using alarm name.

**Kind**: global function  
**Returns**: void

| Param            | Type    | Description               |
| ---------------- |---------| --------------------------|
| entityIdDatastream | String  | You can close an alarm on device, subscription or subscriber identifier. With _entityIdDatastream_ you define selected identifier. If is undefined it will close on _provision.administration.identifier_ identifier. |
| alarmName        | String  | Name of alarm to close. |

Example of use:

```javascript
closeAlarmByAlarmName(undefined, 'alarm name')
```

#### addEmailNotification(recipients, notificationName, notificationBody, ruleName, mailParameters)

> **Deprecated:** Use `notification` object functions instead.

Sends email notification to defined recipients.

**Kind**: global function  
**Returns**: void

| Param            | Type    | Description               |
| ---------------- |---------| --------------------------|
| recipients       | Array   | Array of recipients to send email. This param has same format as defined in easy mode. |
| notificationName | String  | Name of notification that will be received in subject field. |
| notificationBody | String  | Mustache template with email's body |
| ruleName         | String  | Name of rule that launch email request. |
| mailParameters   | Object  | Json object with key-value pairs that will be replaces in mustache evaluation. |

Example of use:

The example send email to _example@recipient.es_ with _highTemperature_ notification.

```javascript
parameters = {};
parameters['deviceIdentifier'] = getDatastreamFromEntity('device.identifier')._current.value;
parameters['deviceTemperature'] = getDatastreamFromEntity('device.temperature')._current.value;
addEmailNotification(['example@recipient.es'], 'highTemperature', 'Received high temperature from {{deviceIdentifier}} with value {{deviceTemperature}}', 'highTemperatureRule', parameters);
```

#### addTrapNotification(recipients, variables, notificationName, trapOID, enterpriseOID, ruleName)

> **Deprecated:** Use `notification` object functions instead.

Sends trap notification to defined recipients.

**Kind**: global function  
**Returns**: void

| Param            | Type    | Description               |
| ---------------- |---------| --------------------------|
| recipients       | Array   | Array of recipients (`<ip>:<port>`) to send trap. This param has same format as defined in easy mode. |
| variables        | Object  | Map of variables. Each pair defines OID variable and sent value for this OID. |
| notificationName | String  | Name of notification |
| trapOID          | String  | OID of trap |
| enterpriseOID    | String  | OID of enterprise |
| ruleName         | String  | Name of rule |

Example of use:

The example send trap to _25.35.98.5:8585_ with _highTemperature_ notification.

```javascript
var recipients = ['25.35.98.5:8585'];
var trapVariables = {
  '1.1.1': entity['provision.administration.organization']._value._current.value,
  '1.1.2': entity['provision.administration.channel']._value._current.value,
  '1.1.3': entity['provision.administration.identifier']._value._current.value,
  '1.1.4': entity['device.temperature']._value._current.value,
  '1.1.5': entity['device.temperature']._value._previous.value,
  '1.1.6': Date.now()
};         

addTrapNotification(recipients, trapVariables, 'highTemperature', '1.100.1', '1.2.7.3.1.2.25841', 'highTemperatureRule');
```

#### sendHttp(httpJson)

> **Deprecated:** Use `notification` object functions instead.

Sends http notification to defined recipients.

**Kind**: global function  
**Returns**: void

| Param            | Type    | Description               |
| ---------------- |---------| --------------------------|
| httpJson         | Object  | Same json that easy mode. |

Example of use:

The example send http request to _http://myService/request_ with _highTemperature_ notification.

```javascript
httpJson = {
  'url': 'http://myService/request',
  'method' : 'POST',
  'headers': {
    'Content-type': 'application/json'
  },
  'queryParams' : {
    'deviceId' : entity['provision.device.identifier']._value._current.value
  },
  'body' : 'New alert received by high temperature received. Current value: ' + entity['device.temperature']._value._current.value
};
sendHttp(httpJson);
```

#### executeOperation(subEntityIdentifier, operationType, operationTimeout, jobUser, retries, ackTimeout, retriesDelay, stopValue, stopMode, parameters, callback)

> **Deprecated:** Use `operation` object functions instead.

Executes selected operation to received identifier.

**Kind**: global function  
**Returns**: void

| Param            | Type    | Description               |
| ---------------- |---------| --------------------------|
| subEntityIdentifier | String  | You can execute operation on device, subscription or subscriber identifier. With _subEntityIdentifier_ you define selected identifier. If is undefined it will open on _provision.administration.identifier_ identifier. |
| operationType    | String  | Operation Identifier. You can get this values getting operation catalog. **Mandatory field**. The rule will be created, but the operation will not. |
| operationTimeout | Number  | Operation timeout in milliseconds. **Default**: 60000 milliseconds |
| jobUser          | String  | User apiKey that launch this operation. **Mandatory field**. The rule will be created, but the operation will not. |
| retries          | Number  | Operation retries number. **Default**: 0. |
| ackTimeout       | Number  | ACK timeout in milliseconds. **Default**: null. |
| retriesDelay     | Number  | Delay in seconds between retries. **Default**: null. |
| stopValue        | Number  | Stop value, this value depends of stop mode selected. **Default**: Operation timeout + 5000. |
| stopMode         | String  | Stop mode. **Default**: delayed. Possible values: **date** (stop value is a date in YYYY-MM-DDThh:mm:ssTZD format) and **delayed** (stop value is a time defined in milliseconds). |
| parameters       | Object  | This value is a json with accepted value in selected operation. You can see parameters getting operation catalog. |
| callback         | String  | URI where the result of the operation execution is received. |

**NOTE**: The Job of the operation will be created with an active status by default.

Example of use:

The example execute _REFRESH\_PRESENCE_ operation to received device.

```javascript
apiKey = getVariableValue(parameters['apiKey']);
parameters = {
  'active': false
};
executeOperation(entity['provision.administration.identifier']._value._current.value, 'REFRESH_PRESENCE', 20000, apiKey, 0, null, null, 25000, 'delayed', parameters, callback);
```

#### cancelDelay(ruleName)

> **Deprecated:** Use `utils` object functions instead.

Cancels active delayed action produced by another rule activation.

**Kind**: global function  
**Returns**: void

| Param            | Type    | Description               |
| ---------------- |---------| --------------------------|
| ruleName         | String  | Name of rule that produce delayed actions. |

Example of use:

The example cancel delay of 'highTemperatureRule' rule.

```javascript
cancelDelay('highTemperatureRule');
```
