> For the complete documentation index, see [llms.txt](https://docs.mikopbx.com/mikopbx/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.mikopbx.com/mikopbx/faq/setup/monitoring-providers-on-mikopbx.md).

# Мониторинг провайдеров на MikoPBX

При работе с поставщиками услуг связи периодически могут возникать проблемы. К примеру сервер поставщика не отвечает / не доступен. В рамках данной статьи будет предложен механизм оповещения на email системного администратора.

{% hint style="success" %}
Для работы оповещений потребуется настроить SMTP клиент. См. инструкции в разделе «[Почта и уведомления](broken://pages/tqyJLzMpdFJ2KU2vrQld)»
{% endhint %}

1. Создайте новое «[Приложение диалплан](/mikopbx/manual/modules/dialplan-applications.md)[а](/mikopbx/manual/modules/dialplan-applications.md)».

<figure><img src="https://3704471835-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPK4TuzRBnP7rt8htho-887967055%2Fuploads%2FLQOODvfJhvXO7R9KSQsr%2FnewDialplanAppliccation.png?alt=media&amp;token=07e83a26-4ce1-459f-92c7-7f8bae78b749" alt=""><figcaption><p>Создание нового приложения диалплана</p></figcaption></figure>

2. Укажите название - например, Provider Monitoring, короткий номер для приложения, к примеру 99, а так жу выберите «**Тип кода**» - «**PHP AGI Скрипт**»

<figure><img src="https://3704471835-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPK4TuzRBnP7rt8htho-887967055%2Fuploads%2Fgit-blob-795bf7bed6ef267adfac984164f5f87aa32e1243%2Fnew1%20(4).png?alt=media" alt=""><figcaption><p>Параметры диалплана</p></figcaption></figure>

3. Перейдите во вкладку "Программный код":

<figure><img src="https://3704471835-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPK4TuzRBnP7rt8htho-887967055%2Fuploads%2FexPUN05Ir0WYTLO3l8gV%2Fnew2.png?alt=media&amp;token=cc6293fc-7955-49e0-a203-522e30c92ec4" alt=""><figcaption><p>Раздел "Программный код"</p></figcaption></figure>

4. Вставьте код:

```php
<?php
use MikoPBX\Common\Models\PbxSettings;
use MikoPBX\Common\Models\LanInterfaces;
use MikoPBX\Core\System\Notifications;
use MikoPBX\PBXCoreREST\Lib\SIPStackProcessor;

require_once 'Globals.php';

$result = SIPStackProcessor::callBack(['action' => 'getRegistry']);
$adminMail = null;
$localIP = '';
$message = '';
foreach ($result->data as $provider) {
    if ($provider['state'] !== 'OFF' && $provider['state'] !== 'REGISTERED') {
        if ($adminMail === null) {
            $adminMail = PbxSettings::getValueByKey('SystemNotificationsEmail');
            $interfaces = LanInterfaces::find("disabled='0'");
            foreach ($interfaces as $interface) {
                if (!empty($interface->ipaddr)) {
                    $localIP = $interface->ipaddr;
                    break;
                }
            }
        }
        $message .= "Provider state: {$provider['state']}<br>" . "Url (local): ']} <br><br>";
    }
}

if (!empty($message) && !empty($adminMail)) {
    $notify = new Notifications();
    try {
        $notify->sendMail($adminMail, 'Provider invalid state...', $message);
    } catch (\Throwable $e) {
    }
}
```

5. Сохраните изменения и скопируйте идентификатор приложения из адресной строки браузера, он имеет вид «**DIALPLAN-APP-9С060381**»

<figure><img src="https://3704471835-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPK4TuzRBnP7rt8htho-887967055%2Fuploads%2F0mlDMS93NEAbUiM4bDnA%2FdialplanCode.png?alt=media&amp;token=ae08cb1e-421a-4fcf-bfd1-387e805d0a5d" alt=""><figcaption><p>Идентификатор приложения диалплана</p></figcaption></figure>

6. Перейдите в раздел **Система** → **Кастомизация системных файлов**, откройте для редактирования файл **/var/spool/cron/crontabs/root**

<figure><img src="https://3704471835-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPK4TuzRBnP7rt8htho-887967055%2Fuploads%2FnCvb9BRfy2tjKOWLq9ef%2FcrontabsRootFile.png?alt=media&amp;token=a95c152c-16c7-4fb2-b4de-3d8027ff39a5" alt=""><figcaption><p>Необходимый файл для редактирования</p></figcaption></figure>

7. Выберите режим **«Добавлять в конец файла»**, внизу в черное поле для редактирования вставьте следующий код:

{% hint style="info" %}
Скорректируйте имя файла согласно вашему идентификатору приложения «**DIALPLAN-APP-9С060381**»
{% endhint %}

```
*/5 * * * * /usr/bin/php -f /var/lib/asterisk/agi-bin/DIALPLAN-APP-9С060381.php start > /dev/null 2> /dev/null 
```

Сохраните изменения.

<figure><img src="https://3704471835-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPK4TuzRBnP7rt8htho-887967055%2Fuploads%2Fu52dGNz9WIwhHj6k7oUP%2FcodeInCrontabs.png?alt=media&amp;token=c5236bb8-7e1b-428b-942b-50a0b1bb7ed6" alt=""><figcaption></figcaption></figure>

Готово!


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.mikopbx.com/mikopbx/faq/setup/monitoring-providers-on-mikopbx.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
