@centreon/js-config 23.10.65 → 24.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,7 @@
1
1
  /* eslint-disable @typescript-eslint/no-namespace */
2
2
 
3
+ import { Action } from 'e2e/features/ACLs/commands';
4
+
3
5
  const apiBase = '/centreon/api';
4
6
  const apiActionV1 = `${apiBase}/index.php`;
5
7
 
@@ -138,12 +140,109 @@ Cypress.Commands.add(
138
140
  }
139
141
  );
140
142
 
143
+ interface Contact {
144
+ admin?: boolean;
145
+ alias?: string | null;
146
+ authenticationType?: 'local' | 'ldap';
147
+ email: string;
148
+ enableNotifications?: boolean;
149
+ GUIAccess?: boolean;
150
+ language?: string;
151
+ name: string;
152
+ password: string;
153
+ }
154
+
155
+ Cypress.Commands.add(
156
+ 'addContact',
157
+ ({
158
+ admin = true,
159
+ alias = null,
160
+ authenticationType = 'local',
161
+ email,
162
+ enableNotifications = true,
163
+ GUIAccess = true,
164
+ language = 'en_US',
165
+ name,
166
+ password
167
+ }: Contact): Cypress.Chainable => {
168
+ const contactAdmin = admin ? 1 : 0;
169
+ const contactAlias = alias === null ? name : alias;
170
+ const contactEnableNotifications = enableNotifications ? 1 : 0;
171
+ const contactGUIAccess = GUIAccess ? 1 : 0;
172
+
173
+ return cy
174
+ .executeActionViaClapi({
175
+ bodyContent: {
176
+ action: 'ADD',
177
+ object: 'CONTACT',
178
+ values: `${name};${contactAlias};${email};${password};${contactAdmin};${contactGUIAccess};${language};${authenticationType}`
179
+ }
180
+ })
181
+ .then(() => {
182
+ const contactParams = {
183
+ enable_notifications: contactEnableNotifications
184
+ };
185
+ Object.entries(contactParams).map(([paramName, paramValue]) => {
186
+ if (paramValue === null) {
187
+ return null;
188
+ }
189
+
190
+ return cy.executeActionViaClapi({
191
+ bodyContent: {
192
+ action: 'SETPARAM',
193
+ object: 'CONTACT',
194
+ values: `${name};${paramName};${paramValue}`
195
+ }
196
+ });
197
+ });
198
+
199
+ return cy.wrap(null);
200
+ });
201
+ }
202
+ );
203
+
204
+ interface ContactGroup {
205
+ alias?: string | null;
206
+ contacts: string[];
207
+ name: string;
208
+ }
209
+
210
+ Cypress.Commands.add(
211
+ 'addContactGroup',
212
+ ({ alias = null, contacts, name }: ContactGroup): Cypress.Chainable => {
213
+ const contactGroupAlias = alias === null ? name : alias;
214
+
215
+ return cy
216
+ .executeActionViaClapi({
217
+ bodyContent: {
218
+ action: 'ADD',
219
+ object: 'CG',
220
+ values: `${name};${contactGroupAlias}`
221
+ }
222
+ })
223
+ .then(() => {
224
+ contacts.map((contact) => {
225
+ return cy.executeActionViaClapi({
226
+ bodyContent: {
227
+ action: 'ADDCONTACT',
228
+ object: 'CG',
229
+ values: `${name};${contact}`
230
+ }
231
+ });
232
+ });
233
+
234
+ return cy.wrap(null);
235
+ });
236
+ }
237
+ );
238
+
141
239
  interface Host {
142
240
  activeCheckEnabled?: boolean;
143
241
  address?: string;
144
242
  alias?: string | null;
145
243
  checkCommand?: string | null;
146
244
  checkPeriod?: string | null;
245
+ hostGroup?: string;
147
246
  maxCheckAttempts?: number | null;
148
247
  name: string;
149
248
  passiveCheckEnabled?: boolean;
@@ -159,6 +258,7 @@ Cypress.Commands.add(
159
258
  alias = null,
160
259
  checkCommand = null,
161
260
  checkPeriod = null,
261
+ hostGroup = '',
162
262
  maxCheckAttempts = 1,
163
263
  name,
164
264
  passiveCheckEnabled = true,
@@ -176,7 +276,7 @@ Cypress.Commands.add(
176
276
  bodyContent: {
177
277
  action: 'ADD',
178
278
  object: 'HOST',
179
- values: `${name};${hostAlias};${address};${template};${poller};`
279
+ values: `${name};${hostAlias};${address};${template};${poller};${hostGroup}`
180
280
  }
181
281
  })
182
282
  .then(() => {
@@ -206,6 +306,26 @@ Cypress.Commands.add(
206
306
  }
207
307
  );
208
308
 
309
+ interface HostGroup {
310
+ alias?: string | null;
311
+ name: string;
312
+ }
313
+
314
+ Cypress.Commands.add(
315
+ 'addHostGroup',
316
+ ({ alias = null, name }: HostGroup): Cypress.Chainable => {
317
+ const hostGroupAlias = alias === null ? name : alias;
318
+
319
+ return cy.executeActionViaClapi({
320
+ bodyContent: {
321
+ action: 'ADD',
322
+ object: 'HG',
323
+ values: `${name};${hostGroupAlias}`
324
+ }
325
+ });
326
+ }
327
+ );
328
+
209
329
  interface ServiceTemplate {
210
330
  activeCheckEnabled?: boolean;
211
331
  checkCommand?: string | null;
@@ -327,6 +447,45 @@ Cypress.Commands.add(
327
447
  }
328
448
  );
329
449
 
450
+ interface ServiceGroup {
451
+ alias?: string | null;
452
+ hostsAndServices: string[][];
453
+ name: string;
454
+ }
455
+
456
+ Cypress.Commands.add(
457
+ 'addServiceGroup',
458
+ ({
459
+ alias = null,
460
+ hostsAndServices,
461
+ name
462
+ }: ServiceGroup): Cypress.Chainable => {
463
+ const serviceGroupAlias = alias === null ? name : alias;
464
+
465
+ return cy
466
+ .executeActionViaClapi({
467
+ bodyContent: {
468
+ action: 'ADD',
469
+ object: 'SG',
470
+ values: `${name};${serviceGroupAlias}`
471
+ }
472
+ })
473
+ .then(() => {
474
+ hostsAndServices.map((hostAndService) => {
475
+ return cy.executeActionViaClapi({
476
+ bodyContent: {
477
+ action: 'ADDSERVICE',
478
+ object: 'SG',
479
+ values: `${name};${hostAndService[0]},${hostAndService[1]}`
480
+ }
481
+ });
482
+ });
483
+
484
+ return cy.wrap(null);
485
+ });
486
+ }
487
+ );
488
+
330
489
  Cypress.Commands.add(
331
490
  'applyPollerConfiguration',
332
491
  (pollerName = 'Central'): Cypress.Chainable => {
@@ -339,12 +498,179 @@ Cypress.Commands.add(
339
498
  }
340
499
  );
341
500
 
501
+ interface ACLGroup {
502
+ alias?: string | null;
503
+ contacts?: string[];
504
+ contactGroups?: string[];
505
+ name: string;
506
+ }
507
+
508
+ Cypress.Commands.add(
509
+ 'addACLGroup',
510
+ ({
511
+ alias = null,
512
+ contacts = [],
513
+ contactGroups = [],
514
+ name
515
+ }: ACLGroup): Cypress.Chainable => {
516
+ const ACLGroupALias = alias === null ? name : alias;
517
+
518
+ return cy
519
+ .executeActionViaClapi({
520
+ bodyContent: {
521
+ action: 'ADD',
522
+ object: 'ACLGROUP',
523
+ values: `${name};${ACLGroupALias}`
524
+ }
525
+ })
526
+ .then(() => {
527
+ if (contacts) {
528
+ contacts.map((contact) => {
529
+ cy.executeActionViaClapi({
530
+ bodyContent: {
531
+ action: 'ADDCONTACT',
532
+ object: 'ACLGROUP',
533
+ values: `${name};${contact}`
534
+ }
535
+ });
536
+ });
537
+ }
538
+ if (contactGroups) {
539
+ contactGroups.map((contactGroup) => {
540
+ cy.executeActionViaClapi({
541
+ bodyContent: {
542
+ action: 'ADDCONTACTGROUP',
543
+ object: 'ACLGROUP',
544
+ values: `${name};${contactGroup}`
545
+ }
546
+ });
547
+ });
548
+ }
549
+ });
550
+ }
551
+ );
552
+
553
+ interface ACLMenu {
554
+ name: string;
555
+ rule?: string[];
556
+ alias?: string | null;
557
+ includeChildren?: boolean;
558
+ readOnly?: boolean;
559
+ }
560
+
561
+ Cypress.Commands.add(
562
+ 'addACLMenu',
563
+ ({
564
+ name,
565
+ rule = [],
566
+ alias = null,
567
+ includeChildren = true,
568
+ readOnly = false
569
+ }: ACLMenu): Cypress.Chainable => {
570
+ const ACLMenuAlias = alias === null ? name : alias;
571
+ const action = readOnly ? 'GRANTRO' : 'GRANTRW';
572
+ const children = includeChildren ? '1' : '0';
573
+
574
+ return cy
575
+ .executeActionViaClapi({
576
+ bodyContent: {
577
+ action: 'ADD',
578
+ object: 'ACLMENU',
579
+ values: `${name};${ACLMenuAlias}`
580
+ }
581
+ })
582
+ .then(() => {
583
+ if (rule.length == 0) {
584
+ return cy.wrap(null);
585
+ }
586
+
587
+ let ruleCommand = '';
588
+ rule.map((rulePage, index) => {
589
+ ruleCommand += rulePage + (index == rule.length - 1 ? '' : ';');
590
+ });
591
+ cy.executeActionViaClapi({
592
+ bodyContent: {
593
+ action: action,
594
+ object: 'ACLMENU',
595
+ values: `${name};${children};${ruleCommand}`
596
+ }
597
+ });
598
+ return cy.wrap(null);
599
+ });
600
+ }
601
+ );
602
+
603
+ interface ACLAction {
604
+ name: string;
605
+ description: string;
606
+ actions?: Action[];
607
+ }
608
+
609
+ Cypress.Commands.add(
610
+ 'addACLAction',
611
+ ({ name, description, actions = [] }: ACLAction): Cypress.Chainable => {
612
+ return cy
613
+ .executeActionViaClapi({
614
+ bodyContent: {
615
+ action: 'ADD',
616
+ object: 'ACLACTION',
617
+ values: `${name};${description}`
618
+ }
619
+ })
620
+ .then(() => {
621
+ if (actions.length == 0) {
622
+ return cy.wrap(null);
623
+ }
624
+
625
+ let actionCommand = '';
626
+ actions.map((action, index) => {
627
+ actionCommand += action + (index == actions.length - 1 ? '' : '|');
628
+ });
629
+ cy.executeActionViaClapi({
630
+ bodyContent: {
631
+ action: 'GRANT',
632
+ object: 'ACLACTION',
633
+ values: `${name};${actionCommand}`
634
+ }
635
+ });
636
+ return cy.wrap(null);
637
+ });
638
+ }
639
+ );
640
+
641
+ interface ACLResource {
642
+ name: string;
643
+ alias?: string | null;
644
+ }
645
+
646
+ Cypress.Commands.add(
647
+ 'addACLResource',
648
+ ({ name, alias = null }: ACLResource): Cypress.Chainable => {
649
+ const ACLResourcesAlias = alias === null ? name : alias;
650
+ return cy.executeActionViaClapi({
651
+ bodyContent: {
652
+ action: 'ADD',
653
+ object: 'ACLRESOURCE',
654
+ values: `${name};${ACLResourcesAlias}`
655
+ }
656
+ });
657
+ }
658
+ );
659
+
342
660
  declare global {
343
661
  namespace Cypress {
344
662
  interface Chainable {
663
+ addACLAction: (props: ACLAction) => Cypress.Chainable;
664
+ addACLGroup: (props: ACLGroup) => Cypress.Chainable;
665
+ addACLMenu: (props: ACLMenu) => Cypress.Chainable;
666
+ addACLResource: (props: ACLResource) => Cypress.Chainable;
345
667
  addCheckCommand: (props: CheckCommand) => Cypress.Chainable;
668
+ addContact: (props: Contact) => Cypress.Chainable;
669
+ addContactGroup: (props: ContactGroup) => Cypress.Chainable;
346
670
  addHost: (props: Host) => Cypress.Chainable;
671
+ addHostGroup: (props: HostGroup) => Cypress.Chainable;
347
672
  addService: (props: Service) => Cypress.Chainable;
673
+ addServiceGroup: (props: ServiceGroup) => Cypress.Chainable;
348
674
  addServiceTemplate: (props: ServiceTemplate) => Cypress.Chainable;
349
675
  addTimePeriod: (props: TimePeriod) => Cypress.Chainable;
350
676
  applyPollerConfiguration: (props?: string) => Cypress.Chainable;
@@ -29,6 +29,12 @@ interface SubmitResult {
29
29
  status: string;
30
30
  }
31
31
 
32
+ interface ServiceCheck {
33
+ host: string;
34
+ isForced?: boolean;
35
+ service: string;
36
+ }
37
+
32
38
  Cypress.Commands.add(
33
39
  'submitResults',
34
40
  (results: Array<SubmitResult>): Cypress.Chainable => {
@@ -64,10 +70,60 @@ Cypress.Commands.add(
64
70
  }
65
71
  );
66
72
 
73
+ Cypress.Commands.add(
74
+ 'scheduleServiceCheck',
75
+ ({
76
+ host,
77
+ isForced = true,
78
+ service
79
+ }: ServiceCheck): Cypress.Chainable => {
80
+ let query = `SELECT parent_id, id FROM resources WHERE parent_name = '${host}' AND name = '${service}'`;
81
+
82
+ return cy
83
+ .requestOnDatabase({
84
+ database: 'centreon_storage',
85
+ query
86
+ })
87
+ .then(([rows]) => {
88
+ if (rows.length === 0) {
89
+ throw new Error(`Cannot find service ${host} / ${service}`);
90
+ }
91
+
92
+ const hostId = rows[0].parent_id;
93
+ const serviceId = rows[0].id;
94
+
95
+ return cy.request({
96
+ body: {
97
+ check: {
98
+ is_forced: isForced
99
+ },
100
+ resources: [
101
+ {
102
+ id: serviceId,
103
+ parent: {
104
+ id: hostId
105
+ },
106
+ type: 'service'
107
+ }
108
+ ]
109
+ },
110
+ method: 'POST',
111
+ timeout: 30000,
112
+ url: '/centreon/api/latest/monitoring/resources/check'
113
+ }).then((response) => {
114
+ expect(response.status).to.eq(204);
115
+
116
+ return cy.wrap(null);
117
+ });
118
+ });
119
+ }
120
+ );
121
+
67
122
  declare global {
68
123
  namespace Cypress {
69
124
  interface Chainable {
70
125
  submitResults: (props: Array<SubmitResult>) => Cypress.Chainable;
126
+ scheduleServiceCheck: (serviceCheck) => Cypress.Chainable;
71
127
  }
72
128
  }
73
129
  }