LAR_Maintenance/app/Http/Controllers/HostController.php

33 lines
721 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()
{
2024-08-16 21:37:42 +00:00
$zabbix = new ZabbixService(config('zabbix.url'));
$zabbix->connect(config('zabbix.username'), config('zabbix.password'));
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 21:37:42 +00:00
"external_id" => $host['hostid'],
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
}