Skip to content

Commit 9bf6e01

Browse files
committed
Merge remote-tracking branch 'origin/main'
2 parents befa9de + 2d68c81 commit 9bf6e01

File tree

336 files changed

+4489
-2239
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

336 files changed

+4489
-2239
lines changed

app/bootstrap/src/main/resources/static/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
</head>
1010
<body>
1111
<div id="root"></div>
12-
<script src="/umi.83a9f38e.js"></script>
12+
<script src="/umi.843dc987.js"></script>
1313
</body>
1414
</html>

app/bootstrap/src/main/resources/static/p__CloudAccount__index.3e44e7a3.async.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/bootstrap/src/main/resources/static/umi.843dc987.js

Lines changed: 402 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one or more
2+
// contributor license agreements. See the NOTICE file distributed with
3+
// this work for additional information regarding copyright ownership.
4+
// The ASF licenses this file to You under the Apache License, Version 2.0
5+
// (the "License"); you may not use this file except in compliance with
6+
// the License. You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
package arms
17+
18+
import (
19+
"context"
20+
"encoding/json"
21+
22+
arms20190808 "github.com/alibabacloud-go/arms-20190808/v8/client"
23+
util "github.com/alibabacloud-go/tea-utils/v2/service"
24+
"github.com/alibabacloud-go/tea/tea"
25+
"github.com/cloudrec/alicloud/collector"
26+
"github.com/core-sdk/constant"
27+
"github.com/core-sdk/log"
28+
"github.com/core-sdk/schema"
29+
"go.uber.org/zap"
30+
)
31+
32+
func GetARMSPrometheusResource() schema.Resource {
33+
return schema.Resource{
34+
ResourceType: collector.ARMSPrometheus,
35+
ResourceTypeName: collector.ARMSPrometheus,
36+
ResourceGroupType: constant.MONITORING,
37+
Desc: `https://api.aliyun.com/product/ARMS`,
38+
ResourceDetailFunc: GetPrometheusDetail,
39+
RowField: schema.RowField{
40+
ResourceId: "$.PrometheusInstance.ClusterId",
41+
ResourceName: "$.PrometheusInstance.ClusterName",
42+
},
43+
Dimension: schema.Global,
44+
}
45+
}
46+
47+
type PrometheusInstance struct {
48+
AgentStatus string `json:"agentStatus,omitempty"`
49+
ClusterId string `json:"clusterId,omitempty"`
50+
ClusterName string `json:"clusterName,omitempty"`
51+
ClusterType string `json:"clusterType,omitempty"`
52+
CommercialConfig interface{} `json:"commercialConfig,omitempty"`
53+
ControllerId string `json:"controllerId,omitempty"`
54+
CreateTime int64 `json:"createTime,omitempty"`
55+
Id int64 `json:"id,omitempty"`
56+
IsAdvancedClusterInstalled bool `json:"isAdvancedClusterInstalled,omitempty"`
57+
IsClusterRunning bool `json:"isClusterRunning,omitempty"`
58+
IsControllerInstalled bool `json:"isControllerInstalled,omitempty"`
59+
IsIntegrationCenter bool `json:"isIntegrationCenter,omitempty"`
60+
RegionId string `json:"regionId,omitempty"`
61+
UpdateTime int64 `json:"updateTime,omitempty"`
62+
UserId string `json:"userId,omitempty"`
63+
SubClustersJson string `json:"subClustersJson,omitempty"`
64+
}
65+
66+
type PrometheusDetail struct {
67+
PrometheusInstance *arms20190808.GetPrometheusInstanceResponseBodyData
68+
AlertRules []*arms20190808.ListPrometheusAlertRulesResponseBodyPrometheusAlertRules
69+
MonitoringConfigs []*arms20190808.ListPrometheusMonitoringResponseBodyData
70+
SubClusters []SubClusterDetail
71+
}
72+
73+
type SubClusterDetail struct {
74+
ClusterName string `json:"clusterName,omitempty"`
75+
ClusterId string `json:"clusterId,omitempty"`
76+
ClusterType string `json:"clusterType,omitempty"`
77+
RegionId string `json:"regionId,omitempty"`
78+
}
79+
80+
func GetPrometheusDetail(ctx context.Context, service schema.ServiceInterface, res chan<- any) error {
81+
cli := service.(*collector.Services).ARMS
82+
83+
request := &arms20190808.ListPrometheusInstancesRequest{}
84+
85+
response, err := cli.ListPrometheusInstancesWithOptions(request, &util.RuntimeOptions{})
86+
if err != nil {
87+
log.CtxLogger(ctx).Warn("ListPrometheusInstances error", zap.Error(err))
88+
return err
89+
}
90+
91+
if response.Body == nil || response.Body.Data == nil {
92+
return nil
93+
}
94+
95+
// Parse JSON response
96+
var instances []PrometheusInstance
97+
if err := json.Unmarshal([]byte(tea.StringValue(response.Body.Data)), &instances); err != nil {
98+
log.CtxLogger(ctx).Warn("Failed to unmarshal Prometheus instances", zap.Error(err))
99+
return err
100+
}
101+
102+
for _, instance := range instances {
103+
if instance.ClusterId == "" {
104+
continue
105+
}
106+
107+
clusterId := instance.ClusterId
108+
109+
// Get detailed Prometheus instance configuration
110+
prometheusInstance := getPrometheusInstance(ctx, cli, clusterId)
111+
112+
// Get alert rules for this Prometheus instance
113+
alertRules := listPrometheusAlertRules(ctx, cli, clusterId)
114+
115+
// Get monitoring configurations
116+
monitoringConfigs := listPrometheusMonitoring(ctx, cli, clusterId)
117+
118+
// Parse sub-clusters if available
119+
var subClusters []SubClusterDetail
120+
if instance.SubClustersJson != "" {
121+
if err := json.Unmarshal([]byte(instance.SubClustersJson), &subClusters); err != nil {
122+
log.CtxLogger(ctx).Warn("Failed to unmarshal SubClustersJson",
123+
zap.String("clusterId", clusterId), zap.Error(err))
124+
}
125+
}
126+
127+
detail := PrometheusDetail{
128+
PrometheusInstance: prometheusInstance,
129+
AlertRules: alertRules,
130+
MonitoringConfigs: monitoringConfigs,
131+
SubClusters: subClusters,
132+
}
133+
134+
res <- detail
135+
}
136+
137+
return nil
138+
}
139+
140+
func getPrometheusInstance(ctx context.Context, cli *arms20190808.Client, clusterId string) *arms20190808.GetPrometheusInstanceResponseBodyData {
141+
request := &arms20190808.GetPrometheusInstanceRequest{
142+
ClusterId: tea.String(clusterId),
143+
}
144+
145+
response, err := cli.GetPrometheusInstanceWithOptions(request, &util.RuntimeOptions{})
146+
if err != nil {
147+
log.CtxLogger(ctx).Warn("GetPrometheusInstance error",
148+
zap.String("clusterId", clusterId), zap.Error(err))
149+
return &arms20190808.GetPrometheusInstanceResponseBodyData{}
150+
}
151+
152+
if response.Body == nil || response.Body.Data == nil {
153+
return &arms20190808.GetPrometheusInstanceResponseBodyData{}
154+
}
155+
156+
return response.Body.Data
157+
}
158+
159+
func listPrometheusAlertRules(ctx context.Context, cli *arms20190808.Client, clusterId string) []*arms20190808.ListPrometheusAlertRulesResponseBodyPrometheusAlertRules {
160+
request := &arms20190808.ListPrometheusAlertRulesRequest{
161+
ClusterId: tea.String(clusterId),
162+
}
163+
164+
response, err := cli.ListPrometheusAlertRulesWithOptions(request, &util.RuntimeOptions{})
165+
if err != nil {
166+
log.CtxLogger(ctx).Warn("ListPrometheusAlertRules error",
167+
zap.String("clusterId", clusterId), zap.Error(err))
168+
return []*arms20190808.ListPrometheusAlertRulesResponseBodyPrometheusAlertRules{}
169+
}
170+
171+
if response.Body == nil || response.Body.PrometheusAlertRules == nil {
172+
return []*arms20190808.ListPrometheusAlertRulesResponseBodyPrometheusAlertRules{}
173+
}
174+
175+
return response.Body.PrometheusAlertRules
176+
}
177+
178+
func listPrometheusMonitoring(ctx context.Context, cli *arms20190808.Client, clusterId string) []*arms20190808.ListPrometheusMonitoringResponseBodyData {
179+
request := &arms20190808.ListPrometheusMonitoringRequest{
180+
ClusterId: tea.String(clusterId),
181+
}
182+
183+
response, err := cli.ListPrometheusMonitoringWithOptions(request, &util.RuntimeOptions{})
184+
if err != nil {
185+
log.CtxLogger(ctx).Warn("ListPrometheusMonitoring error",
186+
zap.String("clusterId", clusterId), zap.Error(err))
187+
return []*arms20190808.ListPrometheusMonitoringResponseBodyData{}
188+
}
189+
190+
if response.Body == nil || response.Body.Data == nil {
191+
return []*arms20190808.ListPrometheusMonitoringResponseBodyData{}
192+
}
193+
194+
return response.Body.Data
195+
}
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one or more
2+
// contributor license agreements. See the NOTICE file distributed with
3+
// this work for additional information regarding copyright ownership.
4+
// The ASF licenses this file to You under the Apache License, Version 2.0
5+
// (the "License"); you may not use this file except in compliance with
6+
// the License. You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
package cloudapi
17+
18+
import (
19+
"context"
20+
cloudapi20160714 "github.com/alibabacloud-go/cloudapi-20160714/v5/client"
21+
"github.com/alibabacloud-go/tea/tea"
22+
"github.com/cloudrec/alicloud/collector"
23+
"github.com/core-sdk/constant"
24+
"github.com/core-sdk/log"
25+
"github.com/core-sdk/schema"
26+
"go.uber.org/zap"
27+
)
28+
29+
func GetAPIGatewayAppResource() schema.Resource {
30+
return schema.Resource{
31+
ResourceType: collector.APIGatewayApp,
32+
ResourceTypeName: "API Gateway App",
33+
ResourceGroupType: constant.NET,
34+
Desc: `https://api.aliyun.com/product/CloudAPI`,
35+
ResourceDetailFunc: GetAPIGatewayAppDetail,
36+
RowField: schema.RowField{
37+
ResourceId: "$.App.AppId",
38+
ResourceName: "$.App.AppName",
39+
},
40+
Dimension: schema.Global,
41+
}
42+
}
43+
44+
type APIGatewayAppDetail struct {
45+
App *cloudapi20160714.DescribeAppsResponseBodyAppsAppItem
46+
AppSecurity *cloudapi20160714.DescribeAppSecurityResponseBody
47+
AuthorizedAPIs []*cloudapi20160714.DescribeAuthorizedApisResponseBodyAuthorizedApisAuthorizedApi
48+
}
49+
50+
func GetAPIGatewayAppDetail(ctx context.Context, service schema.ServiceInterface, res chan<- any) error {
51+
cli := service.(*collector.Services).CloudAPI
52+
53+
describeAppsRequest := &cloudapi20160714.DescribeAppsRequest{}
54+
describeAppsRequest.PageSize = tea.Int32(100)
55+
describeAppsRequest.PageNumber = tea.Int32(1)
56+
57+
for {
58+
response, err := cli.DescribeApps(describeAppsRequest)
59+
if err != nil {
60+
log.CtxLogger(ctx).Warn("DescribeAppsWithOptions error", zap.Error(err))
61+
return err
62+
}
63+
64+
if response.Body.Apps == nil || len(response.Body.Apps.AppItem) == 0 {
65+
break
66+
}
67+
68+
for _, app := range response.Body.Apps.AppItem {
69+
appSecurity := getAppSecurity(ctx, cli, app.AppId)
70+
authorizedAPIs := getAuthorizedAPIs(ctx, cli, app.AppId)
71+
72+
d := APIGatewayAppDetail{
73+
App: app,
74+
AppSecurity: appSecurity,
75+
AuthorizedAPIs: authorizedAPIs,
76+
}
77+
78+
res <- d
79+
}
80+
81+
// Check if there are more pages
82+
totalCount := tea.Int32Value(response.Body.TotalCount)
83+
pageSize := tea.Int32Value(describeAppsRequest.PageSize)
84+
currentPage := tea.Int32Value(describeAppsRequest.PageNumber)
85+
86+
if currentPage*pageSize >= totalCount {
87+
break
88+
}
89+
90+
describeAppsRequest.PageNumber = tea.Int32(currentPage + 1)
91+
}
92+
93+
return nil
94+
}
95+
96+
func getAppSecurity(ctx context.Context, cli *cloudapi20160714.Client, appId *int64) *cloudapi20160714.DescribeAppSecurityResponseBody {
97+
describeAppSecurityRequest := &cloudapi20160714.DescribeAppSecurityRequest{AppId: appId}
98+
99+
response, err := cli.DescribeAppSecurity(describeAppSecurityRequest)
100+
if err != nil {
101+
log.CtxLogger(ctx).Warn("DescribeAppSecurityWithOptions error", zap.Error(err), zap.Int64("appId", *appId))
102+
return nil
103+
}
104+
105+
return response.Body
106+
}
107+
108+
func getAuthorizedAPIs(ctx context.Context, cli *cloudapi20160714.Client, appId *int64) (allAPIs []*cloudapi20160714.DescribeAuthorizedApisResponseBodyAuthorizedApisAuthorizedApi) {
109+
describeAuthorizedApisRequest := &cloudapi20160714.DescribeAuthorizedApisRequest{}
110+
describeAuthorizedApisRequest.AppId = appId
111+
describeAuthorizedApisRequest.PageSize = tea.Int32(100)
112+
113+
pageNumber := int32(1)
114+
115+
for {
116+
describeAuthorizedApisRequest.PageNumber = tea.Int32(pageNumber)
117+
118+
response, err := cli.DescribeAuthorizedApis(describeAuthorizedApisRequest)
119+
if err != nil {
120+
log.CtxLogger(ctx).Warn("DescribeAuthorizedApisWithOptions error", zap.Error(err), zap.Int64("appId", *appId))
121+
return allAPIs
122+
}
123+
124+
if response.Body.AuthorizedApis == nil || len(response.Body.AuthorizedApis.AuthorizedApi) == 0 {
125+
break
126+
}
127+
128+
allAPIs = append(allAPIs, response.Body.AuthorizedApis.AuthorizedApi...)
129+
130+
// Check if there are more pages
131+
totalCount := tea.Int32Value(response.Body.TotalCount)
132+
pageSize := tea.Int32Value(describeAuthorizedApisRequest.PageSize)
133+
currentPage := pageNumber
134+
135+
if currentPage*pageSize >= totalCount {
136+
break
137+
}
138+
139+
pageNumber++
140+
}
141+
142+
return allAPIs
143+
}

0 commit comments

Comments
 (0)