LAR_Maintenance/app/Http/Controllers/HostController.php

40 lines
947 B
PHP
Raw Normal View History

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 ) {
2024-08-16 16:23:04 +00:00
if(Carbon::createFromTimestamp($maintennace['active_till'])->isPast()){
continue;
2024-08-16 16:20:45 +00:00
}
2024-08-16 16:23:04 +00:00
dd(Carbon::createFromTimestamp($maintennace['active_till']));
2024-08-16 16:20:45 +00:00
}
foreach ($zabbix->hosts() as $host) {
Host::updateOrCreate([
2024-08-16 16:23:04 +00:00
"hostname" => $host['host'],
2024-08-16 16:20:45 +00:00
], [
2024-08-16 16:23:04 +00:00
"display_name" => $host['name'],
2024-08-16 16:20:45 +00:00
]);
}
2024-08-16 16:23:04 +00:00
2024-08-16 16:20:45 +00:00
return redirect()->back();
}
2024-07-30 16:13:21 +00:00
}