. * * @package LibreNMS * @link http://librenms.org * @copyright 2018 Tony Murray * @author Tony Murray */ namespace LibreNMS\Snmptrap; use LibreNMS\Config; use LibreNMS\Snmptrap\Handlers\Fallback; use LibreNMS\Alert\AlertRules; use Log; class Dispatcher { /** * Instantiate the correct handler for this trap and call it's handle method * */ public static function handle(Trap $trap) { if (empty($trap->getDevice())) { Log::warning("Could not find device for trap", ['trap_text' => $trap->getRaw()]); return false; } // note, this doesn't clear the resolved SnpmtrapHandler so only one per run /** @var \LibreNMS\Interfaces\SnmptrapHandler $handler */ $handler = app(\LibreNMS\Interfaces\SnmptrapHandler::class, [$trap->getTrapOid()]); $handler->handle($trap->getDevice(), $trap); // log an event if appropriate $fallback = $handler instanceof Fallback; $logging = Config::get('snmptraps.eventlog', 'unhandled'); if ($logging == 'all' || ($fallback && $logging == 'unhandled')) { Log::event("SNMP trap received: " . $trap->getTrapOid(), $trap->getDevice(), 'trap'); } else { $rules = new AlertRules; $rules->runRules($trap->getDevice()->device_id); } return !$fallback; } }