From ecf987820d366bb5ee50db79e18aaa262d4370f8 Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Mon, 2 Sep 2024 21:06:03 +0200 Subject: [PATCH] reporting: style sweep --- .../health/library/OPNsense/RRD/Factory.php | 22 +++++++-------- .../library/OPNsense/RRD/Stats/Base.php | 2 +- .../library/OPNsense/RRD/Stats/Interfaces.php | 2 +- .../library/OPNsense/RRD/Stats/Mbuf.php | 3 --- .../library/OPNsense/RRD/Stats/Memory.php | 3 --- .../health/library/OPNsense/RRD/Stats/Ntp.php | 3 --- .../library/OPNsense/RRD/Stats/OpenVPN.php | 3 --- .../library/OPNsense/RRD/Stats/Processor.php | 5 +--- .../library/OPNsense/RRD/Stats/States.php | 3 --- .../OPNsense/RRD/Stats/Temperature.php | 6 ----- .../library/OPNsense/RRD/Types/Base.php | 27 +++++++++---------- .../OPNsense/RRD/Types/GatewayQuality.php | 2 +- .../library/OPNsense/RRD/Types/Mbuf.php | 2 +- .../library/OPNsense/RRD/Types/Memory.php | 2 +- .../health/library/OPNsense/RRD/Types/Ntp.php | 2 +- .../library/OPNsense/RRD/Types/OpenVPN.php | 2 +- .../library/OPNsense/RRD/Types/Packets.php | 2 +- .../library/OPNsense/RRD/Types/Processor.php | 2 +- .../library/OPNsense/RRD/Types/States.php | 2 +- .../OPNsense/RRD/Types/Temperature.php | 2 +- .../library/OPNsense/RRD/Types/Traffic.php | 2 +- .../library/OPNsense/RRD/Types/Wireless.php | 2 +- src/opnsense/scripts/health/updaterrd.php | 4 +-- 23 files changed, 40 insertions(+), 65 deletions(-) diff --git a/src/opnsense/scripts/health/library/OPNsense/RRD/Factory.php b/src/opnsense/scripts/health/library/OPNsense/RRD/Factory.php index 69d71a77e..06a70a9a2 100644 --- a/src/opnsense/scripts/health/library/OPNsense/RRD/Factory.php +++ b/src/opnsense/scripts/health/library/OPNsense/RRD/Factory.php @@ -28,10 +28,11 @@ namespace OPNsense\RRD; - use ReflectionClass; -class TypeNotFound extends \Exception { } +class TypeNotFound extends \Exception +{ +} /** * RRD Factory class, offers access to RRD types and statistics. @@ -52,7 +53,7 @@ class Factory public function get(string $type, string $target) { try { - $cls = new ReflectionClass('\\OPNsense\\RRD\\Types\\'. $type); + $cls = new ReflectionClass('\\OPNsense\\RRD\\Types\\' . $type); if (!$cls->isInstantiable() || !$cls->isSubclassOf('OPNsense\\RRD\\Types\\Base')) { throw new TypeNotFound(sprintf("%s not found", $type)); } @@ -71,8 +72,8 @@ class Factory { $this->stats = []; foreach (glob(sprintf("%s/Stats/*.php", __DIR__)) as $filename) { - $classname = substr(basename($filename),0, -4); - $cls = new ReflectionClass('\\OPNsense\\RRD\\Stats\\'. $classname); + $classname = substr(basename($filename), 0, -4); + $cls = new ReflectionClass('\\OPNsense\\RRD\\Stats\\' . $classname); if ($cls->isInstantiable() && $cls->isSubclassOf('OPNsense\\RRD\\Stats\\Base')) { try { $start_time = microtime(true); @@ -82,7 +83,7 @@ class Factory 'data' => $tmp, 'runtime' => microtime(true) - $start_time ]; - } catch (\Error | \Exception $e) { + } catch (\Error | \Exception $e) { echo $e; syslog(LOG_ERR, sprintf("Error collecting %s [%s]", $classname, $e)); } @@ -113,11 +114,11 @@ class Factory * update all registered RRD graphs * @return $this */ - public function updateAll($debug=false) + public function updateAll($debug = false) { foreach (glob(sprintf("%s/Types/*.php", __DIR__)) as $filename) { - $classname = substr(basename($filename),0, -4); - $fclassname = '\\OPNsense\\RRD\\Types\\'. $classname; + $classname = substr(basename($filename), 0, -4); + $fclassname = '\\OPNsense\\RRD\\Types\\' . $classname; try { $cls = new ReflectionClass($fclassname); if ($cls->isInstantiable() && $cls->isSubclassOf('OPNsense\\RRD\\Types\\Base')) { @@ -142,7 +143,6 @@ class Factory $obj->create(); /* only creates when no target exists yet */ $obj->update($data, $debug); } - } } catch (\Error | \Exception $e) { echo $e; @@ -151,4 +151,4 @@ class Factory } return $this; } -} \ No newline at end of file +} diff --git a/src/opnsense/scripts/health/library/OPNsense/RRD/Stats/Base.php b/src/opnsense/scripts/health/library/OPNsense/RRD/Stats/Base.php index 8953d2dbc..5f04d3e3f 100644 --- a/src/opnsense/scripts/health/library/OPNsense/RRD/Stats/Base.php +++ b/src/opnsense/scripts/health/library/OPNsense/RRD/Stats/Base.php @@ -102,4 +102,4 @@ abstract class Base { throw new \Exception("Need to implement run()"); } -} \ No newline at end of file +} diff --git a/src/opnsense/scripts/health/library/OPNsense/RRD/Stats/Interfaces.php b/src/opnsense/scripts/health/library/OPNsense/RRD/Stats/Interfaces.php index 3074f665a..a79c13406 100644 --- a/src/opnsense/scripts/health/library/OPNsense/RRD/Stats/Interfaces.php +++ b/src/opnsense/scripts/health/library/OPNsense/RRD/Stats/Interfaces.php @@ -44,4 +44,4 @@ class Interfaces extends Base } return $result; } -} \ No newline at end of file +} diff --git a/src/opnsense/scripts/health/library/OPNsense/RRD/Stats/Mbuf.php b/src/opnsense/scripts/health/library/OPNsense/RRD/Stats/Mbuf.php index 2fd468105..3ade07705 100644 --- a/src/opnsense/scripts/health/library/OPNsense/RRD/Stats/Mbuf.php +++ b/src/opnsense/scripts/health/library/OPNsense/RRD/Stats/Mbuf.php @@ -49,6 +49,3 @@ class Mbuf extends Base return []; } } - - - diff --git a/src/opnsense/scripts/health/library/OPNsense/RRD/Stats/Memory.php b/src/opnsense/scripts/health/library/OPNsense/RRD/Stats/Memory.php index baf6a7065..9e1e77edd 100644 --- a/src/opnsense/scripts/health/library/OPNsense/RRD/Stats/Memory.php +++ b/src/opnsense/scripts/health/library/OPNsense/RRD/Stats/Memory.php @@ -58,6 +58,3 @@ class Memory extends Base return []; } } - - - diff --git a/src/opnsense/scripts/health/library/OPNsense/RRD/Stats/Ntp.php b/src/opnsense/scripts/health/library/OPNsense/RRD/Stats/Ntp.php index 5cc831426..a75cc2c71 100644 --- a/src/opnsense/scripts/health/library/OPNsense/RRD/Stats/Ntp.php +++ b/src/opnsense/scripts/health/library/OPNsense/RRD/Stats/Ntp.php @@ -58,6 +58,3 @@ class Ntp extends Base return $data; } } - - - diff --git a/src/opnsense/scripts/health/library/OPNsense/RRD/Stats/OpenVPN.php b/src/opnsense/scripts/health/library/OPNsense/RRD/Stats/OpenVPN.php index 2e6ff68c7..65ba7b2eb 100644 --- a/src/opnsense/scripts/health/library/OPNsense/RRD/Stats/OpenVPN.php +++ b/src/opnsense/scripts/health/library/OPNsense/RRD/Stats/OpenVPN.php @@ -51,6 +51,3 @@ class OpenVPN extends Base return $result; } } - - - diff --git a/src/opnsense/scripts/health/library/OPNsense/RRD/Stats/Processor.php b/src/opnsense/scripts/health/library/OPNsense/RRD/Stats/Processor.php index f8b683e49..b369672a7 100644 --- a/src/opnsense/scripts/health/library/OPNsense/RRD/Stats/Processor.php +++ b/src/opnsense/scripts/health/library/OPNsense/RRD/Stats/Processor.php @@ -41,12 +41,9 @@ class Processor extends Base 'nice' => $tmp[1], 'system' => $tmp[2], 'interrupt' => $tmp[3], - 'processes' => count($ps)-1 + 'processes' => count($ps) - 1 ]; } return []; } } - - - diff --git a/src/opnsense/scripts/health/library/OPNsense/RRD/Stats/States.php b/src/opnsense/scripts/health/library/OPNsense/RRD/Stats/States.php index add1e27ee..dec6c9dbc 100644 --- a/src/opnsense/scripts/health/library/OPNsense/RRD/Stats/States.php +++ b/src/opnsense/scripts/health/library/OPNsense/RRD/Stats/States.php @@ -39,6 +39,3 @@ class States extends Base return []; } } - - - diff --git a/src/opnsense/scripts/health/library/OPNsense/RRD/Stats/Temperature.php b/src/opnsense/scripts/health/library/OPNsense/RRD/Stats/Temperature.php index 30736aeb7..059d9a165 100644 --- a/src/opnsense/scripts/health/library/OPNsense/RRD/Stats/Temperature.php +++ b/src/opnsense/scripts/health/library/OPNsense/RRD/Stats/Temperature.php @@ -41,9 +41,3 @@ class Temperature extends Base return []; } } - - - - - - diff --git a/src/opnsense/scripts/health/library/OPNsense/RRD/Types/Base.php b/src/opnsense/scripts/health/library/OPNsense/RRD/Types/Base.php index f9388f61d..403642146 100644 --- a/src/opnsense/scripts/health/library/OPNsense/RRD/Types/Base.php +++ b/src/opnsense/scripts/health/library/OPNsense/RRD/Types/Base.php @@ -103,10 +103,10 @@ abstract class Base public function addDataset( string $name, string $opp, - ?int $heartbeat=null, - ?int $min=null, - ?int $max=null - ){ + ?int $heartbeat = null, + ?int $min = null, + ?int $max = null + ) { $this->datasets[] = [ $name, $opp, @@ -128,12 +128,12 @@ abstract class Base public function addDatasets( array $names, string $opp, - ?int $heartbeat=null, - ?int $min=null, - ?int $max=null - ){ + ?int $heartbeat = null, + ?int $min = null, + ?int $max = null + ) { foreach ($names as $name) { - $this->addDataset($name, $opp, $heartbeat, $min, $max); + $this->addDataset($name, $opp, $heartbeat, $min, $max); } return $this; } @@ -143,7 +143,7 @@ abstract class Base * @param bool $overwrite overwrite when file exists * @return $this */ - public function create($overwrite=false) + public function create($overwrite = false) { if (!$overwrite && file_exists($this->filename)) { return $this; @@ -152,8 +152,7 @@ abstract class Base foreach ($this->datasets as $dataset) { $cmd_text .= 'DS:' . implode(':', $dataset) . ' '; } - foreach ($this->round_robin_archives as $rra) - { + foreach ($this->round_robin_archives as $rra) { $cmd_text .= 'RRA:' . implode(':', $rra) . ' '; } $cmd_text .= ' 2>&1'; @@ -174,7 +173,7 @@ abstract class Base * @param bool $debug throw debug messages to stdout * @return $this */ - public function update(array $dataset = [], bool $debug=false) + public function update(array $dataset = [], bool $debug = false) { $values = []; $map_by_name = count($dataset) > 0 && !isset($dataset[0]); @@ -205,4 +204,4 @@ abstract class Base $tmp = explode('\\', static::class); return array_pop($tmp); } -} \ No newline at end of file +} diff --git a/src/opnsense/scripts/health/library/OPNsense/RRD/Types/GatewayQuality.php b/src/opnsense/scripts/health/library/OPNsense/RRD/Types/GatewayQuality.php index c877af5b7..df1c60158 100644 --- a/src/opnsense/scripts/health/library/OPNsense/RRD/Types/GatewayQuality.php +++ b/src/opnsense/scripts/health/library/OPNsense/RRD/Types/GatewayQuality.php @@ -56,4 +56,4 @@ class GatewayQuality extends Base yield static::$basedir . sprintf(static::$stdfilename, $gw) => $data; } } -} \ No newline at end of file +} diff --git a/src/opnsense/scripts/health/library/OPNsense/RRD/Types/Mbuf.php b/src/opnsense/scripts/health/library/OPNsense/RRD/Types/Mbuf.php index 51b3552cf..50db59d2c 100644 --- a/src/opnsense/scripts/health/library/OPNsense/RRD/Types/Mbuf.php +++ b/src/opnsense/scripts/health/library/OPNsense/RRD/Types/Mbuf.php @@ -60,4 +60,4 @@ class Mbuf extends Base ['MAX', 0.5, 1440, 2284], ]); } -} \ No newline at end of file +} diff --git a/src/opnsense/scripts/health/library/OPNsense/RRD/Types/Memory.php b/src/opnsense/scripts/health/library/OPNsense/RRD/Types/Memory.php index eca877205..64a21c15b 100644 --- a/src/opnsense/scripts/health/library/OPNsense/RRD/Types/Memory.php +++ b/src/opnsense/scripts/health/library/OPNsense/RRD/Types/Memory.php @@ -60,4 +60,4 @@ class Memory extends Base ['MAX', 0.5, 1440, 2284], ]); } -} \ No newline at end of file +} diff --git a/src/opnsense/scripts/health/library/OPNsense/RRD/Types/Ntp.php b/src/opnsense/scripts/health/library/OPNsense/RRD/Types/Ntp.php index 2fd9bf4af..7bedb857d 100644 --- a/src/opnsense/scripts/health/library/OPNsense/RRD/Types/Ntp.php +++ b/src/opnsense/scripts/health/library/OPNsense/RRD/Types/Ntp.php @@ -61,4 +61,4 @@ class Ntp extends Base ['MAX', 0.5, 1440, 2284], ]); } -} \ No newline at end of file +} diff --git a/src/opnsense/scripts/health/library/OPNsense/RRD/Types/OpenVPN.php b/src/opnsense/scripts/health/library/OPNsense/RRD/Types/OpenVPN.php index 7d1e77e1d..d0a16d5ed 100644 --- a/src/opnsense/scripts/health/library/OPNsense/RRD/Types/OpenVPN.php +++ b/src/opnsense/scripts/health/library/OPNsense/RRD/Types/OpenVPN.php @@ -57,4 +57,4 @@ class OpenVPN extends Base yield static::$basedir . sprintf(static::$stdfilename, $intf) => $data; } } -} \ No newline at end of file +} diff --git a/src/opnsense/scripts/health/library/OPNsense/RRD/Types/Packets.php b/src/opnsense/scripts/health/library/OPNsense/RRD/Types/Packets.php index 67b78430a..05b151c2e 100644 --- a/src/opnsense/scripts/health/library/OPNsense/RRD/Types/Packets.php +++ b/src/opnsense/scripts/health/library/OPNsense/RRD/Types/Packets.php @@ -77,4 +77,4 @@ class Packets extends Base yield static::$basedir . sprintf(static::$stdfilename, $intf) => $tmp; } } -} \ No newline at end of file +} diff --git a/src/opnsense/scripts/health/library/OPNsense/RRD/Types/Processor.php b/src/opnsense/scripts/health/library/OPNsense/RRD/Types/Processor.php index 38165d8ed..c9bbd53fc 100644 --- a/src/opnsense/scripts/health/library/OPNsense/RRD/Types/Processor.php +++ b/src/opnsense/scripts/health/library/OPNsense/RRD/Types/Processor.php @@ -46,4 +46,4 @@ class Processor extends Base parent::__construct($filename); $this->addDatasets(['user', 'nice', 'system', 'interrupt', 'processes'], 'GAUGE'); } -} \ No newline at end of file +} diff --git a/src/opnsense/scripts/health/library/OPNsense/RRD/Types/States.php b/src/opnsense/scripts/health/library/OPNsense/RRD/Types/States.php index 05c5c563e..dc6738aad 100644 --- a/src/opnsense/scripts/health/library/OPNsense/RRD/Types/States.php +++ b/src/opnsense/scripts/health/library/OPNsense/RRD/Types/States.php @@ -46,4 +46,4 @@ class States extends Base parent::__construct($filename); $this->addDatasets(['pfrate', 'pfstates', 'pfnat', 'srcip', 'dstip'], 'GAUGE'); } -} \ No newline at end of file +} diff --git a/src/opnsense/scripts/health/library/OPNsense/RRD/Types/Temperature.php b/src/opnsense/scripts/health/library/OPNsense/RRD/Types/Temperature.php index 46ae836ca..ebdceb929 100644 --- a/src/opnsense/scripts/health/library/OPNsense/RRD/Types/Temperature.php +++ b/src/opnsense/scripts/health/library/OPNsense/RRD/Types/Temperature.php @@ -63,4 +63,4 @@ class Temperature extends Base ['LAST', 0.5, 1440, 2284], ]); } -} \ No newline at end of file +} diff --git a/src/opnsense/scripts/health/library/OPNsense/RRD/Types/Traffic.php b/src/opnsense/scripts/health/library/OPNsense/RRD/Types/Traffic.php index da1a9a77f..06e034acb 100644 --- a/src/opnsense/scripts/health/library/OPNsense/RRD/Types/Traffic.php +++ b/src/opnsense/scripts/health/library/OPNsense/RRD/Types/Traffic.php @@ -77,4 +77,4 @@ class Traffic extends Base yield static::$basedir . sprintf(static::$stdfilename, $intf) => $tmp; } } -} \ No newline at end of file +} diff --git a/src/opnsense/scripts/health/library/OPNsense/RRD/Types/Wireless.php b/src/opnsense/scripts/health/library/OPNsense/RRD/Types/Wireless.php index 030c961f5..e40a64491 100644 --- a/src/opnsense/scripts/health/library/OPNsense/RRD/Types/Wireless.php +++ b/src/opnsense/scripts/health/library/OPNsense/RRD/Types/Wireless.php @@ -45,4 +45,4 @@ class Wireless extends Base parent::__construct($filename); $this->addDatasets(['snr','rate','channel'], 'GAUGE'); } -} \ No newline at end of file +} diff --git a/src/opnsense/scripts/health/updaterrd.php b/src/opnsense/scripts/health/updaterrd.php index e1022e310..d4b70a98f 100755 --- a/src/opnsense/scripts/health/updaterrd.php +++ b/src/opnsense/scripts/health/updaterrd.php @@ -53,7 +53,7 @@ if ($rrdcnf === null || !isset($rrdcnf->enable)) { exit(0); } -$start_time = microtime(True); +$start_time = microtime(true); if (!is_dir('/var/db/rrd')) { @mkdir('/var/db/rrd', 0775); @@ -65,7 +65,7 @@ $rrd_factory->collect()->updateAll(isset($opts['d'])); if (isset($opts['d'])) { $collect_time = 0.0; - echo sprintf("total runtime [seconds] \t: %0.2f\n", microtime(True) - $start_time); + echo sprintf("total runtime [seconds] \t: %0.2f\n", microtime(true) - $start_time); foreach ($rrd_factory->getRawStats() as $name => $payload) { $collect_time += $payload['runtime']; }