Skip to content
Snippets Groups Projects
Commit 5f753f0f authored by Tibo's avatar Tibo
Browse files

Add SSACLI sensor

parent b64424df
No related branches found
No related tags found
No related merge requests found
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
namespace App\Sensor;
/**
......@@ -20,18 +14,17 @@ class Disks extends \App\AbstractSensor {
public function report() {
$record = $this->getLastRecord("disks");
if ($record == null) {
return "<p>No data availabe...</p>";
return "<p>No data available...</p>";
}
$disks = $this->parse($record->disks);
$partitions = $this->parse($record->disks);
$return = "<table class='table table-sm'>";
$return .= "<tr><th></th><th></th><th>Usage</th></tr>";
foreach ($disks as $disk) {
$return .= "<tr><td>" . $disk->filesystem . "</td><td>" . $disk->mounted . "</td><td>" . $disk->usedPercent() . "%</td></tr>";
foreach ($partitions as $partition) {
$return .= "<tr><td>" . $partition->filesystem . "</td><td>" . $partition->mounted . "</td><td>" . $partition->usedPercent() . "%</td></tr>";
}
$return .= "</table>";
return $return;
}
public function status() {
......@@ -41,12 +34,12 @@ class Disks extends \App\AbstractSensor {
}
$all_status = [];
foreach ($this->parse($record->disks) as $disk) {
/* @var $disk Disk */
foreach ($this->parse($record->disks) as $partition) {
/* @var $partition Partition */
$status = self::STATUS_OK;
if ($disk->usedPercent() > 80) {
if ($partition->usedPercent() > 80) {
$status = self::STATUS_WARNING;
} elseif ($disk->usedPercent() > 95) {
} elseif ($partition->usedPercent() > 95) {
$status = self::STATUS_ERROR;
}
$all_status[] = $status;
......@@ -60,7 +53,7 @@ class Disks extends \App\AbstractSensor {
public function parse($string) {
$values = array();
preg_match_all(self::REGEXP, $string, $values);
$disks = array();
$partitions = array();
$count = count($values[1]);
for ($i = 0; $i < $count; $i++) {
$fs = $values[1][$i];
......@@ -68,18 +61,18 @@ class Disks extends \App\AbstractSensor {
continue;
}
$disk = new Disk();
$disk->filesystem = $fs;
$disk->blocks = $values[2][$i];
$disk->used = $values[3][$i];
$disk->mounted = $values[6][$i];
$disks[] = $disk;
$partition = new Partition();
$partition->filesystem = $fs;
$partition->blocks = $values[2][$i];
$partition->used = $values[3][$i];
$partition->mounted = $values[6][$i];
$partitions[] = $partition;
}
return $disks;
return $partitions;
}
}
class Disk {
class Partition {
public $filesystem = "";
public $blocks = 0;
public $used = 0;
......
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
namespace App\Sensor;
/**
* Description of Ssacli
*
* @author tibo
*/
class Ssacli extends \App\AbstractSensor {
const REGEXP = "/\s*physicaldrive .*\(port (.*):box (\d*):bay (\d*), (.*), (.*), (\w*)\)/";
public function report() {
$record = $this->getLastRecord("ssacli");
if ($record == null) {
return "<p>No data available...</p>";
}
$disks = $this->parse($record->ssacli);
$return = "<table class='table table-sm'>";
foreach ($disks as $disk) {
$return .= "<tr>"
. "<td>" . $disk->port . "</td>"
. "<td>" . $disk->bay . "</td>"
. "<td>" . $disk->box . "</td>"
. "<td>" . $disk->type . "</td>"
. "<td>" . $disk->size . "</td>"
. "<td>" . $disk->status . "</td>"
. "</tr>";
}
$return .= "</table>";
return $return;
}
public function status() {
return \App\AbstractSensor::STATUS_OK;
}
/**
*
* @param type $string
* @return \App\Sensor\Disk[]
*/
public function parse($string) {
$values = array();
preg_match_all(self::REGEXP, $string, $values);
$disks = array();
$count = count($values[1]);
for ($i = 0; $i < $count; $i++) {
$disk = new Disk();
$disk->port = $values[1][$i];
$disk->box = $values[2][$i];
$disk->bay = $values[3][$i];
$disk->type = $values[4][$i];
$disk->size = $values[5][$i];
$disk->status = $values[6][$i];
$disks[] = $disk;
}
return $disks;
}
}
class Disk {
public $port = "";
public $box = 0;
public $bay = 0;
public $type = "";
public $size = "";
public $status = "";
}
\ No newline at end of file
......@@ -22,6 +22,7 @@ class Server extends Model
\App\Sensor\Updates::class,
\App\Sensor\Disks::class,
\App\Sensor\Inodes::class,
\App\Sensor\Ssacli::class,
\App\Sensor\Date::class,
\App\Sensor\ClientVersion::class
];
......
......@@ -48,6 +48,13 @@ class ExampleTest extends TestCase
$this->assertEquals(1128926648, $disks[1]->blocks);
}
public function testSsacli() {
$string = file_get_contents(__DIR__ . "/ssacli");
$sensor = new \App\Sensor\Ssacli(new \App\Server());
$disks = $sensor->parse($string);
$this->assertEquals("OK", $disks[0]->status);
}
public function testUpdates() {
$string = "6 packages can be updated.
2 updates are security updates.";
......
Smart Array P830i in Slot 0 (Embedded) (sn: 0014380405C1600)
Port Name: 1I
Port Name: 2I
Internal Drive Cage at Port 1I, Box 1, OK
Internal Drive Cage at Port 1I, Box 1, OK
Array A (SAS, Unused Space: 0 MB)
logicaldrive 1 (838.3 GB, RAID 1, OK)
physicaldrive 1I:1:1 (port 1I:box 1:bay 1, SAS HDD, 900 GB, OK)
physicaldrive 1I:1:2 (port 1I:box 1:bay 2, SAS HDD, 900 GB, OK)
Array B (SAS, Unused Space: 0 MB)
logicaldrive 2 (1.6 TB, RAID 5, OK)
physicaldrive 1I:1:3 (port 1I:box 1:bay 3, SAS HDD, 900 GB, OK)
physicaldrive 1I:1:4 (port 1I:box 1:bay 4, SAS HDD, 900 GB, OK)
physicaldrive 1I:1:5 (port 1I:box 1:bay 5, SAS HDD, 900 GB, OK)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment