2024-07-30 18:13:21 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2024-08-16 18:20:45 +02:00
|
|
|
use App\Models\Host;
|
|
|
|
use App\Services\ZabbixService;
|
|
|
|
use Carbon\Carbon;
|
|
|
|
|
2024-07-30 18:13:21 +02:00
|
|
|
class HostController extends BaseController
|
|
|
|
{
|
|
|
|
public function index()
|
|
|
|
{
|
|
|
|
return view('hosts.index');
|
|
|
|
}
|
2024-08-16 18:20:45 +02:00
|
|
|
|
|
|
|
public function sync()
|
|
|
|
{
|
2024-08-16 23:37:42 +02:00
|
|
|
$zabbix = new ZabbixService(config('zabbix.url'));
|
|
|
|
$zabbix->connect(config('zabbix.username'), config('zabbix.password'));
|
2024-08-16 18:20:45 +02:00
|
|
|
|
|
|
|
foreach ($zabbix->hosts() as $host) {
|
|
|
|
Host::updateOrCreate([
|
2024-08-16 18:23:04 +02:00
|
|
|
"hostname" => $host['host'],
|
2024-08-16 18:20:45 +02:00
|
|
|
], [
|
2024-08-16 18:23:04 +02:00
|
|
|
"display_name" => $host['name'],
|
2024-08-16 23:37:42 +02:00
|
|
|
"external_id" => $host['hostid'],
|
2024-08-16 18:20:45 +02:00
|
|
|
]);
|
|
|
|
}
|
2024-08-16 18:23:04 +02:00
|
|
|
|
2024-08-16 18:20:45 +02:00
|
|
|
return redirect()->back();
|
|
|
|
}
|
2024-07-30 18:13:21 +02:00
|
|
|
}
|