-
Notifications
You must be signed in to change notification settings - Fork 5
/
monitoringpolicies_test.go
706 lines (626 loc) · 20.9 KB
/
monitoringpolicies_test.go
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
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
package oneandone
import (
"fmt"
"math/rand"
"sync"
"testing"
"time"
)
var (
set_mp sync.Once
test_mp_name string
test_mp_desc string
test_mp_mail string
test_mp_srv_id string
test_mp_srv_name string
test_mp *MonitoringPolicy
mp_request MonitoringPolicy
)
const (
port_responding = "RESPONDING"
port_not_responding = "NOT_RESPONDING"
process_running = "RUNNING"
process_not_running = "NOT_RUNNING"
mp_email = "[email protected]"
)
// Helper functions
func create_monitoring_policy() *MonitoringPolicy {
rand.Seed(time.Now().UnixNano())
rint := rand.Intn(999)
test_mp_name = fmt.Sprintf("MonitoringPolicy_%d", rint)
test_mp_desc = fmt.Sprintf("MonitoringPolicy_%d description", rint)
test_mp_mail = "[email protected]"
mp_request = MonitoringPolicy{
Name: test_mp_name,
Description: test_mp_desc,
Email: test_mp_mail,
Agent: true,
Thresholds: &MonitoringThreshold{
Cpu: &MonitoringLevel{
Warning: &MonitoringValue{
Value: 90,
Alert: false,
},
Critical: &MonitoringValue{
Value: 95,
Alert: false,
},
},
Ram: &MonitoringLevel{
Warning: &MonitoringValue{
Value: 90,
Alert: false,
},
Critical: &MonitoringValue{
Value: 95,
Alert: false,
},
},
Disk: &MonitoringLevel{
Warning: &MonitoringValue{
Value: 80,
Alert: false,
},
Critical: &MonitoringValue{
Value: 90,
Alert: false,
},
},
Transfer: &MonitoringLevel{
Warning: &MonitoringValue{
Value: 1000,
Alert: false,
},
Critical: &MonitoringValue{
Value: 2000,
Alert: false,
},
},
InternalPing: &MonitoringLevel{
Warning: &MonitoringValue{
Value: 50,
Alert: false,
},
Critical: &MonitoringValue{
Value: 100,
Alert: true,
},
},
},
Ports: []MonitoringPort{
{
Protocol: "TCP",
Port: 443,
AlertIf: port_not_responding,
EmailNotification: true,
},
},
Processes: []MonitoringProcess{
{
Process: "httpdeamon",
AlertIf: process_not_running,
EmailNotification: false,
},
},
}
fmt.Printf("Creating new monitoring policy '%s'...\n", test_mp_name)
mp_id, mp, err := api.CreateMonitoringPolicy(&mp_request)
if err != nil {
fmt.Printf("Unable to create a monitoring policy. Error: %s", err.Error())
return nil
}
if mp_id == "" || mp.Id == "" {
fmt.Printf("Unable to create monitoring policy '%s'.", test_mp_name)
return nil
}
api.WaitForState(mp, "ACTIVE", 30, 30)
return mp
}
func set_monitoring_policy() {
test_mp = create_monitoring_policy()
}
// /monitoring_policies tests
func TestCreateMonitoringPolicy(t *testing.T) {
set_mp.Do(set_monitoring_policy)
if test_mp == nil {
t.Errorf("CreateMonitoringPolicy failed.")
}
if test_mp.Id == "" {
t.Errorf("Missing monitoring policy ID.")
}
if test_mp.Name != test_mp_name {
t.Errorf("Wrong name of the monitoring policy.")
}
if test_mp.Description != test_mp_desc {
t.Errorf("Wrong monitoring policy description.")
}
if !test_mp.Agent {
t.Errorf("Missing monitoring policy agent.")
}
if test_mp.Email != test_mp_mail {
t.Errorf("Wrong email of monitoring policy '%s'.", test_mp.Name)
}
if test_mp.Thresholds == nil {
t.Errorf("Not thresholds found for monitoring policy '%s'.", test_mp.Name)
} else {
if test_mp.Thresholds.Cpu.Critical.Alert {
t.Errorf("Wrong alerting state for CPU critical alert of monitoring policy '%s'.", test_mp.Name)
}
if test_mp.Thresholds.Cpu.Critical.Value != 95 {
t.Errorf("Wrong value for CPU critical alert of monitoring policy '%s'.", test_mp.Name)
}
if test_mp.Thresholds.Cpu.Warning.Alert {
t.Errorf("Wrong alerting state for CPU warning alert of monitoring policy '%s'.", test_mp.Name)
}
if test_mp.Thresholds.Cpu.Warning.Value != 90 {
t.Errorf("Wrong value for CPU warning alert of monitoring policy '%s'.", test_mp.Name)
}
if test_mp.Thresholds.Ram.Critical.Alert {
t.Errorf("Wrong alerting state for RAM critical alert of monitoring policy '%s'.", test_mp.Name)
}
if test_mp.Thresholds.Ram.Critical.Value != 95 {
t.Errorf("Wrong value for RAM critical alert of monitoring policy '%s'.", test_mp.Name)
}
if test_mp.Thresholds.Ram.Warning.Alert {
t.Errorf("Wrong alerting state for RAM warning alert of monitoring policy '%s'.", test_mp.Name)
}
if test_mp.Thresholds.Ram.Warning.Value != 90 {
t.Errorf("Wrong value for RAM warning alert of monitoring policy '%s'.", test_mp.Name)
}
if test_mp.Thresholds.Disk.Critical.Alert {
t.Errorf("Wrong alerting state for disk critical alert of monitoring policy '%s'.", test_mp.Name)
}
if test_mp.Thresholds.Disk.Critical.Value != 90 {
t.Errorf("Wrong value for disk critical alert of monitoring policy '%s'.", test_mp.Name)
}
if test_mp.Thresholds.Disk.Warning.Alert {
t.Errorf("Wrong alerting state for disk warning alert of monitoring policy '%s'.", test_mp.Name)
}
if test_mp.Thresholds.Disk.Warning.Value != 80 {
t.Errorf("Wrong value for disk warning alert of monitoring policy '%s'.", test_mp.Name)
}
if test_mp.Thresholds.Transfer.Critical.Alert {
t.Errorf("Wrong alerting state for transfer critical alert of monitoring policy '%s'.", test_mp.Name)
}
if test_mp.Thresholds.Transfer.Critical.Value != 2000 {
t.Errorf("Wrong value for transfer critical alert of monitoring policy '%s'.", test_mp.Name)
}
if test_mp.Thresholds.Transfer.Warning.Alert {
t.Errorf("Wrong alerting state for transfer warning alert of monitoring policy '%s'.", test_mp.Name)
}
if test_mp.Thresholds.Transfer.Warning.Value != 1000 {
t.Errorf("Wrong value for transfer warning alert of monitoring policy '%s'.", test_mp.Name)
}
if !test_mp.Thresholds.InternalPing.Critical.Alert {
t.Errorf("Wrong alerting state for ping critical alert of monitoring policy '%s'.", test_mp.Name)
}
if test_mp.Thresholds.InternalPing.Critical.Value != 100 {
t.Errorf("Wrong value for ping critical alert of monitoring policy '%s'.", test_mp.Name)
}
if test_mp.Thresholds.InternalPing.Warning.Alert {
t.Errorf("Wrong alerting state for ping warning alert of monitoring policy '%s'.", test_mp.Name)
}
if test_mp.Thresholds.InternalPing.Warning.Value != 50 {
t.Errorf("Wrong value for ping warning alert of monitoring policy '%s'.", test_mp.Name)
}
}
if len(test_mp.Ports) != 1 {
t.Errorf("Wrong number of monitoring policy '%s' ports.", test_mp.Name)
} else {
if test_mp.Ports[0].Protocol != "TCP" {
t.Errorf("Wrong monitoring protocol of policy '%s'.", test_mp.Name)
}
if test_mp.Ports[0].AlertIf != port_not_responding {
t.Errorf("Wrong alerting state of monitoring policy '%s' port.", test_mp.Name)
}
if test_mp.Ports[0].Port != 443 {
t.Errorf("Wrong monitoring policy '%s' port number.", test_mp.Name)
}
if !test_mp.Ports[0].EmailNotification {
t.Errorf("Wrong email notification state in monitoring policy '%s' port.", test_mp.Name)
}
}
if len(test_mp.Processes) != 1 {
t.Errorf("Wrong number of monitoring policy '%s' processes.", test_mp.Name)
} else {
if test_mp.Processes[0].Process != "httpdeamon" {
t.Errorf("Wrong monitoring policy '%s' process.", test_mp.Name)
}
if test_mp.Processes[0].AlertIf != process_not_running {
t.Errorf("Wrong alerting state of monitoring policy '%s' process.", test_mp.Name)
}
if test_mp.Processes[0].EmailNotification {
t.Errorf("Wrong email notification state in monitoring policy '%s' process.", test_mp.Name)
}
}
}
func TestGetMonitoringPolicy(t *testing.T) {
set_mp.Do(set_monitoring_policy)
fmt.Printf("Getting monitoring policy '%s'...\n", test_mp.Name)
mp, err := api.GetMonitoringPolicy(test_mp.Id)
if err != nil {
t.Errorf("GetMonitoringPolicy failed. Error: " + err.Error())
}
if mp.Id != test_mp.Id {
t.Errorf("Wrong monitoring policy ID.")
}
}
func TestListMonitoringPolicies(t *testing.T) {
set_mp.Do(set_monitoring_policy)
fmt.Println("Listing all monitoring policies...")
res, err := api.ListMonitoringPolicies()
if err != nil {
t.Errorf("ListMonitoringPolicies failed. Error: " + err.Error())
}
if len(res) == 0 {
t.Errorf("No monitoring policy found.")
}
res, err = api.ListMonitoringPolicies(1, 1, "", "", "id,name,agent")
if err != nil {
t.Errorf("ListMonitoringPolicies with parameter options failed. Error: " + err.Error())
}
if len(res) == 0 {
t.Errorf("No monitoring policy found.")
}
if len(res) > 1 {
t.Errorf("Wrong number of objects per page.")
}
if res[0].Id == "" {
t.Errorf("Filtering parameters failed.")
}
if res[0].Name == "" {
t.Errorf("Filtering parameters failed.")
}
if res[0].State != "" {
t.Errorf("Filtering parameters failed.")
}
res, err = api.ListMonitoringPolicies(0, 0, "", test_mp.Name, "")
if err != nil {
t.Errorf("ListMonitoringPolicies with parameter options failed. Error: " + err.Error())
}
if len(res) != 1 {
t.Errorf("Search parameter failed.")
}
if res[0].Name != test_mp.Name {
t.Errorf("Search parameter failed.")
}
}
func TestAttachMonitoringPolicyServers(t *testing.T) {
set_mp.Do(set_monitoring_policy)
fmt.Printf("Attaching servers to monitoring policy '%s'...\n", test_mp.Name)
sync_server.Do(func() { deploy_test_server(true) })
servers := []string{test_server.Id}
mp, err := api.AttachMonitoringPolicyServers(test_mp.Id, servers)
if err != nil {
t.Errorf("AttachMonitoringPolicyServers failed. Error: " + err.Error())
}
api.WaitForState(mp, "ACTIVE", 30, 60)
mp, _ = api.GetMonitoringPolicy(mp.Id)
if len(mp.Servers) != 1 {
t.Errorf("Found no server attached to the monitoring policy.")
return
}
if mp.Servers[0].Id != test_server.Id {
t.Errorf("Wrong server IP attached to the monitoring policy.")
}
test_mp = mp
test_mp_srv_id = mp.Servers[0].Id
test_mp_srv_name = mp.Servers[0].Name
}
func TestGetMonitoringPolicyServer(t *testing.T) {
set_mp.Do(set_monitoring_policy)
fmt.Printf("Getting server identity attached to monitoring policy '%s'...\n", test_mp.Name)
mp_ser, err := api.GetMonitoringPolicyServer(test_mp.Id, test_mp_srv_id)
if err != nil {
t.Errorf("GetMonitoringPolicyServer failed. Error: " + err.Error())
return
}
if mp_ser.Id != test_mp_srv_id {
t.Errorf("Wrong ID of the server attached to monitoring policy '%s'.", test_mp.Name)
}
if mp_ser.Name != test_mp_srv_name {
t.Errorf("Wrong server name attached to monitoring policy '%s'.", test_mp.Name)
}
}
func TestListMonitoringPolicyServers(t *testing.T) {
set_mp.Do(set_monitoring_policy)
sync_server.Do(func() { deploy_test_server(true) })
fmt.Printf("Listing servers attached to monitoring policy '%s'...\n", test_mp.Name)
mp_srvs, err := api.ListMonitoringPolicyServers(test_mp.Id)
if err != nil {
t.Errorf("ListMonitoringPolicyServers failed. Error: " + err.Error())
return
}
if len(mp_srvs) == 0 {
t.Errorf("Wrong number of servers attached to monitoring policy '%s'.", test_mp.Name)
return
}
if mp_srvs[0].Id != test_server.Id {
t.Errorf("Wrong server attached to monitoring policy '%s'.", test_mp.Name)
}
}
func TestRemoveMonitoringPolicyServer(t *testing.T) {
set_mp.Do(set_monitoring_policy)
sync_server.Do(func() { deploy_test_server(true) })
fmt.Printf("Removing server attached to monitoring policy '%s'...\n", test_mp.Name)
mp, err := api.RemoveMonitoringPolicyServer(test_mp.Id, test_server.Id)
if err != nil {
t.Errorf("RemoveMonitoringPolicyServer failed. Error: " + err.Error())
return
}
api.WaitForState(mp, "ACTIVE", 30, 60)
mp, err = api.GetMonitoringPolicy(mp.Id)
if err != nil {
t.Errorf("Removing server from the monitoring policy failed.")
}
if len(mp.Servers) > 0 {
t.Errorf("Server not removed from the monitoring policy.")
}
}
func TestGetMonitoringPolicyPort(t *testing.T) {
set_mp.Do(set_monitoring_policy)
fmt.Printf("Getting monitoring policy '%s' port...\n", test_mp.Name)
mp_port, err := api.GetMonitoringPolicyPort(test_mp.Id, test_mp.Ports[0].Id)
if err != nil {
t.Errorf("GetMonitoringPolicyPort failed. Error: " + err.Error())
}
if mp_port.Id != test_mp.Ports[0].Id {
t.Errorf("Wrong port ID.")
}
if mp_port.Port != test_mp.Ports[0].Port {
t.Errorf("Wrong port number in the monitoring policy.")
}
if mp_port.AlertIf != test_mp.Ports[0].AlertIf {
t.Errorf("Wrong alert_if field in the monitoring policy port.")
}
if mp_port.Protocol != test_mp.Ports[0].Protocol {
t.Errorf("Wrong port protocol in the monitoring policy.")
}
if mp_port.EmailNotification != test_mp.Ports[0].EmailNotification {
t.Errorf("Wrong email notification state in the monitoring policy port.")
}
}
func TestModifyMonitoringPolicyPort(t *testing.T) {
set_mp.Do(set_monitoring_policy)
fmt.Printf("Modifying monitoring policy '%s' port...\n", test_mp.Name)
mp_port, err := api.GetMonitoringPolicyPort(test_mp.Id, test_mp.Ports[0].Id)
if err != nil {
t.Errorf("GetMonitoringPolicyPort failed. Error: " + err.Error())
}
mp_port.AlertIf = port_responding
mp_port.EmailNotification = false
mp, err := api.ModifyMonitoringPolicyPort(test_mp.Id, mp_port.Id, mp_port)
if mp == nil {
t.Errorf("ModifyMonitoringPolicyPort failed. Error: " + err.Error())
return
}
if mp.Ports[0].AlertIf != port_responding {
t.Errorf("Unable to modify alert_if field in the monitoring policy port.")
}
if mp.Ports[0].EmailNotification {
t.Errorf("Unable to modify email notification state in the monitoring policy port.")
}
test_mp = mp
}
func TestAddMonitoringPolicyPorts(t *testing.T) {
set_mp.Do(set_monitoring_policy)
fmt.Printf("Adding ports to monitoring policy '%s'...\n", test_mp.Name)
ports := []MonitoringPort{
{
Protocol: "TCP",
Port: 43215,
AlertIf: port_not_responding,
EmailNotification: false,
},
{
Protocol: "UDP",
Port: 161,
AlertIf: port_responding,
EmailNotification: true,
},
}
mp, err := api.AddMonitoringPolicyPorts(test_mp.Id, ports)
if err != nil {
t.Errorf("AddMonitoringPolicyPorts failed. Error: " + err.Error())
} else {
api.WaitForState(mp, "ACTIVE", 60, 60)
}
mp, _ = api.GetMonitoringPolicy(test_mp.Id)
if mp == nil || len(mp.Ports) != 3 {
t.Errorf("Unable to add ports to monitoring policy '%s'.\n", test_mp.Name)
}
}
func TestListMonitoringPolicyPorts(t *testing.T) {
set_mp.Do(set_monitoring_policy)
fmt.Printf("Listing monitoring policy '%s' ports...\n", test_mp.Name)
mp_ports, err := api.ListMonitoringPolicyPorts(test_mp.Id)
if err != nil {
t.Errorf("ListMonitoringPolicyPorts failed. Error: " + err.Error())
}
if len(mp_ports) != 3 {
t.Errorf("Wrong number of ports found in monitoring policy '%s'.", test_mp.Name)
}
}
func TestDeleteMonitoringPort(t *testing.T) {
set_mp.Do(set_monitoring_policy)
mp_ports, _ := api.ListMonitoringPolicyPorts(test_mp.Id)
fmt.Printf("Deleting port '%s' from monitoring policy '%s'...\n", mp_ports[0].Id, test_mp.Name)
mp, err := api.DeleteMonitoringPolicyPort(test_mp.Id, mp_ports[0].Id)
if err != nil {
t.Errorf("DeleteMonitoringPolicyPort failed. Error: " + err.Error())
}
api.WaitForState(mp, "ACTIVE", 60, 60)
mp, err = api.GetMonitoringPolicy(mp.Id)
if err != nil {
t.Errorf("Deleting port from the monitoring policy failed.")
return
}
if len(mp.Ports) != 2 {
t.Errorf("Port not deleted from the monitoring policy.")
}
for _, port := range mp.Ports {
if port.Id == mp_ports[0].Id {
t.Errorf("Port not deleted from the monitoring policy.")
}
}
}
func TestGetMonitoringPolicyProcess(t *testing.T) {
set_mp.Do(set_monitoring_policy)
fmt.Printf("Getting monitoring policy '%s' process...\n", test_mp.Name)
mp_process, err := api.GetMonitoringPolicyProcess(test_mp.Id, test_mp.Processes[0].Id)
if err != nil {
t.Errorf("GetMonitoringPolicyProcess failed. Error: " + err.Error())
return
}
if mp_process.Id != test_mp.Processes[0].Id {
t.Errorf("Wrong process ID.")
}
if mp_process.Process != test_mp.Processes[0].Process {
t.Errorf("Wrong process name in the monitoring policy.")
}
if mp_process.AlertIf != test_mp.Processes[0].AlertIf {
t.Errorf("Wrong alert_if field in the monitoring policy process.")
}
if mp_process.EmailNotification != test_mp.Processes[0].EmailNotification {
t.Errorf("Wrong email notification state in the monitoring policy process.")
}
}
func TestModifyMonitoringPolicyProcess(t *testing.T) {
set_mp.Do(set_monitoring_policy)
fmt.Printf("Modifying monitoring policy '%s' process...\n", test_mp.Name)
mp_process, err := api.GetMonitoringPolicyProcess(test_mp.Id, test_mp.Processes[0].Id)
if err != nil {
t.Errorf("GetMonitoringPolicyProcess failed. Error: " + err.Error())
return
}
mp_process.AlertIf = process_running
mp_process.EmailNotification = true
mp, err := api.ModifyMonitoringPolicyProcess(test_mp.Id, mp_process.Id, mp_process)
if err != nil {
t.Errorf("ModifyMonitoringPolicyProcess failed. Error: " + err.Error())
return
}
if mp.Processes[0].AlertIf != process_running {
t.Errorf("Unable to modify alert_if field in the monitoring policy process.")
}
if !mp.Processes[0].EmailNotification {
t.Errorf("Unable to modify email notification state in the monitoring policy process.")
}
test_mp = mp
}
func TestAddMonitoringPolicyProcesses(t *testing.T) {
set_mp.Do(set_monitoring_policy)
fmt.Printf("Adding processes to monitoring policy '%s'...\n", test_mp.Name)
processes := []MonitoringProcess{
{
Process: "iexplorer",
AlertIf: process_not_running,
EmailNotification: false,
},
{
Process: "taskmgr",
AlertIf: process_running,
EmailNotification: true,
},
}
mp, err := api.AddMonitoringPolicyProcesses(test_mp.Id, processes)
if err != nil {
t.Errorf("AddMonitoringPolicyProcesses failed. Error: " + err.Error())
} else {
api.WaitForState(mp, "ACTIVE", 60, 60)
}
mp, _ = api.GetMonitoringPolicy(test_mp.Id)
if mp == nil || len(mp.Processes) != 3 {
t.Errorf("Unable to add processes to monitoring policy '%s'.\n", test_mp.Name)
}
}
func TestListMonitoringPolicyProcesses(t *testing.T) {
set_mp.Do(set_monitoring_policy)
fmt.Printf("Listing monitoring policy '%s' processes...\n", test_mp.Name)
mp_processes, err := api.ListMonitoringPolicyProcesses(test_mp.Id)
if err != nil {
t.Errorf("ListMonitoringPolicyProcesses failed. Error: " + err.Error())
return
}
if len(mp_processes) != 3 {
t.Errorf("Wrong number of processes found in monitoring policy '%s'.", test_mp.Name)
}
}
func TestDeleteMonitoringProcess(t *testing.T) {
set_mp.Do(set_monitoring_policy)
mp_processes, _ := api.ListMonitoringPolicyProcesses(test_mp.Id)
if len(mp_processes) == 0 {
t.Errorf("No monitoring policy process found.")
return
}
fmt.Printf("Deleting process '%s' from monitoring policy '%s'...\n", mp_processes[0].Id, test_mp.Name)
mp, err := api.DeleteMonitoringPolicyProcess(test_mp.Id, mp_processes[0].Id)
if err != nil {
t.Errorf("DeleteMonitoringPolicyProcess failed. Error: " + err.Error())
}
api.WaitForState(mp, "ACTIVE", 60, 60)
mp, err = api.GetMonitoringPolicy(test_mp.Id)
if err != nil {
t.Errorf("Deleting process from the monitoring policy failed.")
}
if len(mp.Processes) != 2 {
t.Errorf("Process not deleted from the monitoring policy.")
}
for _, process := range mp.Processes {
if process.Id == mp_processes[0].Id {
t.Errorf("Process not deleted from the monitoring policy.")
}
}
}
func TestUpdateMonitoringPolicy(t *testing.T) {
set_mp.Do(set_monitoring_policy)
fmt.Printf("Updating monitoring policy '%s'...\n", test_mp.Name)
new_name := test_mp.Name + "_updated"
new_desc := test_mp.Description + "_updated"
new_mail := "[email protected]"
mp_request.Name = new_name
mp_request.Description = new_desc
mp_request.Email = new_mail
mp_request.Thresholds.Cpu.Critical.Value = 99
mp_request.Thresholds.Transfer.Critical.Alert = true
mp, err := api.UpdateMonitoringPolicy(test_mp.Id, &mp_request)
if err != nil {
t.Errorf("UpdateMonitoringPolicy failed. Error: " + err.Error())
} else {
api.WaitForState(mp, "ACTIVE", 60, 30)
mp, _ = api.GetMonitoringPolicy(test_mp.Id)
if mp.Name != new_name {
t.Errorf("Failed to update monitoring policy name.")
}
if mp.Description != new_desc {
t.Errorf("Failed to update monitoring policy description.")
}
if mp.Email != new_mail {
t.Errorf("Failed to update monitoring policy email.")
}
if mp.Thresholds.Cpu.Critical.Value != 99 {
t.Errorf("Failed to update critical CPU threshold of the monitoring policy.")
}
if !mp.Thresholds.Transfer.Critical.Alert {
t.Errorf("Failed to update alerting state for critical transfer threshold of the monitoring policy.")
}
}
}
func TestDeleteMonitoringPolicy(t *testing.T) {
set_mp.Do(set_monitoring_policy)
fmt.Printf("Deleting monitoring policy '%s'...\n", test_mp.Name)
time.Sleep(time.Second)
mp, err := api.DeleteMonitoringPolicy(test_mp.Id)
if err != nil {
t.Errorf("DeleteMonitoringPolicy failed. Error: " + err.Error())
return
}
api.WaitUntilDeleted(mp)
time.Sleep(time.Second)
mp, err = api.GetMonitoringPolicy(mp.Id)
if mp != nil {
t.Errorf("Unable to delete the monitoring policy.")
} else {
test_mp = nil
}
}