Skip to content

Commit

Permalink
Send error when disabled & add a lower timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
austinwbest committed Sep 29, 2024
1 parent 5741f4d commit 16e61ab
Showing 1 changed file with 54 additions and 55 deletions.
109 changes: 54 additions & 55 deletions root/app/www/public/functions/telemetry.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,9 @@ function telemetry($send = false)
{
global $database;

$database = $database ?: new Database();
$settingsTable = $database->getSettings();

//-- TELEMETRY IS DISABLED :(
if (!$settingsTable['telemetry']) {
return ['error' => 'Telemetry is disabled in the settings'];
}

$serversTable = $database->getServers();
$containersTable = $database->getContainers();
$groupsTable = $database->getContainerGroups();
$notificationTable = $database->getNotificationLinks();
$database = $database ?: new Database();
$settingsTable = $database->getSettings();
$serversTable = $database->getServers();

//-- ONE WAY HASH() OF AN MD5() HASHED HOSTNAME + APIKEY TO KEEP THINGS UNIQUE
$telemetry['token'] = hash('sha256', md5($_SERVER['HOSTNAME'] . $serversTable[1]['apikey']));
Expand All @@ -31,61 +22,69 @@ function telemetry($send = false)
$telemetry['branch'] = gitBranch();
$telemetry['version'] = gitVersion();

//-- CONTAINER INFO
$auto = $check = $ignore = 0;
foreach ($containersTable as $container) {
if ($container['updates'] == 1) {
$auto++;
} elseif ($container['updates'] == 2) {
$check++;
} else {
$ignore++;
if ($settingsTable['telemetry']) {
$containersTable = $database->getContainers();
$groupsTable = $database->getContainerGroups();
$notificationTable = $database->getNotificationLinks();

//-- CONTAINER INFO
$auto = $check = $ignore = 0;
foreach ($containersTable as $container) {
if ($container['updates'] == 1) {
$auto++;
} elseif ($container['updates'] == 2) {
$check++;
} else {
$ignore++;
}
}
}

$telemetry['telemetry']['containers']['update']['auto'] = $auto;
$telemetry['telemetry']['containers']['update']['check'] = $check;
$telemetry['telemetry']['containers']['update']['ignore'] = $ignore;
$telemetry['telemetry']['containers']['total'] = count($containersTable);
$telemetry['telemetry']['containers']['update']['auto'] = $auto;
$telemetry['telemetry']['containers']['update']['check'] = $check;
$telemetry['telemetry']['containers']['update']['ignore'] = $ignore;
$telemetry['telemetry']['containers']['total'] = count($containersTable);

//-- GROUP INFO
$telemetry['telemetry']['groups']['total'] = count($groupsTable);
//-- GROUP INFO
$telemetry['telemetry']['groups']['total'] = count($groupsTable);

//-- SERVER INFO
$telemetry['telemetry']['servers']['total'] = count($serversTable);
//-- SERVER INFO
$telemetry['telemetry']['servers']['total'] = count($serversTable);

//-- COMPOSE INFO
$existingComposeFolders = [];
$dir = opendir(COMPOSE_PATH);
while ($folder = readdir($dir)) {
if ($folder[0] == '.') {
continue;
}

$existingComposeFolders[] = COMPOSE_PATH . $folder;
}
closedir($dir);

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

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

if ($notificationTable) {
foreach ($notificationTable as $notificationLink) {
if ($notificationLink['platform_id'] == NotificationPlatforms::NOTIFIARR) {
$telemetry['telemetry']['notifications']['notifiarr']++;
//-- COMPOSE INFO
$existingComposeFolders = [];
$dir = opendir(COMPOSE_PATH);
while ($folder = readdir($dir)) {
if ($folder[0] == '.') {
continue;
}
if ($notificationLink['platform_id'] == NotificationPlatforms::TELEGRAM) {
$telemetry['telemetry']['notifications']['telegram']++;

$existingComposeFolders[] = COMPOSE_PATH . $folder;
}
closedir($dir);

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

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

if ($notificationTable) {
foreach ($notificationTable as $notificationLink) {
if ($notificationLink['platform_id'] == NotificationPlatforms::NOTIFIARR) {
$telemetry['telemetry']['notifications']['notifiarr']++;
}
if ($notificationLink['platform_id'] == NotificationPlatforms::TELEGRAM) {
$telemetry['telemetry']['notifications']['telegram']++;
}
}
}
} else { //-- TELEMETRY IS DISABLED :(
$telemetry['telemetry']['error'] = 'Telemetry is disabled';
}

//-- PUSH THE TELEMETRY DATA
if ($send) {
curl(TELEMETRY_URL, [], 'POST', json_encode($telemetry));
curl(TELEMETRY_URL, [], 'POST', json_encode($telemetry), [], 10);
}

return $telemetry;
Expand Down

0 comments on commit 16e61ab

Please sign in to comment.