~xdavidwu/uptime-monitor

7895b076cf709840c9cd9d2927162156d0c8a11e — xdavidwu 3 years ago ad330b3
add user-facing title to probeinstance
M app/Console/Commands/MonitorList.php => app/Console/Commands/MonitorList.php +2 -2
@@ 38,11 38,11 @@ class MonitorList extends Command
     */
    public function handle()
    {
        $headers = ['ID', 'Description'];
        $headers = ['ID', 'Title', 'Description'];
        $rows = [];
        foreach (ProbeInstance::all() as $probe_instance) {
            $probe = unserialize($probe_instance->probe);
            $rows[] = [$probe_instance->id, $probe->describe()];
            $rows[] = [$probe_instance->id, $probe_instance->title, $probe->describe()];
        }
        $this->table($headers, $rows);
    }

M app/Console/Commands/MonitorRegister.php => app/Console/Commands/MonitorRegister.php +2 -0
@@ 13,6 13,7 @@ class MonitorRegister extends Command
     * @var string
     */
    protected $signature = 'monitor:register
                            {title : User-facing string of service this probe checks}
                            {class : Class of the probe}
                            {args?* : Extra arguments of <class> constructor}';



@@ 48,6 49,7 @@ class MonitorRegister extends Command

        $record = new ProbeInstance();
        $record->probe = serialize($probe);
        $record->title = $this->argument('title');
        $record->save();
    }
}

A database/migrations/2021_07_26_065820_add_title_to_probe_instances.php => database/migrations/2021_07_26_065820_add_title_to_probe_instances.php +32 -0
@@ 0,0 1,32 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddTitleToProbeInstances extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('probe_instances', function (Blueprint $table) {
            $table->string('title')->nullable();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('probe_instances', function (Blueprint $table) {
            $table->dropColumn('title');
        });
    }
}