@@ -5,9 +5,9 @@ discard block |
||
5 | 5 | |
6 | 6 | class Notifiable extends \Spatie\ServerMonitor\Notifications\Notifiable |
7 | 7 | { |
8 | - public function routeNotificationForMail(): ?array |
|
8 | + public function routeNotificationForMail(): ? array |
|
9 | 9 | { |
10 | - if($notification = $this->getSpecificConfiguration('mail')) { |
|
10 | + if ($notification = $this->getSpecificConfiguration('mail')) { |
|
11 | 11 | return $notification; |
12 | 12 | } |
13 | 13 | return parent::routeNotificationForMail(); |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | |
16 | 16 | public function routeNotificationForSlack(): ?string |
17 | 17 | { |
18 | - if($notification = $this->getSpecificConfiguration('slack')) { |
|
18 | + if ($notification = $this->getSpecificConfiguration('slack')) { |
|
19 | 19 | return $notification; |
20 | 20 | } |
21 | 21 | return parent::routeNotificationForSlack(); |
@@ -30,11 +30,11 @@ discard block |
||
30 | 30 | |
31 | 31 | private function getSpecificConfiguration($type) { |
32 | 32 | $notifications = $this->getHost()->getCustomProperty('notifications'); |
33 | - if($notifications) { |
|
34 | - if(!isset($notifications['configuration'][$type])) { |
|
33 | + if ($notifications) { |
|
34 | + if (!isset($notifications['configuration'][$type])) { |
|
35 | 35 | return null; |
36 | 36 | } |
37 | - if(count($notifications['configuration'][$type]) == 1) { |
|
37 | + if (count($notifications['configuration'][$type]) == 1) { |
|
38 | 38 | $configuration = config('server-monitor-plugin-notification-by-host.notifications.channels.'.$type); |
39 | 39 | return $notifications['configuration'][$type][array_keys($configuration)[0]]; |
40 | 40 | } |
@@ -16,12 +16,12 @@ |
||
16 | 16 | /* @var $host \Spatie\ServerMonitor\Models\Host */ |
17 | 17 | $host = $event->check->host()->first(); |
18 | 18 | $notifications = $host->getCustomProperty('notifications'); |
19 | - if(!$notifications) { |
|
19 | + if (!$notifications) { |
|
20 | 20 | return config('server-monitor.notifications.notifications.'.static::class); |
21 | 21 | } |
22 | 22 | var_dump($notifications); |
23 | 23 | var_dump(static::class); |
24 | - if(isset($notifications[static::class]) && isset($notifications[static::class]['channels'])) { |
|
24 | + if (isset($notifications[static::class]) && isset($notifications[static::class]['channels'])) { |
|
25 | 25 | return $notifications[static::class]['channels']; |
26 | 26 | } |
27 | 27 | return []; |
@@ -37,17 +37,17 @@ discard block |
||
37 | 37 | $configure = []; |
38 | 38 | foreach ($notifications as $channel) { |
39 | 39 | $attributes = config('server-monitor-plugin-notification-by-host.notifications.channels.'.$channel); |
40 | - if($attributes) { |
|
40 | + if ($attributes) { |
|
41 | 41 | foreach ($attributes as $attribute => $type) { |
42 | - $configure[$channel][$attribute] = $this->ask("For channel `$channel` attribute `$attribute`?".($type == 'array'?" (values separate by ,)":""), false); |
|
43 | - if($type == 'array') { |
|
42 | + $configure[$channel][$attribute] = $this->ask("For channel `$channel` attribute `$attribute`?".($type == 'array' ? " (values separate by ,)" : ""), false); |
|
43 | + if ($type == 'array') { |
|
44 | 44 | $configure[$channel][$attribute] = explode(',', $configure[$channel][$attribute]); |
45 | 45 | } |
46 | - if(!$configure[$channel][$attribute]) { |
|
46 | + if (!$configure[$channel][$attribute]) { |
|
47 | 47 | unset($configure[$channel][$attribute]); |
48 | 48 | } |
49 | 49 | } |
50 | - if(!$configure[$channel]) { |
|
50 | + if (!$configure[$channel]) { |
|
51 | 51 | unset($configure[$channel]); |
52 | 52 | } |
53 | 53 | } |
@@ -68,10 +68,10 @@ discard block |
||
68 | 68 | : $this->choice('Which host?', $hostList); |
69 | 69 | |
70 | 70 | $host = $this->determineHostModelClass()::where('name', $hostName)->first(); |
71 | - if(!$host) { |
|
71 | + if (!$host) { |
|
72 | 72 | $this->warn("This host `{$hostName}` doesn't exist"); |
73 | 73 | } |
74 | - } while(!$host); |
|
74 | + } while (!$host); |
|
75 | 75 | |
76 | 76 | $this->info("Host: {$host->name}"); |
77 | 77 | return $host; |
@@ -85,11 +85,11 @@ discard block |
||
85 | 85 | $notifications[] = $channel; |
86 | 86 | } |
87 | 87 | $notificationsParameters = []; |
88 | - foreach(config('server-monitor.notifications.notifications') as $class => $notification) { |
|
88 | + foreach (config('server-monitor.notifications.notifications') as $class => $notification) { |
|
89 | 89 | $this->line("Notification for ".$class); |
90 | 90 | |
91 | 91 | $channels = $this->choice('Which channel? (values separate by ,)', $notifications, 0, null, true); |
92 | - if($channels[0] != 'No channel') { |
|
92 | + if ($channels[0] != 'No channel') { |
|
93 | 93 | $notificationsParameters[$class]['channels'] = $channels; |
94 | 94 | } |
95 | 95 | } |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | } |
98 | 98 | |
99 | 99 | private function configuration($host, $notificationsParameters) { |
100 | - if(!$notificationsParameters) { |
|
100 | + if (!$notificationsParameters) { |
|
101 | 101 | $this->warn("The host {$host->name} has no notification configure !"); |
102 | 102 | } |
103 | 103 | else { |
@@ -108,12 +108,12 @@ discard block |
||
108 | 108 | |
109 | 109 | $notificationsUsed = []; |
110 | 110 | foreach ($notificationsParameters as $check) { |
111 | - if(isset($check['channels']) && $check['channels']) { |
|
111 | + if (isset($check['channels']) && $check['channels']) { |
|
112 | 112 | $notificationsUsed = array_unique(array_merge($notificationsUsed, $check['channels']), SORT_REGULAR); |
113 | 113 | } |
114 | 114 | } |
115 | 115 | |
116 | - if($notificationsUsed) { |
|
116 | + if ($notificationsUsed) { |
|
117 | 117 | $configure = $this->askConfiguration($notificationsUsed); |
118 | 118 | $notificationsParameters['configuration'] = $configure; |
119 | 119 | } |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | 'port' => 22, |
30 | 30 | ]); |
31 | 31 | |
32 | - $host->checks()->saveMany(collect($checks)->map(function (string $checkName) { |
|
32 | + $host->checks()->saveMany(collect($checks)->map(function(string $checkName) { |
|
33 | 33 | return new Check([ |
34 | 34 | 'type' => $checkName, |
35 | 35 | 'status' => CheckStatus::NOT_YET_CHECKED, |
@@ -50,12 +50,12 @@ discard block |
||
50 | 50 | function route_notification_for_mail_custom() { |
51 | 51 | /* @var $host Host */ |
52 | 52 | $host = $this->notifiable->getEvent()->check->host()->first(); |
53 | - $notifications = [ |
|
53 | + $notifications = [ |
|
54 | 54 | 'TheCodingMachine\ServerMonitorPluginNotificationByHost\TheCodingMachine\ServerMonitorPluginNotificationByHost\Notifications\Notifications\CheckSucceeded' => |
55 | 55 | [ |
56 | 56 | 'channels' => ['mail'] |
57 | 57 | ], |
58 | - 'configuration' => ['mail' => [ 'to' => ['[email protected]'] ]] |
|
58 | + 'configuration' => ['mail' => ['to' => ['[email protected]']]] |
|
59 | 59 | ]; |
60 | 60 | |
61 | 61 | $host->setCustomProperty('notifications', $notifications); |
@@ -70,12 +70,12 @@ discard block |
||
70 | 70 | function route_notification_no_custom_data() { |
71 | 71 | /* @var $host Host */ |
72 | 72 | $host = $this->notifiable->getEvent()->check->host()->first(); |
73 | - $notifications = [ |
|
73 | + $notifications = [ |
|
74 | 74 | 'TheCodingMachine\ServerMonitorPluginNotificationByHost\TheCodingMachine\ServerMonitorPluginNotificationByHost\Notifications\Notifications\CheckFailed' => |
75 | 75 | [ |
76 | 76 | 'channels' => ['slack'] |
77 | 77 | ], |
78 | - 'configuration' => ['slack' => [ 'webhook' => ['urlSlack'] ]] |
|
78 | + 'configuration' => ['slack' => ['webhook' => ['urlSlack']]] |
|
79 | 79 | ]; |
80 | 80 | |
81 | 81 | $host->setCustomProperty('notifications', $notifications); |
@@ -90,12 +90,12 @@ discard block |
||
90 | 90 | function route_notification_for_mail_custom_array() { |
91 | 91 | /* @var $host Host */ |
92 | 92 | $host = $this->notifiable->getEvent()->check->host()->first(); |
93 | - $notifications = [ |
|
93 | + $notifications = [ |
|
94 | 94 | 'TheCodingMachine\ServerMonitorPluginNotificationByHost\Test\TheCodingMachine\ServerMonitorPluginNotificationByHost\Notifications\Notifications\CheckSucceeded' => |
95 | 95 | [ |
96 | 96 | 'channels' => ['mail'] |
97 | 97 | ], |
98 | - 'configuration' => ['mail' => [ 'to' => ['[email protected]'], 'other' => 'otherData']] |
|
98 | + 'configuration' => ['mail' => ['to' => ['[email protected]'], 'other' => 'otherData']] |
|
99 | 99 | ]; |
100 | 100 | |
101 | 101 | $host->setCustomProperty('notifications', $notifications); |
@@ -118,12 +118,12 @@ discard block |
||
118 | 118 | function route_notification_for_slack_custom() { |
119 | 119 | /* @var $host Host */ |
120 | 120 | $host = $this->notifiable->getEvent()->check->host()->first(); |
121 | - $notifications = [ |
|
121 | + $notifications = [ |
|
122 | 122 | 'TheCodingMachine\ServerMonitorPluginNotificationByHost\Test\TheCodingMachine\ServerMonitorPluginNotificationByHost\Notifications\Notifications\CheckSucceeded' => |
123 | 123 | [ |
124 | 124 | 'channels' => ['slack'] |
125 | 125 | ], |
126 | - 'configuration' => ['slack' => [ 'webhook_url' => 'urlSlack' ]] |
|
126 | + 'configuration' => ['slack' => ['webhook_url' => 'urlSlack']] |
|
127 | 127 | ]; |
128 | 128 | |
129 | 129 | $host->setCustomProperty('notifications', $notifications); |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | 'port' => 22, |
34 | 34 | ]); |
35 | 35 | |
36 | - $host->checks()->saveMany(collect($checks)->map(function (string $checkName) { |
|
36 | + $host->checks()->saveMany(collect($checks)->map(function(string $checkName) { |
|
37 | 37 | return new Check([ |
38 | 38 | 'type' => $checkName, |
39 | 39 | 'status' => CheckStatus::NOT_YET_CHECKED, |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | 'port' => 22, |
59 | 59 | ]); |
60 | 60 | |
61 | - $host->checks()->saveMany(collect($checks)->map(function (string $checkName) { |
|
61 | + $host->checks()->saveMany(collect($checks)->map(function(string $checkName) { |
|
62 | 62 | return new Check([ |
63 | 63 | 'type' => $checkName, |
64 | 64 | 'status' => CheckStatus::NOT_YET_CHECKED, |
@@ -69,12 +69,12 @@ discard block |
||
69 | 69 | $this->notifiable->setEvent($event); |
70 | 70 | |
71 | 71 | $host = $this->notifiable->getEvent()->check->host()->first(); |
72 | - $notifications = [ |
|
72 | + $notifications = [ |
|
73 | 73 | 'TheCodingMachine\ServerMonitorPluginNotificationByHost\Notifications\Notifications\CheckSucceeded' => |
74 | 74 | [ |
75 | 75 | 'channels' => ['mail'] |
76 | 76 | ], |
77 | - 'configuration' => ['mail' => [ 'to' => ['[email protected]'] ]] |
|
77 | + 'configuration' => ['mail' => ['to' => ['[email protected]']]] |
|
78 | 78 | ]; |
79 | 79 | |
80 | 80 | $host->setCustomProperty('notifications', $notifications); |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | 'port' => 22, |
97 | 97 | ]); |
98 | 98 | |
99 | - $host->checks()->saveMany(collect($checks)->map(function (string $checkName) { |
|
99 | + $host->checks()->saveMany(collect($checks)->map(function(string $checkName) { |
|
100 | 100 | return new Check([ |
101 | 101 | 'type' => $checkName, |
102 | 102 | 'status' => CheckStatus::NOT_YET_CHECKED, |
@@ -107,12 +107,12 @@ discard block |
||
107 | 107 | $this->notifiable->setEvent($event); |
108 | 108 | |
109 | 109 | $host = $this->notifiable->getEvent()->check->host()->first(); |
110 | - $notifications = [ |
|
110 | + $notifications = [ |
|
111 | 111 | 'TheCodingMachine\ServerMonitorPluginNotificationByHost\Notifications\Notifications\CheckFailed' => |
112 | 112 | [ |
113 | 113 | 'channels' => ['mail'] |
114 | 114 | ], |
115 | - 'configuration' => ['mail' => [ 'to' => ['[email protected]'] ]] |
|
115 | + 'configuration' => ['mail' => ['to' => ['[email protected]']]] |
|
116 | 116 | ]; |
117 | 117 | |
118 | 118 | $host->setCustomProperty('notifications', $notifications); |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | ]); |
54 | 54 | |
55 | 55 | /* @var $app['config'] Repository */ |
56 | - $app['config']->set(['server-monitor' => include(__DIR__ . '/../vendor/spatie/laravel-server-monitor/config/server-monitor.php')]); |
|
56 | + $app['config']->set(['server-monitor' => include(__DIR__.'/../vendor/spatie/laravel-server-monitor/config/server-monitor.php')]); |
|
57 | 57 | |
58 | 58 | $app['config']->set('server-monitor.notifications.notifications', [ |
59 | 59 | \TheCodingMachine\ServerMonitorPluginNotificationByHost\Notifications\Notifications\CheckSucceeded::class => [], |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | $app['config']->set('server-monitor.notifications.slack', ['webhook_url' => 'test']); |
67 | 67 | $app['config']->set('server-monitor.notifications.notifiable', TheCodingMachine\ServerMonitorPluginNotificationByHost\Notifications\Notifiable::class); |
68 | 68 | |
69 | - $app['config']->set(['server-monitor-plugin-notification-by-host' => include(__DIR__ . '/../config/server-monitor-plugin-notification-by-host.php')]); |
|
69 | + $app['config']->set(['server-monitor-plugin-notification-by-host' => include(__DIR__.'/../config/server-monitor-plugin-notification-by-host.php')]); |
|
70 | 70 | |
71 | 71 | $this->setUpDatabase(); |
72 | 72 | } |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | */ |
87 | 87 | protected function seeInConsoleOutput($searchStrings) |
88 | 88 | { |
89 | - if (! is_array($searchStrings)) { |
|
89 | + if (!is_array($searchStrings)) { |
|
90 | 90 | $searchStrings = [$searchStrings]; |
91 | 91 | } |
92 | 92 | $output = $this->getArtisanOutput(); |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | */ |
101 | 101 | protected function dontSeeInConsoleOutput($searchStrings) |
102 | 102 | { |
103 | - if (! is_array($searchStrings)) { |
|
103 | + if (!is_array($searchStrings)) { |
|
104 | 104 | $searchStrings = [$searchStrings]; |
105 | 105 | } |
106 | 106 | $output = $this->getArtisanOutput(); |
@@ -28,27 +28,27 @@ |
||
28 | 28 | { |
29 | 29 | echo $question."\n"; |
30 | 30 | $result = $this->answers[$this->answer]; |
31 | - if($multiple) { |
|
32 | - if(!is_array($this->answers[$this->answer])) { |
|
31 | + if ($multiple) { |
|
32 | + if (!is_array($this->answers[$this->answer])) { |
|
33 | 33 | $result = [$this->answers[$this->answer]]; |
34 | 34 | } |
35 | 35 | } |
36 | - $this->answer ++; |
|
36 | + $this->answer++; |
|
37 | 37 | return $result; |
38 | 38 | } |
39 | 39 | public function confirm($question, $default = false) |
40 | 40 | { |
41 | 41 | echo $question."\n"; |
42 | - return $this->answers[$this->answer ++]; |
|
42 | + return $this->answers[$this->answer++]; |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | public function ask($question, $default = null) { |
46 | 46 | echo $question."\n"; |
47 | - return $this->answers[$this->answer ++]; |
|
47 | + return $this->answers[$this->answer++]; |
|
48 | 48 | } |
49 | 49 | }; |
50 | 50 | |
51 | - $this->app->bind('command.server-monitor:add-notification-host', function () { |
|
51 | + $this->app->bind('command.server-monitor:add-notification-host', function() { |
|
52 | 52 | return $this->command; |
53 | 53 | }); |
54 | 54 | } |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | } |
29 | 29 | |
30 | 30 | public function choice($question, array $choices, $default = null, $attempts = null, $multiple = null) { |
31 | - echo $question . "\n"; |
|
31 | + echo $question."\n"; |
|
32 | 32 | $result = $this->answers[$this->answer]; |
33 | 33 | if ($multiple) { |
34 | 34 | if (!is_array($this->answers[$this->answer])) { |
@@ -40,17 +40,17 @@ discard block |
||
40 | 40 | } |
41 | 41 | |
42 | 42 | public function confirm($question, $default = false) { |
43 | - echo $question . "\n"; |
|
43 | + echo $question."\n"; |
|
44 | 44 | return $this->answers[$this->answer++]; |
45 | 45 | } |
46 | 46 | |
47 | 47 | public function ask($question, $default = null) { |
48 | - echo $question . "\n"; |
|
48 | + echo $question."\n"; |
|
49 | 49 | return $this->answers[$this->answer++]; |
50 | 50 | } |
51 | 51 | }; |
52 | 52 | |
53 | - $this->app->bind('command.server-monitor:list-notifications', function () { |
|
53 | + $this->app->bind('command.server-monitor:list-notifications', function() { |
|
54 | 54 | return $this->command; |
55 | 55 | }); |
56 | 56 | } |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | /** @test */ |
71 | 71 | public function it_check() { |
72 | 72 | |
73 | - $notifications = [ |
|
73 | + $notifications = [ |
|
74 | 74 | 'TheCodingMachine\ServerMonitorPluginNotificationByHost\Notifications\Notifications\CheckSucceeded' => |
75 | 75 | [ |
76 | 76 | 'channels' => ['mail'] |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | [ |
80 | 80 | 'channels' => ['slack'] |
81 | 81 | ], |
82 | - 'configuration' => ['mail' => [ 'to' => '[email protected]' ]] |
|
82 | + 'configuration' => ['mail' => ['to' => '[email protected]']] |
|
83 | 83 | ]; |
84 | 84 | |
85 | 85 | $host = Host::create([ |