3241 |
rexy |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
namespace mbolli\nfsen_ng\datasources;
|
|
|
4 |
|
|
|
5 |
interface Datasource {
|
|
|
6 |
/**
|
|
|
7 |
* Writes a new record to the datasource.
|
|
|
8 |
* Expects an array in the following format:
|
|
|
9 |
* $data => array(
|
|
|
10 |
* 'source' => 'name_of_souce',
|
|
|
11 |
* 'date_timestamp' => 000000000,
|
|
|
12 |
* 'date_iso' => 'Ymd\THis',
|
|
|
13 |
* 'fields' => array(
|
|
|
14 |
* 'flows',
|
|
|
15 |
* 'flows_tcp',
|
|
|
16 |
* 'flows_udp',
|
|
|
17 |
* 'flows_icmp',
|
|
|
18 |
* 'flows_other',
|
|
|
19 |
* 'packets',
|
|
|
20 |
* 'packets_tcp',
|
|
|
21 |
* 'packets_udp',
|
|
|
22 |
* 'packets_icmp',
|
|
|
23 |
* 'packets_other',
|
|
|
24 |
* 'bytes',
|
|
|
25 |
* 'bytes_tcp',
|
|
|
26 |
* 'bytes_udp',
|
|
|
27 |
* 'bytes_icmp',
|
|
|
28 |
* 'bytes_other')
|
|
|
29 |
* );.
|
|
|
30 |
*
|
|
|
31 |
* @return bool TRUE on success or FALSE on failure
|
|
|
32 |
*
|
|
|
33 |
* @throws \Exception on error
|
|
|
34 |
*/
|
|
|
35 |
public function write(array $data): bool;
|
|
|
36 |
|
|
|
37 |
/**
|
|
|
38 |
* Gets data for plotting the graph in the frontend.
|
|
|
39 |
* Each row in $return['data'] will be a time point in the graph.
|
|
|
40 |
* The lines can be
|
|
|
41 |
* * protocols - $sources must not contain more than one source (legend e.g. gateway_flows_udp, gateway_flows_tcp)
|
|
|
42 |
* * sources - $protocols must not contain more than one protocol (legend e.g. gateway_traffic_icmp, othersource_traffic_icmp)
|
|
|
43 |
* * ports.
|
|
|
44 |
*
|
|
|
45 |
* @param int $start timestamp
|
|
|
46 |
* @param int $end timestamp
|
|
|
47 |
* @param array $sources subset of sources specified in settings
|
|
|
48 |
* @param array $protocols UDP/TCP/ICMP/other
|
|
|
49 |
* @param string $type flows/packets/traffic
|
|
|
50 |
* @param string $display protocols/sources/ports
|
|
|
51 |
*
|
|
|
52 |
* @return array in the following format:
|
|
|
53 |
*
|
|
|
54 |
* $return = array(
|
|
|
55 |
* 'start' => 1490484600, // timestamp of first value
|
|
|
56 |
* 'end' => 1490652000, // timestamp of last value
|
|
|
57 |
* 'step' => 300, // resolution of the returned data in seconds. lowest value would probably be 300 = 5 minutes
|
|
|
58 |
* 'legend' => array('swi6_flows_tcp', 'gate_flows_tcp'), // legend describes the graph series
|
|
|
59 |
* 'data' => array(
|
|
|
60 |
* 1490484600 => array(33.998333333333, 22.4), // the values/measurements for this specific timestamp are in an array
|
|
|
61 |
* 1490485200 => array(37.005, 132.8282),
|
|
|
62 |
* ...
|
|
|
63 |
* )
|
|
|
64 |
* );
|
|
|
65 |
*/
|
|
|
66 |
public function get_graph_data(
|
|
|
67 |
int $start,
|
|
|
68 |
int $end,
|
|
|
69 |
array $sources,
|
|
|
70 |
array $protocols,
|
|
|
71 |
array $ports,
|
|
|
72 |
string $type = 'flows',
|
|
|
73 |
string $display = 'sources',
|
|
|
74 |
): array|string;
|
|
|
75 |
|
|
|
76 |
/**
|
|
|
77 |
* Removes all existing data for every source in $sources.
|
|
|
78 |
* If $sources is empty, remove all existing data.
|
|
|
79 |
*/
|
|
|
80 |
public function reset(array $sources): bool;
|
|
|
81 |
|
|
|
82 |
/**
|
|
|
83 |
* Gets the timestamps of the first and last entry in the datasource (for this specific source).
|
|
|
84 |
*
|
|
|
85 |
* @return array (timestampfirst, timestamplast)
|
|
|
86 |
*/
|
|
|
87 |
public function date_boundaries(string $source): array;
|
|
|
88 |
|
|
|
89 |
/**
|
|
|
90 |
* Gets the timestamp of the last update of the datasource (for this specific source).
|
|
|
91 |
*/
|
|
|
92 |
public function last_update(string $source, int $port = 0): int;
|
|
|
93 |
|
|
|
94 |
/**
|
|
|
95 |
* Gets the path where the datasource's data is stored.
|
|
|
96 |
*/
|
|
|
97 |
public function get_data_path(): string;
|
|
|
98 |
}
|