Name

sn_sow.SOWInvestigateConfigSNC

Description

No description available

Script

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

  UI_TYPES: {
      "OVERVIEW": "OVERVIEW",
      "VISUALIZATION": "VISUALIZATION",
      "TABULAR": "TABULAR"
  },

  DEFINITION_CONFIG: {},

  //List of defintions that needs to be shown in UI for a given table.
  TABLE_DEFINITION_MAP: {
      "incident": "8821d932c7c70110d7e818b1c7c26063,6f8ecd7ec7870110d7e818b1c7c2607b,c1a556909705215055e1b3471153af57,5fa4baed5342111002e6ddeeff7b1201,3061d9fec7870110d7e818b1c7c2604b"
  },

  //List of defintions that needs to be shown in UI for a given table in history tab.
  TABLE_DEFINITION_HISTORY_MAP: {
      "incident": "8821d932c7c70110d7e818b1c7c26063,6f8ecd7ec7870110d7e818b1c7c2607b,c1a556909705215055e1b3471153af57,3061d9fec7870110d7e818b1c7c2604b"
  },

  //List of CI Field Names that needs to be shown in system overview section
  CI_FIELD_NAMES: ['name', 'model_id', 'serial_number', 'os'],

  DEFINITION_CONFIG_MAP: {
      ASSET_UTILIZATION: "8821d932c7c70110d7e818b1c7c26063",
      RUNNING_PROCESSES: "6f8ecd7ec7870110d7e818b1c7c2607b",
      LOGGED_IN_USER: "3061d9fec7870110d7e818b1c7c2604b",
      SYSTEM_OVERVIEW: "9779013ac7870110d7e818b1c7c26033",
      SERVICES: "c1a556909705215055e1b3471153af57",
      INSTALLED_APPLICATIONS: "5fa4baed5342111002e6ddeeff7b1201",
      SYSTEM_INFO_MSINFO32: "028dcd36535a9110ae50ddeeff7b1200",
      SYSTEM_INFO_DSREGCMD: "0c5afbe653a211107234ddeeff7b12af"
  },

  //List of Actions available to remediate
  ACTION_MAP: {
      END_PROCESS_DEVICE: "sn_sow_inc.End_process_-_Device",
      END_PROCESS_SERVER: "sn_sow_inc.End_process_-_Server",
      RESTART_SERVICE_DEVICE: "sn_sow_inc.Restart_service_-_Device",
      RESTART_SERVICE_SERVER: "sn_sow_inc.Restart_service_-_Server"
  },

  //Origin Record
  SERVICE_OPERATIONS_WORKSPACE_ORIGIN_RECORD: "26e78022c3d525104f1a722e3f40dd99",

  UNIT_CONVERSIONS: {
      "size": {
          "B": 1,
          "KB": 1000,
          "MB": 1000000,
          "GB": 1000000000,
          "TB": 1000000000000
      }
  },

  initialize: function() {
      this.setDefinitionConfig();
  },

  setDefinitionConfig: function() {
      var that = this;
      //Asset usage
      this.DEFINITION_CONFIG[this.DEFINITION_CONFIG_MAP.ASSET_UTILIZATION] = {
          "UI_TYPE": this.UI_TYPES.VISUALIZATION,
          "HEADER": gs.getMessage("Asset utilization"),
          "ATTRIBUTES": {
              "selectable" : false,
              "mem_percentage": gs.getMessage("Memory utilization"),
              "disk_percentage": gs.getMessage("Disk utilization"),
              "cpu_percentage": gs.getMessage("CPU utilization"),
              "uptime": gs.getMessage("Uptime")
          },
          "THRESHOLD": {
              "mem_percentage": {
                  "critical": 95,
                  "warning": 80
              },
              "disk_percentage": {
                  "critical": 95,
                  "warning": 80
              },
              "cpu_percentage": {
                  "critical": 95,
                  "warning": 80
              }
          },
          "CALCULATED_FIELDS": {
              "mem_percentage": function(data) {
                  var result = {};
                  if (data["TotalPhysicalMemory"] && data["FreePhysicalMemory"]) {
                      var value = ((Number(data["TotalPhysicalMemory"]) - Number(data["FreePhysicalMemory"])) / Number(data["TotalPhysicalMemory"])) * 100;
                      result.value = (Number(value)).toFixed();
                  } else if (data["TotalPhysicalMemory"] && data["UsedPhysicalMemory"]) {
                      value = (Number(data["UsedPhysicalMemory"]) / Number(data["TotalPhysicalMemory"])) * 100;
                      result.value = (Number(value)).toFixed();
                  }
                  if (that.DEFINITION_CONFIG[that.DEFINITION_CONFIG_MAP['ASSET_UTILIZATION']].THRESHOLD) {
                      var thresholdObj = that.DEFINITION_CONFIG[that.DEFINITION_CONFIG_MAP['ASSET_UTILIZATION']].THRESHOLD.mem_percentage;
                      var threshold = that.updateThreshold(thresholdObj, result);
                      if (threshold) {
                          result.threshold = threshold;
                      }
                  }

                  result.value = result.value ? result.value + "%" : null;
                  return result;
              },
              "disk_percentage": function(data) {
                  var result = {};
                  if (data["total_space"] && data["free_space"]) {
                      var value = ((Number(data["total_space"]) - Number(data["free_space"])) / Number(data["total_space"])) * 100;
                      result.value = Number(value).toFixed();
                  } else if (data["blocks_available"] && data["blocks_free"]) {
                      // for linux and mac
                      var totalSpace = Number(data["blocks_available"]) + Number(data["blocks_free"]);
                      value = ((totalSpace - Number(data["blocks_available"])) / totalSpace) * 100;
                      result.value = Number(value).toFixed();
                  }
                  if (that.DEFINITION_CONFIG[that.DEFINITION_CONFIG_MAP['ASSET_UTILIZATION']].THRESHOLD) {
                      var thresholdObj = that.DEFINITION_CONFIG[that.DEFINITION_CONFIG_MAP['ASSET_UTILIZATION']].THRESHOLD.disk_percentage;
                      var threshold = that.updateThreshold(thresholdObj, result);
                      if (threshold) {
                          result.threshold = threshold;
                      }
                  }

                  result.value = result.value ? result.value + "%" : null;
                  return result;
              },
              "cpu_percentage": function(data) {
                  var result = {};
                  if (data["cpu_percentage"]) {
                      result.value = (Number(data["cpu_percentage"])).toFixed();
                  }

                  if (that.DEFINITION_CONFIG[that.DEFINITION_CONFIG_MAP['ASSET_UTILIZATION']].THRESHOLD) {
                      var thresholdObj = that.DEFINITION_CONFIG[that.DEFINITION_CONFIG_MAP['ASSET_UTILIZATION']].THRESHOLD.cpu_percentage;
                      var threshold = that.updateThreshold(thresholdObj, result);
                      if (threshold) {
                          result.threshold = threshold;
                      }
                  }

                  result.value = result.value ? result.value + "%" : null;
                  return result;
              },
              "uptime": function(data) {
                  if (data["days"] && data["hours"]) {
                      return gs.getMessage("{0}d {1}h", [data["days"], data["hours"]]);
                  }
              }
          }
      };

      //Running processes
      this.DEFINITION_CONFIG[this.DEFINITION_CONFIG_MAP.RUNNING_PROCESSES] = {
          "UI_TYPE": this.UI_TYPES.TABULAR,
          "THRESHOLD": {
              "mem_percentage": {
                  "critical": 90
              },
              "cpu_percentage": {
                  "critical": 90
              }
          },
          "UNITS": {
              "memory": {
                  "type": "size",
                  "unit": "MB" // Byte size - B|KB|MB|GB|TB
              }
          },
          "ITEMS": [{
              "HEADER": gs.getMessage("Top processes by CPU"),
              "ATTRIBUTES": {
                  "selectable": true,
                  "name": gs.getMessage("Process name"),
                  "cpu_percentage": gs.getMessage("% CPU"),
                  "total_size": gs.getMessage("Memory (MB)"),
                  "pid": gs.getMessage("PID"),
                  "uid": gs.getMessage("UID")
              },
              "KEY": "cpu",
              "ACTIONS": [{
                      "name": "End Process",
                      "displayLabel": gs.getMessage("End process"),
                      "internalName": this.ACTION_MAP.END_PROCESS_DEVICE,
                      "isVisible": false,
                      "actionParams": [{
                          "label": "process_id",
                          "field": "pid",
                          "type": "integer"
                      }]
                  },
                  {
                      "name": "End Process",
                      "displayLabel": gs.getMessage("End process"),
                      "internalName": this.ACTION_MAP.END_PROCESS_SERVER,
                      "isVisible": false,
                      "actionParams": [{
                          "label": "process_id",
                          "field": "pid",
                          "type": "integer"
                      }]
                  }
              ],
              "CALCULATED_FIELDS": {
                  "rowData": function(data) {
                      var totalCPU;
                      for (var i = 0; i < data.length; i++) {
                          if (data[i].hasOwnProperty("totalCPU")) {
                              totalCPU = Number(data[i]["totalCPU"]);
                              break;
                          }
                      }
                      var result = [];
                      var runningProcess = that.DEFINITION_CONFIG[that.DEFINITION_CONFIG_MAP['RUNNING_PROCESSES']];
                      var memoryMetric = runningProcess['UNITS']['memory'];
                      var memoryHasTypeandUnit = memoryMetric && memoryMetric['type'] && memoryMetric['unit'];
                      data.forEach(function(item) {
                          if (item.metric_type === "cpu") {
                              // if cpu_percentage doesn't exists, derive it
                              if (totalCPU && !item.hasOwnProperty("cpu_percentage") && item.hasOwnProperty("user_time") && item.hasOwnProperty("system_time")) {
                                  item.cpu_percentage = Number(((Number(item.user_time) + Number(item.system_time)) / (totalCPU * 1000)) * 100).toFixed(2);

                                  if (that.DEFINITION_CONFIG[that.DEFINITION_CONFIG_MAP['RUNNING_PROCESSES']].THRESHOLD) {
                                      var thresholdObj = that.DEFINITION_CONFIG[that.DEFINITION_CONFIG_MAP['RUNNING_PROCESSES']].THRESHOLD.cpu_percentage;
                                      var threshold = that.updateThresholdForTabularUI(thresholdObj, "cpu_percentage", item.cpu_percentage);
                                      if (threshold) {
                                          item.threshold = threshold;
                                      }
                                  }
                              }
                              // if cpu_percentage exists, round off it
                              else if (item.hasOwnProperty("cpu_percentage")) {
                                  item.cpu_percentage = Number(item.cpu_percentage).toFixed(2);
                              }
                              if (item.hasOwnProperty("total_size")) {
                                  var memory = Number(item.total_size);
                                  var unitConversion = that.getUnitConversions(memoryMetric['type'], memoryMetric['unit']);
                                  if (memoryHasTypeandUnit && unitConversion) {
                                      item.total_size = Number(memory / unitConversion).toFixed(2);
                                  }
                              }
                              result.push(item);
                          }
                      });
                      return result.slice(0, 5);
                  }
              }
          }, {
              "HEADER": gs.getMessage("Top processes by Memory"),
              "ATTRIBUTES": {
                  "selectable": true,
                  "name": gs.getMessage("Process name"),
                  "total_size": gs.getMessage("Memory (MB)"),
                  "cpu_percentage": gs.getMessage("% CPU"),
                  "pid": gs.getMessage("PID"),
                  "uid": gs.getMessage("UID")
              },
              "KEY": "memory",
              "ACTIONS": [{
                      "name": "End Process",
                      "displayLabel": gs.getMessage("End process"),
                      "internalName": this.ACTION_MAP.END_PROCESS_DEVICE,
                      "isVisible": false,
                      "actionParams": [{
                          "label": "process_id",
                          "field": "pid",
                          "type": "integer"
                      }]
                  },
                  {
                      "name": "End Process",
                      "displayLabel": gs.getMessage("End process"),
                      "internalName": this.ACTION_MAP.END_PROCESS_SERVER,
                      "isVisible": false,
                      "actionParams": [{
                          "label": "process_id",
                          "field": "pid",
                          "type": "integer"
                      }]
                  }

              ],
              "CALCULATED_FIELDS": {
                  "rowData": function(data, completeData) {
                      var totalCPU;
                      for (var i = 0; i < data.length; i++) {
                          if (data[i].hasOwnProperty("totalCPU")) {
                              totalCPU = Number(data[i]["totalCPU"]);
                              break;
                          }
                      }
                      var result = [];
                      var runningProcess = that.DEFINITION_CONFIG[that.DEFINITION_CONFIG_MAP['RUNNING_PROCESSES']];
                      var memoryMetric = runningProcess['UNITS']['memory'];
                      var memoryHasTypeandUnit = memoryMetric && memoryMetric['type'] && memoryMetric['unit'];
                      data.forEach(function(item) {
                          if (item.metric_type === "memory") {
                              // if cpu_percentage doesn't exists, derive it
                              if (totalCPU && !item.hasOwnProperty("cpu_percentage") && item.hasOwnProperty("user_time") && item.hasOwnProperty("system_time")) {
                                  item.cpu_percentage = Number(((Number(item.user_time) + Number(item.system_time)) / (totalCPU * 1000)) * 100).toFixed(2);
                              }
                              // if cpu_percentage exists, round off it
                              else if (item.hasOwnProperty("cpu_percentage")) {
                                  item.cpu_percentage = Number(item.cpu_percentage).toFixed(2);
                              }
                              var memory = Number(item.total_size);
                              var runningProcessesDefinition = that.DEFINITION_CONFIG_MAP['RUNNING_PROCESSES'];
                              var assetUtilizationDefinition = that.DEFINITION_CONFIG_MAP['ASSET_UTILIZATION'];
                              var unitConversion = that.getUnitConversions(memoryMetric['type'], memoryMetric['unit']);
                              if (memoryHasTypeandUnit && unitConversion) {
                                  item.total_size = Number(memory / unitConversion).toFixed(2);
                              }
                              if (that.DEFINITION_CONFIG[runningProcessesDefinition].THRESHOLD && completeData && completeData[assetUtilizationDefinition]) {
                                  var assetUtilizationMetricData = completeData[assetUtilizationDefinition].payload;
                                  if (assetUtilizationMetricData && assetUtilizationMetricData["TotalPhysicalMemory"]) {
                                      var totalSizePercentage = (memory / Number(assetUtilizationMetricData["TotalPhysicalMemory"])) * 100;
                                      var thresholdObj = that.DEFINITION_CONFIG[runningProcessesDefinition].THRESHOLD.mem_percentage;
                                      var threshold = that.updateThresholdForTabularUI(thresholdObj, "total_size", totalSizePercentage);
                                      if (threshold) {
                                          item.threshold = threshold;
                                      }
                                  }
                              }
                              result.push(item);
                          }
                      });
                      return result.slice(0, 5);
                  }
              }
          }]
      };

      //Services
      this.DEFINITION_CONFIG[this.DEFINITION_CONFIG_MAP.SERVICES] = {
          "UI_TYPE": this.UI_TYPES.TABULAR,
          "ITEMS": [{
              "HEADER": gs.getMessage("Services"),
              "ATTRIBUTES": {
                  "selectable": true,
                  "service_name": {
                      "label": gs.getMessage("Name"),
                      "isSortable": true
                  },
                  "displayName": {
                      "label": gs.getMessage("Display name"),
                      "isSortable": true
                  },
                  "pid": {
                      "label": gs.getMessage("Process ID"),
                      "isSortable": true
                  },
                  "status": {
                      "label": gs.getMessage("Status"),
                      "isSortable": true
                  },
                  "start_type": {
                      "label": gs.getMessage("Start type"),
                      "isSortable": true
                  },
                  "service_exit_code": {
                      "label": gs.getMessage("Service exit code"),
                      "isSortable": true
                  },
                  "plist": {
                      "label": gs.getMessage("Label"),
                      "isSortable": true
                  },
                  "active": {
                      "label": gs.getMessage("Active"),
                      "isSortable": true
                  },
                  "sub": {
                      "label": gs.getMessage("State"),
                      "isSortable": true
                  },
                  "description": {
                      "label": gs.getMessage("Description"),
                      "isSortable": true
                  }
              },
              "KEY": "services",
              "ACTIONS": [{
                      "name": "Restart service",
                      "displayLabel": gs.getMessage("Restart service"),
                      "internalName": this.ACTION_MAP.RESTART_SERVICE_DEVICE,
                      "isVisible": false,
                      "actionParams": [{
                          "label": "service_name",
                          "field": "service_name",
                          "type": "string"
                      }]
                  },
                  {
                      "name": "Restart service",
                      "displayLabel": gs.getMessage("Restart service"),
                      "internalName": this.ACTION_MAP.RESTART_SERVICE_SERVER,
                      "isVisible": false,
                      "actionParams": [{
                          "label": "service_name",
                          "field": "service_name",
                          "type": "string"
                      }]
                  }

              ],
              "PAGINATION": {
                  "pageSize": 10
              },
              "COLLAPSIBLE": true,
              "CALCULATED_FIELDS": {
                  "rowData": function(data) {
                      return data;
                  },
                  "getCount": function(data) {
                      return data.length;
                  }
              }
          }]
      };

      //Logged in users
      this.DEFINITION_CONFIG[this.DEFINITION_CONFIG_MAP.LOGGED_IN_USER] = {
          "UI_TYPE": this.UI_TYPES.TABULAR,
          "ITEMS": [{
              "HEADER": gs.getMessage("Logged in users"),
              "ATTRIBUTES": {
                  "selectable": false,
                  "user": gs.getMessage("User"),
                  "tty": gs.getMessage("TTY"),
                  "time": gs.getMessage("Time")
              },
              "KEY": "logged_users",
              "ACTIONS": [],
              "PAGINATION": {
                  "pageSize": 5
              },
              "COLLAPSIBLE": true,
              "CALCULATED_FIELDS": {
                  "rowData": function(data) {
                      for (var i = 0; i < data.length; i++) {
                          if (data[i].time) {
                              var gdt = new GlideDateTime();
                              gdt.setNumericValue(Number(data[i].time) * 1000);
                              data[i].time = gdt.getDisplayValue();
                          }
                      }
                      return data;
                  }
              }
          }]
      };

      //Installed applications
      this.DEFINITION_CONFIG[this.DEFINITION_CONFIG_MAP.INSTALLED_APPLICATIONS] = {
          "UI_TYPE": this.UI_TYPES.TABULAR,
          "ITEMS": [{
              "HEADER": gs.getMessage("Installed applications"),
              "ATTRIBUTES": {
                  "selectable": false,
                  "name": {
                      "label": gs.getMessage("Name"),
                      "isSortable": true
                  },
                  "version": {
                      "label": gs.getMessage("Version"),
                      "isSortable": true
                  },
                  "publisher": {
                      "label": gs.getMessage("Publisher"),
                      "isSortable": true
                  }
              },
              "KEY": "installed_applications",
              "ACTIONS": [],
              "PAGINATION": {
                  "pageSize": 10
              },
              "COLLAPSIBLE": true,
              "CALCULATED_FIELDS": {
                  "rowData": function(data) {
                      return data;
                  },
                  "getCount": function(data) {
                      return data.length;
                  }
              }
          }]
      };
      return;
  },

  getDefinitionGroupConfig: function() {
      return {
          "header": gs.getMessage("Asset utilization"),
          "definition_ids": [this.DEFINITION_CONFIG_MAP.ASSET_UTILIZATION, this.DEFINITION_CONFIG_MAP.RUNNING_PROCESSES]
      };
  },

  getDefinitionIds: function(table) {
      return this.TABLE_DEFINITION_MAP[table];
  },

  getDefinitionIdsHistory: function(table) {
      return this.TABLE_DEFINITION_HISTORY_MAP[table];
  },

  getDefinitionConfig: function(defintionId) {
      return this.DEFINITION_CONFIG[defintionId];
  },

  getUnitConversions: function(type, unit) {
      return this.UNIT_CONVERSIONS[type] && this.UNIT_CONVERSIONS[type][unit] ? this.UNIT_CONVERSIONS[type][unit] : null;
  },

  updateThreshold: function(thresholdInput, result) {
      var threshold;
      if (thresholdInput.critical && result.value >= thresholdInput.critical) {
          threshold = {
              critical: true,
              message: gs.getMessage("Critical: {0}% threshold exceeded", thresholdInput.critical)
          };

      } else if (thresholdInput.warning && result.value >= thresholdInput.warning) {
          threshold = {
              warning: true,
              message: gs.getMessage("Warning: {0}% threshold exceeded", thresholdInput.warning)
          };
      }
      return threshold;
  },

  updateThresholdForTabularUI: function(thresholdInput, field, value) {
      var threshold = {
          critical: false,
          columnName: field
      };
      if (thresholdInput.critical && value >= thresholdInput.critical) {
          threshold.critical = true;
      }
      return threshold;
  },

  isAnyProviderIntegrated: function() {
      var routeExts = new GlideScriptedExtensionPoint().getExtensions("sn_sow.SOWInvestigationRouteUtil");
      for (var i = 0; i < routeExts.length; i++) {
          if (routeExts[i].isProviderIntegrated()) return true;
      }
      return false;
  },

  getUser: function(userId) {
      var gr = new GlideRecord("sys_user");
      if (gr.get(userId)) {
          return gr;
      }
  },

  getLoggedInUserTimeFormat: function() {
      if (this.timeformat) {
          return this.timeformat;
      }
      var userGr = this.getUser(gs.getUserID());
      var defaultTimeFormat = "HH:mm:ss";
      if (userGr) {
          var timeFormat = userGr.getValue("time_format") || gs.getProperty('glide.sys.time_format', defaultTimeFormat);
          this.timeformat = timeFormat.replace(/([:-]ss)/gi, "");
          return this.timeformat;
      }
      return defaultTimeFormat;
  },

  getSystemOverviewAttributes: function() {
      return this.CI_FIELD_NAMES;
  },

  type: 'SOWInvestigateConfigSNC'
};

Sys ID

4168b07453a301103eacddeeff7b1262

Offical Documentation

Official Docs: