forked from arkime/arkime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi-stats.t
136 lines (101 loc) · 6.44 KB
/
api-stats.t
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
use Test::More tests => 63;
use Cwd;
use URI::Escape;
use MolochTest;
use Data::Dumper;
use JSON;
use Test::Differences;
use strict;
my $pwd = "*/pcap";
my $token = getTokenCookie();
my $test1Token = getTokenCookie("test1");
# stats.json
my $stats = viewerGet("/api/stats");
is (@{$stats->{data}}, 1, "stats.json data set ");
is ($stats->{recordsTotal}, 1, "stats.json recordsTotal");
is ($stats->{data}->[0]->{id}, "test", "stats.json name");
foreach my $i ("diskQueue", "deltaDroppedPerSec") {
is ($stats->{data}->[0]->{$i}, 0, "stats.json $i 0");
}
foreach my $i ("monitoring", "diskQueue", "deltaDropped", "deltaDroppedPerSec") {
is ($stats->{data}->[0]->{$i}, 0, "stats.json $i == 0");
}
foreach my $i ("deltaMS", "totalPackets", "memory", "cpu", "currentTime", "totalK", "totalSessions", "freeSpaceM") {
cmp_ok ($stats->{data}->[0]->{$i}, '>=', 0, "stats.json $i >= 0");
}
foreach my $i ("deltaPackets", "deltaBytes", "deltaBytesPerSec", "deltaPacketsPerSec", "deltaSessions", "deltaSessionsPerSec") {
is (exists $stats->{data}->[0]->{$i}, 1, "stats.json $i");
}
my $mstats = multiGet("/stats.json");
is (@{$mstats->{data}}, 1, "multi stats.json data set ");
# dstats.json
my $dstats = viewerGet("/api/dstats?nodeName=test&start=1399680425&stop=1399680460&step=5&interval=5&name=deltaPackets");
is (@{$dstats}, 7, "dstats.json array size");
# esstats.json
my $esstats = viewerGet("/api/esstats");
is ($esstats->{data}->[0]->{writesRejectedDelta}, 0, "Writes reject");
my $messtats = multiGet("/esstats.json");
is ($messtats->{data}->[0]->{writesRejectedDelta}, 0, "Writes reject");
# esindices
my $indices = viewerGet("/api/esindices");
cmp_ok (@{$indices->{data}}, ">=", 30, "indices array size");
cmp_ok ($indices->{data}->[0]->{index} cmp $indices->{data}->[1]->{index}, "<", 0, "indices index sorted");
$indices = viewerGet("/esindices/list?desc=true");
cmp_ok ($indices->{data}->[0]->{index} cmp $indices->{data}->[1]->{index}, ">", 0, "indices index sorted reverse");
$indices = viewerGet("/esindices/list?sortField=store.size");
cmp_ok ($indices->{data}->[0]->{"store.size"}, "<=", $indices->{data}->[1]->{"store.size"}, "indices store.size sorted");
$indices = viewerGet("/api/esindices?desc=true&sortField=store.size");
cmp_ok ($indices->{data}->[0]->{"store.size"}, ">=", $indices->{data}->[1]->{"store.size"}, "indices store.size sorted reverse");
# estasks
my $tasks = viewerGet("/api/estasks");
cmp_ok (@{$tasks->{data}}, ">=", 1, "tasks array size");
# esshards
my $shards = viewerGet("/api/esshards?show=all");
cmp_ok (@{$shards->{indices}}, ">=", 30, "esshards: indices array size");
cmp_ok ($shards->{indices}->[0]->{name}, "lt", $shards->{indices}->[1]->{name}, "esshard: index[0] before index[1]");
eq_or_diff($shards->{nodeExcludes}, [], "esshard: nodeExcludes empty");
eq_or_diff($shards->{ipExcludes}, [], "esshard: ipExcludes empty");
$shards = viewerGet("/esshard/list?show=notdone");
cmp_ok (@{$shards->{indices}}, "==", 0, "esshards: indices array size");
my $result = viewerPost("/api/esshards/ip/1.2.3.4/exclude", "");
eq_or_diff($result, from_json('{"success": false, "text": "Missing token"}'), "esshard: exclude no token");
$result = viewerPostToken("/esshard/exclude/ip/1.2.3.4", "", $token);
eq_or_diff($result, from_json('{"success": true, "text": "Successfully excluded node"}'), "esshard: exclude ip");
$result = viewerPostToken("/api/esshards/name/thenode/exclude", "", $token);
eq_or_diff($result, from_json('{"success": true, "text": "Successfully excluded node"}'), "esshard: exclude node");
$result = viewerPostToken("/esshard/exclude/foobar/1.2.3.4", "", $token);
eq_or_diff($result, from_json('{"success": false, "text": "Unknown exclude type"}'), "esshard: exclude foobar");
$result = viewerPostToken("/esshard/exclude/foobar/1.2.3.4?molochRegressionUser=test1", "", $test1Token);
eq_or_diff($result, from_json('{"success": false, "text": "You do not have permission to access this resource"}'), "esshard: exclude not admin");
$shards = viewerGet("/api/esshards");
eq_or_diff($shards->{nodeExcludes}, ["thenode"], "esshard: nodeExcludes empty");
eq_or_diff($shards->{ipExcludes}, ["1.2.3.4"], "esshard: ipExcludes empty");
$result = viewerPost("/esshard/include/ip/1.2.3.4", "");
eq_or_diff($result, from_json('{"success": false, "text": "Missing token"}'), "esshard: include no token");
$result = viewerPostToken("/api/esshards/ip/1.2.3.4/include", "", $token);
eq_or_diff($result, from_json('{"success": true, "text": "Successfully included node"}'), "esshard: include ip");
$result = viewerPostToken("/api/esshards/name/thenode/include", "", $token);
eq_or_diff($result, from_json('{"success": true, "text": "Successfully included node"}'), "esshard: include node");
$result = viewerPostToken("/esshard/include/foobar/1.2.3.4", "", $token);
eq_or_diff($result, from_json('{"success": false, "text": "Unknown include type"}'), "esshard: include foodbar");
$result = viewerPostToken("/esshard/include/foobar/1.2.3.4?molochRegressionUser=test1", "", $test1Token);
eq_or_diff($result, from_json('{"success": false, "text": "You do not have permission to access this resource"}'), "esshard: include not admin");
$shards = viewerGet("/esshard/list");
eq_or_diff($shards->{nodeExcludes}, [], "esshard: nodeExcludes empty");
eq_or_diff($shards->{ipExcludes}, [], "esshard: ipExcludes empty");
# esrecovery
my $recovery = viewerGet("/api/esrecovery?show=all");
cmp_ok (@{$recovery->{data}}, ">=", 100, "tasks array size");
$recovery = viewerGet("/esrecovery/list");
cmp_ok (@{$recovery->{data}}, "==", 0, "tasks array size");
$recovery = viewerGet("/esrecovery/list?show=notdone");
cmp_ok (@{$recovery->{data}}, "==", 0, "tasks array size");
# parliament.json
my $stats = viewerGet("/api/parliament");
is (@{$stats->{data}}, 1, "parliament.json data set ");
is ($stats->{recordsTotal}, 1, "parliament.json recordsTotal");
is ($stats->{data}->[0]->{id}, "test", "parliament.json name");
foreach my $i ("deltaBytesPerSec", "deltaPacketsPerSec", "deltaESDroppedPerSec", "deltaTotalDroppedPerSec") {
is (exists $stats->{data}->[0]->{$i}, 1, "parliament.json $i");
}
is (exists $stats->{data}->[0]->{"totalPackets"}, "", "parliament.json doesn't have unnecessary fields");