2024-07-30 16:13:21 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2024-08-16 16:20:45 +00:00
|
|
|
use App\Models\Host;
|
|
|
|
use App\Services\ZabbixService;
|
|
|
|
use Carbon\Carbon;
|
|
|
|
|
2024-07-30 16:13:21 +00:00
|
|
|
class HostController extends BaseController
|
|
|
|
{
|
|
|
|
public function index()
|
|
|
|
{
|
|
|
|
return view('hosts.index');
|
|
|
|
}
|
2024-08-16 16:20:45 +00:00
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
2024-07-30 16:13:21 +00:00
|
|
|
}
|