Name
sn_itom_licensing.RandomizeLicenseDailyCount
Description
Script to randomise license daily count for all value_streams.
Script
var RandomizeLicenseDailyCount = Class.create();
RandomizeLicenseDailyCount.prototype = {
initialize: function() {
this.offsetHour = this._getRandomHour();
this.offsetMinute = this._getRandomMinute();
this.offsetSecond = this._getRandomSecond();
this.randomTime = this.offsetHour + ':' + this.offsetMinute + ':' + this.offsetSecond;
this.unixEpoch = "1970-01-01 00:00:00";
this.gdt = new GlideDateTime(this.unixEpoch);
this.msHour = 3600000;
},
randomizeScheduledJobTime: function() {
this._randomizeExclusionJob();
},
_randomizeExclusionJob: function() {
var gTime = new GlideTime();
gTime.setValue(this.randomTime);
this.gdt.add(gTime);
var jobGr = new GlideRecord('sysauto_script');
var isExclusionJobPresent = jobGr.get('sys_id', '7c745ab8b70e701046df8985de11a9ef');
if (isExclusionJobPresent && jobGr.canWrite()) {
jobGr.setValue('entered_time', this.gdt);
jobGr.setValue('time_zone', 'floating');
jobGr.update();
}
this._randomizeDailyCountJob();
},
_randomizeDailyCountJob: function() {
this.gdt.add(this.msHour);
var jobGr = new GlideRecord('sysauto_script');
jobGr.addEncodedQuery('nameLIKELicensing Usage Count Store');
jobGr.query();
while (jobGr.next() && jobGr.canWrite()) {
jobGr.setValue('entered_time', this.gdt);
jobGr.setValue('time_zone', 'floating');
jobGr.update();
}
this._randomizeAggregatorJob();
},
_randomizeAggregatorJob: function() {
this.gdt.add(this.msHour);
var jobGr = new GlideRecord('sysauto_script');
var isAggregatorJobPresent = jobGr.get('sys_id', '47e51af8b70e701046df8985de11a9b5');
if (isAggregatorJobPresent && jobGr.canWrite()) {
jobGr.setValue('entered_time', this.gdt);
jobGr.setValue('time_zone', 'floating');
jobGr.update();
}
},
_getRandomHour: function() {
var minHour = 0;
var maxHour = 20;
var randomHour = Math.floor(Math.random() * (maxHour - minHour + 1)) + minHour;
return String(randomHour) < 10 ? '0' + randomHour : randomHour;
},
_getRandomMinute: function() {
var minMinute = 1;
var maxMinute = 59;
var randomMinute = Math.floor(Math.random() * (maxMinute - minMinute + 1)) + minMinute;
return String(randomMinute) < 10 ? '0' + randomMinute : randomMinute;
},
_getRandomSecond: function() {
var minSecond = 0;
var maxSecond = 59;
var randomSecond = Math.floor(Math.random() * (maxSecond - minSecond + 1)) + minSecond;
return String(randomSecond) < 10 ? '0' + randomSecond : randomSecond;
},
type: 'RandomizeLicenseDailyCount'
};
Sys ID
6eed885b876351906bb8dac73cbb35d9