-
Notifications
You must be signed in to change notification settings - Fork 0
/
specialization.php
639 lines (604 loc) · 31.4 KB
/
specialization.php
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
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
<?php
/**********************************************************************************************************************
* Copyright 2021, Inesonic, LLC
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see
* <https://www.gnu.org/licenses/>.
***********************************************************************************************************************
*/
namespace Inesonic\SpeedSentry;
/**
* Class that performs specialization of this plug-in. This class will either build the entire plug-in framework
* or bolt onto an already created framework from another SpeedSentry plug-in.
*/
class Specialization extends Helpers {
/**
* Table of plot parameters and required types.
*/
const PLOT_PARAMETER_CONVERTERS = array(
'plot_type' => 'string',
'host_scheme_id' => 'integer',
'monitor_id' => 'integer',
'region_id' => 'integer',
'start_timestamp' => 'double',
'end_timestamp' => 'double',
'title' => 'string',
'x_axis_label' => 'string',
'y_axis_label' => 'string',
'date_format' => 'string',
'title_font' => 'string',
'axis_title_font' => 'string',
'axis_label_font' => 'string',
'minimum_latency' => 'double',
'maximum_latency' => 'double',
'log_scale' => 'boolean',
'width' => 'integer',
'height' => 'integer',
'format' => 'string',
);
/**
* Plug-in priority value. Used to determine which plug-in renders key content.
* A lower priority indicates a higher chance of being the key plug-in.
*/
const PLUGIN_PRIORITY = 10;
/**
* Static method that is triggered when the plug-in is activated.
*
* \param $options The plug-in options instance.
*/
public static function plugin_activated(Options $options) {}
/**
* Static method that is triggered when the plug-in is deactivated.
*
* \param $options The plug-in options instance.
*/
public static function plugin_deactivated(Options $options) {}
/**
* Constructor
*
* \param $short_plugin_name A short version of the plug-in name to be used in the menus.
*
* \param $plugin_name The user visible name for this plug-in.
*
* \param $plugin_slug The slug used for the plug-in. We use this slug as a prefix for slugs this class
* may also require.
*
* \param $login_url The URL to redirect to in order to login.
*
* \param $rest_api The outbound REST API.
*
* \param $options The plug-in options API.
*
* \param $signup_handler The signup-redirect handler.
*/
public function __construct(
string $short_plugin_name,
string $plugin_name,
string $plugin_slug,
string $login_url,
RestApiV1 $rest_api,
Options $options,
SignupHandler $signup_handler
) {
$this->short_plugin_name = $short_plugin_name;
$this->plugin_name = $plugin_name;
$this->plugin_slug = $plugin_slug;
$this->plugin_prefix = str_replace('-', '_', $plugin_slug);
$this->login_url = $login_url;
$this->rest_api = $rest_api;
$this->options = $options;
$this->signup_handler = $signup_handler;
$this->admin_bar = new AdminBar(
$options,
$signup_handler,
$rest_api
);
add_action('init', array($this, 'on_initialization'));
}
/**
* Method that is triggered during initialization to bolt the plug-in settings UI into WordPress.
*/
public function on_initialization() {
add_action(
'inesonic_speedsentry_status_panel_enqueue_scripts',
array($this, 'enqueue_scripts'),
self::PLUGIN_PRIORITY,
2
);
add_action(
'inesonic_speedsentry_status_panel_add_content',
array($this, 'add_content'),
self::PLUGIN_PRIORITY,
2
);
add_action('wp_ajax_inesonic_speedsentry_regions_list' , array($this, 'regions_list'));
add_action('wp_ajax_inesonic_speedsentry_hosts_list' , array($this, 'hosts_list'));
add_action('wp_ajax_inesonic_speedsentry_monitors_list', array($this, 'monitors_list'));
add_action('wp_ajax_inesonic_speedsentry_events_list', array($this, 'events_list'));
add_action('wp_ajax_inesonic_speedsentry_status_list', array($this, 'status_list'));
add_action('wp_ajax_inesonic_speedsentry_multiple_list' , array($this, 'multiple_list'));
add_action('wp_ajax_inesonic_speedsentry_latency_plot', array($this, 'latency_plot'));
}
/**
* Method that adds scripts and styles to the admin page.
*
* \param $plugin_slug The main plugin page prefix. Used to create submenus.
*
* \param $active_plugins A list of currently active plugins.
*/
public function enqueue_scripts(string $plugin_slug, array $active_plugins) {
$user_strings_from_event_types = array(
'INVALID' => __( "Invalid", 'inesonic-speedsentry'),
'WORKING' => __( "Working", 'inesonic-speedsentry'),
'NO_RESPONSE' => __( "No Response", 'inesonic-speedsentry'),
'CONTENT_CHANGED' => __( "Content Changed", 'inesonic-speedsentry'),
'KEYWORDS' => __( "Keyword(s) Changed", 'inesonic-speedsentry'),
'SSL_CERTIFICATE_EXPIRING' => __( "SSL Certificate Expiring", 'inesonic-speedsentry'),
'SSL_CERTIFICATE_RENEWED' => __( "SSL Certificate Renewed", 'inesonic-speedsentry'),
'CUSTOMER_1' => __("Custom 1", 'inesonic-speedsentry'),
'CUSTOMER_2' => __("Custom 2", 'inesonic-speedsentry'),
'CUSTOMER_3' => __("Custom 3", 'inesonic-speedsentry'),
'CUSTOMER_4' => __("Custom 4", 'inesonic-speedsentry'),
'CUSTOMER_5' => __("Custom 5", 'inesonic-speedsentry'),
'CUSTOMER_6' => __("Custom 6", 'inesonic-speedsentry'),
'CUSTOMER_7' => __("Custom 7", 'inesonic-speedsentry'),
'CUSTOMER_8' => __("Custom 8", 'inesonic-speedsentry'),
'CUSTOMER_9' => __("Custom 9", 'inesonic-speedsentry'),
'CUSTOMER_10' => __("Custom 10", 'inesonic-speedsentry')
);
$user_strings_from_status = array(
'UNKNOWN' => __("", 'inesonic-speedsentry'),
'WORKING' => __("", 'inesonic-speedsentry'),
'FAILED' => __("No Response", 'inesonic-speedsentry')
);
$user_strings = array(
'show_all_monitors' => __("Show All Monitors", 'inesonic-speedsentry'),
'show_alerts_only' => __("Show Alerts Only", 'inesonic-speedsentry'),
'all_monitors_on' => __("All Monitors On {0}", 'inesonic-speedsentry'),
'all_monitors' => __("All Monitors", 'inesonic-speedsentry')
);
$default_plot_file = plugin_dir_url(__FILE__) . 'assets/img/default_plot.png';
wp_enqueue_script('jquery');
wp_enqueue_script('jquery-ui-datepicker');
wp_enqueue_script(
'moment-with-locales',
self::javascript_url('moment-with-locales', true)
);
wp_enqueue_script(
'moment-timezone-with-data-1970-2030',
self::javascript_url('moment-timezone-with-data-1970-2030', true)
);
wp_enqueue_script(
'inesonic-speedsentry-status-page',
self::javascript_url('speedsentry-status-page', true),
array(
'jquery',
'jquery-ui-datepicker',
'moment-with-locales',
'moment-timezone-with-data-1970-2030'
),
null,
true
);
wp_localize_script(
'inesonic-speedsentry-status-page',
'ajax_object',
array(
'ajax_url' => admin_url('admin-ajax.php'),
'user_strings_from_event_types' => $user_strings_from_event_types,
'user_strings_from_status' => $user_strings_from_status,
'user_strings' => $user_strings,
'default_plot_file' => $default_plot_file
)
);
wp_enqueue_style(
'inesonic-speedsentry-styles',
self::css_url('inesonic-speedsentry-styles', false),
array(),
null
);
}
/**
* Method that adds content to the status page.
*
* \param $primary_plugin The slug of the primary plugin.
*
* \param $active_plugins The list of active plugins.
*/
public function add_content(string $primary_plugin, array $active_plugins) {
echo '<div class="inesonic-speedsentry-page-title"><h1 class="inesonic-speedsentry-header">' .
esc_html(sprintf(__("Site Status (%s)", 'inesonic-speedsentry'), $this->plugin_name)) .
'</h1></div>' .
'<div id="inesonic-speedsentry-status-main" class="inesonic-speedsentry-status-main">' .
'<div class="inesonic-speedsentry-supports-logging">' .
'<p class="control_area_note">' .
__(
"* Note: Date/time values are <span class=\"timezone\">??</span> local",
'inesonic-speedsentry'
) .
'</p>' .
'<div class="inesonic-speedsentry-controls">' .
'<div class="inesonic-speedsentry-time-controls">' .
'<div class="inesonic-speedsentry-start-date-control">' .
'<span class="inesonic-speedsentry-control-name">' .
__("Start:", 'inesonic-speedsentry') .
'</span>' .
'<div class="inesonic-speedsentry-control-area">' .
'<span class="inesonic-speedsentry-start-control-span">' .
'<input type="text" class="inesonic-speedsentry-start-control" ' .
'id="inesonic-speedsentry-start-date"/>' .
'</span>' .
'<div class="inesonic-speedsentry-button-wrapper">' .
'<a id="inesonic-speedsentry-start-clear-button" ' .
'class="inesonic-speedsentry-button-anchor">' .
__("Clear", 'inesonic-speedsentry') .
'</a>' .
'</div>' .
'</div>' .
'</div>' .
'<div class="inesonic-speedsentry-end-date-control">' .
'<span class="inesonic-speedsentry-control-name">' .
__("End", 'inesonic-speedsentry') .
'</span>' .
'<div class="inesonic-speedsentry-control-area">' .
'<span class="inesonic-speedsentry-end-control-span">' .
'<input type="text" class="inesonic-speedsentry-end-control" ' .
'id="inesonic-speedsentry-end-date"' .
'/>' .
'</span>' .
'<div class="inesonic-speedsentry-button-wrapper">' .
'<a id="inesonic-speedsentry-end-clear-button" ' .
'class="inesonic-speedsentry-button-anchor"' .
'>' .
__("Clear", 'inesonic-speedsentry') .
'</a>' .
'</div>' .
'</div>' .
'</div>' .
'</div>' .
'<div class="inesonic-speedsentry-latency-control">' .
'<span class="inesonic-speedsentry-control-name">' .
__("Latency", 'inesonic-speedsentry') .
'</span>' .
'<div class="inesonic-speedsentry-control-area">' .
'<select class="inesonic-speedsentry-latency-select-control" ' .
'id="inesonic-speedsentry-latency-select-control"' .
'>' .
'<option value="0">' . __("Auto-scale", 'inesonic-speedsentry') . '</option>' .
'<option value="1">' . __("0 - 1 second", 'inesonic-speedsentry') . '</option>' .
'<option value="2">' . __("0 - 2 seconds", 'inesonic-speedsentry') . '</option>' .
'<option value="5">' . __("0 - 5 seconds", 'inesonic-speedsentry') . '</option>' .
'<option value="10">' . __("0 - 10 seconds", 'inesonic-speedsentry') . '</option>' .
'<option value="30">' . __("0 - 30 seconds", 'inesonic-speedsentry') . '</option>' .
'</select>' .
'</div>' .
'</div>' .
'<div class="inesonic-speedsentry-select-controls">' .
'<div class="inesonic-speedsentry-supports-multi-region">' .
'<div class="inesonic-speedsentry-region-control">' .
'<span class="inesonic-speedsentry-control-name">' .
__("Region:", 'inesonic-speedsentry') .
'</span>' .
'<div class="inesonic-speedsentry-control-area">' .
'<select class="inesonic-speedsentry-region-select-control" ' .
'id="inesonic-speedsentry-region-select-control"' .
'>' .
'<option value="0">' . __("All Regions", 'inesonic-speedsentry') . '</option>' .
'</select>' .
'</div>' .
'</div>' .
'</div>' .
'<div class="inesonic-speedsentry-monitor-control">' .
'<span class="inesonic-speedsentry-control-name">' .
__("Monitor/Authority:", 'inesonic-speedsentry') .
'</span>' .
'<div class="inesonic-speedsentry-control-area">' .
'<select class="inesonic-speedsentry-monitor-select-control" ' .
'id="inesonic-speedsentry-monitor-select-control"' .
'>' .
'<option value="0">' . __("All Monitors", 'inesonic-speedsentry') . '</option>' .
'</select>' .
'</div>' .
'</div>' .
'</div>' .
'</div>' .
'</div>' .
'<div id="inesonic-speedsentry-monitor-status-top" ' .
'class="inesonic-speedsentry-monitor-status-top"' .
'>' .
'<div id="inesonic-speedsentry-status-alerts" class="inesonic-speedsentry-status-alerts">' .
'<div class="inesonic-speedsentry-status-alerts-top">' .
'<div class="inesonic-speedsentry-status-alerts-title-line">' .
'<p class="inesonic-speedsentry-status-alerts-title">Status</p>' .
'<div class="inesonic-speedsentry-button-wrapper">' .
'<a id="inesonic-speedsentry-status-alerts-button" ' .
'class="inesonic-speedsentry-button-anchor"' .
'>' .
__("Show All Monitors", 'inesonic-speedsentry') .
'</a>' .
'</div>' .
'</p>' .
'</div>' .
'</div>' .
'<table class="inesonic-speedsentry-status-alerts-table" ' .
'id="inesonic-speedsentry-status-alerts-table"' .
'>' .
'<thead class="inesonic-speedsentry-status-alerts-header">' .
'<tr class="inesonic-speedsentry-status-alerts-header-row">' .
'<td class="inesonic-speedsentry-status-alerts-header-url">' .
__("URL", 'inesonic-speedsentry') .
'</td>' .
'<td class="inesonic-speedsentry-status-alerts-header-last-event">' .
__("Last Event" , 'inesonic-speedsentry') .
'</td>' .
'<td class="inesonic-speedsentry-status-alerts-header-current-status">' .
__("Current Status", 'inesonic-speedsentry') .
'</td>' .
'</tr>' .
'</thead>' .
'<tbody class="inesonic-speedsentry-status-alerts-body" ' .
'id="inesonic-speedsentry-status-alerts-body"' .
'>' .
'<tr class="inesonic-speedsentry-status-alerts-row">' .
'<td class="inesonic-speedsentry-status-alerts-url"></td>' .
'<td class="inesonic-speedsentry-status-alerts-last-event"></td>' .
'<td class="inesonic-speedsentry-status-alerts-current-status"></td>' .
'</tr>' .
'</tbody>' .
'</table>' .
'</div>' .
'<div class="inesonic-speedsentry-supports-logging">' .
'<div class="inesonic-speedsentry-latency-histogram-outer">' .
'<p class="inesonic-speedsentry-latency-histogram-title">' .
__("Latency Histogram" , 'inesonic-speedsentry') .
'</p>' .
'<div class="inesonic-speedsentry-latency-histogram-inner">' .
'<div class="inesonic-speedsentry-latency-histogram-y-axis">' .
'<p class="inesonic-speedsentry-latency-histogram-y-axis-label">' .
__("Counts", 'inesonic-speedsentry') .
'</p>' .
'</div>' .
'<div class="inesonic-speedsentry-latency-histogram-right">' .
'<div class="inesonic-speedsentry-latency-histogram-image-wrapper">' .
'<img class="inesonic-speedsentry-image" ' .
'id="inesonic-speedsentry-latency-histogram-image" ' .
'src="' . plugin_dir_url(__FILE__) . 'assets/img/default_plot.png"' .
'/>' .
'</div>' .
'<div class="inesonic-speedsentry-latency-histogram-x-axis">' .
'<p id="inesonic-speedsentry-latency-histogram-x-axis-label" ' .
'class="inesonic-speedsentry-latency-histogram-x-axis-label"' .
'>' .
__("Latency (Seconds)", 'inesonic-speedsentry') .
'</p>' .
'</div>' .
'</div>' .
'</div>' .
'</div>' .
'</div>' .
'</div>' .
'<div class="inesonic-speedsentry-supports-logging">' .
'<div class="inesonic-speedsentry-history-graph">' .
'<p class="inesonic-speedsentry-history-title">' .
__("Latency Over Time" , 'inesonic-speedsentry') .
'</p>' .
'<div class="inesonic-speedsentry-history-inner" id="inesonic-speedsentry-history-inner">' .
'<div class="inesonic-speedsentry-history-y-axis" ' .
'id="inesonic-speedsentry-history-y-axis-label"' .
'>' .
'<p class="inesonic-speedsentry-history-y-axis-label">' .
__("Latency (Seconds)", 'inesonic-speedsentry') .
'</p>' .
'</div>' .
'<div class="inesonic-speedsentry-history-right">' .
'<div class="inesonic-speedsentry-history-image-wrapper">' .
'<img class="inesonic-speedsentry-image" ' .
'id="inesonic-speedsentry-history-image" ' .
'src="' . plugin_dir_url(__FILE__) . 'assets/img/default_plot.png"' .
'/>' .
'</div>' .
'<div class="inesonic-speedsentry-history-x-axis">' .
'<p class="inesonic-speedsentry-history-x-axis-label">' .
__("Date/Time (UTC)", 'inesonic-speedsentry') .
'</p>' .
'</div>' .
'</div>' .
'</div>' .
'</div>' .
'</div>' .
'<div class="inesonic-speedsentry-supports-ssl-monitoring">' .
'<div class="inesonic-speedsentry-ssl">' .
'<div class="inesonic-speedsentry-ssl_top">' .
'<p class="inesonic-speedsentry-ssl-title">' .
__("SSL Certificates:", 'inesonic-speedsentry') .
'</p>' .
'</div>' .
'<table class="inesonic-speedsentry-ssl-table">' .
'<thead class="inesonic-speedsentry-ssl-header">' .
'<tr class="inesonic-speedsentry-ssl-header-row">' .
'<td class="inesonic-speedsentry-ssl-header-authority">' .
__("Server", 'inesonic-speedsentry') .
'</td>' .
'<td class="inesonic-speedsentry-ssl-header-expiration-datetime">' .
__(
"Expiration Date/Time (<span class=\"timezone\">??</span>)",
'inesonic-speedsentry'
) .
'</td>' .
'</tr>' .
'</thead>' .
'<tbody class="inesonic-speedsentry-ssl-body" id="inesonic-speedsentry-ssl-body">' .
'<tr class="inesonic-speedsentry-ssl-row">' .
'<td class="inesonic-speedsentry-ssl-authority"></td>' .
'<td class="inesonic-speedsentry-ssl-expiration-datetime"></td>' .
'</tr>' .
'</tbody>' .
'</table>' .
'</div>' .
'</div>' .
'<div class="inesonic-speedsentry-events">' .
'<div class="inesonic-speedsentry-events-top">' .
'<p class="inesonic-speedsentry-events-title">' .
__("Events", 'inesonic-speedsentry') .
'</p>' .
'</div>' .
'<table class="inesonic-speedsentry-events-table">' .
'<thead class="inesonic-speedsentry-events-header">' .
'<tr class="inesonic-speedsentry-events-header-row">' .
'<td class="inesonic-speedsentry-events-header-datetime">' .
__("Date/Time (<span class=\"timezone\">??</span>)", 'inesonic-speedsentry') .
'</td>' .
'<td class="inesonic-speedsentry-events-header-type">' .
__("Type", 'inesonic-speedsentry') .
'</td>' .
'<td class="inesonic-speedsentry-events-header-url">' .
__("URL", 'inesonic-speedsentry') .
'</td>' .
'<td class="inesonic-speedsentry-events-header-notes">' .
__("Notes", 'insonic-speedsentry') .
'</td>' .
'</tr>' .
'</thead>' .
'<tbody class="inesonic-speedsentry-events-body" id="inesonic-speedsentry-events-body">' .
'<tr class="inesonic-speedsentry-events-row">' .
'<td class="inesonic-speedsentry-events-datetime"></td>' .
'<td class="inesonic-speedsentry-events-type"></td>' .
'<td class="inesonic-speedsentry-events-url"></td>' .
'<td class="inesonic-speedsentry-events-notes"></td>' .
'</tr>' .
'</tbody>' .
'</table>' .
'</div>' .
'</div>';
}
/**
* Method that is triggered by AJAX to obtain a list of regions.
*/
public function regions_list() {
$regions_data = $this->rest_api->regionsList();
if ($regions_data !== null) {
$response = array('status' => 'OK', 'regions' => $regions_data);
} else {
$response = array('status' => 'failed');
}
echo json_encode($response);
wp_die();
}
/**
* Method that is triggered by AJAX to obtain a list of customer hosts.
*/
public function hosts_list() {
$hosts_data = $this->rest_api->hostsList();
if ($hosts_data !== null) {
$response = array('status' => 'OK', 'hosts' => $hosts_data);
} else {
$response = array('status' => 'failed');
}
echo json_encode($response);
wp_die();
}
/**
* Method that is triggered by AJAX to obtain a list of monitors.
*/
public function monitors_list() {
if (array_key_exists('order_by', $_POST)) {
$order_by = sanitize_text_field($_POST['order_by']);
} else {
$order_by = 'monitor_id';
}
$monitors_data = $this->rest_api->monitorsList($order_by);
if ($monitors_data !== null) {
$response = array('status' => 'OK', 'monitors' => $monitors_data);
} else {
$response = array('status' => 'failed');
}
echo json_encode($response);
wp_die();
}
/**
* Method that is triggered by AJAX to obtain a list of events.
*/
public function events_list() {
if (array_key_exists('start_timestamp', $_POST)) {
$start_timestamp = intval($_POST);
} else {
$start_timestamp = 0;
}
if (array_key_exists('end_timestamp', $_POST)) {
$end_timestamp = intval($_POST);
} else {
$end_timestamp = 0;
}
$events_data = $this->rest_api->eventsList($start_timestamp, $end_timestamp);
if ($events_data !== null) {
$response = array('status' => 'OK', 'events' => $events_data);
} else {
$response = array('status' => 'failed');
}
echo json_encode($response);
wp_die();
}
/**
* Method that is triggered by AJAX to obtain status on our monitors.
*/
public function status_list() {
$status_data = $this->rest_api->statusList();
if ($status_data !== null) {
$response = array('status' => 'OK', 'status' => $status_data);
} else {
$response = array('status' => 'failed');
}
echo json_encode($response);
wp_die();
}
/**
* Method that is triggered by AJAX to obtain all table data in a single request.
*/
public function multiple_list() {
$response = $this->rest_api->multipleList();
echo json_encode($response);
wp_die();
}
/**
* Method that is triggered by AJAX to obtain a plot.
*/
public function latency_plot() {
$request = array('plot_type' => 'histogram');
foreach (self::PLOT_PARAMETER_CONVERTERS as $key => $type) {
if (array_key_exists($key, $_POST)) {
$value = sanitize_text_field($_POST[$key]);
if (settype($value, $type)) {
$request[$key] = $value;
}
}
}
$response = $this->rest_api->latencyPlot($request);
if ($response !== null) {
$content_type = $response['content_type'];
if ($content_type == 'application/json') {
$response = array(
'status' => 'failed',
'response' => json_decode($response['body'])
);
} else {
$response = array(
'status' => 'OK',
'image' => base64_encode($response['body']),
'content_type' => $content_type
);
}
} else {
$response = array('status' => 'failed');
}
echo json_encode($response);
wp_die();
}
};