LAR_Maintenance/app/Http/Controllers/HostController.php
2024-08-16 18:20:45 +02:00

37 lines
926 B
PHP

<?php
namespace App\Http\Controllers;
use App\Models\Host;
use App\Services\ZabbixService;
use Carbon\Carbon;
class HostController extends BaseController
{
public function index()
{
return view('hosts.index');
}
public function sync()
{
$zabbix = new ZabbixService("https://zabbix.itego.cz");
$zabbix->connect("spaninger", "*");
foreach ( $zabbix->maintenances([ "selectTimeperiods" => "extend" ]) as $maintennace ) {
if(!Carbon::createFromTimestamp($maintennace['active_till'])->isPast()){
dd(Carbon::createFromTimestamp($maintennace['active_till']));
}
}
foreach ($zabbix->hosts() as $host) {
Host::updateOrCreate([
"hostname" => $host['host'],
], [
"display_name" => $host['name'],
]);
}
return redirect()->back();
}
}