Name

sn_agent.CheckDefinitionTestBuilder

Description

Build Test Check Requests From Check Definitions.

Script

var CheckDefinitionTestBuilder = Class.create();
CheckDefinitionTestBuilder.prototype = Object.extendsObject(AbstractTestCheckBuilder, {
  _build: function() {
      var retJson = {
          test_result_id: null,
          error: null
      };
      var checkDefJson = this.getCheckGr(this.CHECK_DEFS);
      if (!gs.nil(checkDefJson.error)) {
          retJson.error = checkDefJson.error;
          return retJson;
      }
      if (checkDefJson.checkGr.getValue("background") == "1") {
          retJson.error = this.CHECK_BACKGROUND_ERR;
          return retJson;
      }
      var ciGroupJson = this.validateCiAndGroup(checkDefJson.checkGr);
      if (!gs.nil(ciGroupJson.error)) {
          retJson.error = ciGroupJson.error;
          return retJson;
      }
      var err = this.validateCreds(true, null);
      if (!gs.nil(err)) {
          retJson.error = err;
          return retJson;
      }
      retJson.test_result_id = this.monSync.internalAddTestResults(this.checkId, "true", this.ciId, ciGroupJson.table_name, null, this.credId, this.credAliasId, checkDefJson.checkGr.getValue("command"), null, "");
      if (gs.nil(retJson.test_result_id)) {
          retJson.error = this.ERR;
          retJson.test_result_id = null;
          return retJson;
      }
      if (retJson.test_result_id == this.monSync.NO_AGENT) {
          retJson.error = this.CI_NO_AGENT_ERR;
          retJson.test_result_id = null;
      }
      return retJson;
  },

  validateCiAndGroup: function(checkDefGr) {
      var retJson = {
          table_name: null,
          error: null
      };
      var checkTypeCiTable = this.CMDB_CI_COMPUTERS;
      var checkGroupGr = new GlideRecord(this.CHECK_GROUPS);
      if (checkGroupGr.get(checkDefGr.getValue("check_group"))) {
          var checkGroupCiType = checkGroupGr.getValue("ci_type");
          if (!gs.nil(checkGroupCiType))
              checkTypeCiTable = checkGroupCiType;
      }
      var ciGr = new GlideRecord(checkTypeCiTable);
      if (!ciGr.get(this.ciId)) {
          retJson.error = this.CI_NOT_FOUND_ERR;
          return retJson;
      }
      if (!(new AgentNowHandler().hasAgent(this.ciId))) {
          retJson.error = this.CI_NO_AGENT_ERR;
          return retJson;
      }
      retJson.table_name = checkTypeCiTable;
      return retJson;
  },

  CI_NOT_FOUND_ERR: "given ci sys_id is nil, non existent or not from the class defined by the check group which the check definition belongs to",

  CHECK_DEFS: "sn_agent_check_def",
  CMDB_CI_COMPUTERS: "cmdb_ci_computer",
  CHECK_GROUPS: "sn_agent_check_group",

  initialize: function() {},

  type: 'CheckDefinitionTestBuilder'
});

Sys ID

cc0dcc855374301062d1ddeeff7b12b0

Offical Documentation

Official Docs: