LAR_Maintenance/app/Http/Controllers/HostController.php

33 lines
721 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(config('zabbix.url'));
$zabbix->connect(config('zabbix.username'), config('zabbix.password'));
foreach ($zabbix->hosts() as $host) {
Host::updateOrCreate([
"hostname" => $host['host'],
], [
"display_name" => $host['name'],
"external_id" => $host['hostid'],
]);
}
return redirect()->back();
}
}