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

Show status history

parent 16330a83
No related branches found
No related tags found
No related merge requests found
...@@ -220,4 +220,8 @@ class Server extends Model ...@@ -220,4 +220,8 @@ class Server extends Model
return $this->parseProductName($record->system); return $this->parseProductName($record->system);
} }
public function getChanges($count = 10) {
return \App\StatusChange::getLastChangesForServer($this->id, $count);
}
} }
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
namespace App; namespace App;
use \Carbon\Carbon;
/** /**
* Represents a change of status, that will be saved in MongoDB. * Represents a change of status, that will be saved in MongoDB.
* *
...@@ -13,6 +15,29 @@ class StatusChange { ...@@ -13,6 +15,29 @@ class StatusChange {
public $status = 0; public $status = 0;
public $time = 0; public $time = 0;
public function parse($array) {
if ($array == null) {
return;
}
$fields = ["server_id", "status", "time"];
foreach ($fields as $field) {
if (isset($array[$field])) {
$this->$field = $array[$field];
}
}
return $this;
}
public function getStatusBadge() {
return AbstractSensor::getBadgeForStatus($this->status);
}
public function getTimeCarbon() : Carbon {
return Carbon::createFromTimestamp($this->time);
}
public static function save($status) { public static function save($status) {
$data = [ $data = [
"time" => time(), "time" => time(),
...@@ -25,6 +50,19 @@ class StatusChange { ...@@ -25,6 +50,19 @@ class StatusChange {
$collection->insertOne($data); $collection->insertOne($data);
} }
public static function getLastChangesForServer(int $server_id, int $count) : array {
$collection = \Mongo::get()->monitoring->statuschanges;
$records = $collection->find(
["server_id" => $server_id],
["limit" => $count, "sort" => ["_id" => -1]]);
$changes = [];
foreach ($records as $record) {
$changes[] = (new StatusChange())->parse($record);
}
return $changes;
}
public static function getLastChangeForServer(int $server_id) : StatusChange { public static function getLastChangeForServer(int $server_id) : StatusChange {
$collection = \Mongo::get()->monitoring->statuschanges; $collection = \Mongo::get()->monitoring->statuschanges;
$record = $collection->findOne( $record = $collection->findOne(
...@@ -33,13 +71,7 @@ class StatusChange { ...@@ -33,13 +71,7 @@ class StatusChange {
$change = new StatusChange(); $change = new StatusChange();
$change->server_id = $server_id; $change->server_id = $server_id;
$change->parse($record);
if ($record == null) {
return $change;
}
$change->time = $record["time"];
$change->status = $record["status"];
return $change; return $change;
} }
} }
...@@ -94,6 +94,22 @@ window.monitorServerToken = "{{ $server->read_token }}"; ...@@ -94,6 +94,22 @@ window.monitorServerToken = "{{ $server->read_token }}";
</div> </div>
@endforeach @endforeach
<div class="card">
<div class="card-header">
History
</div>
<div class="card-body">
<table class='table table-sm'>
@foreach($server->getChanges() as $change)
<tr>
<td>{{ $change->getTimeCarbon()->toDateTimeString() }}</td>
<td>{!! $change->getStatusBadge() !!}</td>
</tr>
@endforeach
</table>
</div>
</div>
<h3>PHP Client installation</h3> <h3>PHP Client installation</h3>
<pre style="font-size: 75%; background: #ddd; overflow: hidden"><code> <pre style="font-size: 75%; background: #ddd; overflow: hidden"><code>
wget https://gitlab.cylab.be/cylab/monitoring/raw/master/php-client/bin/monitor.phar wget https://gitlab.cylab.be/cylab/monitoring/raw/master/php-client/bin/monitor.phar
......
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