forked from flexera-public/policy_templates
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfsm-unsanctioned_with_contract.pt
243 lines (222 loc) · 7.12 KB
/
fsm-unsanctioned_with_contract.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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
name "SaaS Manager - Unsanctioned Applications with Existing Contract"
rs_pt_ver 20180301
type "policy"
short_description "This policy will create an incident when Flexera SaaS Manager identifies unsanctioned SaaS purchases for managed applications under an existing license contract. See the [README](https://github.com/flexera-public/policy_templates/tree/master/saas/fsm/unsanctioned_apps_with_contract/) and [docs.flexera.com/flexera/EN/Automation](https://docs.flexera.com/flexera/EN/Automation/AutomationGS.htm) to learn more."
long_description ""
severity "high"
category "SaaS Management"
default_frequency "daily"
info(
version: "2.5",
provider: "Flexera SaaS Manager",
service: "",
policy_set: ""
)
###############################################################################
# User inputs
###############################################################################
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")
end
end
end
datasource "ds_num_unsanctioned" 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, "/financial-discovery"])
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_unsanctioned" do
request do
run_script $js_unsanctioned, $ds_num_unsanctioned, rs_org_id
end
result do
encoding "json"
collect jmes_path(response, "items[*]") do
field "latestExpenseDate", jmes_path(col_item, "latestExpenseDate")
field "department", jmes_path(col_item, "department")
field "purchaser", jmes_path(col_item, "purchaser")
field "expenseSum", jmes_path(col_item, "expenseSum")
field "vendor", jmes_path(col_item, "vendor.name")
field "product", jmes_path(col_item, "product.name")
end
end
end
datasource "ds_format_data" do
run_script $js_format_data, $ds_products, $ds_unsanctioned
end
###############################################################################
# Scripts
###############################################################################
script "js_get_host", type: "javascript" do
parameters "host"
result "result"
code <<-EOS
var result = [];
if(host.indexOf(".eu") !== -1 || 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", 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"],
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
script "js_unsanctioned", type: "javascript" do
parameters "ds_num_unsanctioned", "rs_org_id"
result "request"
code <<-EOS
request = {
auth: "fsm_auth",
host: ds_num_unsanctioned[0]["saas_host"],
verb: "GET",
scheme: "https",
path: "/svc/orgs/"+rs_org_id+"/financial-discovery",
headers: {
"content-type": "application/json"
},
query_params: {
"pageSize": ds_num_unsanctioned[0]["totalItems"].toString()
}
}
EOS
end
script "js_format_data", type: "javascript" do
parameters "ds_products", "ds_unsanctioned"
result "result"
code <<-EOS
var result = [];
var unsanctioned_product_names = _.pluck(ds_unsanctioned, 'product');
_.each(ds_products, function(prod){
if (_.contains(unsanctioned_product_names, prod["application"])){
var expenses = _.where(ds_unsanctioned, {product: prod["application"]});
var latest_expense = _.max(expenses, function(expense){ return expense.latestExpenseDate; });
result.push({
product: prod["application"],
vendor: prod["vendor"],
annualCost: "$"+prod["annualCost"],
licensePOC: prod["pointOfContactEmail"],
expenseSum: "$"+latest_expense["expenseSum"],
latestExpenseDate: Date(latest_expense["latestExpenseDate"]).toString(),
expensePurchaser: latest_expense["purchaser"]
})
}
})
EOS
end
###############################################################################
# Escalations
###############################################################################
escalation "report_summary" do
automatic true
label "Send Email"
description "Send incident email"
email $param_email
end
###############################################################################
# Policy
###############################################################################
policy "policy_fsm_unsanctioned_with_contract" do
validate $ds_format_data do
summary_template "{{ len data }} Unsanctioned SaaS Purchases with Existing Contracts"
export do
field "product" do
label "Application"
end
field "vendor" do
label "Vendor"
end
field "annualCost" do
label "Annual Contract Cost"
end
field "licensePOC" do
label "Contract Point of Contact"
end
field "expenseSum" do
label "Expense Cost"
end
field "latestExpenseDate" do
label "Latest Expense Date"
end
field "expensePurchaser" do
label "Expense Purchaser"
end
end
escalate $report_summary
check eq(size(data), 0)
end
end