Examples for adding tags by using custom tagging rules


This topic provides examples for adding, deleting, or overwriting tags to the required entities by creating custom tagging rules. The following examples show different ways of creating a custom tagging rule by using the required Rule Types. 


Rule type: Copy the value of a configuration metric

You can create a simple tagging rule to apply tags to the entities. When you create a custom tagging rule by using the Copy the value of a configuration metric option, you can quickly filter the entities that belong to an operating system family. In this example, OS Family is the tag type.

  1. On the Add tagging rule page, enter the following details.
    • Name: Type the required name for the tagging rule.
    • Description: Type the required description for the tagging rule.
    • Rule status: Select Active.
    • Rule type: Select Copy the value of a configuration metric.
    • Configuration Metric: Select [OS_FAMILY] Operating System Family.
    • Tag Type: Select OS Family.

      tagging rule_conf metric.png
  2. Click Save.
    The tagging rule for filtering entities that belong to an operating system family is created. 

After the Tagging Rule Manager task (System tasks) is run, tags are added to the entities that match the tagging rule condition. The following image shows a sample system with an OS tag added to it after the task is run.

tagging rule_conf sample.png

Rule type: Use a regular expression based on a configuration metric

You can create a tagging rule to apply a tag to the entities that have used a configuration metric with the matching regular expression. This can be performed by creating a custom tagging rule by using the Use a regular expression based on a configuration metric option. In this example, we have used Clustername as the tag type for adding tags to the systems that have BMC-CLM value as the pattern for the CLUSTER_NAME configuration metric. For details on creating a custom metric, see Viewing-datasets-and-metrics-by-dataset-and-ETL-module.

  1. In the Adding tagging rule page, enter the following details:
    • Name: Enter the required name for the new tagging rule.
    • Description: Enter the required description for the new tagging rule type.
    • Rule status: Select Active.
    • Rule type: Select Use a regular expression based on a configuration metric.
    • Configuration Metric: Select [CLUSTER_NAME] Cluster Name.
    • Regexp: Enter \w{3}- CLM.
    • Tag: Enter CLM.
    • Tag Type: Select Clustername.

  2. Click Save.
    The tagging rule for filtering entities that use a pattern for the CLUSTER_NAME configuration metric is created.

After the Tagging Rule Manager task (System tasks) is run, tags are added to systems that match the tagging rule condition. The following image shows a sample system with a CLM tag added to it after the task is run.


Rule type: Use a regular expression based on the name of a system or business driver

You can create a tagging rule to apply tags to the systems that use a naming convention. This can be performed by creating a custom tagging rule by using the Use a regular expression based on the name of a system or business driver option. In this example, we have used Generic as the tag type for the systems that use the following naming convention vl-bmc-loc-sys.

  1. On the Adding tagging rule page, enter the following details.
    • Name: Enter the required name for the new tagging rule.
    • Description: Enter the required description for the new tagging rule type.
    • Rule status: Select Active.
    • Rule type: Select Use a regular expression based on the name of a system or business driver.
    • Apply to: Select System.
    • Regexp: Enter vl-\w{3}-\w{3}-.*

    • Tag: Enter Regsys.
    • Tag Type: Select Generic.
  1. Click Save.
    The tagging rule to apply tags to the systems that use a naming convention is created.

 After the Tagging Rule Manager task (System tasks) is run, tags are added to the systems that match the tagging rule condition. 


For rule types that use the custom scripts

The custom script is written in Javascript. The following variables are provided:

  • name - the system or business driver name
  • enttypeid - entity type as number
  • enttypenm - entity type as string
  • resname - the values of the selected configuration metrics (For example, CPU_NUM).

Tags need to be placed in the out variable.

Rule type: Use a custom script based on a configuration metric

Example 1: You can create a tagging rule to apply a tag to the systems that use the Timezone configuration metric. This can be performed by creating a custom tagging rule by using the Use a custom script based on a configuration metric option. In this example, we have used Timezone as the tag type that allows multiple values for the systems that use the Timezone configuration metric to identify the continent and country of the system from the timezone. For details on creating a custom metric, see Viewing-datasets-and-metrics-by-dataset-and-ETL-module.

  1. On the Adding tagging rule page, enter the following details.
    • Name: Enter the required name for the new tagging rule.
    • Description: Enter the required description for the new tagging rule type.
    • Rule status: Select Active.
    • Rule type: Select Use a custom script based on a configuration metric.
    • Configuration Metric: Select [TIMEZONE] Timezone for the System.
    • Custom script: Enter the following code:

      var values = TIMEZONE.split ("/");
      for (var i=0; i<values.length; i++)
      {
      out.add(values[i])
      }
    • Tag Type: Select Timezone (allows multiple values).
  2. Click Save.
    The tagging rule to apply tags to the systems that use a naming convention is created.

 After the Tagging Rule Manager task (System tasks) is run, tags are added to the systems that match the tagging rule condition. 

Example 2: You can create a tagging rule to overwrite a tag (delete and set another tag) by using the Use a custom script based on a configuration metric rule type. In this example, we have used cap_include as the tag type to rewrite the existing tags with the value in the custom metric.

  1. On the Adding tagging rule page, enter the following details.
    • Name: Enter the required name for the new tagging rule.
    • Description: Enter the required description for the new tagging rule type.
    • Rule status: Select Active.
    • Rule type: Select Use a custom script based on a configuration metric.
    • Configuration Metric: Select [CAP_INCLUDE_C] Cap Include.
    • Custom script: Enter the following code:

      out.setRewriteTags(true)
      if (!CAP_INCLUDE_C) {return;} 
      else
      out.add(CAP_INCLUDE_C);
    • Tag Type: Select cap_include.
  2. Click Save.
    The tagging rule to overwrite tags to the matching entities is created.

 After the Tagging Rule Manager task (System tasks) is run, existing tags are deleted and new tags are added to the systems that match the tagging rule condition. 

Rule type: Use a custom script based on the name of a system or business driver

You can create a tagging rule to apply tags to the Xen or VMware systems by using the Use a custom script based on the name of a system or business driveoption. In this example, we have used Virtualization Technology as the tag type to add tags to the Xen or VMware systems.

  1. On the Adding tagging rule page, enter the following details:
    • Name: Enter the required name for the new tagging rule.
    • Description: Enter the required description for the new tagging rule type.
    • Rule status: Select Active.
    • Rule type: Select Use a custom script based on the name of a system or business driver.
    • Apply to: Select System.
    • Custom script: Enter the following code:

      if (!enttypenm) {return;} else if (enttypenm.match(/:vmw/)) { out.add('VMware') } else if (enttypenm.match(/:xen/)) { out.add('Xen') }

    • Tag Type: Select Virtualization Technology.
  2. Click Save.
    The tagging rule to apply tags to the systems that use a naming convention is created.

After the Tagging Rule Manager task (System tasks) is run, tags are added to the systems that match the tagging rule condition. 

 

Important

You can delete tags by providing the out.setRewriteTags(true); return; custom script in Use a custom script based on a configuration metric or Use a custom script based on the name of a system or business driver rule type and selecting the tag type for which you want to delete the tags. 



 

Tip: For faster searching, add an asterisk to the end of your partial query. Example: cert*