File size: 21,393 Bytes
7c89ed7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
# MozDef Architecture: Frontend, Backend & Services Integration Guide

## Table of Contents
1. [Frontend vs Backend Overview](#frontend-vs-backend-overview)
2. [Services Breakdown](#services-breakdown)
3. [How Services Integrate](#how-services-integrate)
4. [Complete Data Flow](#complete-data-flow)
5. [Service Communication Patterns](#service-communication-patterns)
6. [How They Run Together](#how-they-run-together)

---

## Frontend vs Backend Overview

### Frontend Components (User-Facing)

**Frontend** = What users interact with directly

| Component | Technology | Purpose | Port |
|-----------|-----------|---------|------|
| **Meteor Web Interface** | Node.js/Meteor | Real-time web UI for incident handling | 80 (via Nginx) |
| **Kibana** | JavaScript/React | Log visualization and analysis | 9090 (via Nginx) |

**Key Characteristics:**
- **Meteor**: Runs on Node.js, provides real-time collaboration
- **Kibana**: Standalone visualization tool, connects directly to Elasticsearch
- Both are served through **Nginx** as a reverse proxy

### Backend Components (Processing & API)

**Backend** = Services that process data and provide APIs

| Component | Technology | Purpose | Port |
|-----------|-----------|---------|------|
| **REST API** | Python/Bottle.py | RESTful API for web interface | 8081 |
| **Loginput** | Python/Bottle.py | HTTP endpoint for event ingestion | 8080 |
| **MQ Workers** | Python | Process events from RabbitMQ queue | N/A (internal) |
| **Alerts Engine** | Python/Celery | Alert correlation and generation | N/A (internal) |
| **Alert Actions** | Python | Post-alert processing | N/A (internal) |
| **Bot** | Python | Slack/IRC notifications | N/A (internal) |

**Key Characteristics:**
- All backend services are **Python-based**
- Use **uWSGI** for process management
- Communicate via **RabbitMQ** message queues
- Query/write to **Elasticsearch** and **MongoDB**

---

## Services Breakdown

### Infrastructure Services (Supporting Services)

These are the foundational services that other components depend on:

| Service | Technology | Purpose | Port |
|---------|-----------|---------|------|
| **Elasticsearch** | Java | Event storage, indexing, search | 9200 (internal) |
| **RabbitMQ** | Erlang | Message queue for event processing | 5672 (internal), 15672 (admin) |
| **MongoDB** | C++ | Database for Meteor (incidents, users) | 3002 (internal) |
| **Nginx** | C | Reverse proxy and web server | 80, 8080, 8081, 9090 |

### Application Services (MozDef Components)

These are the MozDef-specific services:

#### **Ingest Services** (Data Ingestion)
- **Loginput**: Receives JSON events via HTTP
- **MQ Workers**: Process events from queue
- **Syslog**: Receives syslog messages

#### **Alert Services** (Security Alerting)
- **Alerts**: Celery-based alert engine
- **Alert Actions**: Post-alert processing
- **Bot**: Chat notifications

#### **Web Services** (User Interface)
- **REST API**: Backend API for web interface
- **Meteor**: Frontend web application
- **Kibana**: Log visualization (separate service)

---

## How Services Integrate

### Integration Architecture Diagram

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         USER BROWSER                             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                β”‚ HTTP/WebSocket
                β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         NGINX (Reverse Proxy)                     β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”        β”‚
β”‚  β”‚ Port 80  β”‚  β”‚ Port 8080β”‚  β”‚ Port 8081β”‚  β”‚ Port 9090β”‚        β”‚
β”‚  β”‚ Meteor   β”‚  β”‚ Loginput β”‚  β”‚ REST API β”‚  β”‚ Kibana   β”‚        β”‚
β”‚  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
        β”‚             β”‚              β”‚             β”‚
        β–Ό             β–Ό              β–Ό             β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   METEOR    β”‚  β”‚ LOGINPUT β”‚  β”‚ REST API β”‚  β”‚  KIBANA  β”‚
β”‚  (Node.js)  β”‚  β”‚ (Python) β”‚  β”‚ (Python) β”‚  β”‚          β”‚
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜
       β”‚              β”‚              β”‚              β”‚
       β”‚              β”‚              β”‚              β”‚
       β”‚              β–Ό              β”‚              β”‚
       β”‚      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”       β”‚              β”‚
       β”‚      β”‚   RABBITMQ   β”‚       β”‚              β”‚
       β”‚      β”‚  (Message    β”‚       β”‚              β”‚
       β”‚      β”‚   Queue)     β”‚       β”‚              β”‚
       β”‚      β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜       β”‚              β”‚
       β”‚             β”‚               β”‚              β”‚
       β”‚             β–Ό               β”‚              β”‚
       β”‚      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”       β”‚              β”‚
       β”‚      β”‚  MQ WORKERS  β”‚       β”‚              β”‚
       β”‚      β”‚   (Python)   β”‚       β”‚              β”‚
       β”‚      β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜       β”‚              β”‚
       β”‚             β”‚               β”‚              β”‚
       β”‚             β”‚               β”‚              β”‚
       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                     β”‚               β”‚
                     β–Ό               β–Ό
              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
              β”‚ ELASTICSEARCHβ”‚  β”‚   MONGODB    β”‚
              β”‚  (Storage)   β”‚  β”‚  (Database)  β”‚
              β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
                     β”‚                  β”‚
                     β”‚                  β”‚
                     β–Ό                  β”‚
              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”          β”‚
              β”‚   ALERTS     β”‚          β”‚
              β”‚  (Celery)    β”‚          β”‚
              β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜          β”‚
                     β”‚                  β”‚
                     β–Ό                  β”‚
              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”          β”‚
              β”‚ ALERT ACTIONSβ”‚          β”‚
              β”‚   & BOT      β”‚          β”‚
              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜          β”‚
```

---

## Complete Data Flow

### 1. Event Ingestion Flow

```
External Log Shipper
    β”‚
    β”‚ JSON over HTTP POST
    β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚     NGINX       β”‚  (Port 8080)
β”‚   Reverse Proxy β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β”‚ uWSGI socket
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚    LOGINPUT     β”‚  (Python/Bottle.py)
β”‚  - Receives JSONβ”‚
β”‚  - Validates    β”‚
β”‚  - Adds metadataβ”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β”‚ Publishes to RabbitMQ
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚    RABBITMQ     β”‚  (Message Queue)
β”‚  Exchange:      β”‚
β”‚  eventtask      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β”‚ Consumes from queue
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   MQ WORKERS    β”‚  (Python)
β”‚  - Normalize    β”‚
β”‚  - Enrich       β”‚
β”‚  - GeoIP        β”‚
β”‚  - Watchlist    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β”‚ Index document
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  ELASTICSEARCH  β”‚
β”‚  - Stores event β”‚
β”‚  - Indexes      β”‚
β”‚  - Searchable   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

### 2. Frontend-Backend Communication Flow

```
User Browser
    β”‚
    β”‚ HTTP Request
    β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚     NGINX       β”‚  (Port 80)
β”‚   Reverse Proxy β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β”‚ Proxy to Meteor
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚     METEOR      β”‚  (Node.js)
β”‚  Web Interface  β”‚
β”‚                 β”‚
β”‚  Client Code:   β”‚
β”‚  - UI Componentsβ”‚
β”‚  - Reactivity   β”‚
β”‚                 β”‚
β”‚  Server Code:   β”‚
β”‚  - Methods      β”‚
β”‚  - HTTP calls   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β”‚ HTTP POST/GET
         β”‚ (via mozdef.rootAPI)
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚    REST API     β”‚  (Python/Bottle.py)
β”‚  Port 8081      β”‚
β”‚                 β”‚
β”‚  Endpoints:     β”‚
β”‚  - /events      β”‚
β”‚  - /alerts      β”‚
β”‚  - /incidents   β”‚
β”‚  - /watchitem   β”‚
β”‚  - /blockip     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β”‚ Query/Write
         β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
         β–Ό              β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ ELASTICSEARCHβ”‚  β”‚   MONGODB    β”‚
β”‚  (Events)    β”‚  β”‚ (Incidents)  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

**Example: User blocks an IP address**

1. User clicks "Block IP" in Meteor UI
2. Meteor client calls Meteor method: `Meteor.call('blockip', {ip: '1.2.3.4'})`
3. Meteor server method executes: `blockIP(formobj)`
4. Meteor server makes HTTP POST: `HTTP.post(mozdef.rootAPI + '/blockip', {data: formobj})`
5. REST API receives POST at `/blockip`
6. REST API processes request (may call plugins, update watchlist, etc.)
7. REST API returns response
8. Meteor receives response and updates UI reactively

### 3. Alert Processing Flow

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  ELASTICSEARCH  β”‚
β”‚  (Event Store)  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β”‚ Periodic Query
         β”‚ (Every X minutes)
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚     ALERTS      β”‚  (Python/Celery)
β”‚  Alert Engine   β”‚
β”‚                 β”‚
β”‚  - Queries ES   β”‚
β”‚  - Correlates   β”‚
β”‚  - Aggregates   β”‚
β”‚  - Generates    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β”‚ Creates alert document
         β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
         β–Ό                      β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ ELASTICSEARCHβ”‚        β”‚   RABBITMQ   β”‚
β”‚ (alerts-*)   β”‚        β”‚ (alerts)     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜        β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚
                                β”‚ Consume alert
                                β–Ό
                        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                        β”‚ ALERT ACTIONS β”‚
                        β”‚   (Python)    β”‚
                        β”‚               β”‚
                        β”‚ - Notify      β”‚
                        β”‚ - Enrich      β”‚
                        β”‚ - Respond     β”‚
                        β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
                               β”‚
                               β–Ό
                        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                        β”‚     BOT      β”‚
                        β”‚  (Slack/IRC) β”‚
                        β”‚               β”‚
                        β”‚ Sends messageβ”‚
                        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

**Example: SSH Brute Force Alert**

1. **Alerts Engine** (Celery) runs every 5 minutes
2. Queries Elasticsearch: "Find SSH failed login events in last 5 minutes"
3. Aggregates by source IP: "Count failures per IP"
4. If IP has > 10 failures: Create alert
5. Alert saved to Elasticsearch `alerts-*` index
6. Alert published to RabbitMQ `alerts` exchange
7. **Alert Actions** worker consumes alert
8. **Alert Actions** enriches alert (GeoIP, threat intel)
9. **Bot** consumes alert and sends to Slack channel

### 4. Real-Time Collaboration Flow (Meteor)

```
User 1 Browser          User 2 Browser
    β”‚                      β”‚
    β”‚                      β”‚
    β–Ό                      β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ METEOR  β”‚          β”‚ METEOR  β”‚
β”‚ Client  β”‚          β”‚ Client  β”‚
β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜          β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜
     β”‚                     β”‚
     β”‚ WebSocket/DDP       β”‚
     β”‚ (Real-time)         β”‚
     β”‚                     β”‚
     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                β”‚
                β–Ό
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β”‚   METEOR     β”‚
        β”‚   Server     β”‚
        β”‚  (Node.js)   β”‚
        β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚
               β”‚ Read/Write
               β–Ό
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β”‚   MONGODB    β”‚
        β”‚  (Incidents) β”‚
        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

**Example: Two users working on same incident**

1. User 1 opens incident #123 in Meteor UI
2. User 2 opens same incident #123
3. Both users subscribe to MongoDB collection: `incidents`
4. User 1 adds a comment
5. Meteor server updates MongoDB
6. MongoDB change triggers Meteor reactivity
7. Both User 1 and User 2 see the comment appear **instantly** (no page refresh)

---

## Service Communication Patterns

### 1. HTTP/REST Communication

**Used for:**
- Meteor β†’ REST API
- External systems β†’ Loginput
- Kibana β†’ Elasticsearch

**Protocol:** HTTP/HTTPS
**Format:** JSON

**Example:**
```javascript
// Meteor calling REST API
HTTP.post('http://rest:8081/blockip', {
    data: {ip: '1.2.3.4', reason: 'malicious'}
});
```

### 2. Message Queue Communication (RabbitMQ)

**Used for:**
- Loginput β†’ MQ Workers
- Alerts β†’ Alert Actions
- Alerts β†’ Bot

**Protocol:** AMQP (Advanced Message Queuing Protocol)
**Format:** JSON messages

**Exchanges:**
- `eventtask`: Events from loginput
- `mozdef.event`: Processed events (topic exchange)
- `alerts`: Generated alerts

**Example:**
```python
# Loginput publishes to RabbitMQ
mqConn.ensure(mqproducer, mqproducer.publish, max_retries=10)
mqproducer.publish(
    eventDict,
    exchange=eventTaskExchange,
    routing_key=options.taskexchange
)

# MQ Worker consumes from RabbitMQ
taskConsumer(mqConn, eventTaskQueue, eventTopicExchange, es).run()
```

### 3. Direct Database Access

**Used for:**
- REST API β†’ Elasticsearch (queries)
- REST API β†’ MongoDB (incidents)
- MQ Workers β†’ Elasticsearch (indexing)
- Alerts β†’ Elasticsearch (queries)
- Meteor β†’ MongoDB (real-time subscriptions)

**Protocol:** Native client libraries
- Elasticsearch: `elasticsearch` Python client
- MongoDB: `pymongo` (Python) or native (Meteor)

**Example:**
```python
# REST API querying Elasticsearch
es = ElasticsearchClient(options.esservers)
search_query = SearchQuery(minutes=20)
search_query.add_must([TermMatch('category', 'authentication')])
results = es.query(search_query)
```

### 4. WebSocket/DDP (Meteor)

**Used for:**
- Browser β†’ Meteor server (real-time updates)

**Protocol:** DDP (Distributed Data Protocol) over WebSocket
**Format:** JSON

**Example:**
```javascript
// Meteor automatically handles WebSocket
// When MongoDB changes, clients are notified
incidents.find({_id: incidentId}).observe({
    added: function(doc) {
        // Real-time update received
    }
});
```

---

## How They Run Together

### Docker Compose Orchestration

All services are orchestrated via `docker-compose.yml`:

```yaml
services:
  nginx:          # Reverse proxy
  elasticsearch:  # Event storage
  rabbitmq:       # Message queue
  mongodb:        # Database
  kibana:         # Visualization
  
  # MozDef Services
  loginput:       # Event ingestion
  mq_worker:      # Event processing
  rest:           # REST API
  meteor:         # Web interface
  alerts:         # Alert engine
  alertactions:   # Alert processing
  bot:            # Notifications (optional)
  cron:           # Scheduled tasks
```

### Startup Sequence

1. **Infrastructure Services Start First:**
   ```
   elasticsearch β†’ rabbitmq β†’ mongodb β†’ kibana
   ```

2. **Bootstrap Service:**
   - Waits for Elasticsearch to be ready
   - Creates initial indices
   - Sets up Kibana dashboards

3. **Backend Services Start:**
   ```
   loginput β†’ mq_worker β†’ rest β†’ alerts β†’ alertactions
   ```

4. **Frontend Services Start:**
   ```
   meteor (depends on mongodb and rest)
   ```

5. **Nginx Starts Last:**
   - Depends on all services being ready
   - Routes traffic to appropriate services

### Service Dependencies

```
nginx
  β”œβ”€β”€ meteor (port 80)
  β”œβ”€β”€ loginput (port 8080)
  β”œβ”€β”€ rest (port 8081)
  └── kibana (port 9090)

meteor
  β”œβ”€β”€ mongodb (user data, incidents)
  └── rest (API calls)

rest
  β”œβ”€β”€ elasticsearch (event queries)
  └── mongodb (incident storage)

loginput
  └── rabbitmq (publish events)

mq_worker
  β”œβ”€β”€ rabbitmq (consume events)
  └── elasticsearch (index events)

alerts
  β”œβ”€β”€ elasticsearch (query events)
  β”œβ”€β”€ rabbitmq (publish alerts)
  └── rest (sync schedules)

alertactions
  └── rabbitmq (consume alerts)

kibana
  └── elasticsearch (direct connection)
```

### Health Checks

Each service has health checks to ensure proper startup:

```yaml
healthcheck:
  test: ["CMD", "curl", "-f", "127.0.0.1:8080/status"]
  interval: 30s
  timeout: 3s
  retries: 10
```

Services wait for dependencies to be healthy before starting.

### Configuration Integration

**Environment Variables:**
- Services read from environment variables
- Docker Compose sets these via `environment:` section
- Settings cascade: env vars β†’ config files β†’ defaults

**Key Configuration Points:**
- `OPTIONS_METEOR_ROOTAPI`: REST API URL (default: `http://rest:8081`)
- `OPTIONS_METEOR_KIBANAURL`: Kibana URL (default: `http://localhost:9090/app/kibana`)
- `OPTIONS_MQPROTOCOL`: Message queue protocol (`amqp` or `sqs`)

### Network Communication

All services run in the same Docker network (`default`):
- Services can communicate via service names (e.g., `http://rest:8081`)
- Ports are exposed only where needed (80, 8080, 8081, 9090)
- Internal ports (Elasticsearch 9200, RabbitMQ 5672) are not exposed

---

## Summary

### Frontend
- **Meteor**: Real-time web UI (Node.js)
- **Kibana**: Log visualization (JavaScript)

### Backend
- **REST API**: Backend API (Python)
- **Loginput**: Event ingestion (Python)
- **MQ Workers**: Event processing (Python)
- **Alerts**: Alert engine (Python/Celery)
- **Alert Actions**: Alert processing (Python)
- **Bot**: Notifications (Python)

### Services
- **Elasticsearch**: Event storage
- **RabbitMQ**: Message queue
- **MongoDB**: Database
- **Nginx**: Reverse proxy

### Integration Points
1. **HTTP**: Meteor ↔ REST API, External β†’ Loginput
2. **RabbitMQ**: Loginput β†’ MQ Workers, Alerts β†’ Alert Actions
3. **Elasticsearch**: All services query/write events
4. **MongoDB**: Meteor stores incidents, REST API reads/writes
5. **WebSocket**: Browser ↔ Meteor (real-time)

### How They Run
- Docker Compose orchestrates all services
- Services start in dependency order
- Health checks ensure proper startup
- All services communicate via Docker network

This architecture allows MozDef to:
- **Scale horizontally** (multiple MQ workers, loginput instances)
- **Process events asynchronously** (via RabbitMQ)
- **Provide real-time collaboration** (via Meteor)
- **Handle high event volumes** (300M+ events/day)