Skip to content

Instantly share code, notes, and snippets.

@beberlei
Created November 20, 2021 23:20
Show Gist options
  • Save beberlei/1ce50c81c134d1567a4467316ec92092 to your computer and use it in GitHub Desktop.
Save beberlei/1ce50c81c134d1567a4467316ec92092 to your computer and use it in GitHub Desktop.
Migrate from Laravel Cachet to Atlassian StatusPage.io
<?php
use Buzz\Browser;
use Buzz\Client\Curl;
require_once __DIR__ . '/vendor/autoload.php';
$statusPageApiKey = "";
$statusPageId = "";
$nextUrl = 'https://status.tideways.io/api/v1/incidents'; // Cachet API endpoint
$curl = new Curl();
$curl->setTimeout(30);
$buzz = new Browser($curl);
$headers = ['Authorization: OAuth ' . $statusPageApiKey];
do {
$response = $buzz->get($nextUrl);
$payload = $response->getContent();
$incidents = json_decode($payload, true);
foreach ($incidents['data'] as $incident) {
$occurredAt = DateTime::createFromFormat('Y-m-d H:i:s', $incident['occurred_at']);
if ($incident['updates']) {
foreach (array_reverse($incident['updates']) as $update) {
$updateCreatedAt = DateTime::createFromFormat('Y-m-d H:i:s', $update['created_at']);
$incident['message'] .= "\n\n**Edit " . $updateCreatedAt->format('H:i') . ':** ' . $update['message'];
}
}
$response = $buzz->post('https://api.statuspage.io/v1/pages/' . $statusPageId . '/incidents', $headers, http_build_query([
'incident' => [
'name' => $incident['name'],
'body' => $incident['message'],
'backfilled' => true,
'backfill_date' => $occurredAt->format('Y-m-d'),
'deliver_notifications' => false,
'status' => 'resolved',
'impact_override' => 'major',
]
]));
echo $incident['name'] . " " . $occurredAt->format('Y-m-d') . "\n";
}
$nextUrl = $incidents['meta']['pagination']['links']['next_page'] ?? null;
} while ($nextUrl);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment