forked from flexera-public/policy_templates
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfsm-renewal_reminder.pt
227 lines (207 loc) · 6.48 KB
/
fsm-renewal_reminder.pt
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
name "SaaS Manager - Renewal Reminder"
rs_pt_ver 20180301
type "policy"
short_description "This policy will create an incident when Flexera SaaS Manager identifies applications whose expiration date is approaching. See the [README](https://github.com/flexera-public/policy_templates/tree/master/saas/fsm/renewal_reminder/) and [docs.flexera.com/flexera/EN/Automation](https://docs.flexera.com/flexera/EN/Automation/AutomationGS.htm) to learn more."
long_description ""
severity "medium"
category "SaaS Management"
default_frequency "daily"
info(
version: "2.6",
provider: "Flexera SaaS Manager",
service: "",
policy_set: ""
)
###############################################################################
# User inputs
###############################################################################
parameter "param_days" do
type "number"
label "Upcoming Number of Days"
default 60
description "If an application renewal is due in the upcoming time period, raise an incident"
end
parameter "param_email" do
type "list"
label "Email addresses to notify"
description "Email addresses of the recipients you wish to notify"
end
###############################################################################
# Authentication
###############################################################################
#authenticate with FSM
credentials "fsm_auth" do
schemes "oauth2"
label "FSM"
description "Select the FSM Resource Manager Credential from the list."
tags "provider=flexera_fsm"
end
###############################################################################
# Datasources
###############################################################################
datasource "ds_get_host" do
run_script $js_get_host, rs_governance_host
end
datasource "ds_num_products" do
iterate $ds_get_host
request do
auth $fsm_auth
host val(iter_item,"host")
verb "GET"
scheme "https"
path join(["/svc/orgs/", rs_org_id, "/managed-products"])
header "content-type", "application/json"
end
result do
encoding "json"
field "totalItems", jmes_path(response, "totalItems")
field "saas_host", val(iter_item,"host")
end
end
datasource "ds_products" do
request do
run_script $js_products, $ds_num_products, rs_org_id
end
result do
encoding "json"
collect jmes_path(response, "items[*]") do
field "application", jmes_path(col_item, "name")
field "pointOfContactEmail", jmes_path(col_item, "pointOfContactEmail")
field "vendor", jmes_path(col_item, "product.vendor.name")
field "annualCost", jmes_path(col_item, "annualCost")
field "licenses" do
collect jmes_path(col_item, "licenses") do
field "lic_id", jmes_path(col_item, "id")
end
end
end
end
end
datasource "ds_licenses_summary" do
iterate $ds_get_host
request do
auth $fsm_auth
host val(iter_item,"host")
verb "GET"
scheme "https"
path join(["/svc/orgs/", rs_org_id, "/licenses/summaries"])
header "content-type", "application/json"
end
result do
encoding "json"
collect jmes_path(response, "[*]") do
field "lic_id", jmes_path(col_item, "id")
field "end_date", jmes_path(col_item, "endDate")
end
end
end
datasource "ds_products_with_enddate" do
run_script $js_products_with_enddate, $ds_products, $ds_licenses_summary, $param_days
end
###############################################################################
# Scripts
###############################################################################
script "js_get_host", type: "javascript" do
parameters "rs_governance_host"
result "result"
code <<-EOS
var result = [];
if(rs_governance_host.indexOf(".eu") !== -1 || rs_governance_host.indexOf("-eu") !== -1){
result.push({host: "api.fsm-eu.flexeraeng.com"});
}else{
result.push({host: "api.fsm.flexeraeng.com"});
}
EOS
end
script "js_products_with_enddate", type: "javascript" do
parameters "ds_products", "ds_licenses_summary", "param_days"
result "result"
code <<-EOS
var result = [];
var lic_enddate = {};
_.each(ds_licenses_summary, function(license){
if(license.end_date != null){
lic_enddate[license.lic_id]= license.end_date;
}
})
var end_date="";
_.each(ds_products, function(product){
_.each(product.licenses, function(license){
end_date=lic_enddate[license.lic_id];
})
var date = new Date();
date = date.setHours(24 * param_days);
date = new Date(date);
if(end_date != null){
var expiration_date = new Date(end_date);
if(expiration_date < date){
result.push({
"application":product.application
"pointOfContactEmail":product.pointOfContactEmail
"vendor":product.vendor
"annualCost": product.annualCost
"endDate":end_date
})
}
}
})
result = _.sortBy(result, 'endDate');
EOS
end
script "js_products", type: "javascript" do
parameters "ds_num_products", "rs_org_id"
result "request"
code <<-EOS
request = {
auth: "fsm_auth",
host: ds_num_products[0]["saas_host"].toString(),
verb: "GET",
scheme: "https",
path: "/svc/orgs/"+rs_org_id+"/managed-products",
headers: {
"content-type": "application/json"
},
query_params: {
"pageSize": ds_num_products[0]["totalItems"].toString(),
"includeInactive": "false"
}
}
EOS
end
###############################################################################
# Escalations
###############################################################################
escalation "report_summary" do
automatic true
label "Send Email"
description "Send incident email"
email $param_email
end
###############################################################################
# Policy
###############################################################################
policy "policy_fsm_renewal_reminder" do
validate $ds_products_with_enddate do
summary_template "{{ len data }} Expiring Applications Found"
escalate $report_summary
check eq(size(data), 0)
export do
field "endDate" do
label "Expiration Date (YYYY-MM-DD)"
end
field "vendor" do
label "Vendor"
end
field "id" do
label "Application"
path "application"
end
field "pointOfContactEmail" do
label "Point of Contact"
end
field "annualCost" do
label "Annual Cost"
end
end
end
end