> For the complete documentation index, see [llms.txt](https://docs.cennso.com/components/tposs/6.16/llms.txt) (all documentation: [llms.txt](https://docs.cennso.com/llms.txt)). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cennso.com/components/tposs/6.16/configuration/hooks.md).

# Hooks configuration

TPOSS supports a set of events that you can enable or disable. If an event is enabled, you must provide a pre-configured endpoint to TPOSS for sending events.

The following events are supported:

| Event | Description |
| --- | --- |
| `hooks.balance.volume.threshold` | Event is triggered on a volume threshold by the configurable level of consumption |
| `hooks.mccmnc.changed` | Event is triggered on the change of Mobile Country Code (MCC) and Mobile Network Code (MNC) |
| `hooks.visited_country.changed` | Event is triggered on the change of a visited country |
| `hooks.network_attachment.first` | Event is triggered on the first attachment to the network |
| `hooks.charging_rules.changed` | Event is triggered on the change of subscriber charging rules |

For more information, see the [TPOSS chart configuration](https://docs.cennso.com/components/tposs/6.16/installation/configuration.md#hooks-configuration) document.

## Events

All the hooks described above are triggered based on a different event. The usual reaction on any event is an HTTP call to the pre-configured HTTP endpoint. The endpoint is specified by the **hooks.{EVENT_NAME}.url** configuration parameter where event name is one of the following:

- [balance_volume_threshold](#balance-threshold-event)
- [mccmnc_changed](#mccmnc-change-event)
- [visited_country_changed](#visited-country-change-event)
- [network_attachment.first](#first-network-attachment-event)
- [charging_rules_changed](#charging-rules-change-event)

If the outgoing HTTP request failed, TPOSS may try again to send the request. You can control this behaviour using the **hooks.{EVENT_NAME}.attempts** configuration parameter of each hook. To avoid the storm of requests, the **hooks.{EVENT_NAME}.delay** configuration option exist. It defines the delay between retries to send HTTP requests in milliseconds.

You can enable or disable any hook with the **hooks.{EVENT_NAME}.enabled** configuration parameter by setting it to `true` or `false`.

### Balance threshold event

The `balance threshold` event is triggered when a subscriber's balance reached a certain level of threshold. The threshold level is determined by the following configuration parameter:

```yaml
hooks:
  balance_volume_threshold:
    # Level of used balance when a notification is sent. It takes the value between `0.0` and `1.0`.
    # Multiple threshold values separated by a comma are supported.
    level: "0.8"
```

The value of the **level** parameter is a number between `0.0` and `1.0` which represents the percentage of used balance when the event is triggered.

The content of the outgoing HTTP notification is a follows:

```json
{
  "volumeThreshold":80.0,
  "usedOctets":800,
  "totalOctets":1000,
  "event":"tposs/change/balance/updated",
  "date":"2017-03-14T10:04:25",
  "balanceId":"a7bc0e7c-be04-4140-8008-c6ab2ef31dee"
}
```

### MCC/MNC change event

The `MCC/MNC change` event is triggered when TPOSS catches an update of subscriber's MCC or MNC when handling RADIUS Accounting requests. TPOSS checks the value of the `3GPP-SGSN-MCC-MNC` RADIUS AVP when handling each RADIUS Accounting-Request, and compares it with the MCC/MNC in the current network sessions. If they are different, TPOSS sends a notification. If a TPOSS instance is launched with Diameter, a Gy-ASR request is sent towards TDF to re-attach a service session.

The content of the outgoing HTTP notification is as follows:

```json
{
  "event": "tposs/location/mccmnc/changed",
  "subscriberId": "112233@int.str.carisp.net",
  "date": "2017-03-10T09:22:00Z",
  "currentMCCMNC": "26201",
  "previousMCCMNC": "26203"
}
```

### Visited country change event

The `visited country change` event is similar to the `MCC/MNC change event`. It is also triggered when TPOSS catches an update of subscriber's MCC/MNC when handling RADIUS Accounting Requests.

The content of the outgoing HTTP notification is as follows:

```json
{
  "event": "tposs/location/visitedCountry/changed",
  "subscriberId": "112233@int.str.carisp.net",
  "date": "2017-03-10T09:22:00Z",
  "currentCountry": "DE",
  "previousCountry": "FR"
}
```

### First network attachment event

The `first network attachment` event is triggered when TPOSS receives RADIUS Access-Request and the IMSI from the request is attached for the first time.

The content of the outgoing HTTP notification is as follows:

```json
{
  "event": "tposs/network/attachment/first",
  "imsi": "310170845466094",
  "imeisv": "3520990017614887",
  "imei": "352099001761481",
  "sgsnMCCMNC": "26201",
  "date": "2017-03-10T09:22:00Z"
}
```

All fields in the outgoing HTTP notification are mandatory, except for `imeisv` and `imei`. If the network session was created without an IMEISV (based on a RADIUS Access-Request or Accounting-Request without the `3GPP-IMEISV` AVP), the values of these attributes are skipped in the notification payload.

### Charging rules change event

The `charging rules change` event is triggered when there is a change of a service session for the given subscriber.

By default, TPOSS sends a notification to all subscribers. The content of the outgoing HTTP notification is as follows:

```json
{
  "event": "tposs/charging_rules/changed",
  "subscriber_name": "112233@example.net",
  "date": "2017-03-10T09:22:00Z",
  "imsi": "262019876543210",
  "currentChargingRules": ["Online"],
  "previousChargingRules": ["Portal"],
  "id": "Session-Id",
  "success": true
}
```

TPOSS may also send a notification only for subscribers with the specified mobile country codes. To achieve this, use this configuration option:

```yaml
hooks:
  charging_rules_changed:
    # List of Mobile Country Codes separated by comma for which the `Mobile Country Code Change` event is triggered
    mcc_whitelist: "262"
```
