Files
librenms-librenms/LibreNMS/Exceptions/HostUnreachableException.php

72 lines
1.9 KiB
PHP
Raw Normal View History

2016-08-08 15:47:35 -05:00
<?php
/**
* HostUnreachableException.php
2016-08-08 15:47:35 -05:00
*
* -Description-
2016-08-08 15:47:35 -05:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2016-08-08 15:47:35 -05:00
*
* @link https://www.librenms.org
2021-09-10 20:09:53 +02:00
*
2016-08-08 15:47:35 -05:00
* @copyright 2016 Tony Murray
* @author Tony Murray <murraytony@gmail.com>
*/
namespace LibreNMS\Exceptions;
2016-08-08 15:47:35 -05:00
class HostUnreachableException extends \Exception
2016-08-08 15:47:35 -05:00
{
protected $reasons = [];
2016-08-08 15:47:35 -05:00
public function __toString()
{
$string = __CLASS__ . ": [{$this->code}]: {$this->message}\n";
foreach ($this->reasons as $reason) {
$string .= " $reason\n";
}
2016-08-08 15:47:35 -05:00
return $string;
}
/**
* Add additional reasons
2021-09-10 20:09:53 +02:00
*
* @param string $snmpVersion
* @param string $credentials
2016-08-08 15:47:35 -05:00
*/
public function addReason(string $snmpVersion, string $credentials)
2016-08-08 15:47:35 -05:00
{
$vars = [
'snmpver' => $snmpVersion,
'credentials' => $credentials,
];
if ($snmpVersion == 'v3') {
$this->reasons[] = trans('exceptions.host_unreachable.no_reply_credentials', $vars);
} else {
$this->reasons[] = trans('exceptions.host_unreachable.no_reply_community', $vars);
}
2016-08-08 15:47:35 -05:00
}
/**
* Get the reasons
2021-09-10 20:09:53 +02:00
*
2016-08-08 15:47:35 -05:00
* @return array
*/
public function getReasons()
{
return $this->reasons;
}
}