Show when a device was added and last discovered (#11104)

* Add inserted column to devices table

* Added schema for devices.inserted

* Show when a device was added and last discovered

* Added collection rule for "Device added within the last 60 minutes"
This commit is contained in:
Joseph Tingiris
2020-02-05 15:06:43 -05:00
committed by GitHub
parent ac84eea243
commit 79bdbe91b5
4 changed files with 55 additions and 7 deletions

View File

@@ -0,0 +1,34 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddInsertedToDevices extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('devices', function (Blueprint $table) {
// add inserted column after device id with a default of current_timestamp
$table->timestamp('inserted')->default(DB::raw('CURRENT_TIMESTAMP'))->after('device_id');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('devices', function (Blueprint $table) {
// revert add inserted column after device id with a default of current_timestamp
$table->dropColumn('inserted');
});
}
}

View File

@@ -23,9 +23,6 @@ echo '</div><div class="panel-body">';
echo '<script src="js/leaflet.js"></script>';
echo '<script src="js/L.Control.Locate.min.js"></script>';
$uptime = (Time::formatInterval($device['status'] ? $device['uptime'] : time() - strtotime($device['last_polled'])));
$uptime_text = ($device['status'] ? 'Uptime' : 'Downtime');
if ($device['os'] == 'ios' || $device['os'] == 'iosxe') {
formatCiscoHardware($device);
}
@@ -103,11 +100,23 @@ if ($device['sysContact']) {
</div>';
}
if (!empty($device['inserted'])) {
$inserted_text = "Device Added";
$inserted = (Time::formatInterval(time() - strtotime($device['inserted'])) . " ago");
echo "<div class='row'><div class='col-sm-4'>$inserted_text</div><div class='col-sm-8' title='$inserted_text on " . $device['inserted'] . "'>$inserted</div></div>";
}
if (!empty($device['last_discovered'])) {
$last_discovered_text = "Last Discovered";
$last_discovered = (empty($device['last_discovered']) ? "Never" : Time::formatInterval(time() - strtotime($device['last_discovered'])) . " ago");
echo "<div class='row'><div class='col-sm-4'>$last_discovered_text</div><div class='col-sm-8' title='$last_discovered_text at " . $device['last_discovered'] . "'>$last_discovered</div></div>";
}
$uptime = (Time::formatInterval($device['status'] ? $device['uptime'] : time() - strtotime($device['last_polled'])));
$uptime_text = ($device['status'] ? 'Uptime' : 'Downtime');
if ($uptime) {
echo "<div class='row'>
<div class='col-sm-4'>$uptime_text</div>
<div class='col-sm-8'>$uptime</div>
</div>";
echo "<div class='row'><div class='col-sm-4'>$uptime_text</div><div class='col-sm-8'>$uptime</div></div>";
}
if ($device['location_id']) {

View File

@@ -116,6 +116,10 @@
"rule": "ports.ifOutErrors_rate >= \"100\" || ports.ifInErrors_rate >= \"100\"",
"name": "Interface Errors Rate greater than 100"
},
{
"rule": "devices.inserted >= `macros.past_60m`",
"name": "Device added within the last 60 minutes"
},
{
"rule": "eventlog.type = \"discovery\" && eventlog.message ~ \"@autodiscovered@\" && eventlog.datetime >= `macros.past_60m`",
"name": "Device discovered within the last 60 minutes"

View File

@@ -451,6 +451,7 @@ dbSchema:
devices:
Columns:
- { Field: device_id, Type: 'int(10) unsigned', 'Null': false, Extra: auto_increment }
- { Field: inserted, Type: timestamp, 'Null': false, Extra: '', Default: CURRENT_TIMESTAMP }
- { Field: hostname, Type: varchar(128), 'Null': false, Extra: '' }
- { Field: sysName, Type: varchar(128), 'Null': true, Extra: '' }
- { Field: ip, Type: varbinary(16), 'Null': true, Extra: '' }