Nov 19, 2020 by Thibault Debatty | 2122 views
https://cylab.be/blog/105/getting-started-with-mark-create-a-php-data-injector
The Multi-Agent Ranking framework (MARk) aims to provide all the building blocks that are required to build large scale detection and ranking systems. For this blog post we will use docker and docker-compose to run a MARk server, then we will use PHP and composer to inject data in the framework.
But first a few key concepts:
The easiest way to start a MARk server is using Docker and docker-compose. So you should first create a file docker-compose.yml with following content:
version: '2.0'
services:
mark-web:
image: cylab/mark-web:1.3.2
container_name: mark-web
environment:
- MARK_HOST=mark-server
- MARK_PORT=8080
ports:
- "8000:80"
depends_on:
- mark
mark:
image: cylab/mark:2.2.1
container_name: mark-server
volumes:
- ./modules:/mark/modules
environment:
- MARK_MONGO_HOST=mark-mongo
ports:
- "8080:8080"
depends_on:
- mongo
mongo:
image: mongo:4.4
container_name: mark-mongo
Then you can start the containers with:
docker-compose up
This will create 3 containers:
After a few seconds MARk will be up and running.
The web interface will be available at http://127.0.0.1:8000
The default credentials are:
mark-admin@cylab.be
change-me!
Currently there is not much to see as there is no data entering the system, and no detection algorithm configured. You can browse to the Status page to check that MARk is running smoothly.
We will now use PHP to inject data into MARk. First, create a new composer project:
composer init
Now you can use composer again to download and install cylab/mark-php-client
, the PHP library that allows to easily connect and use the MARk server.
composer require cylab/mark-php-client
Now we can start writing our code. We will first write a small script that checks the status of the server. So this is basically the equivalent of the Status page of the web interface. Let's call it status.php :
<?php
require_once __DIR__ . '/vendor/autoload.php';
$client = new CylabMarkClient();
var_dump($client->status());
You can run your script with
php status.php
We can now create a data injector. For this tutorial we have different cats, and we will have to rank them according to some very smart criteria! So let's create a script called injector.php :
<?php
require __DIR__ . '/vendor/autoload.php';
$subjects = ["garfield", "snowball", "felix", "hello"];
$server = new CylabMarkClient();
while (true) {
echo "Insert a record ...
";
// select one of the cats at random
$subject = $subjects[array_rand($subjects)];
$record = new CylabMarkRecord();
$record->data = rand();
$record->label = "data";
// time must be expressed in milliseconds!
$record->time = time() * 1000;
$record->subject = ["name" => $subject];
$server->addData($record);
sleep(2);
}
You can now run the injector:
php injector.php
On the web interface, you will see that data is now flowing into the system:
And by clicking on 'Inspect' you can even what this data is looking like:
So now you have a running MARk server, with a PHP injector. In the next tutorials we will see how to use and configure the built-in detection algorithms, then how to create you own algorithms.
This blog post is licensed under CC BY-SA 4.0