Blame view

api/app/Http/Controllers/V1/Partners/XlsiemController.php 2.84 KB
0d8c0f816   Thanasis Naskos   initial commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
  <?php
  
  namespace App\Http\Controllers\V1\Partners;
  
  use App\Http\Controllers\Controller;
  use App\Http\Requests\XlsiemRequest;
  use Carbon\Carbon;
  use Illuminate\Support\Facades\DB;
  use Salman\Mqtt\Facades\Mqtt;
  
  class XlsiemController extends Controller
  {
      public function store(XlsiemRequest $request)
      {
          $dbEvents = [];
37f7f2d14   Thanasis Naskos   Bug fix
16
          $eventAlarms = [];
0d8c0f816   Thanasis Naskos   initial commit
17
18
19
20
21
22
23
24
25
26
27
28
29
30
          foreach ($request->get('event_alarm') as $ev) {
              $dbEvents[] = [
                  'asset_id' => $request->get('asset_id'),
                  'event_alarm_id' => $ev['event_alarm_id'],
                  'event_alarm_char' => $ev['event_alarm_char'],
                  'name' => isset($ev['name']) ? $ev['name'] : null,
                  'time' => Carbon::createFromTimestamp($request->get('timestamp')),
                  'source_ip' => $ev['source_ip'],
                  'source_port' => isset($ev['source_port']) ? $ev['source_port'] : null,
                  'destination_ip' => $ev['destination_ip'],
                  'destination_port' => isset($ev['destination_port']) ? $ev['destination_port'] : null,
                  'priority' => isset($ev['priority']) ? $ev['priority'] : null,
                  'confidence' => isset($ev['confidence']) ? $ev['confidence'] : null,
              ];
e0d6f0a8e   Thanasis Naskos   Changed the forma...
31
              $eventAlarms[] = [
0d8c0f816   Thanasis Naskos   initial commit
32
33
34
                  'event_alarm_id' => $ev['event_alarm_id'],
                  'event_alarm_char' => $ev['event_alarm_char'],
                  'name' => isset($ev['name']) ? $ev['name'] : null,
0d8c0f816   Thanasis Naskos   initial commit
35
36
37
38
39
40
41
42
                  'source_ip' => $ev['source_ip'],
                  'source_port' => isset($ev['source_port']) ? $ev['source_port'] : null,
                  'destination_ip' => $ev['destination_ip'],
                  'destination_port' => isset($ev['destination_port']) ? $ev['destination_port'] : null,
                  'priority' => isset($ev['priority']) ? $ev['priority'] : null,
                  'confidence' => isset($ev['confidence']) ? $ev['confidence'] : null
              ];
          }
37f7f2d14   Thanasis Naskos   Bug fix
43
          $mqttEvents = array(
e0d6f0a8e   Thanasis Naskos   Changed the forma...
44
45
46
          	'asset_id' => $request->get('asset_id'),
          	'timestamp' => Carbon::createFromTimestamp($request->get('timestamp')),
          	'event_alarm' => $eventAlarms
37f7f2d14   Thanasis Naskos   Bug fix
47
          );
e0d6f0a8e   Thanasis Naskos   Changed the forma...
48
          
0d8c0f816   Thanasis Naskos   initial commit
49
50
  
          // publish to MQTT Broker
7c65431cf   Chris Bellas   Temporary removed...
51
52
          //Mqtt::ConnectAndPublish('xlsiem/event', json_encode($mqttEvents), $request->user()->id);
          Mqtt::ConnectAndPublish('xlsiem/event', json_encode($mqttEvents), 1);
0d8c0f816   Thanasis Naskos   initial commit
53
54
55
56
          DB::table('xlsiem')->insert($dbEvents);
  
          return response()->json(['success' => 'success'], 200);
      }
2f4aeec4c   Chris Bellas   Added GET endpoin...
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
  
      public function get()
      {
          return DB::table('xlsiem')->select([
              'asset_id',
              'event_alarm_id',
              'event_alarm_char',
              'name',
              'time',
              'source_ip',
              'source_port',
              'destination_ip',
              'destination_port',
              'priority',
              'confidence',
          ])->paginate(20);
      }
0d8c0f816   Thanasis Naskos   initial commit
74
  }