mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
add json_app_get and convert fail2ban over to JSON (#8571)
* add json_app_get function * add numeric testing and version support * now use json_app_get * remove some unneeded code * update the docs for json_app_get some more * make the format checker happy * add in min version support and now take extend name instead of the partial OID * hmm... don't make min version optional * add Exception usage for this all make min version actually work * minor formatting cleanup * minor style cleanup * update json_app_get with $throw_me setting * Use exceptions to fully handle errors. Always update the application. Include error message for use in UI. Move data to data key for easier parsing. Add test data * make a few changes to the lovely changes from @murrant * style cleanup * now attempt parsing it the old way if a error of -5 is returned * add new exceptions and rework them all * add new exceptions and min version 0 no longer bypasses the key checks * redo the error codes a bit and improve the comment about it all * fix a a bit of formatting * added JsonAppException and make the other JsonApp stuff a sub of it * note JsonAppException * fix class creation * JsonAppBlank now extends JsonApp * doh! add <?php * update the poller to properly use the new exceptions * no longer check for error twice and make sure the data key is present * cleanup processing of legacy scripts * tweak this a bit * white space fix * fix the tests for fail2ban
This commit is contained in:
21
LibreNMS/Exceptions/JsonAppBlankJsonException.php
Normal file
21
LibreNMS/Exceptions/JsonAppBlankJsonException.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace LibreNMS\Exceptions;
|
||||
|
||||
use Throwable;
|
||||
|
||||
class JsonAppBlankJsonException extends JsonAppException
|
||||
{
|
||||
private $output;
|
||||
|
||||
public function __construct($message, $output, $code = 0, Throwable $previous = null)
|
||||
{
|
||||
parent::__construct($message, $code, $previous);
|
||||
$this->output = $output;
|
||||
}
|
||||
|
||||
public function getOutput()
|
||||
{
|
||||
return $this->output;
|
||||
}
|
||||
}
|
8
LibreNMS/Exceptions/JsonAppException.php
Normal file
8
LibreNMS/Exceptions/JsonAppException.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace LibreNMS\Exceptions;
|
||||
|
||||
class JsonAppException extends \Exception
|
||||
{
|
||||
|
||||
}
|
28
LibreNMS/Exceptions/JsonAppExtendErroredException.php
Normal file
28
LibreNMS/Exceptions/JsonAppExtendErroredException.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace LibreNMS\Exceptions;
|
||||
|
||||
use Throwable;
|
||||
|
||||
class JsonAppExtendErroredException extends JsonAppException
|
||||
{
|
||||
private $output;
|
||||
private $parsed_json;
|
||||
|
||||
public function __construct($message, $output, $parsed_json = [], $code = 0, Throwable $previous = null)
|
||||
{
|
||||
parent::__construct($message, $code, $previous);
|
||||
$this->output = $output;
|
||||
$this->parsed_json = $parsed_json;
|
||||
}
|
||||
|
||||
public function getOutput()
|
||||
{
|
||||
return $this->output;
|
||||
}
|
||||
|
||||
public function getParsedJson()
|
||||
{
|
||||
return $this->parsed_json;
|
||||
}
|
||||
}
|
28
LibreNMS/Exceptions/JsonAppMissingKeysException.php
Normal file
28
LibreNMS/Exceptions/JsonAppMissingKeysException.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace LibreNMS\Exceptions;
|
||||
|
||||
use Throwable;
|
||||
|
||||
class JsonAppMissingKeysException extends JsonAppException
|
||||
{
|
||||
private $output;
|
||||
private $parsed_json;
|
||||
|
||||
public function __construct($message, $output, $parsed_json = [], $code = 0, Throwable $previous = null)
|
||||
{
|
||||
parent::__construct($message, $code, $previous);
|
||||
$this->output = $output;
|
||||
$this->parsed_json = $parsed_json;
|
||||
}
|
||||
|
||||
public function getOutput()
|
||||
{
|
||||
return $this->output;
|
||||
}
|
||||
|
||||
public function getParsedJson()
|
||||
{
|
||||
return $this->parsed_json;
|
||||
}
|
||||
}
|
21
LibreNMS/Exceptions/JsonAppParsingFailedException.php
Normal file
21
LibreNMS/Exceptions/JsonAppParsingFailedException.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace LibreNMS\Exceptions;
|
||||
|
||||
use Throwable;
|
||||
|
||||
class JsonAppParsingFailedException extends JsonAppException
|
||||
{
|
||||
private $output;
|
||||
|
||||
public function __construct($message, $output, $code = 0, Throwable $previous = null)
|
||||
{
|
||||
parent::__construct($message, $code, $previous);
|
||||
$this->output = $output;
|
||||
}
|
||||
|
||||
public function getOutput()
|
||||
{
|
||||
return $this->output;
|
||||
}
|
||||
}
|
8
LibreNMS/Exceptions/JsonAppPollingFailedException.php
Normal file
8
LibreNMS/Exceptions/JsonAppPollingFailedException.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace LibreNMS\Exceptions;
|
||||
|
||||
class JsonAppPollingFailedException extends JsonAppException
|
||||
{
|
||||
|
||||
}
|
28
LibreNMS/Exceptions/JsonAppWrongVersionException.php
Normal file
28
LibreNMS/Exceptions/JsonAppWrongVersionException.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace LibreNMS\Exceptions;
|
||||
|
||||
use Throwable;
|
||||
|
||||
class JsonAppWrongVersionException extends JsonAppException
|
||||
{
|
||||
private $output;
|
||||
private $parsed_json;
|
||||
|
||||
public function __construct($message, $output, $parsed_json = [], $code = 0, Throwable $previous = null)
|
||||
{
|
||||
parent::__construct($message, $code, $previous);
|
||||
$this->output = $output;
|
||||
$this->parsed_json = $parsed_json;
|
||||
}
|
||||
|
||||
public function getOutput()
|
||||
{
|
||||
return $this->output;
|
||||
}
|
||||
|
||||
public function getParsedJson()
|
||||
{
|
||||
return $this->parsed_json;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user