Commit 91344c37 authored by Jakob Moser's avatar Jakob Moser
Browse files

Add first working prototype

parent 592d40cb
Loading
Loading
Loading
Loading
+30 −13
Original line number Diff line number Diff line
<?php

// TODO Replace this with actual true data
$services = [
  array(
    "name" => "Website",
    "host" => "fachschaft.cl.uni-heidelberg.de",
    "status" => "up",
    "category" => "public"
  ),
  array(
    "name" => "Tickets",
    "host" => "tickets.cl.uni-heidelberg.de",
    "status" => "up",
    "category" => "public"
  ),
  ["name" => "Website", "host" => "fachschaft.cl.uni-heidelberg.de", "category" => "public"],
  ["name" => "Tickets", "host" => "tickets.fachschaft.cl.uni-heidelberg.de", "category" => "public"],
  ["name" => "Finanzen", "host" => "finanzen.fachschaft.cl.uni-heidelberg.de", "category" => "down"],
  ["name" => "Todo", "host" => "todo.fachschaft.cl.uni-heidelberg.de", "category" => "public"],
  ["name" => "Framadate", "host" => "framadate.fachschaft.cl.uni-heidelberg.de", "category" => "public"],
  ["name" => "Automation", "host" => "automation.fachschaft.cl.uni-heidelberg.de", "category" => "auth"],
  ["name" => "Traefik", "host" => "traefik.fachschaft.cl.uni-heidelberg.de", "category" => "auth"],
  ["name" => "Grafana", "host" => "grafana.fachschaft.cl.uni-heidelberg.de", "category" => "down"],
  ["name" => "Planet", "host" => "planet.fachschaft.cl.uni-heidelberg.de", "category" => "down"],
];

// The browser expects to see a Content-Type indication in the HTTP headers, so we
// send one. If we hadn't written this, the content type would be text/html.
header("Content-Type: application/json; charset=utf-8");

$multi_handle = curl_multi_init();
$handles = [];

foreach($services as $service) {
  $ch = curl_init("https://{$service['host']}");
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  $handles[] = $ch;

  curl_multi_add_handle($multi_handle, $ch);
}

$active_requests = -1;
do {
  curl_multi_exec($multi_handle, $active_requests);
  curl_multi_select($multi_handle);
} while($active_requests > 0);

foreach($handles as $index => $handle) {
  $services[$index]["status"] = curl_getinfo($handle, CURLINFO_RESPONSE_CODE);
}

// Everything that is written using `echo` is sent to the client (i.e. the browser)
echo json_encode($services);