@@ -67,6 +67,7 @@ public function handle(ResultCreated $event): void
6767 if ($ this ->notificationSettings ->discord_enabled == true && $ this ->notificationSettings ->discord_on_threshold_failure == true ) {
6868 $ this ->discordChannel ($ event );
6969 }
70+
7071 // Webhook notification channel
7172 if ($ this ->notificationSettings ->webhook_enabled == true && $ this ->notificationSettings ->webhook_on_threshold_failure == true ) {
7273 $ this ->webhookChannel ($ event );
@@ -226,50 +227,51 @@ protected function telegramChannel(ResultCreated $event): void
226227 /**
227228 * Handle Discord notifications.
228229 */
229-
230230 protected function discordChannel (ResultCreated $ event ): void
231231 {
232- if ($ this ->notificationSettings ->discord_enabled ) {
233- $ failedThresholds = []; // Initialize an array to keep track of failed thresholds
234-
235- // Check Download threshold
236- if ($ this ->thresholdSettings ->absolute_download > 0 && absoluteDownloadThresholdFailed ($ this ->thresholdSettings ->absolute_download , $ event ->result ->downloadBits )) {
237- $ failedThresholds ['Download ' ] = ($ event ->result ->downloadBits / 1000000 ) . ' (Mbps) ' ;
238- }
239-
240- // Check Upload threshold
241- if ($ this ->thresholdSettings ->absolute_upload > 0 && absoluteUploadThresholdFailed ($ this ->thresholdSettings ->absolute_upload , $ event ->result ->uploadBits )) {
242- $ failedThresholds ['Upload ' ] = ($ event ->result ->uploadBits / 1000000 ) . ' (Mbps) ' ;
243- }
244-
245- // Check Ping threshold
246- if ($ this ->thresholdSettings ->absolute_ping > 0 && absolutePingThresholdFailed ($ this ->thresholdSettings ->absolute_ping , $ event ->result ->ping )) {
247- $ failedThresholds ['Ping ' ] = $ event ->result ->ping . " ms " ;
248- }
249-
250- // Proceed with sending notifications only if there are any failed thresholds
251- if (count ($ failedThresholds ) > 0 ) {
252- if ($ this ->notificationSettings ->discord_on_threshold_failure && count ($ this ->notificationSettings ->discord_webhooks )) {
253- foreach ($ this ->notificationSettings ->discord_webhooks as $ webhook ) {
254- // Construct the payload with the failed thresholds information
255- $ contentLines = [
256- "Result ID: " . $ event ->result ->id ,
257- "Site Name: " . $ this ->generalSettings ->site_name
258- ];
259- foreach ($ failedThresholds as $ metric => $ result ) {
260- $ contentLines [] = "{$ metric } threshold failed with result: {$ result }. " ;
232+ if ($ this ->notificationSettings ->discord_enabled ) {
233+ $ failedThresholds = []; // Initialize an array to keep track of failed thresholds
234+
235+ // Check Download threshold
236+ if ($ this ->thresholdSettings ->absolute_download > 0 && absoluteDownloadThresholdFailed ($ this ->thresholdSettings ->absolute_download , $ event ->result ->downloadBits )) {
237+ $ failedThresholds ['Download ' ] = ($ event ->result ->downloadBits / 1000000 ).' (Mbps) ' ;
238+ }
239+
240+ // Check Upload threshold
241+ if ($ this ->thresholdSettings ->absolute_upload > 0 && absoluteUploadThresholdFailed ($ this ->thresholdSettings ->absolute_upload , $ event ->result ->uploadBits )) {
242+ $ failedThresholds ['Upload ' ] = ($ event ->result ->uploadBits / 1000000 ).' (Mbps) ' ;
243+ }
244+
245+ // Check Ping threshold
246+ if ($ this ->thresholdSettings ->absolute_ping > 0 && absolutePingThresholdFailed ($ this ->thresholdSettings ->absolute_ping , $ event ->result ->ping )) {
247+ $ failedThresholds ['Ping ' ] = $ event ->result ->ping .' ms ' ;
248+ }
249+
250+ // Proceed with sending notifications only if there are any failed thresholds
251+ if (count ($ failedThresholds ) > 0 ) {
252+ if ($ this ->notificationSettings ->discord_on_threshold_failure && count ($ this ->notificationSettings ->discord_webhooks )) {
253+ foreach ($ this ->notificationSettings ->discord_webhooks as $ webhook ) {
254+ // Construct the payload with the failed thresholds information
255+ $ contentLines = [
256+ 'Result ID: ' .$ event ->result ->id ,
257+ 'Site Name: ' .$ this ->generalSettings ->site_name ,
258+ ];
259+
260+ foreach ($ failedThresholds as $ metric => $ result ) {
261+ $ contentLines [] = "{$ metric } threshold failed with result: {$ result }. " ;
262+ }
263+
264+ $ payload = [
265+ 'content ' => implode ("\n" , $ contentLines ),
266+ ];
267+
268+ // Send the request using Laravel's HTTP client
269+ $ response = Http::post ($ webhook ['discord_webhook_url ' ], $ payload );
261270 }
262- $ payload = [
263- 'content ' => implode ("\n" , $ contentLines ),
264- ];
265-
266- // Send the request using Laravel's HTTP client
267- $ response = Http::post ($ webhook ['discord_webhook_url ' ], $ payload );
268271 }
269272 }
270273 }
271274 }
272- }
273275
274276 /**
275277 * Handle webhook notifications.
0 commit comments