forked from GoogleCloudPlatform/professional-services
-
Notifications
You must be signed in to change notification settings - Fork 0
/
recommendations-example.yaml
203 lines (198 loc) · 8.92 KB
/
recommendations-example.yaml
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
# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
retryPeriod: 10 years ago
processors:
- recommendations
# If set to true, all outputs must succeed in order the function to be considered successful.
allOutputsMustSucceed: true
recommendations:
fetch_recommendations: true
fetch_insights: true
recommender_types:
# Full list: https://cloud.google.com/recommender/docs/recommenders#recommenders
- google.compute.instance.MachineTypeRecommender # Location: zone
- google.compute.instanceGroupManager.MachineTypeRecommender # Location: zone
- google.compute.instance.IdleResourceRecommender # Location: zone
- google.compute.disk.IdleResourceRecommender # Location: region & zone
- google.compute.address.IdleResourceRecommender # Location: region & global
- google.compute.image.IdleResourceRecommender # Location: region & global
- google.compute.commitment.UsageCommitmentRecommender # Location: region
recommendation_filter: 'stateInfo.state=ACTIVE'
insight_types:
# Full list: https://cloud.google.com/recommender/docs/insights/insight-types
- google.compute.firewall.Insight
- google.iam.policy.Insight
- google.iam.serviceAccount.Insight
insight_filter: 'stateInfo.state=ACTIVE'
projects: "{{ projects|json_encode() }}" # Projects from Pub/Sub message
# projects:
# - fixed-project-list
# organizations:
# - 123456789
# folders:
# - 987654321
# billingAccounts:
# - 000000-ABCDEF-000000
locations:
- global
- europe
- us
- europe-west1*
- us-central1*
vars:
types:
organizations: "Organization"
projects: "Project"
folders: "Folder"
billingAccounts: "Billing account"
commitment_types:
THIRTY_SIX_MONTH: "36 months"
TWELVE_MONTH: "12 months"
links:
google.compute.instance.IdleResourceRecommender: https://console.cloud.google.com/home/recommendations/list/COMPUTE_IDLE_RESOURCES?
google.compute.instance.MachineTypeRecommender: https://console.cloud.google.com/home/recommendations/list/VM_COST?
google.compute.instanceGroupManager.MachineTypeRecommender: https://console.cloud.google.com/home/recommendations/list/VM_COST?
google.compute.disk.IdleResourceRecommender: https://console.cloud.google.com/home/recommendations/list/COMPUTE_IDLE_RESOURCES?
google.compute.firewall.Insight: https://console.cloud.google.com/home/recommendations/list/SHADOWED_FIREWALL_RULES?
google.compute.commitment.UsageCommitmentRecommender: https://console.cloud.google.com/home/recommendations/list/PROJECT_COMMITMENTS?
google.iam.policy.Insight: https://console.cloud.google.com/home/recommendations/list/IAM_ROLES?
outputs:
- type: mail
# Transports will be tried in sequence, until one succeeds
transports:
- type: smtp
host: your.smtp.server
port: 25
starttls: false
# ssl: false
- type: sendgrid
apiKey: API-KEY-HERE
from: [email protected]
subject: |
[Google Cloud Platform] Recommendations and Insights report, {{ ""|strftime('%b %Y') }}
body:
images: # Images to inline in the email
- img/sample-logo-small.png
html: |
<html><head><title>Recommendations and Insights, {{ ""|strftime('%b %Y') }}</title>
<style type="text/css">
body {
font-family: 'Google Sans', 'Segoe UI', sans-serif;
}
table {
border-collapse: collapse;
}
thead {
background-color: #0F9D58;
color: white;
}
th {
padding: 0.5em;
text-align: left;
}
td {
padding: 0.2em;
}
.even {
background-color: #ddd;
}
</style>
</head>
<body>
<h1>Google Cloud Platform - Recommendations and Insights report, {{ ""|strftime('%b %Y') }}</h1>
<img src="cid:sample-logo-small.png" alt="Sample logo" />
<h2>Recommendations</h2>
{% for parent, parent_recommendations in recommendations.items() %}
{% set total_cost = namespace(cost=0) %}
{% set row_class = cycler('odd', 'even') %}
{% for r in parent_recommendations %}
{% if loop.first %}
<h3>{{ types[r.type] }}: {% if r.type == "projects" %}{{ r.parent[2] }} ({{ r.parent[0] }}){% else %}{{ r.parent|make_list|first }}{% endif %}</h3>
<table>
<thead>
<th>Resource</th>
<th>Recommended action</th>
<th>Description</th>
<th>Impact</th>
</thead>
<tbody>
{% endif %}
{% for og in r.recommendation.content.operation_groups %}
{% for op in og.operations %}
{% if op.action != 'test' and not op.resource.endswith('$snapshot-name') %}
<tr class="{{ row_class.next() }}">
<td>{% if r.recommender_type in links %}<a href="{{ links[r.recommender_type] }}{{ r.link }}">{% endif %}{% if op.resource_type != 'compute.googleapis.com/Commitment' -%}
{{ op.resource|split("/")|index(-1) }}
{%- else -%}
{% for res in op.value.resources %}{{ res.type|title }}: {% if res.type == 'VCPU' %}{{ res.amount }} vCPU(s){% else %}{{ (res.amount/1024)|round }} GB{% endif %}{% endfor %}
{%- endif %}{% if r.recommender_type in links %}</a>{% endif %}
</td>
<td>{{ op.action|title }}</td>
<td>{{ r.recommendation.description }}</td>
<td>{% if 'cost_projection' in r.recommendation.primary_impact %}{{ r.recommendation.primary_impact.cost_projection.cost|format_cost() }}{% endif %}</td>
</tr>
{% endif %}
{% endfor %}
{% endfor %}
{%- if 'cost_projection' in r.recommendation.primary_impact -%}
{%- set total_cost.cost = total_cost.cost + r.recommendation.primary_impact.cost_projection.cost|get_cost() -%}
{%- endif -%}
{% if loop.last %}
<tfoot>
<tr>
<td colspan="3">Total cost impact:</td>
<td>{{ "{:.2f}".format(total_cost.cost) }} USD</td>
</tr>
</tfoot>
</tbody>
</table>
{% endif %}
{% endfor %}
{% endfor %}
{% for parent, parent_insights in insights.items() %}
{% if loop.first %}
<h2>Insights</h2>
{% endif %}
{% set total_cost = namespace(cost=0) %}
{% for i in parent_insights %}
{% if loop.first %}
<h3>{{ types[i.type] }}: {% if i.type == "projects" %}{{ i.parent[2] }} ({{ i.parent[0] }}){% else %}{{ i.parent|make_list|first }}{% endif %}</h3>
<table>
<thead>
<th>Resource</th>
<th>Content</th>
<th>Description</th>
</thead>
<tbody>
{% endif %}
<tr class="{{ loop.cycle('odd', 'even') }}"
{% for tr in i.insight.target_resources %}
<td>{{ tr|split("/")|reverse|batch(2)|first|reverse|join("/")}}</td>
<td>
{%- if 'shadowingFirewalls' in i.insight.content %}{% for fw in i.insight.content.shadowingFirewalls %}{% if not loop.first %}, {% endif %}{{ fw }}{% endfor %}{% endif -%}
{%- if 'member' in i.insight.content %}{{ i.insight.content.member }} ({{ i.insight.content.role }}){% endif -%}
{%- if 'email' in i.insight.content %}{{ i.insight.content.email }} {%- if 'lastAuthenticatedTime' in i.insight.content %}({{ i.insight.content.lastAuthenticatedTime }}){% endif -%}{% endif -%}
</td>
<td>{{ i.insight.description }}</td>
{% endfor %}
</tr>
{% if loop.last %}
</tbody>
</table>
{% endif %}
{% endfor %}
{% endfor %}
</body>
</html>