# Set up on-call calls to your iPhone

Pair your iPhone with the console, put it in an on-call target, and point an uptime check or an App Monitoring rule at the target, so an alert rings your phone like a call.

An alert can call your iPhone: the phone shows the system call screen, rings through silent mode,
and reads the alert aloud when you answer. No phone number is involved. How a page rings and
escalates is in [How on-call works](how-on-call-works.md).

## Prerequisites

- An iPhone with iOS 17 or later and the **On-call** app installed.
- Permission for `monitoring:CreateOnCallPairing`, `monitoring:CreateOnCallTarget` and
  `monitoring:UpdateCheck` on `rn:ews::<organization id>:monitoring:*`, and
  `monitoring:DescribeOnCallPages` to open **On-call** in the console (and
  `monitoring:DescribeOnCallDevices` for its **Devices** tab).
- To acknowledge from the phone, your own permissions must allow
  `monitoring:AcknowledgeOnCallPage`: the phone acts as you, and never with more than you have.

## Pair the phone

**Console**
1. Open **Monitoring**, then **On-call**, then **Devices**, and choose **Pair device**.
2. On the iPhone, open **On-call** and scan the QR code, or scan it with the Camera app. The code
   works once, for ten minutes.
3. Allow notifications when the app asks. The dialog in the console closes when the phone is
   paired.

**CLI**
```sh
dcloud monitoring oncall-pairings create
```

The answer's `qrPayload` is what the QR code encodes; show it as a QR code to the phone, for
example with `qrencode -t ansiutf8`.

**API**
```sh
curl -X POST Deutsche Cloud Console/monitoring/api/oncall/pairings \
  -H "Authorization: EWS-ACCESS-KEY $KEY_ID:$SECRET"
```

Pairing gives the phone an access key of yours, named "On-call device: _name_" in your access keys.
It can read targets and pages, acknowledge, resolve and escalate pages, and change or unpair its own
device, nothing else. Deleting the key unpairs the phone.

## Create a target

A target is who to ring. One step with one device rings one phone; one step with several devices
rings them together; several steps escalate: the next step rings when nobody acknowledged within the
step's wait.

**Console**
1. In **On-call**, open **Targets** and choose **Create target**.
2. For **Name**, enter Primary.
3. In step 1, choose your phone. To escalate, add a step with another phone, and set the first
   step's wait (the default is 5 minutes).
4. Choose **Create target**.

**CLI**
```sh
dcloud monitoring oncall-targets create --name Primary \
  --steps '{"deviceIds":["<device id>"],"waitMinutes":5}' \
  --steps '{"deviceIds":["<second device id>"]}'
```

**API**
```sh
curl -X POST Deutsche Cloud Console/monitoring/api/oncall/targets \
  -H "Authorization: EWS-ACCESS-KEY $KEY_ID:$SECRET" -H 'Content-Type: application/json' \
  -d '{"name":"Primary","steps":[{"deviceIds":["<device id>"],"waitMinutes":5},{"deviceIds":["<second device id>"]}]}'
```

## Point an alert at the target

- **Uptime check**: in the check's form, choose the target under **On-call target**, or
  `dcloud monitoring checks update <check id> --oncall-target-id <target id>`. A DOWN rings the
  target; UP again resolves the page.
- **App Monitoring alert rule**: in the rule's actions, choose **On-call target**, or add the
  action `{"kind": "oncall", "targetId": "<target id>"}`.

## Test it

In **Devices**, choose **Test call** on your phone (`dcloud monitoring oncall-devices test <device id>`).
The phone rings; answer and choose **Acknowledge**. **Pages** shows the test page and what Apple
answered for each push.

## Related

- [How on-call works](how-on-call-works.md)
- [Create an uptime check](create-an-uptime-check.md)
