Name
sn_cimaf.CIMetricAdapterSNC
Description
No description available
Script
var CIMetricAdapterSNC = Class.create();
CIMetricAdapterSNC.prototype = {
initialize: function (adapterGr, ci) {
this.adapterGr = adapterGr;
this.ci = ci;
},
TABLES: {
CMDB_CI: "cmdb_ci"
},
FIELDS: {
QUERY_SCRIPT: "query_script",
SYS_DOMAIN: "sys_domain"
},
QUERY_ACTION_TYPE: {
FLOW: "flow",
SCRIPT: "script"
},
exec: function (skipPreRequestChecks) {
var batchId = gs.generateGUID();
var inputs = {
"adapter_config_sys_id": this.adapterGr.getUniqueValue(), // sys_id of the adapater config record
"ci_sys_id": this.ci + '', // String - SysId of CI record
"batch_id": batchId, // String - Unique sys ids
"skip_pre_request_checks": !!skipPreRequestChecks
};
var cmdbGr = this._getGlideRecord(this.TABLES.CMDB_CI, this.ci);
if (!cmdbGr) {
gs.error("[exec]: Provided CI is not a valid record");
return;
}
var cmdbDomain = cmdbGr.getValue(this.FIELDS.SYS_DOMAIN);
if (this.adapterGr.query_action == this.QUERY_ACTION_TYPE.FLOW && global.JSUtil.notNil(this.adapterGr.query_flow))
this.execSubFlow(batchId, this.adapterGr.query_flow, inputs, cmdbDomain);
else if (this.adapterGr.query_action == this.QUERY_ACTION_TYPE.SCRIPT && global.JSUtil.notNil(this.adapterGr.query_script))
this.execScript(batchId, inputs);
else if (global.JSUtil.notNil(this.adapterGr.provider) && global.JSUtil.notNil(this.adapterGr.provider.default_query_flow))
this.execSubFlow(batchId, this.adapterGr.provider.default_query_flow, inputs, cmdbDomain);
return batchId;
},
execScript: function (batchId, inputs) {
var script = this.adapterGr.getValue(this.FIELDS.QUERY_SCRIPT);
if (!script)
return;
var evaluator = new GlideScopedEvaluator();
try {
evaluator.evaluateScript(this.adapterGr, this.FIELDS.QUERY_SCRIPT, inputs);
} catch(e) {
gs.error("Error while executing the query script defined at adapter: " + e);
}
},
execSubFlow: function (batchId, queryFlow, inputs, cmdbDomain) {
if (!queryFlow || !queryFlow.internal_name) {
gs.error("Query subflow is not defined for the Adapter: " + this.adapterGr.getDisplayVaue());
return;
}
var scopeName = queryFlow.sys_scope.scope + "";
var flowInternalName = queryFlow.internal_name + "";
if (!scopeName || !flowInternalName)
return;
var flowName = scopeName + "." + flowInternalName;
var outputs = sn_fd.FlowAPI.getRunner()
.subflow(flowName)
.withInputs(inputs)
.inBackground()
.inDomain(cmdbDomain)
.run();
},
_getGlideRecord: function(tableName, sysId) {
var gr = new GlideRecord(tableName);
if (gr.get(sysId))
return gr;
},
type: 'CIMetricAdapterSNC'
};
Sys ID
8b2ce66e8787c150450d8f59dabb3503