Name
sn_itom_licensing.HLALicenseReportPopulatorStore
Description
No description available
Script
var HLALicenseReportPopulatorStore = Class.create();
var HLA_CI_TABLE = "itom_lu_hla_ci";
var LICENSE_REPORT_TABLE = "itom_lu_licensable_cis";
var itomLicensingUtils = new ITOMLicensingUtilsStore();
var metadata = new ITOMLicensingMetaDataStore();
var batchUtil = new global.BatchCommandUtilScript();
var utilScript = new global.UtilScript();
var licenseCounter = new HLAValueStreamLicenseCounterForStore("report");
HLALicenseReportPopulatorStore.prototype = {
initialize: function() {
},
populateReportTable: function(skuTypeGr) {
var skuType = skuTypeGr.getValue('sku');
var skuTypeSysId = skuTypeGr.getValue('sys_id');
var counter = 0;
var total = 0;
var jsonArr = [];
var start = new Date().getTime();
// update em_unique_nodes and itom_lu_hla_ci with most recent data
if (!this.refreshData())
return;
var bulkSize = parseInt(gs.getProperty("evt_mgmt.batchInsertSingleField.bulk_size", 500));
var suRatio = itomLicensingUtils.getCategory2Ratio();
var ciConditions = utilScript.getAdditionalFiltersQuery(HLA_CI_TABLE, 'cmdb_ci', itomLicensingUtils.getHLAVSLabel());
var maxRecords = itomLicensingUtils.getMaxResultsFor(itomLicensingUtils.getHLAVSLabel(), skuType);
var gr = new GlideRecord(HLA_CI_TABLE);
if (!gs.nil(ciConditions))
gr.addEncodedQuery(ciConditions);
licenseCounter.addSkuConditions(gr, skuType);
gr.query();
//create array of json objects like these:
//{"configuration_item":"12345678901233", "category":"server", "su_ratio":"1:1", "sys_domain":"global"}
//or {"node_id":"someNode", "category":"Unresolved monitored objects","su_ratio":"1:1," "sys_domain":"global"}
while (gr.next()) {
var jsonObj = {};
if (!gs.nil(gr.cmdb_ci)) {
var category = metadata.getCategory(gr.cmdb_ci.sys_class_name);
if (gs.nil(category))
continue;
var su_ratio = suRatio[category];
if (gs.nil(su_ratio))
continue;
jsonObj.configuration_item = '' + gr.cmdb_ci;
jsonObj.sys_domain = '' + gr.cmdb_ci.sys_domain;
jsonObj.value_stream = '' + 'HLA';
jsonObj.category = category;
jsonObj.su_ratio = su_ratio + ':1';
jsonObj.sku = skuTypeSysId;
} else if (!gs.nil(gr.node)) {
jsonObj.node_id = '' + gr.node;
jsonObj.sys_domain = '' + gr.sys_domain;
jsonObj.value_stream = '' + 'HLA';
jsonObj.category = metadata.getCategoryNameForUnknown();
jsonObj.sku = skuTypeSysId;
su_ratio = suRatio[jsonObj.category];
if (gs.nil(su_ratio))
continue;
jsonObj.su_ratio = su_ratio + ':1';
}
jsonArr.push(jsonObj);
counter++;
total++;
if (total >= maxRecords)
break;
if (counter >= bulkSize) {
if (itomLicensingUtils.isHLAJobCanceled())
return;
// 1. insert bulk into the target table
batchUtil.batchInsertMultiple(JSON.stringify(jsonArr), LICENSE_REPORT_TABLE, '');
// 2. set counter to 0
counter = 0;
// 3. re-init json array
jsonArr = [];
}
}
if (counter > 0) {
if (itomLicensingUtils.isHLAJobCanceled())
return;
//insert rest of records in batch
batchUtil.batchInsertMultiple(JSON.stringify(jsonArr), LICENSE_REPORT_TABLE, '');
}
var end = new Date().getTime();
var perfJson = {};
perfJson.script_name = 'HLALicenseReportPopulatorStore';
this.writeToPerfTable(total, end - start, perfJson);
},
refreshData: function() {
if (itomLicensingUtils.isHLAJobCanceled())
return false;
new EvtMgmtNodeCountStore().calculateNodeCount();
if (itomLicensingUtils.isHLAJobCanceled())
return false;
licenseCounter.process();
if (itomLicensingUtils.isHLAJobCanceled())
return false;
return true;
},
writeToPerfTable: function(count, duration, json) {
var doPerf = gs.getProperty('hla_license_report_perf_on', false) == "true";
if (!doPerf)
return;
var gr = new GlideRecord("sa_performance_statistics");
gr.setValue("type", "hlaLicensingProcess");
gr.setValue("count", count);
gr.setValue("duration", duration);
gr.setValue("extra_data", JSON.stringify(json));
gr.insert();
},
type: 'HLALicenseReportPopulatorStore'
};
Sys ID
77bd115c4384111016b23f28fab8f2e9