NodeOffline.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace App\Notifications;
  3. use Illuminate\Bus\Queueable;
  4. use Illuminate\Contracts\Queue\ShouldQueue;
  5. use Illuminate\Notifications\Messages\MailMessage;
  6. use Illuminate\Notifications\Notification;
  7. class NodeOffline extends Notification implements ShouldQueue
  8. {
  9. use Queueable;
  10. private $data;
  11. public function __construct($data)
  12. {
  13. $this->data = $data;
  14. }
  15. public function via($notifiable)
  16. {
  17. return sysConfig('node_offline_notification');
  18. }
  19. public function toMail($notifiable)
  20. {
  21. return (new MailMessage)
  22. ->subject(trans('notification.node_offline'))
  23. ->markdown('mail.simpleMarkdown', ['title' => trans('notification.node_offline_content'), 'content' => $this->markdownMessage(), 'url' => route('admin.node.index')]);
  24. }
  25. private function markdownMessage()
  26. {
  27. $content = '';
  28. foreach ($this->data as $node) {
  29. $content .= "- {$node['name']} {$node['host']}\r\n";
  30. }
  31. return $content;
  32. }
  33. public function toCustom($notifiable)
  34. {
  35. return [
  36. 'title' => trans('notification.node_offline'),
  37. 'content' => $this->markdownMessage(),
  38. ];
  39. }
  40. public function toBark($notifiable)
  41. {
  42. return [
  43. 'title' => trans('notification.node_offline'),
  44. 'content' => $this->stringMessage(),
  45. ];
  46. }
  47. private function stringMessage()
  48. {
  49. $content = '';
  50. foreach ($this->data as $node) {
  51. $content .= "{$node['name']} {$node['host']}| ";
  52. }
  53. return $content;
  54. }
  55. }