Merge pull request 'send FCM push for threshold breach notifications' (#74) from feat/fcm-apk-v1.8.2 into master
Reviewed-on: #74
This commit was merged in pull request #74.
This commit is contained in:
@@ -453,16 +453,18 @@ class ApiController
|
|||||||
if (!empty($breaches)) {
|
if (!empty($breaches)) {
|
||||||
$userIds = $serverModel->getAccessibleUserIds((int) $server['id']);
|
$userIds = $serverModel->getAccessibleUserIds((int) $server['id']);
|
||||||
$notificationModel = new Notification();
|
$notificationModel = new Notification();
|
||||||
|
$fcm = new FCMService();
|
||||||
foreach ($breaches as $b) {
|
foreach ($breaches as $b) {
|
||||||
$title = strtoupper($b['metric']) . " {$b['level']} on {$server['name']}";
|
$title = strtoupper($b['metric']) . " {$b['level']} on {$server['name']}";
|
||||||
$message = "{$server['name']}: {$b['metric']} at {$b['current']}% ({$b['level']} threshold: {$b['threshold']}%)";
|
$message = "{$server['name']}: {$b['metric']} at {$b['current']}% ({$b['level']} threshold: {$b['threshold']}%)";
|
||||||
foreach ($userIds as $uid) {
|
foreach ($userIds as $uid) {
|
||||||
$notificationModel->create([
|
$noteId = $notificationModel->create([
|
||||||
'user_id' => (int) $uid,
|
'user_id' => (int) $uid,
|
||||||
'title' => $title,
|
'title' => $title,
|
||||||
'message' => $message,
|
'message' => $message,
|
||||||
'type' => $b['level'],
|
'type' => $b['level'],
|
||||||
]);
|
]);
|
||||||
|
$fcm->sendToUser((int) $uid, $title, $message, $b['level'], $noteId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user