Skip to content

Commit

Permalink
Add server name setting
Browse files Browse the repository at this point in the history
Fix notifiarr response code placement
  • Loading branch information
austinwbest committed Nov 22, 2023
1 parent 44a9615 commit 5877855
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
2 changes: 1 addition & 1 deletion root/app/www/public/ajax/notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
<div class="bg-secondary rounded h-100 p-4 mt-3">
<h4 class="mt-3">Platforms</h4>
<?php foreach ($notificationPlatforms as $platformId => $platform) { ?>
<h6><?= $platform['name'] ?> <i style="cursor: pointer;" class="fas fa-bell text-info" title="test" onclick="testNotify('<?= $platformId ?>')"></i></h6>
<h6><?= $platform['name'] ?> <i style="cursor: pointer;" class="fas fa-bell text-info" title="Test notification" onclick="testNotify('<?= $platformId ?>')"></i></h6>
<div class="table-responsive mt-2">
<table class="table">
<thead>
Expand Down
21 changes: 21 additions & 0 deletions root/app/www/public/ajax/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,27 @@
?>
<div class="container-fluid pt-4 px-4">
<div class="bg-secondary rounded h-100 p-4">
<h4>General</h4>
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">Setting</th>
<th scope="col">Description</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Server name</th>
<td>
<input class="form-control" type="text" id="globalSetting-serverName" value="<?= $globalSettings['serverName'] ?>">
</td>
<td>The name of this server, also passed in the notification payload</td>
</tr>
</tbody>
</table>
</div>
<h4>New Containers</h4>
<div class="table-responsive">
<table class="table">
Expand Down
6 changes: 6 additions & 0 deletions root/app/www/public/classes/notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Notifications
protected $platformSettings;
protected $headers;
protected $logpath;
protected $serverName;
public function __construct()
{
global $platforms;
Expand All @@ -35,6 +36,7 @@ public function __construct()
$this->platforms = $platforms; //-- includes/platforms.php
$this->platformSettings = $settings['notifications']['platforms'];
$this->logpath = LOGS_PATH . 'notifications/';
$this->serverName = $settings['global']['serverName'];
}

public function __toString()
Expand All @@ -44,6 +46,10 @@ public function __toString()

public function notify($platform, $payload)
{
if ($this->serverName) {
$payload['server']['name'] = $this->serverName;
}

$platformData = $this->getNotificationPlatformFromId($platform);
$logfile = $this->logpath . $platformData['name'] . '-'. date('Ymd') .'.log';

Expand Down
8 changes: 4 additions & 4 deletions root/app/www/public/classes/traits/notification/notifiarr.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ public function notifiarr($logfile, $payload)
$url = 'https://notifiarr.com/api/v1/notification/dockwatch';
$curl = curl($url, $headers, 'POST', json_encode($payload));

logger($logfile, 'notification response:' . json_encode($curl), ($curl['response']['code'] != 200 ? 'error' : 'info'));
logger($logfile, 'notification response:' . json_encode($curl), ($curl['code'] != 200 ? 'error' : 'info'));

$return = ['code' => 200];
if ($curl['response']['code'] != 200) {
$return = ['code' => $curl['response']['code'], 'error' => $curl['response']['details']['response']];
if ($curl['code'] != 200) {
$return = ['code' => $curl['code'], 'error' => $curl['response']['details']['response']];
}

return $return;
}
}
}

0 comments on commit 5877855

Please sign in to comment.