When working with telecom service providers, issues may occasionally arise. For example, the provider's server might become unresponsive or unavailable. This article provides a mechanism for notifying the system administrator via email.
To enable notifications, you will need to configure the SMTP client. See instructions in the section "Mail and Notifications".
Create a new "Dialplan Application".
Enter a name (e.g., Blacklist), a short number for the application (e.g., 99), and select "Code Type" - "PHP AGI Script".
Go to the "Program Code" tab:
Insert the following code:
<?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) {
}
}
Save the changes and copy the dialplan application identifier from the browser's address bar. It will look like "DIALPLAN-APP-CF967EE0".
Go to System → Customizing System Files and open the file /var/spool/cron/crontabs/root for editing.
Select the mode "Append to the end of the file", and in the black editing field at the bottom, insert the following code:
Adjust the file name according to your dialplan application identifier "DIALPLAN-APP-CF967EE0