Name

sn_itom_pattern.EnrichMSSQLcontainer

Description

This script picks information from the container environment variable tables and follows relations to the container image repository entry in order to populate the edition and version fields of MS-SQL server

Script

var EnrichMSSQLcontainer = Class.create();
EnrichMSSQLcontainer.prototype = {
  initialize: function() {
  	this.logger = new Logger('EnrichMSSQLcontainer');
  },
  
  process: function(containerSysId) {
  	this.logger.debug(['Enriching container ', containerSysId]);
  	var attrs = {};
  	var containerEnvGr = new GlideRecord('cmdb_container_environment_variables');
  	if (containerEnvGr.isValid()) {
  		containerEnvGr.addQuery('key','MSSQL_PID');
  		containerEnvGr.addQuery('configuration_item', containerSysId);
  		containerEnvGr.query();
  		if (containerEnvGr.next())
  			attrs['edition'] = containerEnvGr.value + '';
  	}
  	
  	// Follow relation to container image
  	var relGr = new GlideRecord('cmdb_rel_ci');
  	relGr.addQuery('child',containerSysId);
  	relGr.addQuery('type','1bb40e370a0a0b323d85a1ce84f8feae'); // Instantiates::Instantiated by
  	relGr.query();
  	if (relGr.next()) {
  		var imageGr = new GlideRecord('cmdb_ci_oslv_image');
  		var imageId = relGr.parent + '';
  		if (!imageGr.get(imageId))
  			return attrs;
  		// From the image we need to follow the relation to cmdb_ci_repository_entry
  		relGr = new GlideRecord('cmdb_rel_ci');
  		relGr.addQuery('parent',imageId);
  		relGr.addQuery('type','72e003db0b032200639be0d425673aa1'); // Provisioned From::Provisioned
  		relGr.query();
  		if (relGr.next()) {
  			var imageTag = relGr.child.name;
  			// Now split by dash. Tag examples
  			// 2019-CU18-ubuntu-20.04
  			// 2017-CU31-ubuntu-18.04
  			// 2022-latest
  			// 2019-latest
  			var imageTagParts = imageTag.split('-');
  			attrs['version'] = imageTagParts[0];
  		}
  	}
  	return attrs;
  },


  type: 'EnrichMSSQLcontainer'
};

Sys ID

ea70657ca1a75510f8775b4b0fc68dae

Offical Documentation

Official Docs: