5 Replies Latest reply on Mar 20, 2019 1:38 PM by Andrew Waters

    'default' key of table is not workign it seems

    Nirmal Sharma
      Share:|

      Hi Experts,

       

       

      I am writing a pattern to map the host with its environment based on some rules. Rules are mentioned in the regex list which is looked in the table for its value. However I have noticed that it never populated the value of default key defined in the table. Can someone please help me with this.

       

      Here is the pattern:

      tpl 1.8 module HostToEnvironment;

       

       

      metadata

          tree_path := 'ETRADE Infrastructure', 'Environment';

      end metadata;

       

       

      table Environment_Mapping 1.0

       

       

      "^iadc1" -> ["CAT"];

      "^iadd1" -> ["Development"];

      "^iadu1" -> ["UAT"];

      "^iads1" -> ["SIT"];

      "^iad1" -> ["DR/BCP"];

      "^atl1" -> ["PRD"];

      "^iadp1|atlp1" -> ["Winprod Domain Systems"];

      "^test" -> ["Test"];

      "^dit"  -> ["DIT"];

      "^(?:dvl|dev)"  -> ["Development"];

      "^sit"  -> ["SIT"];

      "^uat"  -> ["UAT"];         

      "^(plt|pplt)"  -> ["PLT"];

      "^(bld|bnr)"  -> ["Build Release"];

      "^dr"  -> ["DR"];

      "^prd|m[35]$" -> ["PRD"];

      default -> "nirmal";

      end table;

       

       

      pattern HostEnvironment 1.0

          '''Pattern to determine and record environment of a Linux/Unix host.'''

       

       

      overview

      tags Extension, Environment;

      end overview;

       

      triggers

      on node := Host created, confirmed;

      end triggers;

       

       

      body               

       

      //Extract only the hostname in case of FQDN

      if (node.name matches regex ".com$") then

      host_name := text.split(node.name,".")[0];

      else

      host_name := node.name;

      end if;

       

      if node.os_class = "UNIX" then

      reg_list := ["^test","^dit","^(?:dvl|dev)","^sit","^uat","^(plt|pplt)","^(bld|bnr)","^dr","^prd|m[35]$"];

      for r in reg_list do

      if host_name matches r then

      node.Environment := Environment_Mapping[r];

      model.addDisplayAttribute(node, 'Environment');

      end if;

      end for;

       

      //Now will determin the environment based on the running instance and will populate or append if needed.

      if node.Environment then

      env_list := node.Environment;

                                      log.debug("value of host's environment is %node.Environment%");

      else

      env_list := [];

      end if;

       

      si := search(in node traverse Host:HostedSoftware:RunningSoftware:SoftwareInstance where type='INSTANCE');

       

      if si then

      for si_instance in si do

      log.debug(">>>>Debug info: Instance name is %si_instance.name%");

      env := text.upper(text.split(si_instance.name,":")[0]);

      log.debug("value of Env is => %env%");

      if env in env_list then

      break;

      elif env matches 'adm|ADM' then

      continue;

      else

      list.append(env_list,env);

      log.debug("value of env_list is => %env_list%");

      //node.Environment := env_list;

      //model.addDisplayAttribute(node, 'Environment');

      end if;

      end for;

      env_st := text.join(env_list,",");

      node.Environment := env_st;

      model.addDisplayAttribute(node, 'Environment');

       

       

      end if;

      elif node.os_class = "Windows" then

      reg_list := ["^iadc1","^iadd1","^iadu1","^iads1","^iad1","^atl1","^iadp1|atlp1"];

      for r in reg_list do

      if host_name matches r then

      node.Environment := Environment_Mapping[r];

      model.addDisplayAttribute(node, 'Environment');

      end if;

      end for;

      elif node.os_class = "Other" then

      node.Environment := "Others";

      model.addDisplayAttribute(node, 'Environment');

      end if;

      end body;

      end pattern;