Skip to content

Commit

Permalink
Some mattermost platform adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
austinwbest committed Nov 16, 2024
1 parent c14c83b commit f7413e1
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 27 deletions.
114 changes: 90 additions & 24 deletions root/app/www/public/classes/traits/Notifications/Mattermost.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,37 +64,69 @@ public function buildMattermostMessage($payload, $test = false)
if ($payload['network']) {
$pruned = [];
foreach ($payload['network'] as $network) {
$pruned[] = str_replace('_', '\_', $network);
if (!trim($network)) {
continue;
}

$pruned[] = $network;
}

$table[] = '| Networks | ' . implode(', ', $pruned) . ' |';
if ($pruned) {
$table[] = '| Networks | ' . implode(', ', $pruned) . ' |';
}
}
if ($payload['volume']) {
$pruned = [];
foreach ($payload['volume'] as $volume) {
$pruned[] = truncateMiddle($volume, 20);
if (!trim($volume)) {
continue;
}

if ($pruned) {
$pruned[] = truncateMiddle($volume, 20);
}
}

$table[] = '| Volumes | ' . implode(', ', $pruned) . ' |';
}
if ($payload['image']) {
$pruned = [];
foreach ($payload['image'] as $image) {
$pruned[] = $image;
if (!trim($image)) {
continue;
}

if ($pruned) {
$pruned[] = $image;
}
}

$table[] = '| Images | ' . implode(', ', $pruned) . ' |';
}
if ($payload['imageList']) {
$pruned = [];
foreach ($payload['imageList'] as $imageList) {
$pruned[] = $imageList['cr'] . ' (' . byteConversion($imageList['size']) . ')';
if (!trim($imageList['cr'])) {
continue;
}

if ($pruned) {
$pruned[] = $imageList['cr'] . ' (' . byteConversion($imageList['size']) . ')';
}
}

$table[] = '| Image List | ' . implode(', ', $pruned) . ' |';
if ($pruned) {
$table[] = '| Image List | ' . implode(', ', $pruned) . ' |';
} else {
$table = [];
}
}

$message .= implode("\n", $table) . "\n";
if (count($table) > 2) {
$message .= implode("\n", $table) . "\n";
} else {
$message = '';
}
break;
case 'state':
$message .= '##### ' . APP_NAME . ': Container state change' . "\n";
Expand All @@ -107,34 +139,53 @@ public function buildMattermostMessage($payload, $test = false)
if ($payload['added']) {
$state = [];
foreach ($payload['added'] as $added) {
if (!trim($added['container'])) {
continue;
}

$state[] = $added['container'];
}
$table[] = '| Added | ' . implode(', ', $state) . ' |';
} else {
$table[] = '| Added | None |';

if ($state) {
$table[] = '| Added | ' . implode(', ', $state) . ' |';
}
}

if ($payload['removed']) {
$state = [];
foreach ($payload['removed'] as $removed) {
if (!trim($removed['container'])) {
continue;
}

$state[] = $removed['container'];
}
$table[] = '| Removed | ' . implode(', ', $state) . ' |';
} else {
$table[] = '| Removed | None |';

if ($state) {
$table[] = '| Removed | ' . implode(', ', $state) . ' |';
}
}

if ($payload['changes']) {
$state = [];
foreach ($payload['changes'] as $changes) {
if (!trim($changes['container'])) {
continue;
}

$state[] = $changes['container'] . ' [' . $changes['previous'] . '' . $changes['current'] . ']';
}
$table[] = '| Changed | ' . implode("\n", $state) . ' |';
} else {
$table[] = '| Changed | None |';

if (!$state) {
$table[] = '| Changed | ' . implode("\n", $state) . ' |';
}
}

$message .= implode("\n", $table) . "\n";
if (count($table) > 2) {
$message .= implode("\n", $table) . "\n";
} else {
$message = '';
}
break;
case 'updates':
$message .= '##### ' . APP_NAME . ': Updates' . "\n";
Expand All @@ -147,23 +198,38 @@ public function buildMattermostMessage($payload, $test = false)
if ($payload['available']) {
$updates = [];
foreach ($payload['available'] as $available) {
if (!trim($available['container'])) {
continue;
}

$updates[] = $available['container'];
}
$table[] = '| Available | ' . implode(', ', $updates) . ' |';
} else {
$table[] = '| Available | None |';

if ($updates) {
$table[] = '| Available | ' . implode(', ', $updates) . ' |';
}
}

if ($payload['updated']) {
$updates = [];
foreach ($payload['updated'] as $updated) {
if (!trim($updated['container'])) {
continue;
}

$updates[] = $updated['container'] . ' [' . $updated['pre'] . '' . $updated['post'] . ']';
}
$table[] = '| Updated | ' . implode("\n", $updates) . ' |';
} else {
$table[] = '| Updated | None |';

if ($updates) {
$table[] = '| Updated | ' . implode("\n", $updates) . ' |';
}
}

$message .= implode("\n", $table) . "\n";
if (count($table) > 2) {
$message .= implode("\n", $table) . "\n";
} else {
$message = '';
}
break;
case 'usage':
$message .= '##### :warning: ' . APP_NAME . ': High usage' . "\n";
Expand Down
10 changes: 7 additions & 3 deletions root/app/www/public/functions/telemetry.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ function telemetry($send = false)

$telemetry['telemetry']['compose']['total'] = count($existingComposeFolders);

//-- NOTIFICATIONS INFO
$telemetry['telemetry']['notifications']['notifiarr'] = 0;
$telemetry['telemetry']['notifications']['telegram'] = 0;
//-- NOTIFICATION INFO
$telemetry['telemetry']['notifications']['notifiarr'] = 0;
$telemetry['telemetry']['notifications']['telegram'] = 0;
$telemetry['telemetry']['notifications']['mattermost'] = 0;

if ($notificationTable) {
foreach ($notificationTable as $notificationLink) {
Expand All @@ -76,6 +77,9 @@ function telemetry($send = false)
if ($notificationLink['platform_id'] == NotificationPlatforms::TELEGRAM) {
$telemetry['telemetry']['notifications']['telegram']++;
}
if ($notificationLink['platform_id'] == NotificationPlatforms::MATTERMOST) {
$telemetry['telemetry']['notifications']['mattermost']++;
}
}
}
} else { //-- TELEMETRY IS DISABLED :(
Expand Down

0 comments on commit f7413e1

Please sign in to comment.