Name

global.AWAStatsExtnPointImpl

Description

Implements extension point global.AWAStatsExtnPoint Default/OOB Extension point implementation for populating the AWAQueueStats and AWAInstanceStats tables

Script

var AWAStatsExtnPointImpl = Class.create();
AWAStatsExtnPointImpl.prototype = {

  initialize: function() {},
  
  _queueStats: function(queueVsGroups, time, windowStartTime, windowEndTime) {

      var extnPoints = new GlideScriptedExtensionPoint().getExtensions("AWAStatsStore");
      var point;
      var queueStatsList = [];
      for (var i = 0; i < extnPoints.length; i++) {
          point = extnPoints[i];
          queueStatsList.push(point.getQueueStats(queueVsGroups, windowStartTime, windowEndTime));
      }

      for (var id in queueVsGroups) {
          gr = new GlideRecord('awa_queue_stats');
          gr.initialize();
          for (var item in queueStatsList) {
              var statDefaultValue = queueStatsList[item]["statDefaultValue"];
              var queueStats = queueStatsList[item]["queueStats"];
              for (var stat in statDefaultValue) {
                  gr[stat] = (queueStats[id] && queueStats[id][stat]) ? queueStats[id][stat] : statDefaultValue[stat];
              }
          }
          gr.queue = id ? id : "";
          gr.captured_at = time;
          gr.insert();
      }

  },

  _channelStats: function(channelVsGroups, time, windowStartTime, windowEndTime) {
      var extnPoints = new GlideScriptedExtensionPoint().getExtensions("AWAStatsStore");
      var point;
      var channelStatsList = [];
      for (var i = 0; i < extnPoints.length; i++) {
          point = extnPoints[i];
          channelStatsList.push(point.getChannelStats(channelVsGroups, windowStartTime, windowEndTime));
      }
      for (var id in channelVsGroups) {
          gr = new GlideRecord('awa_service_channel_stats');
          gr.initialize();
          for (var item in channelStatsList) {
              var statDefaultValue = channelStatsList[item]["statDefaultValue"];
              var channelStats = channelStatsList[item]["channelStats"];
              for (var stat in statDefaultValue) {
                  gr[stat] = (channelStats[id] && channelStats[id][stat]) ? channelStats[id][stat] : statDefaultValue[stat];
              }
          }
          gr.service_channel = id ? id : "";
          gr.captured_at = time;
          gr.insert();
      }

  },

  _instanceStats: function(time, windowStartTime, windowEndTime) {

      gr = new GlideRecord('awa_instance_stats');
      gr.initialize();

      var extnPoints = new GlideScriptedExtensionPoint().getExtensions("AWAStatsStore");
      var point;
      for (var i = 0; i < extnPoints.length; i++) {
          point = extnPoints[i];
          var map = point.getInstanceStats(windowStartTime, windowEndTime);
          for (var key in map) {
              gr[key] = map[key];
          }
      }

      gr.captured_at = time;
      gr.insert();
  },

  populateMetrics: function() {
      var queueVsGroups = {};
      var channelVsGroups = {};

      var gr = new GlideRecord('awa_eligibility_pool');
      gr.addQuery('queue.active', true);
      gr.addQuery('queue.service_channel.active', true);
      gr.query();

      var group;
      while (gr.next()) {
          var groups = gr.groups.split(',');
          for (group in groups) {
              queueVsGroups[gr.queue] = queueVsGroups[gr.queue] || [];
              channelVsGroups[gr.queue.service_channel] = channelVsGroups[gr.queue.service_channel] || [];
              if (queueVsGroups[gr.queue].indexOf(groups[group]) == -1)
                  queueVsGroups[gr.queue].push(groups[group]);
              if (channelVsGroups[gr.queue.service_channel].indexOf(groups[group]) == -1)
                  channelVsGroups[gr.queue.service_channel].push(groups[group]);
          }
      }

      var time = new GlideDateTime();
      var windowDuration = gs.getProperty('glide.awa.queue_metrics_duration', 120);
      var windowStartTime = new GlideDateTime();
      var windowEndTime = new GlideDateTime();
      windowStartTime.addSeconds(-windowDuration);

      this._queueStats(queueVsGroups, time, windowStartTime, windowEndTime);
      this._channelStats(channelVsGroups, time, windowStartTime, windowEndTime);
      this._instanceStats(time, windowStartTime, windowEndTime);

  },

  type: 'AWAStatsExtnPointImpl'
};

Sys ID

b1f4c6de5b2710108c5409f8e281c7a3

Offical Documentation

Official Docs: