Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //Status page to Discord Webhook
- $start_time = microtime(true);
- $UAstring = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:115.0) Gecko/20100101 Firefox/115.0";
- //Discord channel
- $webhook_url = 'https://discord.com/api/webhooks/--------Your Discord Web Hook----------------------------------------------------------';
- if ($_SERVER['REQUEST_METHOD'] != 'POST') {
- header('HTTP/1.0 405 Method Not Allowed');
- echo "Only POST requests allowed\n";
- exit();
- }
- if ($_SERVER['CONTENT_TYPE'] != 'application/json') {
- header('HTTP/1.0 415 Unsupported Media Type');
- echo "I only accept application/json data\n";
- exit();
- }
- $json = file_get_contents('php://input');
- $data = json_decode($json, true);
- if (!array_key_exists('incident', $data)) exit();
- $title = $data['incident']['name'];
- $link = $data['incident']['shortlink'];
- $timestamp = $data['incident']['updated_at'];
- $sta_str = $data['incident']['status'];
- if( $sta_str == 'investigating') $description = ":yellow_circle:";
- else if($sta_str == 'monitoring') $description = ":yellow_circle:";
- else if($sta_str == 'in_progress') $description = ":yellow_circle:";
- else if($sta_str == 'update') $description = ":red_circle:";
- else if($sta_str == 'identified') $description = ":red_circle:";
- else if($sta_str == 'resolved') $description = ":green_circle:";
- else if($sta_str == 'completed') $description = ":green_circle:";
- else if($sta_str == 'scheduled') $description = ":calendar:";
- else $description = ":white_circle:";
- //status文字を付加
- $description .= " **" . ucfirst($sta_str) . "**\n";
- //最新のupdate内容のみを付加
- if (count($data['incident']['incident_updates']) >= 1) {
- $description .= $data['incident']['incident_updates'][0]['body'];
- }
- $message = array(
- // "content" => "文字のところ 必要ならセットする。",
- "username" => "Status page",
- // "avatar_url" => "https://my-icons-server.com/avatar_icon.png",
- "embeds" => [
- [
- "title" => $title,
- "type" => "rich",
- "description" => $description,
- "url" => $link,
- "timestamp" => $timestamp,
- "color" => hexdec( "73ba00" )
- ]
- ]
- );
- //Discordへ出力
- $ch = curl_init();
- curl_setopt_array( $ch, [
- CURLOPT_URL => $webhook_url,
- CURLOPT_POST => true,
- CURLOPT_HTTPHEADER => array('Content-Type: application/json; charset=utf-8'),
- CURLOPT_USERAGENT => $UAstring,
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_SSL_VERIFYPEER => false,
- CURLOPT_POSTFIELDS => json_encode($message, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ),
- CURLOPT_TIMEOUT => 60
- ]);
- curl_exec($ch);
- curl_close($ch);
- $end_time = microtime(true);
- echo "ok";
- echo "\ntimes = " . ($end_time - $start_time) . " seconds.";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement