@centreon/ui 24.4.1-MON-38245-ba-tree-widget.7 → 24.4.1-MON-38245-ba-tree-widget.8
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.
- package/package.json +1 -1
- package/src/utils/index.ts +1 -0
- package/src/utils/resourcesStatusURL.ts +146 -0
package/package.json
CHANGED
package/src/utils/index.ts
CHANGED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import {
|
|
2
|
+
always,
|
|
3
|
+
cond,
|
|
4
|
+
equals,
|
|
5
|
+
flatten,
|
|
6
|
+
groupBy,
|
|
7
|
+
identity,
|
|
8
|
+
includes,
|
|
9
|
+
map,
|
|
10
|
+
pipe,
|
|
11
|
+
T
|
|
12
|
+
} from 'ramda';
|
|
13
|
+
|
|
14
|
+
import { SelectEntry } from '..';
|
|
15
|
+
|
|
16
|
+
import { centreonBaseURL } from './centreonBaseURL';
|
|
17
|
+
|
|
18
|
+
export interface Resource {
|
|
19
|
+
resourceType: string;
|
|
20
|
+
resources: Array<SelectEntry>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface GetResourcesUrlProps {
|
|
24
|
+
allResources: Array<Resource>;
|
|
25
|
+
isForOneResource: boolean;
|
|
26
|
+
resource?;
|
|
27
|
+
states: Array<string>;
|
|
28
|
+
statuses: Array<string>;
|
|
29
|
+
type: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const getDetailsPanelQueriers = ({ resource, type }): object => {
|
|
33
|
+
const { id, parentId, uuid, type: resourceType } = resource;
|
|
34
|
+
|
|
35
|
+
const resourcesDetailsEndpoint =
|
|
36
|
+
equals(type, 'host') || equals(resourceType, 'host')
|
|
37
|
+
? `${centreonBaseURL}/api/latest/monitoring/resources/hosts/${id}`
|
|
38
|
+
: `${centreonBaseURL}/api/latest/monitoring/resources/hosts/${parentId}/services/${id}`;
|
|
39
|
+
|
|
40
|
+
const queryParameters = {
|
|
41
|
+
id,
|
|
42
|
+
resourcesDetailsEndpoint,
|
|
43
|
+
selectedTimePeriodId: 'last_24_h',
|
|
44
|
+
tab: 'details',
|
|
45
|
+
tabParameters: {},
|
|
46
|
+
uuid
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
return queryParameters;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const getResourcesUrl = ({
|
|
53
|
+
type,
|
|
54
|
+
statuses,
|
|
55
|
+
states,
|
|
56
|
+
allResources,
|
|
57
|
+
isForOneResource,
|
|
58
|
+
resource
|
|
59
|
+
}: GetResourcesUrlProps): string => {
|
|
60
|
+
const resourcesCriterias = equals(type, 'all')
|
|
61
|
+
? {
|
|
62
|
+
name: 'resource_types',
|
|
63
|
+
value: [
|
|
64
|
+
{ id: 'service', name: 'Service' },
|
|
65
|
+
{ id: 'host', name: 'Host' }
|
|
66
|
+
]
|
|
67
|
+
}
|
|
68
|
+
: {
|
|
69
|
+
name: 'resource_types',
|
|
70
|
+
value: [
|
|
71
|
+
{ id: type, name: `${type.charAt(0).toUpperCase()}${type.slice(1)}` }
|
|
72
|
+
]
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const formattedStatuses = pipe(
|
|
76
|
+
flatten,
|
|
77
|
+
map((status: string) => {
|
|
78
|
+
return {
|
|
79
|
+
id: status.toLocaleUpperCase(),
|
|
80
|
+
name: `${status.charAt(0).toUpperCase()}${status.slice(1)}`
|
|
81
|
+
};
|
|
82
|
+
})
|
|
83
|
+
)(statuses);
|
|
84
|
+
|
|
85
|
+
const formattedStates = states.map((state) => {
|
|
86
|
+
return {
|
|
87
|
+
id: state,
|
|
88
|
+
name: `${state.charAt(0).toUpperCase()}${state.slice(1)}`
|
|
89
|
+
};
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
const groupedResources = groupBy(
|
|
93
|
+
({ resourceType }) => resourceType,
|
|
94
|
+
allResources
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
const resourcesFilters = Object.entries(groupedResources).map(
|
|
98
|
+
([resourceType, res]) => {
|
|
99
|
+
const name = cond<Array<string>, string>([
|
|
100
|
+
[equals('host'), always('parent_name')],
|
|
101
|
+
[equals('service'), always('name')],
|
|
102
|
+
[T, identity]
|
|
103
|
+
])(resourceType);
|
|
104
|
+
|
|
105
|
+
return {
|
|
106
|
+
name: name.replace('-', '_'),
|
|
107
|
+
value: flatten(
|
|
108
|
+
(res || []).map(({ resources: subResources }) => {
|
|
109
|
+
return subResources.map(({ name: resourceName }) => ({
|
|
110
|
+
id: includes(name, ['name', 'parent_name'])
|
|
111
|
+
? `\\b${resourceName}\\b`
|
|
112
|
+
: resourceName,
|
|
113
|
+
name: resourceName
|
|
114
|
+
}));
|
|
115
|
+
})
|
|
116
|
+
)
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
const filterQueryParameter = {
|
|
122
|
+
criterias: [
|
|
123
|
+
resourcesCriterias,
|
|
124
|
+
{ name: 'statuses', value: formattedStatuses },
|
|
125
|
+
{ name: 'states', value: formattedStates },
|
|
126
|
+
...resourcesFilters,
|
|
127
|
+
{ name: 'search', value: '' }
|
|
128
|
+
]
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const encodedFilterParams = encodeURIComponent(
|
|
132
|
+
JSON.stringify(filterQueryParameter)
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
if (!isForOneResource) {
|
|
136
|
+
return `/monitoring/resources?filter=${encodedFilterParams}&fromTopCounter=true`;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const detailsPanelQueriers = getDetailsPanelQueriers({ resource, type });
|
|
140
|
+
|
|
141
|
+
const encodedDetailsParams = encodeURIComponent(
|
|
142
|
+
JSON.stringify(detailsPanelQueriers)
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
return `/monitoring/resources?details=${encodedDetailsParams}&filter=${encodedFilterParams}&fromTopCounter=true`;
|
|
146
|
+
};
|